I'm trying to synchronise my cuda routine by using cudaStreamAddCallback(), but I can't implement it, also because the documentation is not unambiguous. The cuda-C-programming-guide says that the callback has to be defined as:
void CUDART_CB MyCallback(void *data){}
and is talking about flags like the cudaStreamCallbackBlocking that needs to be set; while the Cuda_Toolhit_Reference_Manual and the cuda_runtime_api.h requiring an other implementation of the callback:
void CUDART_CB MyCallback (cudaStream_t stream, cudaError_t status, void *userData){}
and mentioning that the flag is for future use and require a 0 as argument. Furthermore, calling the function as follow:
cudaStreamAddCallback(GpuStream, MyCallback, &BufSwitchParams, 0);
and working using VS 2010 trying to compile for 64bit I'm getting the message: argument of type “ void(__stdcall CMyClass::*)(cudaStream_t stream, cudaError_t status, void *userData)” is incompatible with parameter of type "cudaStreamCallback_t".
Does someone has already implemented this function and would be able to help me out of my dilemma, while posting a snippet here?
You pass a class method to cudaStreamAddCallback
, but it should be a non-member function (global or static). If you want to use class method you should implement wrapper function that will call the method:
class MyClass
{
public:
static void CUDART_CB Callback(cudaStream_t stream, cudaError_t status, void *userData);
private:
void callbackFunc();
};
void CUDART_CB MyClass::Callback(cudaStream_t stream, cudaError_t status, void *userData)
{
MyClass* thiz = (MyClass*) userData;
thiz->callbackFunc();
}
void MyClass::callbackFunc()
{
// implementation here
}
MyClass* obj = new MyClass;
cudaStreamAddCallback(GpuStream, MyClass::Callback, obj, 0);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With