Skip to content

Commit

Permalink
fix(//cpp): Remove deprecated script namespace
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 May 7, 2020
1 parent 2c5c0d5 commit d70760f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
26 changes: 13 additions & 13 deletions cpp/benchmark/main.cpp
Expand Up @@ -37,7 +37,7 @@ void print_avg_std_dev(std::string type, std::vector<float>& runtimes, uint64_t
std::transform(runtimes.begin(), runtimes.end(), rt_diff.begin(), [avg_runtime](float x) { return x - avg_runtime; });
float rt_sq_sum = std::inner_product(rt_diff.begin(), rt_diff.end(), rt_diff.begin(), 0.0);
float rt_std_dev = std::sqrt(rt_sq_sum / runtimes.size());

std::vector<float> fps_diff(runtimes.size());
std::transform(runtimes.begin(), runtimes.end(), fps_diff.begin(), [fps, batch_size](float x) { return ((1000.f / x) * batch_size) - fps; });
float fps_sq_sum = std::inner_product(fps_diff.begin(), fps_diff.end(), fps_diff.begin(), 0.0);
Expand All @@ -62,7 +62,7 @@ std::vector<float> benchmark_module(torch::jit::script::Module& mod, std::vector
cudaDeviceSynchronize();

}

for (uint64_t i = 0; i < NUM_RUNS; i++) {
std::vector<torch::jit::IValue> inputs_ivalues;
auto in = at::rand(shape, {at::kCUDA});
Expand All @@ -71,7 +71,7 @@ std::vector<float> benchmark_module(torch::jit::script::Module& mod, std::vector
#endif
inputs_ivalues.push_back(in.clone());
cudaDeviceSynchronize();

execution_timer.start();
mod.forward(inputs_ivalues);
cudaDeviceSynchronize();
Expand All @@ -80,7 +80,7 @@ std::vector<float> benchmark_module(torch::jit::script::Module& mod, std::vector
auto time = execution_timer.milliseconds();
execution_timer.reset();
execution_runtimes.push_back(time);

c10::cuda::CUDACachingAllocator::emptyCache();
}
return execution_runtimes;
Expand All @@ -91,9 +91,9 @@ int main(int argc, const char* argv[]) {
std::cerr << "usage: benchmark <path-to-exported-script-module> <input-size>\n" << std::endl;
return -1;
}
torch::jit::script::Module mod;


torch::jit::Module mod;
try {
// Deserialize the ScriptModule from a file using torch::jit::load().
mod = torch::jit::load(argv[1]);
Expand All @@ -104,16 +104,16 @@ int main(int argc, const char* argv[]) {
}

mod.to(at::kCUDA);

#ifdef HALF
mod.to(torch::kHalf);
for (auto layer : mod.named_modules()) {
if (layer.name.find(".bn") != std::string::npos) {
layer.value.to(torch::kFloat);
}
}
#endif
#endif

std::vector<std::vector<int64_t>> dims;
for (int i = 2; i < argc; i++) {
auto arg = std::string(argv[i]);
Expand All @@ -128,7 +128,7 @@ int main(int argc, const char* argv[]) {
}

at::globalContext().setBenchmarkCuDNN(true);

#ifdef JIT
auto jit_runtimes = benchmark_module(mod, dims[0]);
print_avg_std_dev("JIT", jit_runtimes, dims[0][0]);
Expand All @@ -140,11 +140,11 @@ int main(int argc, const char* argv[]) {
#ifdef HALF
extra_info.op_precision = at::kHalf;
#endif

auto trt_mod = trtorch::CompileGraph(mod, extra_info);
auto trt_runtimes = benchmark_module(trt_mod, dims[0]);
print_avg_std_dev("JIT/TRT", trt_runtimes, dims[0][0]);
#endif

std::cout << "ok\n";
}
2 changes: 1 addition & 1 deletion cpp/ptq/main.cpp
Expand Up @@ -18,7 +18,7 @@ int main(int argc, const char* argv[]) {
return -1;
}

torch::jit::script::Module mod;
torch::jit::Module mod;
try {
/// Deserialize the ScriptModule from a file using torch::jit::load().
mod = torch::jit::load(argv[1]);
Expand Down
2 changes: 1 addition & 1 deletion cpp/trtorchexec/main.cpp
Expand Up @@ -27,7 +27,7 @@ int main(int argc, const char* argv[]) {
}


torch::jit::script::Module mod;
torch::jit::Module mod;
try {
// Deserialize the ScriptModule from a file using torch::jit::load().
mod = torch::jit::load(argv[1]);
Expand Down

0 comments on commit d70760f

Please sign in to comment.