From dd4541f38ad68311a9191ecb9f87d17aca8ed82b Mon Sep 17 00:00:00 2001 From: jsandham Date: Fri, 30 May 2025 19:43:24 +0000 Subject: [PATCH 1/6] Better handle building with roctx when it is not available --- clients/benchmarks/CMakeLists.txt | 46 ++++++++++++++++++++++- clients/tests/CMakeLists.txt | 45 +++++++++++++++++++++- library/CMakeLists.txt | 62 ++++++++++++++++++++++++++++++- 3 files changed, 148 insertions(+), 5 deletions(-) diff --git a/clients/benchmarks/CMakeLists.txt b/clients/benchmarks/CMakeLists.txt index 02a2d0ab4..24ba431bf 100644 --- a/clients/benchmarks/CMakeLists.txt +++ b/clients/benchmarks/CMakeLists.txt @@ -232,8 +232,50 @@ endif() if (NOT WIN32) if (BUILD_WITH_ROCTX) - target_link_libraries(rocsparse-bench PRIVATE -lroctx64) - target_compile_definitions( rocsparse-bench PRIVATE ROCSPARSE_CLIENTS_WITH_ROCTX ) + + set(ROCTX_PATH "" CACHE STRING "Path to the roctx library (directory containing libroctx64.so)") + + find_path(ROCTRACER_INCLUDE_DIR + NAMES roctracer/roctx.h + HINTS + ${ROCTX_PATH} + ${ROCTX_PATH}/include + /opt/rocm/include + ${ROCTX_PATH}/../include + DOC "Path to the roctracer include directory containing roctx.h") + + find_library(ROCTX_LIBRARY + NAMES roctx64 + HINTS + ${ROCTX_PATH} # User-provided path + ${ROCTX_PATH}/lib + PATHS + /opt/rocm/lib # Default ROCm path + NO_DEFAULT_PATH + ) + + if(ROCTRACER_INCLUDE_DIR AND ROCTX_LIBRARY) + message(STATUS "Found roctracer include directory: ${ROCTRACER_INCLUDE_DIR}") + message(STATUS "Found roctx library: ${ROCTX_LIBRARY}") + + # Add the include directory + target_include_directories(rocsparse-bench PRIVATE ${ROCTRACER_INCLUDE_DIR}) + + # Link the rocTx lib + target_link_libraries(rocsparse-bench PRIVATE ${ROCTX_LIBRARY}) + target_compile_definitions( rocsparse-bench PRIVATE ROCSPARSE_CLIENTS_WITH_ROCTX ) + message(STATUS "ROCTX tracing support enabled for target rocsparse-bench.") + else() + message(WARNING "ROCTX tracing will be disabled for target rocsparse-bench.") + + if(NOT ROCTRACER_INCLUDE_DIR) + message(WARNING "Header 'roctracer/roctx.h' not found.") + endif() + + if(NOT ROCTX_LIBRARY) + message(WARNING "Library 'roctx64' not found. ROCTX_PATH: '${ROCTX_PATH}' Default PATH: '/opt/rocm/lib'.") + endif() + endif() endif() endif() diff --git a/clients/tests/CMakeLists.txt b/clients/tests/CMakeLists.txt index d26a10cdf..c09eb69cc 100644 --- a/clients/tests/CMakeLists.txt +++ b/clients/tests/CMakeLists.txt @@ -416,8 +416,49 @@ endif() if (NOT WIN32) if (BUILD_WITH_ROCTX) - target_link_libraries(rocsparse-test PRIVATE -lroctx64) - target_compile_definitions( rocsparse-test PRIVATE ROCSPARSE_CLIENTS_WITH_ROCTX ) + set(ROCTX_PATH "" CACHE STRING "Path to the roctx library (directory containing libroctx64.so)") + + find_path(ROCTRACER_INCLUDE_DIR + NAMES roctracer/roctx.h + HINTS + ${ROCTX_PATH} + ${ROCTX_PATH}/include + /opt/rocm/include + ${ROCTX_PATH}/../include + DOC "Path to the roctracer include directory containing roctx.h") + + find_library(ROCTX_LIBRARY + NAMES roctx64 + HINTS + ${ROCTX_PATH} # User-provided path + ${ROCTX_PATH}/lib + PATHS + /opt/rocm/lib # Default ROCm path + NO_DEFAULT_PATH + ) + + if(ROCTRACER_INCLUDE_DIR AND ROCTX_LIBRARY) + message(STATUS "Found roctracer include directory: ${ROCTRACER_INCLUDE_DIR}") + message(STATUS "Found roctx library: ${ROCTX_LIBRARY}") + + # Add the include directory + target_include_directories(rocsparse-test PRIVATE ${ROCTRACER_INCLUDE_DIR}) + + # Link the rocTx lib + target_link_libraries(rocsparse-test PRIVATE ${ROCTX_LIBRARY}) + target_compile_definitions( rocsparse-test PRIVATE ROCSPARSE_CLIENTS_WITH_ROCTX ) + message(STATUS "ROCTX tracing support enabled for target rocsparse-test.") + else() + message(WARNING "ROCTX tracing will be disabled for target rocsparse-test.") + + if(NOT ROCTRACER_INCLUDE_DIR) + message(WARNING "Header 'roctracer/roctx.h' not found.") + endif() + + if(NOT ROCTX_LIBRARY) + message(WARNING "Library 'roctx64' not found. ROCTX_PATH: '${ROCTX_PATH}' Default PATH: '/opt/rocm/lib'.") + endif() + endif() endif() endif() diff --git a/library/CMakeLists.txt b/library/CMakeLists.txt index 902ffbe55..cf4a0ffe9 100644 --- a/library/CMakeLists.txt +++ b/library/CMakeLists.txt @@ -96,7 +96,67 @@ endif() if (NOT WIN32) if (BUILD_SHARED_LIBS AND BUILD_WITH_ROCTX) target_link_libraries(rocsparse PRIVATE -lroctx64) - target_compile_definitions( rocsparse PRIVATE ROCSPARSE_BUILT_WITH_ROCTX ) + + + + + + + + + + set(ROCTX_PATH "" CACHE STRING "Path to the roctx library (directory containing libroctx64.so)") + + find_path(ROCTRACER_INCLUDE_DIR + NAMES roctracer/roctx.h + HINTS + ${ROCTX_PATH} + ${ROCTX_PATH}/include + /opt/rocm/include + ${ROCTX_PATH}/../include + DOC "Path to the roctracer include directory containing roctx.h") + + find_library(ROCTX_LIBRARY + NAMES roctx64 + HINTS + ${ROCTX_PATH} # User-provided path + ${ROCTX_PATH}/lib + PATHS + /opt/rocm/lib # Default ROCm path + NO_DEFAULT_PATH + ) + + if(ROCTRACER_INCLUDE_DIR AND ROCTX_LIBRARY) + message(STATUS "Found roctracer include directory: ${ROCTRACER_INCLUDE_DIR}") + message(STATUS "Found roctx library: ${ROCTX_LIBRARY}") + + # Add the include directory + target_include_directories(rocsparse PRIVATE ${ROCTRACER_INCLUDE_DIR}) + + # Link the rocTx lib + target_link_libraries(rocsparse PRIVATE ${ROCTX_LIBRARY}) + target_compile_definitions( rocsparse PRIVATE ROCSPARSE_BUILT_WITH_ROCTX ) + message(STATUS "ROCTX tracing support enabled for target rocsparse.") + else() + message(WARNING "ROCTX tracing will be disabled for target rocsparse.") + + if(NOT ROCTRACER_INCLUDE_DIR) + message(WARNING "Header 'roctracer/roctx.h' not found.") + endif() + + if(NOT ROCTX_LIBRARY) + message(WARNING "Library 'roctx64' not found. ROCTX_PATH: '${ROCTX_PATH}' Default PATH: '/opt/rocm/lib'.") + endif() + endif() + + + + + + + + + endif() endif() From 4063e590a92958cc7981e95433ac0552d86ce2c1 Mon Sep 17 00:00:00 2001 From: jsandham Date: Fri, 30 May 2025 19:46:12 +0000 Subject: [PATCH 2/6] Better handle building with roctx when it is not available --- library/CMakeLists.txt | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/library/CMakeLists.txt b/library/CMakeLists.txt index cf4a0ffe9..a787e3842 100644 --- a/library/CMakeLists.txt +++ b/library/CMakeLists.txt @@ -95,15 +95,6 @@ endif() if (NOT WIN32) if (BUILD_SHARED_LIBS AND BUILD_WITH_ROCTX) - target_link_libraries(rocsparse PRIVATE -lroctx64) - - - - - - - - set(ROCTX_PATH "" CACHE STRING "Path to the roctx library (directory containing libroctx64.so)") @@ -148,15 +139,6 @@ if (NOT WIN32) message(WARNING "Library 'roctx64' not found. ROCTX_PATH: '${ROCTX_PATH}' Default PATH: '/opt/rocm/lib'.") endif() endif() - - - - - - - - - endif() endif() From 9775f0fe5a84b8b01108cb18da4c75b941c7ad12 Mon Sep 17 00:00:00 2001 From: jsandham Date: Tue, 3 Jun 2025 14:41:15 +0000 Subject: [PATCH 3/6] PR fixes --- CMakeLists.txt | 1 - clients/benchmarks/CMakeLists.txt | 71 +++++++++++++------------- clients/tests/CMakeLists.txt | 84 +++++++++++++++---------------- install.sh | 11 ---- library/CMakeLists.txt | 2 +- 5 files changed, 76 insertions(+), 93 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9f95d30fd..e1c20f3c5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -86,7 +86,6 @@ option(BUILD_MEMSTAT "Build rocSPARSE with memory statistics enabled" OFF) option(BUILD_ROCSPARSE_ILP64 "Build rocSPARSE with rocsparse_int equal to int64_t" OFF) option(BUILD_COMPRESSED_DBG "Enable compressed debug symbols" ON) option(BUILD_WITH_ROCBLAS "Enable building rocSPARSE with rocBLAS" ON) -option(BUILD_WITH_ROCTX "Enable building rocSPARSE with rocTX" ON) option(BUILD_WITH_OFFLOAD_COMPRESS "Enable offload compression during compilation" ON) diff --git a/clients/benchmarks/CMakeLists.txt b/clients/benchmarks/CMakeLists.txt index 24ba431bf..ce4ee7ce2 100644 --- a/clients/benchmarks/CMakeLists.txt +++ b/clients/benchmarks/CMakeLists.txt @@ -231,50 +231,47 @@ if (NOT WIN32) endif() if (NOT WIN32) - if (BUILD_WITH_ROCTX) + set(ROCTX_PATH "" CACHE STRING "Path to the roctx library (directory containing libroctx64.so)") - set(ROCTX_PATH "" CACHE STRING "Path to the roctx library (directory containing libroctx64.so)") + find_path(ROCTRACER_INCLUDE_DIR + NAMES roctracer/roctx.h + HINTS + ${ROCTX_PATH} + ${ROCTX_PATH}/include + /opt/rocm/include + ${ROCTX_PATH}/../include + DOC "Path to the roctracer include directory containing roctx.h") - find_path(ROCTRACER_INCLUDE_DIR - NAMES roctracer/roctx.h - HINTS - ${ROCTX_PATH} - ${ROCTX_PATH}/include - /opt/rocm/include - ${ROCTX_PATH}/../include - DOC "Path to the roctracer include directory containing roctx.h") + find_library(ROCTX_LIBRARY + NAMES roctx64 + HINTS + ${ROCTX_PATH} # User-provided path + ${ROCTX_PATH}/lib + PATHS + /opt/rocm/lib # Default ROCm path + NO_DEFAULT_PATH + ) - find_library(ROCTX_LIBRARY - NAMES roctx64 - HINTS - ${ROCTX_PATH} # User-provided path - ${ROCTX_PATH}/lib - PATHS - /opt/rocm/lib # Default ROCm path - NO_DEFAULT_PATH - ) + if(ROCTRACER_INCLUDE_DIR AND ROCTX_LIBRARY) + message(STATUS "Found roctracer include directory: ${ROCTRACER_INCLUDE_DIR}") + message(STATUS "Found roctx library: ${ROCTX_LIBRARY}") - if(ROCTRACER_INCLUDE_DIR AND ROCTX_LIBRARY) - message(STATUS "Found roctracer include directory: ${ROCTRACER_INCLUDE_DIR}") - message(STATUS "Found roctx library: ${ROCTX_LIBRARY}") + # Add the include directory + target_include_directories(rocsparse-bench PRIVATE ${ROCTRACER_INCLUDE_DIR}) - # Add the include directory - target_include_directories(rocsparse-bench PRIVATE ${ROCTRACER_INCLUDE_DIR}) - - # Link the rocTx lib - target_link_libraries(rocsparse-bench PRIVATE ${ROCTX_LIBRARY}) - target_compile_definitions( rocsparse-bench PRIVATE ROCSPARSE_CLIENTS_WITH_ROCTX ) - message(STATUS "ROCTX tracing support enabled for target rocsparse-bench.") - else() - message(WARNING "ROCTX tracing will be disabled for target rocsparse-bench.") + # Link the rocTx lib + target_link_libraries(rocsparse-bench PRIVATE ${ROCTX_LIBRARY}) + target_compile_definitions( rocsparse-bench PRIVATE ROCSPARSE_CLIENTS_WITH_ROCTX ) + message(STATUS "ROCTX tracing support enabled for target rocsparse-bench.") + else() + message(WARNING "ROCTX tracing will be disabled for target rocsparse-bench.") - if(NOT ROCTRACER_INCLUDE_DIR) - message(WARNING "Header 'roctracer/roctx.h' not found.") - endif() + if(NOT ROCTRACER_INCLUDE_DIR) + message(WARNING "Header 'roctracer/roctx.h' not found.") + endif() - if(NOT ROCTX_LIBRARY) - message(WARNING "Library 'roctx64' not found. ROCTX_PATH: '${ROCTX_PATH}' Default PATH: '/opt/rocm/lib'.") - endif() + if(NOT ROCTX_LIBRARY) + message(WARNING "Library 'roctx64' not found. ROCTX_PATH: '${ROCTX_PATH}' Default PATH: '/opt/rocm/lib'.") endif() endif() endif() diff --git a/clients/tests/CMakeLists.txt b/clients/tests/CMakeLists.txt index c09eb69cc..1d84b3a63 100644 --- a/clients/tests/CMakeLists.txt +++ b/clients/tests/CMakeLists.txt @@ -415,49 +415,47 @@ if (NOT WIN32) endif() if (NOT WIN32) - if (BUILD_WITH_ROCTX) - set(ROCTX_PATH "" CACHE STRING "Path to the roctx library (directory containing libroctx64.so)") - - find_path(ROCTRACER_INCLUDE_DIR - NAMES roctracer/roctx.h - HINTS - ${ROCTX_PATH} - ${ROCTX_PATH}/include - /opt/rocm/include - ${ROCTX_PATH}/../include - DOC "Path to the roctracer include directory containing roctx.h") - - find_library(ROCTX_LIBRARY - NAMES roctx64 - HINTS - ${ROCTX_PATH} # User-provided path - ${ROCTX_PATH}/lib - PATHS - /opt/rocm/lib # Default ROCm path - NO_DEFAULT_PATH - ) - - if(ROCTRACER_INCLUDE_DIR AND ROCTX_LIBRARY) - message(STATUS "Found roctracer include directory: ${ROCTRACER_INCLUDE_DIR}") - message(STATUS "Found roctx library: ${ROCTX_LIBRARY}") - - # Add the include directory - target_include_directories(rocsparse-test PRIVATE ${ROCTRACER_INCLUDE_DIR}) - - # Link the rocTx lib - target_link_libraries(rocsparse-test PRIVATE ${ROCTX_LIBRARY}) - target_compile_definitions( rocsparse-test PRIVATE ROCSPARSE_CLIENTS_WITH_ROCTX ) - message(STATUS "ROCTX tracing support enabled for target rocsparse-test.") - else() - message(WARNING "ROCTX tracing will be disabled for target rocsparse-test.") - - if(NOT ROCTRACER_INCLUDE_DIR) - message(WARNING "Header 'roctracer/roctx.h' not found.") - endif() - - if(NOT ROCTX_LIBRARY) - message(WARNING "Library 'roctx64' not found. ROCTX_PATH: '${ROCTX_PATH}' Default PATH: '/opt/rocm/lib'.") - endif() + set(ROCTX_PATH "" CACHE STRING "Path to the roctx library (directory containing libroctx64.so)") + + find_path(ROCTRACER_INCLUDE_DIR + NAMES roctracer/roctx.h + HINTS + ${ROCTX_PATH} + ${ROCTX_PATH}/include + /opt/rocm/include + ${ROCTX_PATH}/../include + DOC "Path to the roctracer include directory containing roctx.h") + + find_library(ROCTX_LIBRARY + NAMES roctx64 + HINTS + ${ROCTX_PATH} # User-provided path + ${ROCTX_PATH}/lib + PATHS + /opt/rocm/lib # Default ROCm path + NO_DEFAULT_PATH + ) + + if(ROCTRACER_INCLUDE_DIR AND ROCTX_LIBRARY) + message(STATUS "Found roctracer include directory: ${ROCTRACER_INCLUDE_DIR}") + message(STATUS "Found roctx library: ${ROCTX_LIBRARY}") + + # Add the include directory + target_include_directories(rocsparse-test PRIVATE ${ROCTRACER_INCLUDE_DIR}) + + # Link the rocTx lib + target_link_libraries(rocsparse-test PRIVATE ${ROCTX_LIBRARY}) + target_compile_definitions( rocsparse-test PRIVATE ROCSPARSE_CLIENTS_WITH_ROCTX ) + message(STATUS "ROCTX tracing support enabled for target rocsparse-test.") + else() + message(WARNING "ROCTX tracing will be disabled for target rocsparse-test.") + + if(NOT ROCTRACER_INCLUDE_DIR) + message(WARNING "Header 'roctracer/roctx.h' not found.") + endif() + + if(NOT ROCTX_LIBRARY) + message(WARNING "Library 'roctx64' not found. ROCTX_PATH: '${ROCTX_PATH}' Default PATH: '/opt/rocm/lib'.") endif() endif() endif() diff --git a/install.sh b/install.sh index d234afc98..10506d3c3 100755 --- a/install.sh +++ b/install.sh @@ -308,7 +308,6 @@ build_address_sanitizer=false build_memstat=false build_rocsparse_ILP64=false build_with_rocblas=true -build_with_roctx=true build_with_offload_compress=true matrices_dir= matrices_dir_install= @@ -389,9 +388,6 @@ while true; do --no-rocblas) build_with_rocblas=false shift ;; - --no-roctx) - build_with_roctx=false - shift ;; -k|--relwithdebinfo) build_release=false build_release_debug=true @@ -595,13 +591,6 @@ pushd . cmake_common_options+=("-DBUILD_WITH_ROCBLAS=OFF") fi - # roctx - if [[ "${build_with_roctx}" == true ]]; then - cmake_common_options+=("-DBUILD_WITH_ROCTX=ON") - else - cmake_common_options+=("-DBUILD_WITH_ROCTX=OFF") - fi - # freorg backward compatible support enable if [[ "${build_freorg_bkwdcomp}" == true ]]; then cmake_common_options+=("-DBUILD_FILE_REORG_BACKWARD_COMPATIBILITY=ON") diff --git a/library/CMakeLists.txt b/library/CMakeLists.txt index a787e3842..88835bb34 100644 --- a/library/CMakeLists.txt +++ b/library/CMakeLists.txt @@ -94,7 +94,7 @@ if (BUILD_WITH_ROCBLAS AND rocblas_FOUND) endif() if (NOT WIN32) - if (BUILD_SHARED_LIBS AND BUILD_WITH_ROCTX) + if (BUILD_SHARED_LIBS) set(ROCTX_PATH "" CACHE STRING "Path to the roctx library (directory containing libroctx64.so)") From d63bd657dcb9590d943df2bc65b0ef4a074a5c34 Mon Sep 17 00:00:00 2001 From: jsandham Date: Wed, 4 Jun 2025 19:59:32 +0000 Subject: [PATCH 4/6] PR fixes --- clients/benchmarks/CMakeLists.txt | 36 +++------------- clients/tests/CMakeLists.txt | 36 +++------------- cmake/Findroctx.cmake | 72 +++++++++++++++++++++++++++++++ library/CMakeLists.txt | 36 +++------------- 4 files changed, 87 insertions(+), 93 deletions(-) create mode 100644 cmake/Findroctx.cmake diff --git a/clients/benchmarks/CMakeLists.txt b/clients/benchmarks/CMakeLists.txt index ce4ee7ce2..0312b351f 100644 --- a/clients/benchmarks/CMakeLists.txt +++ b/clients/benchmarks/CMakeLists.txt @@ -231,47 +231,21 @@ if (NOT WIN32) endif() if (NOT WIN32) - set(ROCTX_PATH "" CACHE STRING "Path to the roctx library (directory containing libroctx64.so)") + find_package(roctx) - find_path(ROCTRACER_INCLUDE_DIR - NAMES roctracer/roctx.h - HINTS - ${ROCTX_PATH} - ${ROCTX_PATH}/include - /opt/rocm/include - ${ROCTX_PATH}/../include - DOC "Path to the roctracer include directory containing roctx.h") - - find_library(ROCTX_LIBRARY - NAMES roctx64 - HINTS - ${ROCTX_PATH} # User-provided path - ${ROCTX_PATH}/lib - PATHS - /opt/rocm/lib # Default ROCm path - NO_DEFAULT_PATH - ) - - if(ROCTRACER_INCLUDE_DIR AND ROCTX_LIBRARY) - message(STATUS "Found roctracer include directory: ${ROCTRACER_INCLUDE_DIR}") - message(STATUS "Found roctx library: ${ROCTX_LIBRARY}") - - # Add the include directory - target_include_directories(rocsparse-bench PRIVATE ${ROCTRACER_INCLUDE_DIR}) - - # Link the rocTx lib - target_link_libraries(rocsparse-bench PRIVATE ${ROCTX_LIBRARY}) + if(ROCTX_FOUND) + target_link_libraries(rocsparse-bench PRIVATE roctx::roctx) target_compile_definitions( rocsparse-bench PRIVATE ROCSPARSE_CLIENTS_WITH_ROCTX ) message(STATUS "ROCTX tracing support enabled for target rocsparse-bench.") else() message(WARNING "ROCTX tracing will be disabled for target rocsparse-bench.") - if(NOT ROCTRACER_INCLUDE_DIR) + if(NOT ROCTX_INCLUDE_DIR) message(WARNING "Header 'roctracer/roctx.h' not found.") endif() if(NOT ROCTX_LIBRARY) - message(WARNING "Library 'roctx64' not found. ROCTX_PATH: '${ROCTX_PATH}' Default PATH: '/opt/rocm/lib'.") + message(WARNING "Library 'roctx64' not found.") endif() endif() endif() diff --git a/clients/tests/CMakeLists.txt b/clients/tests/CMakeLists.txt index 1d84b3a63..91d0218e1 100644 --- a/clients/tests/CMakeLists.txt +++ b/clients/tests/CMakeLists.txt @@ -415,47 +415,21 @@ if (NOT WIN32) endif() if (NOT WIN32) - set(ROCTX_PATH "" CACHE STRING "Path to the roctx library (directory containing libroctx64.so)") + find_package(roctx) - find_path(ROCTRACER_INCLUDE_DIR - NAMES roctracer/roctx.h - HINTS - ${ROCTX_PATH} - ${ROCTX_PATH}/include - /opt/rocm/include - ${ROCTX_PATH}/../include - DOC "Path to the roctracer include directory containing roctx.h") - - find_library(ROCTX_LIBRARY - NAMES roctx64 - HINTS - ${ROCTX_PATH} # User-provided path - ${ROCTX_PATH}/lib - PATHS - /opt/rocm/lib # Default ROCm path - NO_DEFAULT_PATH - ) - - if(ROCTRACER_INCLUDE_DIR AND ROCTX_LIBRARY) - message(STATUS "Found roctracer include directory: ${ROCTRACER_INCLUDE_DIR}") - message(STATUS "Found roctx library: ${ROCTX_LIBRARY}") - - # Add the include directory - target_include_directories(rocsparse-test PRIVATE ${ROCTRACER_INCLUDE_DIR}) - - # Link the rocTx lib - target_link_libraries(rocsparse-test PRIVATE ${ROCTX_LIBRARY}) + if(ROCTX_FOUND) + target_link_libraries(rocsparse-test PRIVATE roctx::roctx) target_compile_definitions( rocsparse-test PRIVATE ROCSPARSE_CLIENTS_WITH_ROCTX ) message(STATUS "ROCTX tracing support enabled for target rocsparse-test.") else() message(WARNING "ROCTX tracing will be disabled for target rocsparse-test.") - if(NOT ROCTRACER_INCLUDE_DIR) + if(NOT ROCTX_INCLUDE_DIR) message(WARNING "Header 'roctracer/roctx.h' not found.") endif() if(NOT ROCTX_LIBRARY) - message(WARNING "Library 'roctx64' not found. ROCTX_PATH: '${ROCTX_PATH}' Default PATH: '/opt/rocm/lib'.") + message(WARNING "Library 'roctx64' not found.") endif() endif() endif() diff --git a/cmake/Findroctx.cmake b/cmake/Findroctx.cmake new file mode 100644 index 000000000..33f692161 --- /dev/null +++ b/cmake/Findroctx.cmake @@ -0,0 +1,72 @@ +# ######################################################################## +# Copyright (C) 2025 Advanced Micro Devices, Inc. All rights reserved. +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell cop- +# ies of the Software, and to permit persons to whom the Software is furnished +# to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IM- +# PLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNE- +# CTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# +# ######################################################################## + +#[=======================================================================[.rst: +Findroctx +---------- + +Find the roctx library + +Imported targets +^^^^^^^^^^^^^^^^ + +This module defines the :prop_tgt:`IMPORTED` target if roctx is found: + +``roctx::roctx`` + +Result Variables +^^^^^^^^^^^^^^^^ + +This module defines the following variables: + +``ROCTX_INCLUDE_DIR`` +``ROCTX_LIBRARY`` +``ROCTX_LIBRARIES`` +``ROCTX_FOUND`` + +#]=======================================================================] + +find_path(ROCTX_INCLUDE_DIR + NAMES roctx.h + PATH_SUFFIXES roctracer + ) +find_library(ROCTX_LIBRARY roctx64) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(roctx ROCTX_INCLUDE_DIR ROCTX_LIBRARY) + +if(ROCTX_FOUND) + if(NOT DEFINED ROCTX_LIBRARIES) + set(ROCTX_LIBRARIES ${ROCTX_LIBRARY}) + endif() + + if(NOT TARGET roctx::roctx) + add_library(roctx::roctx UNKNOWN IMPORTED) + + set_target_properties(roctx::roctx PROPERTIES + IMPORTED_LOCATION "${ROCTX_LIBRARY}" + ) + set_target_properties(roctx::roctx PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${ROCTX_INCLUDE_DIR}" + ) + endif() +endif() diff --git a/library/CMakeLists.txt b/library/CMakeLists.txt index 88835bb34..9b3f14724 100644 --- a/library/CMakeLists.txt +++ b/library/CMakeLists.txt @@ -96,47 +96,21 @@ endif() if (NOT WIN32) if (BUILD_SHARED_LIBS) - set(ROCTX_PATH "" CACHE STRING "Path to the roctx library (directory containing libroctx64.so)") - - find_path(ROCTRACER_INCLUDE_DIR - NAMES roctracer/roctx.h - HINTS - ${ROCTX_PATH} - ${ROCTX_PATH}/include - /opt/rocm/include - ${ROCTX_PATH}/../include - DOC "Path to the roctracer include directory containing roctx.h") - - find_library(ROCTX_LIBRARY - NAMES roctx64 - HINTS - ${ROCTX_PATH} # User-provided path - ${ROCTX_PATH}/lib - PATHS - /opt/rocm/lib # Default ROCm path - NO_DEFAULT_PATH - ) - - if(ROCTRACER_INCLUDE_DIR AND ROCTX_LIBRARY) - message(STATUS "Found roctracer include directory: ${ROCTRACER_INCLUDE_DIR}") - message(STATUS "Found roctx library: ${ROCTX_LIBRARY}") - - # Add the include directory - target_include_directories(rocsparse PRIVATE ${ROCTRACER_INCLUDE_DIR}) + find_package(roctx) - # Link the rocTx lib - target_link_libraries(rocsparse PRIVATE ${ROCTX_LIBRARY}) + if(ROCTX_FOUND) + target_link_libraries(rocsparse PRIVATE roctx::roctx) target_compile_definitions( rocsparse PRIVATE ROCSPARSE_BUILT_WITH_ROCTX ) message(STATUS "ROCTX tracing support enabled for target rocsparse.") else() message(WARNING "ROCTX tracing will be disabled for target rocsparse.") - if(NOT ROCTRACER_INCLUDE_DIR) + if(NOT ROCTX_INCLUDE_DIR) message(WARNING "Header 'roctracer/roctx.h' not found.") endif() if(NOT ROCTX_LIBRARY) - message(WARNING "Library 'roctx64' not found. ROCTX_PATH: '${ROCTX_PATH}' Default PATH: '/opt/rocm/lib'.") + message(WARNING "Library 'roctx64' not found.") endif() endif() endif() From 635e94ab91a6148014fa8b68e2ab0dbb4071fd8a Mon Sep 17 00:00:00 2001 From: jsandham Date: Wed, 4 Jun 2025 22:08:13 +0000 Subject: [PATCH 5/6] PR fixes --- CMakeLists.txt | 1 + clients/benchmarks/CMakeLists.txt | 16 ++-------------- clients/tests/CMakeLists.txt | 16 ++-------------- install.sh | 11 +++++++++++ library/CMakeLists.txt | 23 ++++------------------- 5 files changed, 20 insertions(+), 47 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3fea0480d..d1f08e23b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -88,6 +88,7 @@ option(BUILD_COMPRESSED_DBG "Enable compressed debug symbols" ON) option(BUILD_WITH_ROCBLAS "Enable building rocSPARSE with rocBLAS" ON) option(BUILD_WITH_OFFLOAD_COMPRESS "Enable offload compression during compilation" ON) +option(BUILD_WITH_ROCTX "Enable building rocSPARSE with rocTX" ON) # Clients utilize rocsparse fortran API and a fortran compiler if( NOT BUILD_FORTRAN_CLIENTS ) diff --git a/clients/benchmarks/CMakeLists.txt b/clients/benchmarks/CMakeLists.txt index 0312b351f..55040b64b 100644 --- a/clients/benchmarks/CMakeLists.txt +++ b/clients/benchmarks/CMakeLists.txt @@ -231,22 +231,10 @@ if (NOT WIN32) endif() if (NOT WIN32) - find_package(roctx) - - if(ROCTX_FOUND) + if(BUILD_WITH_ROCTX) + find_package(roctx REQUIRED) target_link_libraries(rocsparse-bench PRIVATE roctx::roctx) target_compile_definitions( rocsparse-bench PRIVATE ROCSPARSE_CLIENTS_WITH_ROCTX ) - message(STATUS "ROCTX tracing support enabled for target rocsparse-bench.") - else() - message(WARNING "ROCTX tracing will be disabled for target rocsparse-bench.") - - if(NOT ROCTX_INCLUDE_DIR) - message(WARNING "Header 'roctracer/roctx.h' not found.") - endif() - - if(NOT ROCTX_LIBRARY) - message(WARNING "Library 'roctx64' not found.") - endif() endif() endif() diff --git a/clients/tests/CMakeLists.txt b/clients/tests/CMakeLists.txt index 91d0218e1..2fe4abca2 100644 --- a/clients/tests/CMakeLists.txt +++ b/clients/tests/CMakeLists.txt @@ -415,22 +415,10 @@ if (NOT WIN32) endif() if (NOT WIN32) - find_package(roctx) - - if(ROCTX_FOUND) + if(BUILD_WITH_ROCTX) + find_package(roctx REQUIRED) target_link_libraries(rocsparse-test PRIVATE roctx::roctx) target_compile_definitions( rocsparse-test PRIVATE ROCSPARSE_CLIENTS_WITH_ROCTX ) - message(STATUS "ROCTX tracing support enabled for target rocsparse-test.") - else() - message(WARNING "ROCTX tracing will be disabled for target rocsparse-test.") - - if(NOT ROCTX_INCLUDE_DIR) - message(WARNING "Header 'roctracer/roctx.h' not found.") - endif() - - if(NOT ROCTX_LIBRARY) - message(WARNING "Library 'roctx64' not found.") - endif() endif() endif() diff --git a/install.sh b/install.sh index 10506d3c3..d234afc98 100755 --- a/install.sh +++ b/install.sh @@ -308,6 +308,7 @@ build_address_sanitizer=false build_memstat=false build_rocsparse_ILP64=false build_with_rocblas=true +build_with_roctx=true build_with_offload_compress=true matrices_dir= matrices_dir_install= @@ -388,6 +389,9 @@ while true; do --no-rocblas) build_with_rocblas=false shift ;; + --no-roctx) + build_with_roctx=false + shift ;; -k|--relwithdebinfo) build_release=false build_release_debug=true @@ -591,6 +595,13 @@ pushd . cmake_common_options+=("-DBUILD_WITH_ROCBLAS=OFF") fi + # roctx + if [[ "${build_with_roctx}" == true ]]; then + cmake_common_options+=("-DBUILD_WITH_ROCTX=ON") + else + cmake_common_options+=("-DBUILD_WITH_ROCTX=OFF") + fi + # freorg backward compatible support enable if [[ "${build_freorg_bkwdcomp}" == true ]]; then cmake_common_options+=("-DBUILD_FILE_REORG_BACKWARD_COMPATIBILITY=ON") diff --git a/library/CMakeLists.txt b/library/CMakeLists.txt index 9b3f14724..43eabf421 100644 --- a/library/CMakeLists.txt +++ b/library/CMakeLists.txt @@ -94,25 +94,10 @@ if (BUILD_WITH_ROCBLAS AND rocblas_FOUND) endif() if (NOT WIN32) - if (BUILD_SHARED_LIBS) - - find_package(roctx) - - if(ROCTX_FOUND) - target_link_libraries(rocsparse PRIVATE roctx::roctx) - target_compile_definitions( rocsparse PRIVATE ROCSPARSE_BUILT_WITH_ROCTX ) - message(STATUS "ROCTX tracing support enabled for target rocsparse.") - else() - message(WARNING "ROCTX tracing will be disabled for target rocsparse.") - - if(NOT ROCTX_INCLUDE_DIR) - message(WARNING "Header 'roctracer/roctx.h' not found.") - endif() - - if(NOT ROCTX_LIBRARY) - message(WARNING "Library 'roctx64' not found.") - endif() - endif() + if (BUILD_SHARED_LIBS AND BUILD_WITH_ROCTX) + find_package(roctx REQUIRED) + target_link_libraries(rocsparse PRIVATE roctx::roctx) + target_compile_definitions( rocsparse PRIVATE ROCSPARSE_BUILT_WITH_ROCTX ) endif() endif() From 3d9fab0327db812a0372bf1ae6bac88b28ffb6f4 Mon Sep 17 00:00:00 2001 From: jsandham Date: Wed, 4 Jun 2025 22:12:48 +0000 Subject: [PATCH 6/6] PR fixes --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d1f08e23b..ce286b313 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -86,9 +86,9 @@ option(BUILD_MEMSTAT "Build rocSPARSE with memory statistics enabled" OFF) option(BUILD_ROCSPARSE_ILP64 "Build rocSPARSE with rocsparse_int equal to int64_t" OFF) option(BUILD_COMPRESSED_DBG "Enable compressed debug symbols" ON) option(BUILD_WITH_ROCBLAS "Enable building rocSPARSE with rocBLAS" ON) +option(BUILD_WITH_ROCTX "Enable building rocSPARSE with rocTX" ON) option(BUILD_WITH_OFFLOAD_COMPRESS "Enable offload compression during compilation" ON) -option(BUILD_WITH_ROCTX "Enable building rocSPARSE with rocTX" ON) # Clients utilize rocsparse fortran API and a fortran compiler if( NOT BUILD_FORTRAN_CLIENTS )