Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a macro to check CUDA API #3090

Open
bernhardmgruber opened this issue Dec 9, 2024 · 3 comments
Open

Add a macro to check CUDA API #3090

bernhardmgruber opened this issue Dec 9, 2024 · 3 comments

Comments

@bernhardmgruber
Copy link
Contributor

bernhardmgruber commented Dec 9, 2024

A lot of CUDA host codes use a macro to check the error codes of native API calls. E.g.:

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

@fbusato
Copy link
Contributor

fbusato commented Dec 9, 2024

do you mean for internal or external use?
IIRC @miscco has strong opinion about exposing macros for user code

@bernhardmgruber
Copy link
Contributor Author

do you mean for internal or external use? IIRC @miscco has strong opinion about exposing macros for user code

For public use, since everybody always has to copy and paste it from somewhere. As a CUDA standard library, we are the ideal place to host such a macro.

Internally, we have _CCCL_TRY_CUDA_API and _CCCL_ASSERT_CUDA_API.

@fbusato
Copy link
Contributor

fbusato commented Dec 9, 2024

there are tons of macros that are copy&paste in most CUDA projects, e.g. attributes like host/device, nodiscard, etc. or compiler macros, or platform macros. Would be nice to have a similar decision...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Todo
Development

No branches or pull requests

2 participants