Ask Your Question

How to assign cv::Mat to point to the page-locked memory (pinned memory)

asked 2017-07-21 03:07:30 -0500

arrfou gravatar image

I have a cv::Mat on the CPU that I want to pass later to a CUDA kernel but the problem I can not figure out how to allocate the data inside cv::Mat form Pagable (Default). I want to this because Pagable memory locked the multi-threading or concurrent streaming feature. what I have understod from the documenttion is one may change the DefaultAllocator of cv::Mat . Here below the snippet:

static uint8_t *d_im0;
cv::Mat input= cv::imread(imagePath,0);
cudaMemcpyAsync(d_im0, input.ptr(), sizeof(uint8_t)*size, cudaMemcpyHostToDevice,stream1));

Please any Ideas?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2017-07-24 06:41:10 -0500

arrfou gravatar image

Well, I have found that ones can modify the default allocator of cv::Mat to be page-locked memory. This can be done in OpenCV by this code line which have to be written before declaring the cv::Mat.

cv::Mat::setDefaultAllocator(cv::cuda::HostMem::getAllocator (cv::cuda::HostMem::AllocType::PAGE_LOCKED));
edit flag offensive delete link more

Question Tools



Asked: 2017-07-21 03:07:30 -0500

Seen: 1,523 times

Last updated: Jul 24 '17