I use “return” in the kernel, as following:
__global__ void mykernel()
{
int i=threadIdx.x;
if(i>100) return;
....
}
When I run the kernel, i gol a lot of error.
Is it because I use “return” in the kernel?
I use “return” in the kernel, as following:
__global__ void mykernel()
{
int i=threadIdx.x;
if(i>100) return;
....
}
When I run the kernel, i gol a lot of error.
Is it because I use “return” in the kernel?
kernel is always void type, So cant return anything
kernel is always void type, So cant use return statement
Why not? Indeed, you can’t
return value;
But
return;
is always legal.
Regards
Navier
Yea, Navier is right. I should have say " Cant Return value"
I used to play with returns a lot with kernels, for some reason it is not mentioned at all in guides. My observations are:
It is perfectly OK to have some individual threads return early, despite what others in this thread have said. You just have to be careful with __synthreads() so you don’t cause deadlocks.
The return statement, however, does just that. Only the current thread returns. There is no way to stop an entire kernel from running with a decision made in a single thread.