Skip to content

Commit

Permalink
fix(//core/conversion/conversionctx): Guard final engine building
Browse files Browse the repository at this point in the history
Fixes an issue where if final network validation fails, a segfault
occurs. Now an exception is thrown which can be handled by the user

Signed-off-by: Naren Dasan <naren@narendasan.com>
Signed-off-by: Naren Dasan <narens@nvidia.com>
  • Loading branch information
narendasan committed May 19, 2021
1 parent aecf17c commit dfa9ae8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
12 changes: 7 additions & 5 deletions core/conversion/conversionctx/ConversionCtx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,15 @@ std::ostream& operator<<(std::ostream& os, const BuilderSettings& s) {
<< "\n Max Workspace Size: " << s.workspace_size;

if (s.max_batch_size != 0) {
os << "\n Max Batch Size: " << s.max_batch_size;
os << "\n Max Batch Size: " << s.max_batch_size;
} else {
os << "\n Max Batch Size: Not set";
os << "\n Max Batch Size: Not set";
}

os << "\n Device Type: " << s.device.device_type \
<< "\n GPU ID: " << s.device.gpu_id;
if (s.device.device_type == nvinfer1::DeviceType::kDLA)
{
os << "\n DLACore: " << s.device.dla_core;
if (s.device.device_type == nvinfer1::DeviceType::kDLA) {
os << "\n DLACore: " << s.device.dla_core;
}
os << "\n Engine Capability: " << s.capability \
<< "\n Calibrator Created: " << (s.calibrator != nullptr);
Expand Down Expand Up @@ -146,6 +145,9 @@ torch::jit::IValue* ConversionCtx::AssociateValueAndIValue(const torch::jit::Val

std::string ConversionCtx::SerializeEngine() {
auto engine = builder->buildEngineWithConfig(*net, *cfg);
if (!engine) {
TRTORCH_THROW_ERROR("Building TensorRT engine failed");
}
auto serialized_engine = engine->serialize();
engine->destroy();
auto engine_str = std::string((const char*)serialized_engine->data(), serialized_engine->size());
Expand Down
2 changes: 1 addition & 1 deletion core/util/Exception.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Error::Error(const std::string& new_msg, const void* caller) : msg_stack_{new_ms
}

Error::Error(const char* file, const uint32_t line, const std::string& msg, const void* caller)
: Error(str("[enforce fail at ", file, ":", line, "] ", msg, "\n"), caller) {}
: Error(str("[Error thrown at ", file, ":", line, "] ", msg, "\n"), caller) {}

std::string Error::msg() const {
return std::accumulate(msg_stack_.begin(), msg_stack_.end(), std::string(""));
Expand Down

0 comments on commit dfa9ae8

Please sign in to comment.