CUDA Error Handling

Çeşitli CUDA fonksiyonları dönüş tipi olarak cudaError_t döndürür. Bunu yakalayıp bir if checkiyle başarılı olup olmadığını kontrol ediyoruz.

    hello<<<1, dataSize>>>(d_data, mySize);
    cudaError_t err = cudaDeviceSynchronize();

    if (err != cudaSuccess)
    {
        printf("CUDA errorString: %s\n", cudaGetErrorString(err));
        return 1;
    }
C++
  • cudaGetErrorName() : Verilen error’un ismini döndürür
  • cudaGetErrorString() : Verilen error’un tanımlamasını döndürür
  • cudaGetLastError() : Returns the last error that has been produced by any of the runtime calls in the same instance of the CUDA Runtime library in the host thread and resets it to cudaSuccess.
  • cudaPeekAtLastError() : Returns the last error that has been produced by any of the runtime calls in the same instance of the CUDA Runtime library in the host thread. This call does not reset the error to cudaSuccess  like  cudaGetLastError().

Genelde bu iş için Macro yazılıyormuş.

#define CUDA_CHECK(call)                                      \
do {                                                         \
    cudaError_t err = call;                                  \
    if (err != cudaSuccess) {                                \
        printf("CUDA Error: %s\n", cudaGetErrorString(err));  \
        exit(EXIT_FAILURE);                                  \
    }                                                        \
} while (0)



int main()
{
  // ...
  CUDA_CHECK(cudaMalloc(&d_data, size));
  CUDA_CHECK(cudaMemcpy(...));
  CUDA_CHECK(cudaDeviceSynchronize());
  // ...
}
C++

gibi


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *