From 4c6f249cc10094e4e38d627804b65258248082a4 Mon Sep 17 00:00:00 2001 From: Laurent Morichetti Date: Thu, 2 Jun 2022 21:17:29 -0700 Subject: [PATCH] Fix test errors Check the HIP API calls status, and abort if != success. Change-Id: Ifc38d8f28092ffdce1674a05a7886f7c0c97a885 --- test/app/roctx_test.cpp | 13 +++++++++++-- test/hip/MatrixTranspose.cpp | 23 ++++++++++++++++------- 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/test/app/roctx_test.cpp b/test/app/roctx_test.cpp index ef863bdafc..42e194c8e2 100644 --- a/test/app/roctx_test.cpp +++ b/test/app/roctx_test.cpp @@ -22,10 +22,19 @@ #include "roctx.h" +#define HIP_CALL(call) \ + do { \ + hipError_t err = call; \ + if (err != hipSuccess) { \ + fprintf(stderr, "%s\n", hipGetErrorString(err)); \ + abort(); \ + } \ + } while (0) + __global__ void kernel() {} int main(int argc, char* argv[]) { - hipSetDevice(0); + HIP_CALL(hipSetDevice(0)); // Not in a roctx range. kernel<<<1, 1>>>(); @@ -59,6 +68,6 @@ int main(int argc, char* argv[]) { if (roctxRangePop() != 0) return -1; - hipDeviceSynchronize(); + HIP_CALL(hipDeviceSynchronize()); return 0; } diff --git a/test/hip/MatrixTranspose.cpp b/test/hip/MatrixTranspose.cpp index de5136a42d..7f19fe991e 100644 --- a/test/hip/MatrixTranspose.cpp +++ b/test/hip/MatrixTranspose.cpp @@ -26,6 +26,14 @@ // roctx header file #include +#define HIP_CALL(call) \ + do { \ + hipError_t err = call; \ + if (err != hipSuccess) { \ + fprintf(stderr, "%s\n", hipGetErrorString(err)); \ + abort(); \ + } \ + } while (0) #define WIDTH 1024 @@ -65,7 +73,7 @@ int main() { float* gpuTransposeMatrix; hipDeviceProp_t devProp; - hipGetDeviceProperties(&devProp, 0); + HIP_CALL(hipGetDeviceProperties(&devProp, 0)); std::cerr << "Device name " << devProp.name << std::endl; @@ -82,15 +90,15 @@ int main() { } // allocate the memory on the device side - hipMalloc((void**)&gpuMatrix, NUM * sizeof(float)); - hipMalloc((void**)&gpuTransposeMatrix, NUM * sizeof(float)); + HIP_CALL(hipMalloc((void**)&gpuMatrix, NUM * sizeof(float))); + HIP_CALL(hipMalloc((void**)&gpuTransposeMatrix, NUM * sizeof(float))); uint32_t iterations = 100; while (iterations-- > 0) { std::cerr << "## Iteration (" << iterations << ") #################" << std::endl; // Memory transfer from host to device - hipMemcpy(gpuMatrix, Matrix, NUM * sizeof(float), hipMemcpyHostToDevice); + HIP_CALL(hipMemcpy(gpuMatrix, Matrix, NUM * sizeof(float), hipMemcpyHostToDevice)); roctracer_mark("before HIP LaunchKernel"); roctxMark("before hipLaunchKernel"); @@ -106,7 +114,8 @@ int main() { // Memory transfer from device to host roctxRangePush("hipMemcpy"); - hipMemcpy(TransposeMatrix, gpuTransposeMatrix, NUM * sizeof(float), hipMemcpyDeviceToHost); + HIP_CALL( + hipMemcpy(TransposeMatrix, gpuTransposeMatrix, NUM * sizeof(float), hipMemcpyDeviceToHost)); roctxRangePop(); // for "hipMemcpy" roctxRangePop(); // for "hipLaunchKernel" @@ -131,8 +140,8 @@ int main() { } // free the resources on device side - hipFree(gpuMatrix); - hipFree(gpuTransposeMatrix); + HIP_CALL(hipFree(gpuMatrix)); + HIP_CALL(hipFree(gpuTransposeMatrix)); // free the resources on host side free(Matrix);