Add a macro to check CUDA API
- 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
Assessment
This issue has not been assessed yet.