| 158 | } |
| 159 | |
| 160 | nvinfer1::safe::ICudaEngine* LazilyDeserializedEngine::getSafe() |
| 161 | { |
| 162 | SMP_RETVAL_IF_FALSE( |
| 163 | mIsSafe, "Safe mode is not enabled, but trying to get safe engine!", nullptr, sample::gLogError); |
| 164 | |
| 165 | ASSERT(sample::hasSafeRuntime()); |
| 166 | if (mSafeEngine == nullptr) |
| 167 | { |
| 168 | SMP_RETVAL_IF_FALSE( |
| 169 | !mEngineBlob.empty(), "Engine blob is empty. Nothing to deserialize!", nullptr, sample::gLogError); |
| 170 | |
| 171 | SMP_RETVAL_IF_FALSE( |
| 172 | mDLACore == -1, "Safe DLA engine built with kDLA_STANDALONE should not be deserialized in TRT!", nullptr, |
| 173 | sample::gLogError); |
| 174 | |
| 175 | using time_point = std::chrono::time_point<std::chrono::high_resolution_clock>; |
| 176 | using duration = std::chrono::duration<float>; |
| 177 | time_point const deserializeStartTime{std::chrono::high_resolution_clock::now()}; |
| 178 | |
| 179 | std::unique_ptr<safe::IRuntime> safeRuntime{sample::createSafeInferRuntime(sample::gLogger.getTRTLogger())}; |
| 180 | SMP_RETVAL_IF_FALSE(safeRuntime != nullptr, "SafeRuntime creation failed", nullptr, sample::gLogError); |
| 181 | safeRuntime->setErrorRecorder(&gRecorder); |
| 182 | mSafeEngine.reset( |
| 183 | safeRuntime->deserializeCudaEngine(mEngineBlob.data(), mEngineBlob.size())); |
| 184 | SMP_RETVAL_IF_FALSE(mSafeEngine != nullptr, "SafeEngine deserialization failed", nullptr, sample::gLogError); |
| 185 | |
| 186 | time_point const deserializeEndTime{std::chrono::high_resolution_clock::now()}; |
| 187 | sample::gLogInfo << "SafeEngine deserialized in " |
| 188 | << duration(deserializeEndTime - deserializeStartTime).count() << " sec." << std::endl; |
| 189 | } |
| 190 | |
| 191 | return mSafeEngine.get(); |
| 192 | } |
| 193 | |
| 194 | void setTensorScalesFromCalibration(nvinfer1::INetworkDefinition& network, std::vector<IOFormat> const& inputFormats, |
| 195 | std::vector<IOFormat> const& outputFormats, std::string const& calibrationFile) |
no test coverage detected