NVIDIA / NVIDIA/cccl

Add a macro to check CUDA API

Open
#3,090 5 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
2.5k
Forks
486
Avg merge
2d 6h
Merged PRs (30d)
295

Description

A lot of CUDA host codes use a macro to check the error codes of native API calls. E.g.:
```c++
#define CUDA_CHECK_ERROR(call) do { \
cudaError_t err = call; \
if (err != cudaSuccess) { \
std::cerr << "CUDA error in " << __FILE__ << " at line " << __LINE__ << ": " \
<< cudaGetErrorString(err) << std::endl; \
std::exit(EXIT_FAILURE); \
} \
} while (0)

CUDA_CHECK_ERROR(cudaMalloc(...));
CUDA_CHECK_ERROR(cudaDeviceSynchronize());
```
Given the wide use of such macros, we should provide one in CCCL for public use.

We should probably not name it `CUDA_CHECK_ERROR` to avoid clashing with equally-named macros in user code, but `CCCL_CHECK_ERROR` or similar should work. Furthermore, we should probably use exceptions over exiting as error handling strategy, since this is in line with Thrust. Otherwise, we could provide two macros `CCCL_THROW_ON_ERROR` and `CCCL_DIE_ON_ERROR`.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.