Hi I want to do op profiling on a TVM model with C++ API, and followed this discussion Profiling Report C++ - #15 by tkonolige
But it seems the profile function is not working properly. What’s wrong with my code? I didn’t find any doc either. Here goes my code segment:
DLDevice dev{kDLCPU, 0};
tvm::runtime::Module mod_factory = tvm::runtime::Module::LoadFromFile("model.so");
// create the graph executor module
tvm::runtime::Module gmod = mod_factory.GetFunction("default")(dev);
tvm::runtime::PackedFunc set_input_f = gmod.GetFunction("set_input");
tvm::runtime::PackedFunc get_output_f = gmod.GetFunction("get_output");
tvm::runtime::PackedFunc get_graph_json_f = mod_factory.GetFunction("get_graph_json");
tvm::runtime::PackedFunc run_f = gmod.GetFunction("run");
...... // Preparing for the input data
std::string json = get_graph_json_f();
int64_t device_type = kDLCPU;
int64_t device_id = 0;
tvm::runtime::Module executor = (*tvm::runtime::Registry::Get("tvm.graph_executor_debug.create"))(json, mod_factory, device_type, device_id);
//Set up profiler
tvm::runtime::PackedFunc debug_run_f = executor.GetFunction("run"); //Get inference function 'run'
tvm::runtime::PackedFunc profile_f = executor.GetFunction("profile");
tvm::runtime::PackedFunc debug_get_output_f = gmod.GetFunction("debug_get_output");
tvm::Device cpu;
cpu.device_type = kDLCPU;
cpu.device_id = device_id;
std::vector<tvm::Device> devices;
devices.push_back(cpu);
tvm::runtime::profiling::Profiler prof(devices, {});
std::cout << "Start profiling\n";
prof.Start();
prof.StartCall("profile", cpu);
auto start = getCurrentTime();
// run the code
for (int i=0; i<100; ++i) {
run_f();
}
tvm::runtime::profiling::Report report = profile_f(); <<<<<<<<<<<<<<<<< This step failed
prof.StopCall();
prof.Stop();
auto end = getCurrentTime();
std::cout << (end - start)/1000/100 << "ms" << std::endl;
std::cout << prof.Report()->AsTable() << std::endl;
std::cout << report->AsTable() << std::endl;
Here is the error dumped out:
Start profiling
terminate called after throwing an instance of 'tvm::runtime::InternalError'
what(): [20:35:39] /data/tvm-0.7/include/tvm/runtime/packed_func.h:1489: Function <anonymous> expects 1 arguments, but 0 were provided.
Stack trace:
0: std::_Function_handler<void (tvm::runtime::TVMArgs, tvm::runtime::TVMRetValue*), tvm::runtime::TypedPackedFunc<tvm::runtime::profiling::Report (tvm::runtime::Array<tvm::runtime::profiling::MetricCollector, void>)>::AssignTypedLambda<tvm::runtime::GraphExecutorDebug::GetFunction(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, tvm::runtime::ObjectPtr<tvm::runtime::Object> const&)::{lambda(tvm::runtime::Array<tvm::runtime::profiling::MetricCollector, void>)#5}>(tvm::runtime::GraphExecutorDebug::GetFunction(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, tvm::runtime::ObjectPtr<tvm::runtime::Object> const&)::{lambda(tvm::runtime::Array<tvm::runtime::profiling::MetricCollector, void>)#5})::{lambda(tvm::runtime::TVMArgs const&, tvm::runtime::TVMRetValue*)#1}>::_M_invoke(std::_Any_data const&, tvm::runtime::TVMArgs&&, tvm::runtime::TVMRetValue*&&)
1: std::function<void (tvm::runtime::TVMArgs, tvm::runtime::TVMRetValue*)>::operator()(tvm::runtime::TVMArgs, tvm::runtime::TVMRetValue*) const
at /usr/include/c++/8.3.0/bits/std_function.h:687
2: tvm::runtime::TVMRetValue tvm::runtime::PackedFunc::operator()<>() const
at /data/tvm-0.7/include/tvm/runtime/packed_func.h:1369
3: DeployGraphExecutor()
at /data/tvm-0.7/tools/tvm_cross_runner.cc:138
4: main
at /data/tvm-0.7/tools/tvm_cross_runner.cc:161
5: __libc_start_main
6: 0x00000000004058e8
7: 0xffffffffffffffff
Thanks.