From b2576cbd8e6e919fc9618ad567ea1bc0010d2d22 Mon Sep 17 00:00:00 2001 From: ROCm CI Service Account <66695075+rocm-ci@users.noreply.github.com> Date: Tue, 20 Jun 2023 10:40:49 +0530 Subject: [PATCH] SWDEV-397031 - Fix issue in Release mode where hipMalloc was never called (#308) Change-Id: Id99a5f39035f14ea9a63f9b339e4fb6525e1d3c1 [ROCm/hip-tests commit: 62b22183682d0f344d8ac3af3499670111e8e971] --- .../host_functions/CMakeLists.txt | 2 +- .../host_functions/hipOptLibrary.cpp | 55 +++++++++++-------- 2 files changed, 32 insertions(+), 25 deletions(-) diff --git a/projects/hip-tests/samples/2_Cookbook/15_static_library/host_functions/CMakeLists.txt b/projects/hip-tests/samples/2_Cookbook/15_static_library/host_functions/CMakeLists.txt index 3c7c306866..8404ac58b2 100644 --- a/projects/hip-tests/samples/2_Cookbook/15_static_library/host_functions/CMakeLists.txt +++ b/projects/hip-tests/samples/2_Cookbook/15_static_library/host_functions/CMakeLists.txt @@ -37,7 +37,7 @@ endif() add_library(HipOptLibrary STATIC ${CPP_SOURCES}) # Set-up the correct flags to generate the static library. -target_link_libraries(HipOptLibrary PRIVATE --emit-static-lib) +target_link_options(HipOptLibrary PRIVATE --emit-static-lib) target_include_directories(HipOptLibrary PRIVATE /opt/rocm/hsa/include) # Create test executable that uses libHipOptLibrary.a diff --git a/projects/hip-tests/samples/2_Cookbook/15_static_library/host_functions/hipOptLibrary.cpp b/projects/hip-tests/samples/2_Cookbook/15_static_library/host_functions/hipOptLibrary.cpp index 68f54184b4..2fe948a0f3 100644 --- a/projects/hip-tests/samples/2_Cookbook/15_static_library/host_functions/hipOptLibrary.cpp +++ b/projects/hip-tests/samples/2_Cookbook/15_static_library/host_functions/hipOptLibrary.cpp @@ -23,40 +23,47 @@ #include #include #include +#include -#define HIP_ASSERT(status) assert(status == hipSuccess) +#define HIP_ASSERT(status) \ + { \ + if ((status != hipSuccess)) { \ + std::cerr << "Failed in: " << __LINE__ << " on hip call: " #status << std::endl; \ + throw std::runtime_error("generic failure"); \ + } \ + } #define LEN 512 __global__ void copy(uint32_t* A, uint32_t* B) { - size_t tid = threadIdx.x + blockIdx.x * blockDim.x; - B[tid] = A[tid]; + size_t tid = threadIdx.x + blockIdx.x * blockDim.x; + B[tid] = A[tid]; } void run_test1() { - uint32_t *A_h, *B_h, *A_d, *B_d; - size_t valbytes = LEN * sizeof(uint32_t); + uint32_t *A_h, *B_h, *A_d, *B_d; + size_t valbytes = LEN * sizeof(uint32_t); - A_h = (uint32_t*)malloc(valbytes); - B_h = (uint32_t*)malloc(valbytes); - for (uint32_t i = 0; i < LEN; i++) { - A_h[i] = i; - B_h[i] = 0; - } + A_h = (uint32_t*)malloc(valbytes); + B_h = (uint32_t*)malloc(valbytes); + for (uint32_t i = 0; i < LEN; i++) { + A_h[i] = i; + B_h[i] = 0; + } - HIP_ASSERT(hipMalloc((void**)&A_d, valbytes)); - HIP_ASSERT(hipMalloc((void**)&B_d, valbytes)); + HIP_ASSERT(hipMalloc((void**)&A_d, valbytes)); + HIP_ASSERT(hipMalloc((void**)&B_d, valbytes)); - HIP_ASSERT(hipMemcpy(A_d, A_h, valbytes, hipMemcpyHostToDevice)); - hipLaunchKernelGGL(copy, dim3(LEN/64), dim3(64), 0, 0, A_d, B_d); - HIP_ASSERT(hipMemcpy(B_h, B_d, valbytes, hipMemcpyDeviceToHost)); + HIP_ASSERT(hipMemcpy(A_d, A_h, valbytes, hipMemcpyHostToDevice)); + hipLaunchKernelGGL(copy, dim3(LEN / 64), dim3(64), 0, 0, A_d, B_d); + HIP_ASSERT(hipMemcpy(B_h, B_d, valbytes, hipMemcpyDeviceToHost)); - for (uint32_t i = 0; i < LEN; i++) { - assert(A_h[i] == B_h[i]); - } + for (uint32_t i = 0; i < LEN; i++) { + assert(A_h[i] == B_h[i]); + } - HIP_ASSERT(hipFree(A_d)); - HIP_ASSERT(hipFree(B_d)); - free(A_h); - free(B_h); - std::cout << "Test Passed!\n"; + HIP_ASSERT(hipFree(A_d)); + HIP_ASSERT(hipFree(B_d)); + free(A_h); + free(B_h); + std::cout << "Test Passed!\n"; }