Convert gpumat to pytorch tensor

How can i convert a gpumat to pytorch tensor? My gpumat comes from cv::cudacodec as the following code:

cv::cuda::GpuMat d_frame;
cv::Ptr<cv::cudacodec::VideoReader> d_reader = cv::cudacodec::createVideoReader(video_path);

Now I want to convert the d_frame to pytorch gpu tensor, and I have searched for a while but still don’t know how to do it properly.

I guess you might be able to use torch::from_blob to create a tensor from the raw data.