Tests/Cuda: Print asynchronous error messages, if any

As kernel launches are asynchronous, a `cudaGetLastError()` right after
the kernel launch might be executed while the kernel is still running.
Synchronizing the device will ensure that all the work is completed
before progressing further on, and allows to catch errors that were
previously missed.
The `cudaGetLastError()` after the `cudaDeviceSynchronize()` is there
to reset the error variable to `cudaSuccess`.
This commit is contained in:
Pierre Moreau
2017-02-02 13:58:09 +01:00
committed by Brad King
parent 21a125cdbf
commit c0d7bb8368
3 changed files with 20 additions and 0 deletions

View File

@@ -31,4 +31,10 @@ EXPORT void cuda_dynamic_lib_func()
std::cerr << "DetermineIfValidCudaDevice [SYNC] failed: "
<< cudaGetErrorString(err) << std::endl;
}
err = cudaDeviceSynchronize();
if(err != cudaSuccess)
{
std::cerr << "DetermineIfValidCudaDevice [ASYNC] failed: "
<< cudaGetErrorString(cudaGetLastError()) << std::endl;
}
}

View File

@@ -26,5 +26,12 @@ int file3_launch_kernel(int x)
<< cudaGetErrorString(err) << std::endl;
return x;
}
err = cudaDeviceSynchronize();
if(err != cudaSuccess)
{
std::cerr << "file3_kernel [ASYNC] failed: "
<< cudaGetErrorString(cudaGetLastError()) << std::endl;
return x;
}
return r.sum;
}

View File

@@ -38,5 +38,12 @@ EXPORT int mixed_launch_kernel(int x)
<< cudaGetErrorString(err) << std::endl;
return x;
}
err = cudaDeviceSynchronize();
if(err != cudaSuccess)
{
std::cerr << "mixed_kernel [ASYNC] failed: "
<< cudaGetErrorString(cudaGetLastError()) << std::endl;
return x;
}
return r.sum;
}