The NvBufsurface is created with NVBUF_MEM_HANDLE. As I know, it can’t be mapped to cuda with the API “NvBufSurfaceMapCudaBuffer” directly, therefore I tried to import the DMA-FD as external memory. The demo code is attached.
In the runtime, an error occurs in the execution of “cudaImportExternalMemory”. the error code is 999, which means unkown internal error.
If such an implementation doesn’t work, how to map the flat data to cuda instead of “NVBUF_MEM_SURFACE_ARRAY”, which requires the definiation of width and height.
fd_cuda.txt (2.4 KB)
Hi,
Please refer to cuda_postprocess() in the sample:
/usr/src/jetson_multimedia_api/samples/12_v4l2_camera_cuda
You can access the buffer through CUDA by following the function calls. Please take a look and give it a try.
Thank you for your reply!
I have implement the eglimage mapping as the sample done for image data, but would like to map the flat data(such as lidar) to cuda.
I changed the set of APIs, from “cudaImportExternalMemory” to “cuImportExternalMemory”, from “cudaExternalMemoryGetMappedBuffer” to “cuExternalMemoryGetMappedBuffer”, in my demo code, it works. I get the expected value in dev address.
What’s the difference between these two sets of APIs?
The cuda mapping works, but there is a defect during the surface destroy:
NvBufSurfaceUnMapCudaBufferImpl: Wrong memType(5)
My destruct process looks like:
cuDestroyExternalMemory(ext_mem_);
cuMemFree(devaddr);
NvBufSurfaceUnMap(surface_, 0, -1);
NvBufSurfaceDestroy(surface_);
What else should be done to eliminate such a defect?
Hi,
We don’t see the prints when running 12_v4l2_camera_cuda sample. Do you follow function calls in the sample?
Hi Danell,
I don’t use the function calls in the sample, the cuda APIs for dma-buf importing are used instead. I have uploaded my implementation in file named fd_cuda.txt again, have you seen it?
I have no idea how to avoid this, you can compile the source code in fd_cuda.txt and run it, the prints will appear.
fd_cuda.txt (3.4 KB)
Hi,
Please follow function calls in the sample. Need to map NvBufSurface to EGLImage first and then acquire CUDA pointer.