Skip to content

Commit

Permalink
fix(trtorchc): Allow for workspaces larger than 2G and better debugging
Browse files Browse the repository at this point in the history
Signed-off-by: Naren Dasan <naren@narendasan.com>
Signed-off-by: Naren Dasan <narens@nvidia.com>
  • Loading branch information
narendasan committed Aug 2, 2021
1 parent 24de61b commit e1e7812
Showing 1 changed file with 26 additions and 26 deletions.
52 changes: 26 additions & 26 deletions cpp/trtorchc/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand All @@ -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;
}
}
Expand Down Expand Up @@ -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<int> gpu_id(parser, "gpu_id", "GPU id if running on multi-GPU platform (defaults to 0)", {"gpu-id"});
args::ValueFlag<int> dla_core(
args::ValueFlag<uint64_t> gpu_id(parser, "gpu_id", "GPU id if running on multi-GPU platform (defaults to 0)", {"gpu-id"});
args::ValueFlag<uint64_t> dla_core(
parser, "dla_core", "DLACore id if running on available DLA (defaults to 0)", {"dla-core"});

args::ValueFlag<std::string> engine_capability(
Expand All @@ -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<int> num_min_timing_iters(
args::ValueFlag<uint64_t> num_min_timing_iters(
parser, "num_iters", "Number of minimization timing iterations used to select kernels", {"num-min-timing-iter"});
args::ValueFlag<int> num_avg_timing_iters(
args::ValueFlag<uint64_t> num_avg_timing_iters(
parser, "num_iters", "Number of averaging timing iterations used to select kernels", {"num-avg-timing-iters"});
args::ValueFlag<int> workspace_size(
args::ValueFlag<uint64_t> workspace_size(
parser, "workspace_size", "Maximum size of workspace given to TensorRT", {"workspace-size"});
args::ValueFlag<int> max_batch_size(
args::ValueFlag<uint64_t> 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<double> threshold(
parser,
Expand All @@ -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;
}

Expand Down Expand Up @@ -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) {
Expand All @@ -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
Expand All @@ -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) {
Expand All @@ -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);
}
}
Expand All @@ -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) {
Expand All @@ -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
Expand All @@ -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);
}
}
Expand Down Expand Up @@ -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;
}
}
Expand All @@ -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;
}
}
Expand All @@ -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;
}
}
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit e1e7812

Please sign in to comment.