J.kol
J.kol

Reputation: 43

Cuda: synchronize one kernel function out of n

I'm wondering about this question: is there a way to synchronize just one kernel function? For example if I have something like this:

function_1 <<< dimgrid, dimblock >>> (param1, param2, param3);
funckion_2 <<< dimgrid, dimblock >>> (param4, param5, param5);
function_1 <<< dimgrid, dimblock >>> (param6, param7, param8);

is it possible to know if the second function_1 has finished before the first?. Could the cudaDeviceSynchronize() function help me for this problem? I need this because I have to reuse some of the resources (param-i) for other kernel functions.

Upvotes: 0

Views: 63

Answers (1)

talonmies
talonmies

Reputation: 72372

If you launch each kernel into its own stream, then you can use cudaStreamSynchronize on the stream running the kernel you want to wait on. So something like:

//stream creation for stream1, stream2
...
function_1 <<< dimgrid, dimblock, 0, stream1 >>> (param1, param2, param3);
funckion_2 <<< dimgrid, dimblock, 0, stream2 >>> (param4, param5, param5);
function_1 <<< dimgrid, dimblock, 0, stream1 >>> (param6, param7, param8);

cudaStreamSynchronize(stream1);

would probably do what you want.

Upvotes: 1

Related Questions