Skip to content

Commit fded0fb

Browse files
committed
gdb/testsuite/gdb.rocm: Check value returned by hipDeviceSynchronize
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 <[email protected]>
1 parent 0f79aa9 commit fded0fb

File tree

6 files changed

+52
-6
lines changed

6 files changed

+52
-6
lines changed

gdb/testsuite/gdb.rocm/fork-exec-gpu-to-non-gpu-execer.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,17 @@
1818
#include <hip/hip_runtime.h>
1919
#include <unistd.h>
2020

21+
#define CHECK(cmd) \
22+
{ \
23+
hipError_t error = cmd; \
24+
if (error != hipSuccess) \
25+
{ \
26+
fprintf (stderr, "error: '%s'(%d) at %s:%d\n", \
27+
hipGetErrorString (error), error, __FILE__, __LINE__); \
28+
exit (EXIT_FAILURE); \
29+
} \
30+
}
31+
2132
__global__ static void
2233
kernel1 ()
2334
{}
@@ -50,6 +61,6 @@ main ()
5061

5162
kernel2<<<1, 1>>> ();
5263

53-
hipDeviceSynchronize ();
64+
CHECK (hipDeviceSynchronize ());
5465
return 0;
5566
}

gdb/testsuite/gdb.rocm/fork-exec-non-gpu-to-gpu-execee.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,18 @@
1717

1818
#include <hip/hip_runtime.h>
1919

20+
#define CHECK(cmd) \
21+
{ \
22+
hipError_t error = cmd; \
23+
if (error != hipSuccess) \
24+
{ \
25+
fprintf (stderr, "error: '%s'(%d) at %s:%d\n", \
26+
hipGetErrorString (error), error, __FILE__, __LINE__); \
27+
exit (EXIT_FAILURE); \
28+
} \
29+
}
30+
31+
2032
__device__ static void
2133
break_here_execee ()
2234
{}
@@ -31,6 +43,6 @@ int
3143
main ()
3244
{
3345
kernel<<<1, 1>>> ();
34-
hipDeviceSynchronize ();
46+
CHECK (hipDeviceSynchronize ());
3547
return 0;
3648
}

gdb/testsuite/gdb.rocm/multi-inferior-gpu.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ child (int argc, char **argv)
9595

9696
CHECK (hipSetDevice (dev_number));
9797
kern<<<1, 1>>> ();
98-
hipDeviceSynchronize ();
98+
CHECK (hipDeviceSynchronize ());
9999
return 0;
100100
}
101101

gdb/testsuite/gdb.rocm/precise-memory-warning-sigsegv.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,17 @@
1717

1818
#include <hip/hip_runtime.h>
1919

20+
#define CHECK(cmd) \
21+
{ \
22+
hipError_t error = cmd; \
23+
if (error != hipSuccess) \
24+
{ \
25+
fprintf (stderr, "error: '%s'(%d) at %s:%d\n", \
26+
hipGetErrorString (error), error, __FILE__, __LINE__); \
27+
exit (EXIT_FAILURE); \
28+
} \
29+
}
30+
2031
__global__ void
2132
kernel ()
2233
{
@@ -28,6 +39,6 @@ int
2839
main (int argc, char* argv[])
2940
{
3041
kernel<<<1, 1>>> ();
31-
hipDeviceSynchronize ();
42+
CHECK (hipDeviceSynchronize ());
3243
return 0;
3344
}

gdb/testsuite/gdb.rocm/precise-memory.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,17 @@
1717

1818
#include <hip/hip_runtime.h>
1919

20+
#define CHECK(cmd) \
21+
{ \
22+
hipError_t error = cmd; \
23+
if (error != hipSuccess) \
24+
{ \
25+
fprintf (stderr, "error: '%s'(%d) at %s:%d\n", \
26+
hipGetErrorString (error), error, __FILE__, __LINE__); \
27+
exit (EXIT_FAILURE); \
28+
} \
29+
}
30+
2031
__global__ void
2132
kernel ()
2233
{
@@ -27,6 +38,6 @@ int
2738
main (int argc, char* argv[])
2839
{
2940
kernel<<<1, 1>>> ();
30-
hipDeviceSynchronize ();
41+
CHECK (hipDeviceSynchronize ());
3142
return 0;
3243
}

gdb/testsuite/lib/rocm.exp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@ gdb_caching_proc allow_hipcc_tests {} {
9393
main ()
9494
{
9595
kern<<<1, 1>>> ();
96-
hipDeviceSynchronize ();
96+
if (hipDeviceSynchronize () != hipSuccess)
97+
return -1;
9798
return 0;
9899
}
99100
} executable $flags]} {

0 commit comments

Comments
 (0)