Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solve name conflict in TensorRT engine caching #5128

Merged
merged 6 commits into from
Sep 11, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add verbose for engine deserialization and destroy old engine memory …
…if new engine is generated
  • Loading branch information
stevenlix authored Sep 10, 2020
commit 9db5bbc68dda38ca296439c2cddabf0306e5a7cf
Original file line number Diff line number Diff line change
Expand Up @@ -1034,12 +1034,16 @@ common::Status TensorrtExecutionProvider::Provider_Compile(const std::vector<onn
plan_file.read((char*)engine_buf.get(), engine_size);

auto runtime_ = trt_state->runtime;
if (trt_state->engine->get() != nullptr) {
trt_state->engine->get()->destroy();
}
trt_state->engine->reset();
*(trt_state->engine) = tensorrt_ptr::unique_pointer<nvinfer1::ICudaEngine>(
runtime_->deserializeCudaEngine(engine_buf.get(), engine_size, nullptr));
if (trt_state->engine->get() == nullptr) {
return ORT_MAKE_STATUS(ONNXRUNTIME, EP_FAIL, "TensorRT EP Failed to Build Engine.");
}
LOGS_DEFAULT(VERBOSE) << "[TensorRT EP] DeSerialized " + cached_path;
trt_engine = trt_state->engine->get();

} else {
Expand All @@ -1049,7 +1053,9 @@ common::Status TensorrtExecutionProvider::Provider_Compile(const std::vector<onn
if (*(trt_state->fp16_enable_ptr) && trt_builder->platformHasFastFp16()) {
trt_config->setFlag(nvinfer1::BuilderFlag::kFP16);
}
trt_state->context->reset();
if (trt_state->engine->get() != nullptr) {
trt_state->engine->get()->destroy();
}
trt_state->engine->reset();
*(trt_state->engine) = tensorrt_ptr::unique_pointer<nvinfer1::ICudaEngine>(
trt_builder->buildEngineWithConfig(*trt_state->network, *trt_config));
Expand All @@ -1066,6 +1072,10 @@ common::Status TensorrtExecutionProvider::Provider_Compile(const std::vector<onn
LOGS_DEFAULT(VERBOSE) << "[TensorRT EP] Serialized " + cached_path;
}
}

if (trt_state->context->get() != nullptr) {
trt_state->context->get()->destroy();
}
trt_state->context->reset();
*(trt_state->context) = tensorrt_ptr::unique_pointer<nvinfer1::IExecutionContext>(
trt_state->engine->get()->createExecutionContext());
Expand Down