From 0e397a196d8fcce79964f11e31d76c8a3f5a2584 Mon Sep 17 00:00:00 2001 From: Nils Friess Date: Tue, 20 Feb 2024 15:10:34 +0100 Subject: [PATCH 1/2] Use out-of-place trmm functions if rocBLAS version >= 4.0.0 --- cmake/FindrocBLAS.cmake | 3 +++ src/blas/backends/rocblas/CMakeLists.txt | 4 ++++ src/blas/backends/rocblas/rocblas_level3.cpp | 18 ++++++++++++++++++ 3 files changed, 25 insertions(+) diff --git a/cmake/FindrocBLAS.cmake b/cmake/FindrocBLAS.cmake index bbcb56664..c545bfeb4 100644 --- a/cmake/FindrocBLAS.cmake +++ b/cmake/FindrocBLAS.cmake @@ -34,6 +34,7 @@ list(APPEND CMAKE_PREFIX_PATH find_package(HIP QUIET) find_package(rocblas REQUIRED) +set(ROCBLAS_VERSION ${rocblas_VERSION}) # this is work around to avoid duplication half creation in both HIP and SYCL add_compile_definitions(HIP_NO_HALF) @@ -47,6 +48,8 @@ find_package_handle_standard_args(rocBLAS HIP_LIBRARIES ROCBLAS_INCLUDE_DIR ROCBLAS_LIBRARIES + VERSION_VAR + ROCBLAS_VERSION ) # OPENCL_INCLUDE_DIR if(NOT TARGET ONEMKL::rocBLAS::rocBLAS) diff --git a/src/blas/backends/rocblas/CMakeLists.txt b/src/blas/backends/rocblas/CMakeLists.txt index 0d5559155..c5b9a20ca 100644 --- a/src/blas/backends/rocblas/CMakeLists.txt +++ b/src/blas/backends/rocblas/CMakeLists.txt @@ -41,6 +41,10 @@ target_include_directories(${LIB_OBJ} ${ONEMKL_GENERATED_INCLUDE_PATH} ) +if (${ROCBLAS_VERSION} VERSION_GREATER_EQUAL "4.0") + target_compile_definitions(${LIB_OBJ} PRIVATE ROCBLAS_NO_LEGACY_TRMM) +endif() + if(NOT ${ONEMKL_SYCL_IMPLEMENTATION} STREQUAL "hipsycl") target_compile_options(${LIB_OBJ} PRIVATE ${ONEMKL_BUILD_COPT}) target_compile_options(ONEMKL::SYCL::SYCL INTERFACE diff --git a/src/blas/backends/rocblas/rocblas_level3.cpp b/src/blas/backends/rocblas/rocblas_level3.cpp index ec6dd220d..7abb8f287 100644 --- a/src/blas/backends/rocblas/rocblas_level3.cpp +++ b/src/blas/backends/rocblas/rocblas_level3.cpp @@ -381,10 +381,19 @@ inline void trmm(Func func, sycl::queue &queue, side left_right, uplo upper_lowe auto a_ = sc.get_mem(a_acc); auto b_ = sc.get_mem(b_acc); rocblas_status err; + +// rocblas version 4.0.0 removed the legacy BLAS trmm implementation +#ifdef ROCBLAS_NO_LEGACY_TRMM ROCBLAS_ERROR_FUNC_SYNC(func, err, handle, get_rocblas_side_mode(left_right), + get_rocblas_fill_mode(upper_lower), + get_rocblas_operation(trans), get_rocblas_diag_type(unit_diag), + m, n, (rocDataType *)&alpha, a_, lda, b_, ldb, b_, ldb); +#else + ROCBLAS_ERROR_FUNC_SYNC(func, err, handle, get_rocblas_side_mode(left_right), get_rocblas_fill_mode(upper_lower), get_rocblas_operation(trans), get_rocblas_diag_type(unit_diag), m, n, (rocDataType *)&alpha, a_, lda, b_, ldb); +#endif }); }); } @@ -805,10 +814,19 @@ inline sycl::event trmm(Func func, sycl::queue &queue, side left_right, uplo upp auto a_ = reinterpret_cast(a); auto b_ = reinterpret_cast(b); rocblas_status err; + +// rocblas version 4.0.0 removed the legacy BLAS trmm implementation +#ifdef ROCBLAS_NO_LEGACY_TRMM + ROCBLAS_ERROR_FUNC_SYNC(func, err, handle, get_rocblas_side_mode(left_right), + get_rocblas_fill_mode(upper_lower), + get_rocblas_operation(trans), get_rocblas_diag_type(unit_diag), + m, n, (rocDataType *)&alpha, a_, lda, b_, ldb, b_, ldb); +#else ROCBLAS_ERROR_FUNC_SYNC(func, err, handle, get_rocblas_side_mode(left_right), get_rocblas_fill_mode(upper_lower), get_rocblas_operation(trans), get_rocblas_diag_type(unit_diag), m, n, (rocDataType *)&alpha, a_, lda, b_, ldb); +#endif }); }); From 643f610adec3b1d71554cb81fb655f1aaa5f4f66 Mon Sep 17 00:00:00 2001 From: Nils Friess Date: Tue, 20 Feb 2024 15:13:57 +0100 Subject: [PATCH 2/2] Use rocblas_INCLUDE_DIR to define path to librocblas --- cmake/FindrocBLAS.cmake | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/cmake/FindrocBLAS.cmake b/cmake/FindrocBLAS.cmake index c545bfeb4..1ffed2d32 100644 --- a/cmake/FindrocBLAS.cmake +++ b/cmake/FindrocBLAS.cmake @@ -51,11 +51,18 @@ find_package_handle_standard_args(rocBLAS VERSION_VAR ROCBLAS_VERSION ) + +if (DEFINED rocblas_INCLUDE_DIR) + set(ROCBLAS_LIB_PATH "${rocblas_INCLUDE_DIR}/../lib/librocblas.so") +else() + set(ROCBLAS_LIB_PATH "${HIP_PATH}/../rocblas/lib/librocblas.so") +endif() + # OPENCL_INCLUDE_DIR if(NOT TARGET ONEMKL::rocBLAS::rocBLAS) add_library(ONEMKL::rocBLAS::rocBLAS SHARED IMPORTED) set_target_properties(ONEMKL::rocBLAS::rocBLAS PROPERTIES - IMPORTED_LOCATION "${HIP_PATH}/../rocblas/lib/librocblas.so" + IMPORTED_LOCATION "${ROCBLAS_LIB_PATH}" INTERFACE_INCLUDE_DIRECTORIES "${ROCBLAS_INCLUDE_DIR};${HIP_INCLUDE_DIRS};" INTERFACE_LINK_LIBRARIES "Threads::Threads;${ROCBLAS_LIBRARIES};" )