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



I follow the tutorial to deploy TVM using C++ API ( and get problem with this line:

cv::Mat test(128,1,CV_32F);

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:
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 ="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,, 128 * sizeof(float));


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