Copy data from tvm::runtime::NDArray to cv::Mat or std::vector

Hi,

I follow the tutorial to deploy TVM using C++ API (https://github.com/deepinsight/insightface/wiki/Tutorial:-Deploy-Face-Recognition-Model-via-TVM) and get problem with this line:

cv::Mat test(128,1,CV_32F);
memcpy(test.data,res->data,128*4);

The program has unexpectedly finished.

Is this a bug and what is the official way to copy data from tvm::runtime::NDArray to cv::Mat or std::vector?

My environment:
NVIDIA Tx2
Ubuntu 16.04
TVM 0.5dev
opencv 3.4.3
cudnn 7.5
cuda 9

The model is mobildefacenet from insightface tutorial above and compiled with
target = tvm.target.create("cuda -model=tx2")

if res->data is on gpu, you cannot use memcpy.

The correct way is to use TVMArrayCopyToBytes, like this

TVMArrayCopyToBytes(res->data, test.data, 128 * sizeof(float));
1 Like

Thank you @masahi. Got it work as expected. Haven’t noticed the output is on GPU.

This operation is very slow on Jetson-NX. Any idea to make it faster ?