mirror of
https://github.com/Kitware/CMake.git
synced 2026-02-21 14:40:26 -06:00
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:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user