From 14e200cb07e135097775a5e8097ef5d8cc5127db Mon Sep 17 00:00:00 2001 From: Ernie Pasveer Date: Sat, 28 Dec 2024 17:11:08 -0600 Subject: [PATCH] Add simple rocm test program. --- tests/hellorocm/README.commands | 13 +++++++++++++ tests/hellorocm/simple.cpp | 34 +++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 tests/hellorocm/README.commands create mode 100644 tests/hellorocm/simple.cpp diff --git a/tests/hellorocm/README.commands b/tests/hellorocm/README.commands new file mode 100644 index 0000000..6fefed2 --- /dev/null +++ b/tests/hellorocm/README.commands @@ -0,0 +1,13 @@ + $ hipcc simple.cpp -g -O0 -o simple + $ ./simple + + + $ roc-obj-ls simple + $ rocm-smi --showdriverversion + $ /opt/rocm/bin/rocminfo | grep gfx + $ sudo /opt/rocm/bin/rocminfo --support + + $ export HIP_ENABLE_DEFERRED_LOADING=0 + $ export AMD_LOG_LEVEL=3 + $ /usr/local/bin/seergdb --gdb-program=/usr/bin/rocgdb -s ./simple + diff --git a/tests/hellorocm/simple.cpp b/tests/hellorocm/simple.cpp new file mode 100644 index 0000000..e26c7f5 --- /dev/null +++ b/tests/hellorocm/simple.cpp @@ -0,0 +1,34 @@ +#include "hip/hip_runtime.h" +#include +#include + +__global__ +void do_an_addition (int a, int b, int *out) { + *out = a + b; +} + +int main () { + int *result_ptr, result; + + /* Allocate memory for the device to write the result to. */ + hipError_t error_code = hipMalloc (&result_ptr, sizeof (int)); + + printf("HIP Error %d %s: %s.\n", error_code, hipGetErrorName(error_code), hipGetErrorString(error_code)); + assert (error_code == hipSuccess); + + /* Run `do_an_addition` on one workgroup containing one work item. */ + do_an_addition<<>> (1, 2, result_ptr); + + /* Copy result from device to host. Note that this acts as a synchronization + point, waiting for the kernel dispatch to complete. */ + error_code = hipMemcpyDtoH (&result, result_ptr, sizeof (int)); + + printf("HIP Error %d %s: %s.\n", error_code, hipGetErrorName(error_code), hipGetErrorString(error_code)); + assert (error_code == hipSuccess); + + printf ("result is %d\n", result); + assert (result == 3); + + return 0; +} +