Browse Source

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`.
Pierre Moreau 8 years ago
parent
commit
c0d7bb8368
3 changed files with 20 additions and 0 deletions
  1. 6 0
      Tests/Cuda/Complex/dynamic.cu
  2. 7 0
      Tests/Cuda/Complex/file3.cu
  3. 7 0
      Tests/Cuda/Complex/mixed.cu

+ 6 - 0
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;
+    }
 }

+ 7 - 0
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;
 }

+ 7 - 0
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;
 }