My question is - if the following is the correct way to check if a kernel was launched:
__global__ void suspiciousKernel(int *i) {
*i=123;
__syncthreads();
[...] //some big code goes over here
}
int main() {
cudaError err;
int *gpuI;
int cpuI=42;
err=cudaMalloc( (void**)&gpuI, sizeof(int));
printf("Allocate: %s\n",cudaGetErrorString(err));
err=cudaMemcpy( gpuI,&cpuI,sizeof(int),cudaMemcpyHostToDevice);
printf("Send: %s\n",cudaGetErrorString(err));
suspiciousKernel<<<1,512>>>(gpuI);
err=cudaThreadSynchronize();
printf("Launch: %s\n",cudaGetErrorString(err));
err=cudaMemcpy(&cpuI,gpuI,sizeof(int),cudaMemcpyDeviceToHost);
printf("Receive: %s\n",cudaGetErrorString(err));
printf("Got value %d\n",cpuI);
}
According to Programming Guide:
So I would expect that if my kernel call crashes or is not executed for whatever reason, I will get err different than cudaSuccess out from cudaThreadSynchronize.
On the other hand, if the kernel is executed, I should now have value 123 under gpuI pointer, assuming my “some big code goes over here” does not modify (or even read/depend on) the value. What I get out from the above code is:
Allocate: no error
Send: no error
Launch: no error
Receive: no error
Got value 42
So my question is - what must happen so that I have these results?
Some notes:
-
I launch only one block of my suspicious kernel so __syncthreads() stops all threads on whole GPU.
-
It could happen that I change *i accidently, but if that happens what are the odds of setting it back to the old value?