| 92 | } // namespace |
| 93 | |
| 94 | nvinfer1::ICudaEngine* LazilyDeserializedEngine::get() |
| 95 | { |
| 96 | SMP_RETVAL_IF_FALSE( |
| 97 | !mIsSafe, "Safe mode is enabled, but trying to get standard engine!", nullptr, sample::gLogError); |
| 98 | |
| 99 | if (mEngine == nullptr) |
| 100 | { |
| 101 | SMP_RETVAL_IF_FALSE( |
| 102 | !mEngineBlob.empty(), "Engine blob is empty. Nothing to deserialize!", nullptr, sample::gLogError); |
| 103 | |
| 104 | using time_point = std::chrono::time_point<std::chrono::high_resolution_clock>; |
| 105 | using duration = std::chrono::duration<float>; |
| 106 | time_point const deserializeStartTime{std::chrono::high_resolution_clock::now()}; |
| 107 | |
| 108 | if (mLeanDLLPath.empty()) |
| 109 | { |
| 110 | mRuntime.reset(createRuntime()); |
| 111 | } |
| 112 | else |
| 113 | { |
| 114 | mParentRuntime.reset(createRuntime()); |
| 115 | ASSERT(mParentRuntime.get() != nullptr); |
| 116 | |
| 117 | mRuntime.reset(mParentRuntime->loadRuntime(mLeanDLLPath.c_str())); |
| 118 | } |
| 119 | ASSERT(mRuntime.get() != nullptr); |
| 120 | |
| 121 | if (mVersionCompatible) |
| 122 | { |
| 123 | // Application needs to opt into allowing deserialization of engines with embedded lean runtime. |
| 124 | mRuntime->setEngineHostCodeAllowed(true); |
| 125 | } |
| 126 | |
| 127 | if (!mTempdir.empty()) |
| 128 | { |
| 129 | mRuntime->setTemporaryDirectory(mTempdir.c_str()); |
| 130 | } |
| 131 | |
| 132 | mRuntime->setTempfileControlFlags(mTempfileControls); |
| 133 | |
| 134 | SMP_RETVAL_IF_FALSE(mRuntime != nullptr, "runtime creation failed", nullptr, sample::gLogError); |
| 135 | if (mDLACore != -1) |
| 136 | { |
| 137 | mRuntime->setDLACore(mDLACore); |
| 138 | } |
| 139 | mRuntime->setErrorRecorder(&gRecorder); |
| 140 | for (auto const& pluginPath : mDynamicPlugins) |
| 141 | { |
| 142 | mRuntime->getPluginRegistry().loadLibrary(pluginPath.c_str()); |
| 143 | } |
| 144 | mEngine.reset(mRuntime->deserializeCudaEngine(mEngineBlob.data(), mEngineBlob.size())); |
| 145 | SMP_RETVAL_IF_FALSE(mEngine != nullptr, "Engine deserialization failed", nullptr, sample::gLogError); |
| 146 | |
| 147 | time_point const deserializeEndTime{std::chrono::high_resolution_clock::now()}; |
| 148 | sample::gLogInfo << "Engine deserialized in " |
| 149 | << duration(deserializeEndTime - deserializeStartTime).count() << " sec." << std::endl; |
| 150 | } |
| 151 |
no test coverage detected