enc
enc

Reputation: 3415

how to synchronize between cuda kernel function?

I have two cuda kernel functions like this

a<<<BLK_SIZE,THR_SIZE>>>(params,...);
b<<<BLK_SIZE,THR_SIZE>>>(params,...);

After function a started, I want to wait until a finishes and then start function b. so I inserted cudaThreadSynchronize() between a and b like this,

a<<<BLK_SIZE,THR_SIZE>>>(params,...);
err=cudaThreadSynchronize();
if( err != cudaSuccess)
    printf("cudaThreadSynchronize error: %s\n", cudaGetErrorString(err));
b<<<BLK_SIZE,THR_SIZE>>>(params,...);

but cudaThreadSynchronize() returns error code: the launch timed out and was terminated cuda error

how can I fix it?


A simple code explanation:

mmap(sequence file);
mmap(reference file);

cudaMemcpy(seq_cuda, sequence);
cudaMemcpy(ref_cuda,reference);

kernel<<<>>>(params); //find short sequence in reference
cudaThreadSynchronize();
kernel<<<>>>(params);

cudaMemcpy(result, result_cuda);
report result

and in kernel function, there is a big for loop which contains some if-else for the pattern matching algorithm to reduce number of comparisons.

Upvotes: 0

Views: 5682

Answers (1)

Ashwin Nanjappa
Ashwin Nanjappa

Reputation: 78478

This launch error means that something went wrong when your first kernel was launched or maybe even something before that. To work your way out of this, try checking the output of all CUDA runtime calls for errors. Also, do a cudaThreadSync followed by error check after all kernel calls. This should help you find the first place where the error occurs.

If it is indeed a launch failure, you will need to investigate the execution configuration and the code of the kernel to find the cause of your error.

Finally, note that it is highly unlikely that your action of adding in a cudaThreadSynchronize caused this error. I say this because the way you have worded the query points to the cudaThreadSynchronize as the culprit. All this call did was to catch your existing error earlier.

Upvotes: 1

Related Questions