I was a bit upset yesterday and posted here to grumble (I’m french, this is a national sport here :p).
As a “modern” C++ developer trying to learn C++ CUDA with the latest feature and the best practice, the first recommendation I found was to encapsulate all CUDA calls with a C macro “cudaCheck” or whatever to check the return status of the actual function call. This is a way to go when dealing with old / legacy C API like FFMPEG that I am using in my current project. So defining custom C++ Exception and then throw it in the callCheck if needed, something like that
/**
* @brief Check if FFMPEG library calls are successful and throw an exception if they are not
*/
#define CHECK_ERROR(ffmpegError) \
do { \
int errorCode = ffmpegError; \
\
if (errorCode < 0) { \
throw FFMPEG::Exception(errorCode, __FUNCTION__, __FILE__, __LINE__); \
} \
} while (0)
Even if I found this solution not very convenient (wrapping functions in macro is repetitive and makes my IDE loss the syntax color feature) I tried to do the same with CUDA. I wanted to propagate the exception to the application top level so I looked for how to propagate an exception from device to host after a kernel launch. As I remember it is possible by giving a pointer parameter to the CUDA kernel launch call and then check this pointer to retrieve the error but I gave up as this solution started to be complicated and a bit verbose.
Maybe CUDA C++ can fork from C version and provide a version with modern C++ feature such as smart pointers and change the error system with a throw / try catch one. I found a nice library https://github.com/eyalroz/cuda-api-wrappers that works as a C++ wrapper and deliver those nice C++ feature but is this project gonna be maintained ?
Talking about IDE, it can be one of the best tool for tracking / debbuging or catching errors so I tried Nsight Eclipse Edition in the latest CUDA 10.1 toolkit release. I am using Clion (JetBrains IDE for C++) but it lacks of CUDA understanding / code insight / kernel debugging so I gave a try with Nsight.
In Ubuntu 18.06 Nsight is crashing by default due to a wrong Java JDK version. I had to downgrade JDK version from 11 to 8 using “update-alternative” to make the IDE working.
Then the code inspection seems to need a makefile to inspect the code, ok I just ran “cmake .” and here we go. Then I wanted a dark theme, it appeared that the default one is broken so I tried to fixed it and used a plugin but there was an error installing it and I gave up there.
This is my little CUDA experience, I really need to improve myself but I have a lack of time to make things properly.