I have a project which contains a kernel, two streams and a callback function.
Let me show you the code skeleton.
/* The parameters i am passing to callback function */
typedef struct {
uint8_t alpha;
uint16_t beta;
uint8_t gamma;
.
uint32_t stream0_argument;
uint32_t stream1_argument;
.
.
}CallbackArgumentStruct *CallbackArgumentsPointer;
The main body:
loop {
.
.
kernel<,,,stream0>
kernel<,,,stream1>
cudaStreamAddCallback(stream0,...., &CallBackFunction1, 0);
cudaStreamAddCallback(stream1,...., &CallBackFunction2, 0);
.
.
}
The CallBackFunction1 and CallBackFunction2 are identical in their procedure but their is only a single argument which is different for both, let say stream0_argument is used when the callback function is called by stream0 and stream1_argument is used if callback function is called by stream1.
So instead of two callbacks, i would like to use a single callback definition for both.
The solution that i have in mind:
-
I can use a simple if-statement inside callback to select the corresponding value if i somehow knew the stream number in which the callback is called. [One function definition, Same pointer passed to both]
-
Use two definitions of callbacks [Two function definition, single pointer passed to both]
-
Use single callback definition with two different pointers. [Single function definition, two different pointers]
Any suggestions ?