]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb/testsuite/gdb.rocm: Check value returned by hipDeviceSynchronize
authorLancelot Six <lancelot.six@amd.com>
Tue, 17 Oct 2023 15:45:45 +0000 (15:45 +0000)
committerLancelot Six <lancelot.six@amd.com>
Wed, 18 Oct 2023 08:26:23 +0000 (08:26 +0000)
Functions of the hip runtime returning a hipError_t can be marked
nodiscard depending on the configuration[1] (when compiled with C++17).

This patch makes sure that we always check the value returned by
hipDeviceSynchronize and friends, and print an error message when
appropriate.  This avoid a wall of warnings when running the testsuite
if the compiler defaults to using C++17.

It is always a good practice to check the return values anyway.

[1] https://github.com/ROCm-Developer-Tools/HIP/blob/docs/5.7.1/include/hip/hip_runtime_api.h#L203-L218

Change-Id: I2a819a8ac45f4bcf814efe9a2ff12c6a7ad22f97
Approved-By: Simon Marchi <simon.marchi@efficios.com>
gdb/testsuite/gdb.rocm/fork-exec-gpu-to-non-gpu-execer.cpp
gdb/testsuite/gdb.rocm/fork-exec-non-gpu-to-gpu-execee.cpp
gdb/testsuite/gdb.rocm/multi-inferior-gpu.cpp
gdb/testsuite/gdb.rocm/precise-memory-warning-sigsegv.cpp
gdb/testsuite/gdb.rocm/precise-memory.cpp
gdb/testsuite/lib/rocm.exp

index 1a731aeca517182202c2cf15ca76ea536e38bb32..e42c8f10bb3db697410f0fca1b158bf2c3785609 100644 (file)
 #include <hip/hip_runtime.h>
 #include <unistd.h>
 
+#define CHECK(cmd)                                                           \
+  {                                                                          \
+    hipError_t error = cmd;                                                  \
+    if (error != hipSuccess)                                                 \
+      {                                                                      \
+       fprintf (stderr, "error: '%s'(%d) at %s:%d\n",                       \
+                hipGetErrorString (error), error, __FILE__, __LINE__);      \
+       exit (EXIT_FAILURE);                                                 \
+      }                                                                      \
+  }
+
 __global__ static void
 kernel1 ()
 {}
@@ -50,6 +61,6 @@ main ()
 
   kernel2<<<1, 1>>> ();
 
-  hipDeviceSynchronize ();
+  CHECK (hipDeviceSynchronize ());
   return 0;
 }
index 2de8fe20a0d6c040cd5e2f550274f07f02cfb32e..cffeedb7896a4a9ef058d2e45f2c251d0b45b3c9 100644 (file)
 
 #include <hip/hip_runtime.h>
 
+#define CHECK(cmd)                                                           \
+  {                                                                          \
+    hipError_t error = cmd;                                                  \
+    if (error != hipSuccess)                                                 \
+      {                                                                      \
+       fprintf (stderr, "error: '%s'(%d) at %s:%d\n",                       \
+                hipGetErrorString (error), error, __FILE__, __LINE__);      \
+       exit (EXIT_FAILURE);                                                 \
+      }                                                                      \
+  }
+
+
 __device__ static void
 break_here_execee ()
 {}
@@ -31,6 +43,6 @@ int
 main ()
 {
   kernel<<<1, 1>>> ();
-  hipDeviceSynchronize ();
+  CHECK (hipDeviceSynchronize ());
   return 0;
 }
index d64afdd1994ee6322ffad1ea3a110e750d0a8ea2..4ba406f639804106af900227fba7cdebe8b7bfac 100644 (file)
@@ -95,7 +95,7 @@ child (int argc, char **argv)
 
   CHECK (hipSetDevice (dev_number));
   kern<<<1, 1>>> ();
-  hipDeviceSynchronize ();
+  CHECK (hipDeviceSynchronize ());
   return 0;
 }
 
index bf1451ad8d5b91a199a59cf5b63482aa44ebce97..d8ea86920e34b16b039173a8c46bdada0c63ae39 100644 (file)
 
 #include <hip/hip_runtime.h>
 
+#define CHECK(cmd)                                                           \
+  {                                                                          \
+    hipError_t error = cmd;                                                  \
+    if (error != hipSuccess)                                                 \
+      {                                                                      \
+       fprintf (stderr, "error: '%s'(%d) at %s:%d\n",                       \
+                hipGetErrorString (error), error, __FILE__, __LINE__);      \
+       exit (EXIT_FAILURE);                                                 \
+      }                                                                      \
+  }
+
 __global__ void
 kernel ()
 {
@@ -28,6 +39,6 @@ int
 main (int argc, char* argv[])
 {
   kernel<<<1, 1>>> ();
-  hipDeviceSynchronize ();
+  CHECK (hipDeviceSynchronize ());
   return 0;
 }
index 034f02382adc928c8ec616167e98ee48d01417d9..610f1873df6d53a7ff6bb747c21533de79c76867 100644 (file)
 
 #include <hip/hip_runtime.h>
 
+#define CHECK(cmd)                                                           \
+  {                                                                          \
+    hipError_t error = cmd;                                                  \
+    if (error != hipSuccess)                                                 \
+      {                                                                      \
+       fprintf (stderr, "error: '%s'(%d) at %s:%d\n",                       \
+                hipGetErrorString (error), error, __FILE__, __LINE__);      \
+       exit (EXIT_FAILURE);                                                 \
+      }                                                                      \
+  }
+
 __global__ void
 kernel ()
 {
@@ -27,6 +38,6 @@ int
 main (int argc, char* argv[])
 {
   kernel<<<1, 1>>> ();
-  hipDeviceSynchronize ();
+  CHECK (hipDeviceSynchronize ());
   return 0;
 }
index fcdf665aef96f817e7bd9819e9543ddec9302c42..c2ffc57193383b01c5d903c403cd6920af81b801 100644 (file)
@@ -93,7 +93,8 @@ gdb_caching_proc allow_hipcc_tests {} {
            main ()
            {
                kern<<<1, 1>>> ();
-               hipDeviceSynchronize ();
+               if (hipDeviceSynchronize () != hipSuccess)
+                 return -1;
                return 0;
            }
        } executable $flags]} {