From e1e78128914b60804a2abab071a04422c9bbfee1 Mon Sep 17 00:00:00 2001 From: Naren Dasan Date: Mon, 2 Aug 2021 15:49:36 -0700 Subject: [PATCH] fix(trtorchc): Allow for workspaces larger than 2G and better debugging Signed-off-by: Naren Dasan Signed-off-by: Naren Dasan --- cpp/trtorchc/main.cpp | 52 +++++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/cpp/trtorchc/main.cpp b/cpp/trtorchc/main.cpp index f5412eb969..203ea234d3 100644 --- a/cpp/trtorchc/main.cpp +++ b/cpp/trtorchc/main.cpp @@ -52,7 +52,7 @@ trtorch::CompileSpec::TensorFormat parseTensorFormat(std::string str) { } else { trtorch::logging::log( trtorch::logging::Level::kERROR, - "Invalid tensor format, options are [ linear | nchw | chw | contiguous | nhwc | hwc | channels_last ]"); + "Invalid tensor format, options are [ linear | nchw | chw | contiguous | nhwc | hwc | channels_last ], found: " + str); return trtorch::CompileSpec::TensorFormat::kUnknown; } } @@ -73,7 +73,7 @@ trtorch::CompileSpec::DataType parseDataType(std::string dtype_str) { } else { trtorch::logging::log( trtorch::logging::Level::kERROR, - "Invalid precision, options are [ float | float32 | f32 | half | float16 | f16 | char | int8 | i8 | int | int32 | i32 | bool | b]"); + "Invalid precision, options are [ float | float32 | f32 | half | float16 | f16 | char | int8 | i8 | int | int32 | i32 | bool | b], found: " + dtype_str); return trtorch::CompileSpec::DataType::kUnknown; } } @@ -221,8 +221,8 @@ int main(int argc, char** argv) { "type", "The type of device the engine should be built for [ gpu | dla ] (default: gpu)", {'d', "device-type"}); - args::ValueFlag gpu_id(parser, "gpu_id", "GPU id if running on multi-GPU platform (defaults to 0)", {"gpu-id"}); - args::ValueFlag dla_core( + args::ValueFlag gpu_id(parser, "gpu_id", "GPU id if running on multi-GPU platform (defaults to 0)", {"gpu-id"}); + args::ValueFlag dla_core( parser, "dla_core", "DLACore id if running on available DLA (defaults to 0)", {"dla-core"}); args::ValueFlag engine_capability( @@ -243,13 +243,13 @@ int main(int argc, char** argv) { "Whether to treat input file as a serialized TensorRT engine and embed it into a TorchScript module (device spec must be provided)", {"embed-engine"}); - args::ValueFlag num_min_timing_iters( + args::ValueFlag num_min_timing_iters( parser, "num_iters", "Number of minimization timing iterations used to select kernels", {"num-min-timing-iter"}); - args::ValueFlag num_avg_timing_iters( + args::ValueFlag num_avg_timing_iters( parser, "num_iters", "Number of averaging timing iterations used to select kernels", {"num-avg-timing-iters"}); - args::ValueFlag workspace_size( + args::ValueFlag workspace_size( parser, "workspace_size", "Maximum size of workspace given to TensorRT", {"workspace-size"}); - args::ValueFlag max_batch_size( + args::ValueFlag max_batch_size( parser, "max_batch_size", "Maximum batch size (must be >= 1 to be set, 0 means not set)", {"max-batch-size"}); args::ValueFlag threshold( parser, @@ -276,8 +276,8 @@ int main(int argc, char** argv) { std::cout << parser; return 0; } catch (args::ParseError e) { - std::cerr << e.what() << std::endl; - std::cerr << parser; + trtorch::logging::log(trtorch::logging::Level::kERROR, e.what()); + std::cerr << std::endl << parser; return 1; } @@ -309,13 +309,13 @@ int main(int argc, char** argv) { auto parsed_dtype = parseDataType(dtype); if (parsed_dtype == trtorch::CompileSpec::DataType::kUnknown) { trtorch::logging::log(trtorch::logging::Level::kERROR, "Invalid datatype for input specification " + spec); - std::cerr << parser; + std::cerr << std::endl << parser; exit(1); } auto parsed_format = parseTensorFormat(format); if (parsed_format == trtorch::CompileSpec::TensorFormat::kUnknown) { trtorch::logging::log(trtorch::logging::Level::kERROR, "Invalid format for input specification " + spec); - std::cerr << parser; + std::cerr << std::endl << parser; exit(1); } if (shapes.rfind("(", 0) == 0) { @@ -326,7 +326,7 @@ int main(int argc, char** argv) { trtorch::CompileSpec::Input(dyn_shapes[0], dyn_shapes[1], dyn_shapes[2], parsed_dtype, parsed_format)); } else { trtorch::logging::log(trtorch::logging::Level::kERROR, spec_err_str); - std::cerr << parser; + std::cerr << std::endl << parser; exit(1); } // THERE IS NO SPEC FOR FORMAT @@ -337,7 +337,7 @@ int main(int argc, char** argv) { auto parsed_dtype = parseDataType(dtype); if (parsed_dtype == trtorch::CompileSpec::DataType::kUnknown) { trtorch::logging::log(trtorch::logging::Level::kERROR, "Invalid datatype for input specification " + spec); - std::cerr << parser; + std::cerr << std::endl << parser; exit(1); } if (shapes.rfind("(", 0) == 0) { @@ -347,7 +347,7 @@ int main(int argc, char** argv) { ranges.push_back(trtorch::CompileSpec::Input(dyn_shapes[0], dyn_shapes[1], dyn_shapes[2], parsed_dtype)); } else { trtorch::logging::log(trtorch::logging::Level::kERROR, spec_err_str); - std::cerr << parser; + std::cerr << std::endl << parser; exit(1); } } @@ -359,7 +359,7 @@ int main(int argc, char** argv) { auto parsed_format = parseTensorFormat(format); if (parsed_format == trtorch::CompileSpec::TensorFormat::kUnknown) { trtorch::logging::log(trtorch::logging::Level::kERROR, "Invalid format for input specification " + spec); - std::cerr << parser; + std::cerr << std::endl << parser; exit(1); } if (shapes.rfind("(", 0) == 0) { @@ -369,7 +369,7 @@ int main(int argc, char** argv) { ranges.push_back(trtorch::CompileSpec::Input(dyn_shapes[0], dyn_shapes[1], dyn_shapes[2], parsed_format)); } else { trtorch::logging::log(trtorch::logging::Level::kERROR, spec_err_str); - std::cerr << parser; + std::cerr << std::endl << parser; exit(1); } // JUST SHAPE USE DEFAULT DTYPE @@ -381,7 +381,7 @@ int main(int argc, char** argv) { ranges.push_back(trtorch::CompileSpec::Input(dyn_shapes[0], dyn_shapes[1], dyn_shapes[2])); } else { trtorch::logging::log(trtorch::logging::Level::kERROR, spec_err_str); - std::cerr << parser; + std::cerr << std::endl << parser; exit(1); } } @@ -430,14 +430,15 @@ int main(int argc, char** argv) { trtorch::logging::log( trtorch::logging::Level::kERROR, "If targeting INT8 default operating precision with trtorchc, a calibration cache file must be provided"); - std::cerr << parser; return 1; } } else { + std::stringstream ss; + ss << "Invalid precision, options are [ float | float32 | f32 | half | float16 | f16 | char | int8 | i8 ], found: "; + ss << dtype; trtorch::logging::log( - trtorch::logging::Level::kERROR, - "Invalid precision, options are [ float | float32 | f32 | half | float16 | f16 | char | int8 | i8 ]"); - std::cerr << parser; + trtorch::logging::Level::kERROR, ss.str()); + std::cerr << std::endl << parser; return 1; } } @@ -460,8 +461,8 @@ int main(int argc, char** argv) { compile_settings.device.dla_core = args::get(dla_core); } } else { - trtorch::logging::log(trtorch::logging::Level::kERROR, "Invalid device type, options are [ gpu | dla ]"); - std::cerr << parser; + trtorch::logging::log(trtorch::logging::Level::kERROR, "Invalid device type, options are [ gpu | dla ] found: " + device); + std::cerr << std::endl << parser; return 1; } } @@ -479,7 +480,7 @@ int main(int argc, char** argv) { } else { trtorch::logging::log( trtorch::logging::Level::kERROR, "Invalid engine capability, options are [ default | safe_gpu | safe_dla ]"); - std::cerr << parser; + std::cerr << std::endl << parser; return 1; } } @@ -517,7 +518,6 @@ int main(int argc, char** argv) { mod = torch::jit::load(real_input_path); } catch (const c10::Error& e) { trtorch::logging::log(trtorch::logging::Level::kERROR, "Error loading the model (path may be incorrect)"); - std::cerr << parser; return 1; }