Skip to content

Commit a7d2b5e

Browse files
authored
Merge pull request #480 from NVIDIA/catch_failed_build
fix(//core/conversion/conversionctx): Guard final engine building
2 parents cbe1866 + dfa9ae8 commit a7d2b5e

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

core/conversion/conversionctx/ConversionCtx.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,15 @@ std::ostream& operator<<(std::ostream& os, const BuilderSettings& s) {
2323
<< "\n Max Workspace Size: " << s.workspace_size;
2424

2525
if (s.max_batch_size != 0) {
26-
os << "\n Max Batch Size: " << s.max_batch_size;
26+
os << "\n Max Batch Size: " << s.max_batch_size;
2727
} else {
28-
os << "\n Max Batch Size: Not set";
28+
os << "\n Max Batch Size: Not set";
2929
}
3030

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

147146
std::string ConversionCtx::SerializeEngine() {
148147
auto engine = builder->buildEngineWithConfig(*net, *cfg);
148+
if (!engine) {
149+
TRTORCH_THROW_ERROR("Building TensorRT engine failed");
150+
}
149151
auto serialized_engine = engine->serialize();
150152
engine->destroy();
151153
auto engine_str = std::string((const char*)serialized_engine->data(), serialized_engine->size());

core/util/Exception.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Error::Error(const std::string& new_msg, const void* caller) : msg_stack_{new_ms
1111
}
1212

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

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

0 commit comments

Comments
 (0)