Returns true if deserialization is slower than expected or fails.
| 1179 | |
| 1180 | //! Returns true if deserialization is slower than expected or fails. |
| 1181 | bool timeDeserialize(InferenceEnvironment& iEnv, SystemOptions const& sys) |
| 1182 | { |
| 1183 | constexpr int32_t kNB_ITERS{20}; |
| 1184 | std::unique_ptr<IRuntime> rt{createRuntime()}; |
| 1185 | std::unique_ptr<ICudaEngine> engine; |
| 1186 | |
| 1187 | std::unique_ptr<safe::IRuntime> safeRT{sample::createSafeInferRuntime(sample::gLogger.getTRTLogger())}; |
| 1188 | std::unique_ptr<safe::ICudaEngine> safeEngine; |
| 1189 | |
| 1190 | if (iEnv.safe) |
| 1191 | { |
| 1192 | ASSERT(sample::hasSafeRuntime() && safeRT != nullptr); |
| 1193 | safeRT->setErrorRecorder(&gRecorder); |
| 1194 | } |
| 1195 | |
| 1196 | auto timeDeserializeFn = [&]() -> float { |
| 1197 | bool deserializeOK{false}; |
| 1198 | engine.reset(nullptr); |
| 1199 | safeEngine.reset(nullptr); |
| 1200 | auto startClock = std::chrono::high_resolution_clock::now(); |
| 1201 | if (iEnv.safe) |
| 1202 | { |
| 1203 | safeEngine.reset(safeRT->deserializeCudaEngine(iEnv.engine.getBlob().data(), iEnv.engine.getBlob().size())); |
| 1204 | deserializeOK = (safeEngine != nullptr); |
| 1205 | } |
| 1206 | else |
| 1207 | { |
| 1208 | for (auto const& pluginPath : sys.dynamicPlugins) |
| 1209 | { |
| 1210 | rt->getPluginRegistry().loadLibrary(pluginPath.c_str()); |
| 1211 | } |
| 1212 | engine.reset( |
| 1213 | rt->deserializeCudaEngine(iEnv.engine.getBlob().data(), iEnv.engine.getBlob().size(), nullptr)); |
| 1214 | deserializeOK = (engine != nullptr); |
| 1215 | } |
| 1216 | auto endClock = std::chrono::high_resolution_clock::now(); |
| 1217 | // return NAN if deserialization failed. |
| 1218 | return deserializeOK ? std::chrono::duration<float, std::milli>(endClock - startClock).count() : NAN; |
| 1219 | }; |
| 1220 | |
| 1221 | // Warmup the caches to make sure that cache thrashing isn't throwing off the results |
| 1222 | { |
| 1223 | sample::gLogInfo << "Begin deserialization warmup..." << std::endl; |
| 1224 | for (int32_t i = 0, e = 2; i < e; ++i) |
| 1225 | { |
| 1226 | timeDeserializeFn(); |
| 1227 | } |
| 1228 | } |
| 1229 | sample::gLogInfo << "Begin deserialization engine timing..." << std::endl; |
| 1230 | float const first = timeDeserializeFn(); |
| 1231 | |
| 1232 | // Check if first deserialization succeeded. |
| 1233 | if (std::isnan(first)) |
| 1234 | { |
| 1235 | sample::gLogError << "Engine deserialization failed." << std::endl; |
| 1236 | return true; |
| 1237 | } |
| 1238 |
no test coverage detected