diff --git a/clients/benchmarks/CMakeLists.txt b/clients/benchmarks/CMakeLists.txt index 55040b64b..e23bbf958 100644 --- a/clients/benchmarks/CMakeLists.txt +++ b/clients/benchmarks/CMakeLists.txt @@ -231,10 +231,16 @@ if (NOT WIN32) endif() if (NOT WIN32) - 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 ) + if (BUILD_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 2fe4abca2..f5611d52b 100644 --- a/clients/tests/CMakeLists.txt +++ b/clients/tests/CMakeLists.txt @@ -415,10 +415,15 @@ if (NOT WIN32) endif() if (NOT WIN32) - 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 ) + if (BUILD_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/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..7defb2de8 100644 --- a/library/CMakeLists.txt +++ b/library/CMakeLists.txt @@ -95,9 +95,50 @@ endif() if (NOT WIN32) 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 ) + + 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()