Reputation: 131808
I can get the returned status of the last CUDA API call with cudaGetLastError()
. How about getting its name? I don't see a cudaGetLastAPICallName()
, but is there some (un)documented equivalent?
Upvotes: 0
Views: 209
Reputation: 72339
To the best of my knowledge, no you cannot. It is important to keep in mind that
cudaGetLastError()
returns the status of an earlier runtime API call, but not necessarily the last one. An asynchronous call can report an error during operation, after it has already returned cudaSuccess
, in which case its error will be returned by the next API function which returns a status. Parsing the results of his can get particularly complex with concurrent operations in streams.It isn't clear to me how either case could be cleanly handled in a way that would give meaningful additional information, especially when some classes of device runtime errors can kill the active context, which looses a lot of state anyway....
Upvotes: 3
Reputation: 24558
No. You are supposed to wrap all your CUDA calls in a macro that gives you file name and line number. This way, you can easily find the culprit.
Here is an example:
template< typename T >
inline void __checkCudaErrors(T result, char const *const func, const char *const file, int const line)
{
cudaError_t err = cudaGetLastError();
if (cudaSuccess != err)
{
fprintf(stderr, "%s:%i : checkCudaErrors() CUDA error (#%d): %s.\n",
file, line, (int)err, cudaGetErrorString(err));
exit(-1);
}
}
#define CCE(val) __checkCudaErrors( (val), #val, __FILE__, __LINE__ )
// ...
CCE(cudaMalloc(...));
CCE(cuda...);
myKernel...;
CCE(nextCudaCall);
Upvotes: 0