Skip to content

Commit

Permalink
gdb/testsuite/gdb.rocm: Check value returned by hipDeviceSynchronize
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
lancesix committed Oct 18, 2023
1 parent 0f79aa9 commit fded0fb
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 6 deletions.
13 changes: 12 additions & 1 deletion gdb/testsuite/gdb.rocm/fork-exec-gpu-to-non-gpu-execer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,17 @@
#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 ()
{}
Expand Down Expand Up @@ -50,6 +61,6 @@ main ()

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

hipDeviceSynchronize ();
CHECK (hipDeviceSynchronize ());
return 0;
}
14 changes: 13 additions & 1 deletion gdb/testsuite/gdb.rocm/fork-exec-non-gpu-to-gpu-execee.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,18 @@

#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 ()
{}
Expand All @@ -31,6 +43,6 @@ int
main ()
{
kernel<<<1, 1>>> ();
hipDeviceSynchronize ();
CHECK (hipDeviceSynchronize ());
return 0;
}
2 changes: 1 addition & 1 deletion gdb/testsuite/gdb.rocm/multi-inferior-gpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ child (int argc, char **argv)

CHECK (hipSetDevice (dev_number));
kern<<<1, 1>>> ();
hipDeviceSynchronize ();
CHECK (hipDeviceSynchronize ());
return 0;
}

Expand Down
13 changes: 12 additions & 1 deletion gdb/testsuite/gdb.rocm/precise-memory-warning-sigsegv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,17 @@

#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 ()
{
Expand All @@ -28,6 +39,6 @@ int
main (int argc, char* argv[])
{
kernel<<<1, 1>>> ();
hipDeviceSynchronize ();
CHECK (hipDeviceSynchronize ());
return 0;
}
13 changes: 12 additions & 1 deletion gdb/testsuite/gdb.rocm/precise-memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,17 @@

#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 ()
{
Expand All @@ -27,6 +38,6 @@ int
main (int argc, char* argv[])
{
kernel<<<1, 1>>> ();
hipDeviceSynchronize ();
CHECK (hipDeviceSynchronize ());
return 0;
}
3 changes: 2 additions & 1 deletion gdb/testsuite/lib/rocm.exp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ gdb_caching_proc allow_hipcc_tests {} {
main ()
{
kern<<<1, 1>>> ();
hipDeviceSynchronize ();
if (hipDeviceSynchronize () != hipSuccess)
return -1;
return 0;
}
} executable $flags]} {
Expand Down

0 comments on commit fded0fb

Please sign in to comment.