From 1850afb84a10ccc833c8875dea9501ba7f5514d4 Mon Sep 17 00:00:00 2001 From: James Sandham <33790278+jsandham@users.noreply.github.com> Date: Wed, 18 Jun 2025 11:18:48 -0400 Subject: [PATCH 1/2] Revert "Better handle building rocSPARSE with ROC-TX (#484)" (#511) This reverts commit eb9b5cd7762d9d9a70681d2f3841fe6643af97cc. --- clients/benchmarks/CMakeLists.txt | 5 +-- clients/tests/CMakeLists.txt | 5 +-- cmake/Findroctx.cmake | 72 ------------------------------- library/CMakeLists.txt | 3 +- 4 files changed, 5 insertions(+), 80 deletions(-) delete mode 100644 cmake/Findroctx.cmake diff --git a/clients/benchmarks/CMakeLists.txt b/clients/benchmarks/CMakeLists.txt index 55040b64b..02a2d0ab4 100644 --- a/clients/benchmarks/CMakeLists.txt +++ b/clients/benchmarks/CMakeLists.txt @@ -231,9 +231,8 @@ if (NOT WIN32) endif() if (NOT WIN32) - if(BUILD_WITH_ROCTX) - find_package(roctx REQUIRED) - target_link_libraries(rocsparse-bench PRIVATE roctx::roctx) + if (BUILD_WITH_ROCTX) + target_link_libraries(rocsparse-bench PRIVATE -lroctx64) target_compile_definitions( rocsparse-bench PRIVATE ROCSPARSE_CLIENTS_WITH_ROCTX ) endif() endif() diff --git a/clients/tests/CMakeLists.txt b/clients/tests/CMakeLists.txt index 2fe4abca2..d26a10cdf 100644 --- a/clients/tests/CMakeLists.txt +++ b/clients/tests/CMakeLists.txt @@ -415,9 +415,8 @@ if (NOT WIN32) endif() if (NOT WIN32) - if(BUILD_WITH_ROCTX) - find_package(roctx REQUIRED) - target_link_libraries(rocsparse-test PRIVATE roctx::roctx) + if (BUILD_WITH_ROCTX) + target_link_libraries(rocsparse-test PRIVATE -lroctx64) target_compile_definitions( rocsparse-test PRIVATE ROCSPARSE_CLIENTS_WITH_ROCTX ) endif() endif() diff --git a/cmake/Findroctx.cmake b/cmake/Findroctx.cmake deleted file mode 100644 index 33f692161..000000000 --- a/cmake/Findroctx.cmake +++ /dev/null @@ -1,72 +0,0 @@ -# ######################################################################## -# 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 43eabf421..902ffbe55 100644 --- a/library/CMakeLists.txt +++ b/library/CMakeLists.txt @@ -95,8 +95,7 @@ endif() if (NOT WIN32) if (BUILD_SHARED_LIBS AND BUILD_WITH_ROCTX) - find_package(roctx REQUIRED) - target_link_libraries(rocsparse PRIVATE roctx::roctx) + target_link_libraries(rocsparse PRIVATE -lroctx64) target_compile_definitions( rocsparse PRIVATE ROCSPARSE_BUILT_WITH_ROCTX ) endif() endif() From 00f92a166077dc656f000a35c38107e89a451661 Mon Sep 17 00:00:00 2001 From: James Sandham <33790278+jsandham@users.noreply.github.com> Date: Fri, 20 Jun 2025 08:43:01 -0400 Subject: [PATCH 2/2] Handle ROCTX using find_path and find_library instead of Findroctx.cmake module (#513) * Alternate way to handle building rocsparse with roctx since we cannot use Findroctx.cmake modules --- clients/benchmarks/CMakeLists.txt | 11 ++++++-- clients/tests/CMakeLists.txt | 10 +++++-- library/CMakeLists.txt | 46 +++++++++++++++++++++++++++++-- 3 files changed, 61 insertions(+), 6 deletions(-) diff --git a/clients/benchmarks/CMakeLists.txt b/clients/benchmarks/CMakeLists.txt index 02a2d0ab4..e23bbf958 100644 --- a/clients/benchmarks/CMakeLists.txt +++ b/clients/benchmarks/CMakeLists.txt @@ -232,8 +232,15 @@ 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 ) + + if(ROCTRACER_INCLUDE_DIR AND 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 ) + endif() endif() endif() diff --git a/clients/tests/CMakeLists.txt b/clients/tests/CMakeLists.txt index d26a10cdf..f5611d52b 100644 --- a/clients/tests/CMakeLists.txt +++ b/clients/tests/CMakeLists.txt @@ -416,8 +416,14 @@ 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 ) + if(ROCTRACER_INCLUDE_DIR AND 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 ) + endif() endif() endif() diff --git a/library/CMakeLists.txt b/library/CMakeLists.txt index 902ffbe55..7defb2de8 100644 --- a/library/CMakeLists.txt +++ b/library/CMakeLists.txt @@ -95,8 +95,50 @@ 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 + ${ROCTX_PATH}/lib64 + PATHS + /opt/rocm/lib # Default ROCm 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()