Вопрос

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?

Это было полезно?

Решение

To the best of my knowledge, no you cannot. It is important to keep in mind that

  1. 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.
  2. There is at least one operation (kernel launches themselves) which don't have an explicit runtime API call which can be related to any programmer visible source, even though they call a series of documented and private API calls behind the curtains.

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....

Другие советы

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);
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top