Debugging CUDA MEX in VS2017 (v2)

3 次查看(过去 30 天)
Hello,
I'm going to mirror a question asked two years because I've run into a similar issue :
I've also asked this question at NVIDIA developper forum and will include the link for cross reference:
I've run into "CUDA_ERROR_ILLEGAL_ADDRESS", and using the host side debugger identified that it occurs when I try to fetch data back from the GPU while invoking "mxGPUCreateMxArrayOnCPU()". I would like to enter debugging mode inside the kernel to follow what is happening device side but I can't use the legacy debugger via VS2017 because it does not support my graphics card, and the next-gen debugger does not support remote debugging.
Does anyone know a workaround about this without having to resort to print statements?
Thanks in advance
  1 个评论
Joss Knight
Joss Knight 2021-3-24
编辑:Joss Knight 2021-3-24
First, synchronize using cudaDeviceSynchronize(), then call cudaGetLastError() and make sure the error hasn't actually already occurred before you call mxGPUCreateMxArrayOnCPU. Hamza's suggestion of cuda-memcheck is a good idea. If everything is fine then you might want to post your kernel code here for us to debug by inspection.

请先登录,再进行评论。

采纳的回答

Hamza Butt
Hamza Butt 2021-3-23
According to NVIDIA's release notes for Nsight Compute, support for Pascal GPUs has been removed since 2020.1. Also, as you mentioned, remote debugging is not currently supported with Nsight Compute's next gen debugger. This is more suited for NVIDIA's forum, as the question is generic to debugging device-side CUDA C++, with or without MATLAB. However, I will try to help as much as I can, though this is a difficult question for someone outside NVIDIA. MATLAB does not include a debugger for GPU code, instead it relies on third party debugging tools for the CUDA infrastructure, and only NVIDIA can answer this question definitively.
Of the ideas that I can think of: Try using an older version of Nsight compute that does support your GPU, to see if it works. Maybe you can use cuda-gdb directly? If you think you are leaking memory, try compiling in debug mode and running it through cuda-memcheck. This should identify the location of code where it thinks you are leaking memory.
  1 个评论
Vyacheslav Samokhvalov
编辑:Vyacheslav Samokhvalov 2021-3-23
Thank you for your answer!
For some reason somewhere between invoking mxGPUCopyFromMxArray, mxGPUGetData to work on the underlying data, and copying data back wtih mxGPUCreateMxArrayOnCPU there's unexpected behaviour. Because I cannot inspect what was happening on device code, to solve this issue I avoid using mxGPUArrays altogether, get pointers to data in Matlab arrays with mxGetSingles, do work with them in an outside CUDA library, and write data back to Matlab's mxArray.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 GPU Computing 的更多信息

产品


版本

R2019b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by