I notice that we need to use this line to get a Module from seriailized model for inference:
Module mod = (*tvm::runtime::Registry::Get("tvm.graph_runtime.create"))(
sjson, mod_dylib, device_type, device_id);
auto set_input = mod.GetFunction("set_input");
This would returns a pointer, thus I wonder if I need to explicitly free it module in my code, or would tvmruntime free that for me so that I do not need to take specially care about the resources ?
If the data comes from the C API(in this case TVMArrayAlloc) then you need to free them(by calling TVMArrayFree). Note that you can also directly use the C++ API(NDArray::Empty) and pass it to the same function, in this case the array will be freed automatically
How could I copy data to NDArray ? I saw in the tvm/runtime/ndarray.h that there are CopyFrom method but only supports DLTensor or NDArray. If I read the image with opencv(which I can access its data with Mat::data as binary bytes), how could I fill the empty NDArray with the image data please ?
We can create a DLTensor inplace(which points to the array) and copy to the NDArray content. But you bring up a good point. Perhaps we should add CopyFromBytes and CopyToBytes as member functions of NDArray.
@tqchen A CopyFromBytes and CopyToBytes would be very welcome! I would also like to suggest an “NDArray::FromBytes(...)” that would create an CPU ctx NDArray and use the supplied buffer w/o copying.