From c0d7bb8368c3d157d1a2758b620fc726355e554d Mon Sep 17 00:00:00 2001 From: Pierre Moreau Date: Thu, 2 Feb 2017 13:58:09 +0100 Subject: 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`. --- Tests/Cuda/Complex/dynamic.cu | 6 ++++++ Tests/Cuda/Complex/file3.cu | 7 +++++++ Tests/Cuda/Complex/mixed.cu | 7 +++++++ 3 files changed, 20 insertions(+) diff --git a/Tests/Cuda/Complex/dynamic.cu b/Tests/Cuda/Complex/dynamic.cu index fc22c8b..0206bb4 100644 --- a/Tests/Cuda/Complex/dynamic.cu +++ b/Tests/Cuda/Complex/dynamic.cu @@ -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; + } } diff --git a/Tests/Cuda/Complex/file3.cu b/Tests/Cuda/Complex/file3.cu index 1daf47e..912105a 100644 --- a/Tests/Cuda/Complex/file3.cu +++ b/Tests/Cuda/Complex/file3.cu @@ -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; } diff --git a/Tests/Cuda/Complex/mixed.cu b/Tests/Cuda/Complex/mixed.cu index 429f1f3..a7bcd4e 100644 --- a/Tests/Cuda/Complex/mixed.cu +++ b/Tests/Cuda/Complex/mixed.cu @@ -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; } -- cgit v0.12