cudaLaunchHostFunc compiler error with cmake 3.17.1

we define a callback functio and call with cudaLaunchHostFunc such as

    void CUDART_CB WriteProcessStart(cudaStream_t stream, cudaError_t status, void *data){
    }
  cudaLaunchHostFunc(*cuda_stream_ptr, WriteProcessStart, (void*)data);

but it throws out some errors

error : argument of type "void (*)(cudaStream_t, cudaError_t, void *)" is incompatible with parameter of type "cudaHostFn_t"

From rummaging through the CUDA documentation: The callback function needs be of type cudaHostFn_t, i.e. conform to a particular callback function prototype. This requires a callback function with the following interface:

void CUDART_CB myHostCallback (void *data);

So all of the data passed to the callback function is a single data object of an opaque data type, accessed via a void pointer.

1 Like

it seems ok… :)
but see in document https://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#stream-callbacks

the function is defined

void CUDART_CB MyCallback(cudaStream_t stream, cudaError_t status, void *data){
    printf("Inside callback %d\n", (size_t)data);
}

it seems misleadding me

You may be conflating two different mechanisms:

The callback function for cudaLaunchHostFunc is defined as typedef void (CUDART_CB *cudaHostFn_t)(void *userData);.

The callback function for cudaStreamAddCallback is defined as typedef void (CUDART_CB *cudaStreamCallback_t)(cudaStream_t stream, cudaError_t status, void *userData);

According to the CUDA documentation, the latter function should be considered deprecated and the former is preferred for future-proof code.

1 Like