From 3883bd3e930271081e80e413b8d009bd35b2dbc0 Mon Sep 17 00:00:00 2001 From: David Galiffi Date: Mon, 10 Nov 2025 14:38:51 -0500 Subject: [PATCH] Support for TheRock builds (#1545) * Cleaning up some BUILD_ config variables The `ROCPROFSYS_BUILD_` settings were being translated to `BUILD_` for the old Dyninst dependencies. Remove this extra layer Add `rocprofiler_systems_add_option` for the `ROCPROFSYS_BUILD_` options, so there is a better description in the in the CMakeCache. * Changes to support USE_ROCM in TheRock builds * Removed `amd-smi::roctx` from Findamd-smi.cmake * Fix linking error on rocm-6.4 when including amd_smi * Format cmake * Fix typo in logs * Removing Findamd-smi.cmake * Refactor the cmake parameters for `amd-smi`. The `drm` libraries were only required ba amdsmi for rocm-6.4.0. There was no point adding them for other versions. --- projects/rocprofiler-systems/CMakeLists.txt | 12 +++ .../cmake/DyninstBoost.cmake | 10 +-- .../cmake/DyninstElfUtils.cmake | 12 +-- .../cmake/DyninstExternals.cmake | 21 ----- .../cmake/DyninstLibIberty.cmake | 6 +- .../cmake/DyninstTBB.cmake | 14 +-- .../cmake/Modules/Findamd-smi.cmake | 86 ------------------- .../rocprofiler-systems/cmake/Packages.cmake | 52 +++++++++-- 8 files changed, 77 insertions(+), 136 deletions(-) delete mode 100644 projects/rocprofiler-systems/cmake/Modules/Findamd-smi.cmake diff --git a/projects/rocprofiler-systems/CMakeLists.txt b/projects/rocprofiler-systems/CMakeLists.txt index 861df97f38..f45c79887e 100644 --- a/projects/rocprofiler-systems/CMakeLists.txt +++ b/projects/rocprofiler-systems/CMakeLists.txt @@ -214,6 +214,18 @@ rocprofiler_systems_add_option(ROCPROFSYS_USE_PYTHON "Enable Python support" OFF rocprofiler_systems_add_option(ROCPROFSYS_BUILD_DYNINST "Build dyninst from submodule" OFF ) +rocprofiler_systems_add_option(ROCPROFSYS_BUILD_ELFUTILS "Build elfutils from submodule" + OFF +) +rocprofiler_systems_add_option(ROCPROFSYS_BUILD_LIBIBERTY "Build libiberty from submodule" + OFF +) +rocprofiler_systems_add_option(ROCPROFSYS_BUILD_BOOST "Build boost from submodule" + OFF +) +rocprofiler_systems_add_option(ROCPROFSYS_BUILD_TBB "Build tbb from submodule" + OFF +) rocprofiler_systems_add_option(ROCPROFSYS_BUILD_LIBUNWIND "Build libunwind from submodule" ON ) diff --git a/projects/rocprofiler-systems/cmake/DyninstBoost.cmake b/projects/rocprofiler-systems/cmake/DyninstBoost.cmake index b14f113868..84d5e46b54 100644 --- a/projects/rocprofiler-systems/cmake/DyninstBoost.cmake +++ b/projects/rocprofiler-systems/cmake/DyninstBoost.cmake @@ -44,7 +44,7 @@ include_guard(GLOBAL) -if(NOT BUILD_BOOST) +if(NOT ROCPROFSYS_BUILD_BOOST) find_package(Boost) endif() @@ -153,13 +153,13 @@ set(_boost_components timer ) -if(NOT BUILD_BOOST) +if(NOT ROCPROFSYS_BUILD_BOOST) find_package(Boost ${Boost_MIN_VERSION} QUIET COMPONENTS ${_boost_components}) endif() # -------------- SOURCE BUILD ------------------------------------------------- -if(Boost_FOUND AND NOT BUILD_BOOST) +if(Boost_FOUND AND NOT ROCPROFSYS_BUILD_BOOST) # Force the cache entries to be updated Normally, these would not be exported. # However, we need them in the Testsuite set(Boost_INCLUDE_DIRS @@ -179,10 +179,10 @@ elseif(NOT Boost_FOUND AND STERILE_BUILD) rocprofiler_systems_message( FATAL_ERROR "Boost not found and cannot be downloaded because build is sterile." ) -elseif(NOT BUILD_BOOST) +elseif(NOT ROCPROFSYS_BUILD_BOOST) rocprofiler_systems_message( FATAL_ERROR - "Boost was not found. Either configure cmake to find Boost properly or set BUILD_BOOST=ON to download and build" + "Boost was not found. Either configure cmake to find Boost properly or set ROCPROFSYS_BUILD_BOOST=ON to download and build" ) else() rocprofiler_systems_add_option(BOOST_LINK_STATIC "Link to boost libraries statically" diff --git a/projects/rocprofiler-systems/cmake/DyninstElfUtils.cmake b/projects/rocprofiler-systems/cmake/DyninstElfUtils.cmake index 1ed36cb7f9..5f9e9492c6 100644 --- a/projects/rocprofiler-systems/cmake/DyninstElfUtils.cmake +++ b/projects/rocprofiler-systems/cmake/DyninstElfUtils.cmake @@ -28,7 +28,7 @@ include_guard(GLOBAL) -if(NOT BUILD_ELFUTILS) +if(NOT ROCPROFSYS_BUILD_ELFUTILS) find_package(Elfutils) endif() @@ -84,7 +84,7 @@ endforeach() # -------------- PACKAGES------------------------------------------------------ -if(NOT BUILD_ELFUTILS) +if(NOT ROCPROFSYS_BUILD_ELFUTILS) find_package(LibElf ${ElfUtils_MIN_VERSION}) # Don't search for libdw or libdebuginfod if we didn't find a suitable libelf @@ -123,10 +123,10 @@ elseif(NOT (LibElf_FOUND AND LibDwarf_FOUND) AND STERILE_BUILD) FATAL_ERROR "ElfUtils not found and cannot be downloaded because build is sterile." ) -elseif(NOT BUILD_ELFUTILS) +elseif(NOT ROCPROFSYS_BUILD_ELFUTILS) rocprofiler_systems_message( FATAL_ERROR - "ElfUtils was not found. Either configure cmake to find ElfUtils properly or set BUILD_ELFUTILS=ON to download and build" + "ElfUtils was not found. Either configure cmake to find ElfUtils properly or set ROCPROFSYS_BUILD_ELFUTILS=ON to download and build" ) else() # If we didn't find a suitable version on the system, then download one from the web @@ -188,8 +188,8 @@ else() CXX=${CMAKE_CXX_COMPILER} CXXFLAGS=-fPIC\ -O3 [=[LDFLAGS=-Wl,-rpath='$$ORIGIN']=] /configure --enable-install-elfh --prefix=${_eu_root} --disable-libdebuginfod - --disable-debuginfod --enable-thread-safety ${ElfUtils_CONFIG_OPTIONS} - --libdir=${_eu_root}/lib + --disable-debuginfod --enable-thread-safety --disable-nls + ${ElfUtils_CONFIG_OPTIONS} --libdir=${_eu_root}/lib BUILD_COMMAND make install BUILD_BYPRODUCTS ${_eu_build_byproducts} INSTALL_COMMAND "" diff --git a/projects/rocprofiler-systems/cmake/DyninstExternals.cmake b/projects/rocprofiler-systems/cmake/DyninstExternals.cmake index 92d6aa15bd..e8f4a95116 100644 --- a/projects/rocprofiler-systems/cmake/DyninstExternals.cmake +++ b/projects/rocprofiler-systems/cmake/DyninstExternals.cmake @@ -11,27 +11,6 @@ foreach(dep BOOST TBB ELFUTILS LIBIBERTY) endif() endforeach() -# Set BUILD_* to ON if ROCPROFSYS_BUILD_* is ON -foreach(dep BOOST TBB ELFUTILS LIBIBERTY) - if(ROCPROFSYS_BUILD_${dep}) - if(dep STREQUAL "BOOST") - rocprofiler_systems_add_option(BUILD_BOOST "Enable building Boost internally" - ON - ) - elseif(dep STREQUAL "TBB") - rocprofiler_systems_add_option(BUILD_TBB "Enable building TBB internally" ON) - elseif(dep STREQUAL "ELFUTILS") - rocprofiler_systems_add_option(BUILD_ELFUTILS - "Enable building elfutils internally" ON - ) - elseif(dep STREQUAL "LIBIBERTY") - rocprofiler_systems_add_option(BUILD_LIBIBERTY - "Enable building libiberty internally" ON - ) - endif() - endif() -endforeach() - set(TPL_STAGING_PREFIX "${PROJECT_BINARY_DIR}/external" CACHE PATH diff --git a/projects/rocprofiler-systems/cmake/DyninstLibIberty.cmake b/projects/rocprofiler-systems/cmake/DyninstLibIberty.cmake index 007c390f8a..d8111a23cc 100644 --- a/projects/rocprofiler-systems/cmake/DyninstLibIberty.cmake +++ b/projects/rocprofiler-systems/cmake/DyninstLibIberty.cmake @@ -39,7 +39,7 @@ set(LibIberty_LIBRARYDIR # -------------- PACKAGES ----------------------------------------------------- -if(NOT BUILD_LIBIBERTY) +if(NOT ROCPROFSYS_BUILD_LIBIBERTY) find_package(LibIberty) endif() @@ -55,10 +55,10 @@ elseif(STERILE_BUILD) FATAL_ERROR "LibIberty not found and cannot be downloaded because build is sterile." ) -elseif(NOT BUILD_LIBIBERTY) +elseif(NOT ROCPROFSYS_BUILD_LIBIBERTY) rocprofiler_systems_message( FATAL_ERROR - "LibIberty was not found. Either configure cmake to find TBB properly or set BUILD_LIBIBERTY=ON to download and build" + "LibIberty was not found. Either configure cmake to find LibIberty properly or set ROCPROFSYS_BUILD_LIBIBERTY=ON to download and build" ) else() rocprofiler_systems_message(STATUS "${LibIberty_ERROR_REASON}") diff --git a/projects/rocprofiler-systems/cmake/DyninstTBB.cmake b/projects/rocprofiler-systems/cmake/DyninstTBB.cmake index 3a8e01ca70..c79b7ee8d6 100644 --- a/projects/rocprofiler-systems/cmake/DyninstTBB.cmake +++ b/projects/rocprofiler-systems/cmake/DyninstTBB.cmake @@ -76,7 +76,7 @@ set(TBB_INCLUDE_DIR ${TBB_INCLUDEDIR}) # The specific TBB libraries we need NB: This should _NOT_ be a cache variable set(_tbb_components tbb tbbmalloc_proxy tbbmalloc) -if(NOT BUILD_TBB) +if(NOT ROCPROFSYS_BUILD_TBB) find_package(TBB ${TBB_MIN_VERSION} COMPONENTS ${_tbb_components}) endif() @@ -92,10 +92,10 @@ elseif(STERILE_BUILD) rocprofiler_systems_message( FATAL_ERROR "TBB not found and cannot be downloaded because build is sterile." ) -elseif(NOT BUILD_TBB) +elseif(NOT ROCPROFSYS_BUILD_TBB) rocprofiler_systems_message( FATAL_ERROR - "TBB was not found. Either configure cmake to find TBB properly or set BUILD_TBB=ON to download and build" + "TBB was not found. Either configure cmake to find TBB properly or set ROCPROFSYS_BUILD_TBB=ON to download and build" ) else() # If we didn't find a suitable version on the system, then download one from the web @@ -237,7 +237,7 @@ target_compile_definitions(rocprofiler-systems-tbb INTERFACE ${TBB_DEFINITIONS}) target_link_directories(rocprofiler-systems-tbb INTERFACE ${TBB_LIBRARY_DIRS}) target_link_libraries(rocprofiler-systems-tbb INTERFACE ${TBB_LIBRARIES}) -rocprofiler_systems_message(STATUS "TBB include directory: ${TBB_INCLUDE_DIRS}") -rocprofiler_systems_message(STATUS "TBB library directory: ${TBB_LIBRARY_DIRS}") -rocprofiler_systems_message(STATUS "TBB libraries: ${TBB_LIBRARIES}") -rocprofiler_systems_message(STATUS "TBB definitions: ${TBB_DEFINITIONS}") +rocprofiler_systems_message(STATUS "TBB include directory: ${TBB_INCLUDE_DIRS}.") +rocprofiler_systems_message(STATUS "TBB library directory: ${TBB_LIBRARY_DIRS}.") +rocprofiler_systems_message(STATUS "TBB libraries: ${TBB_LIBRARIES}.") +rocprofiler_systems_message(STATUS "TBB definitions: ${TBB_DEFINITIONS}.") diff --git a/projects/rocprofiler-systems/cmake/Modules/Findamd-smi.cmake b/projects/rocprofiler-systems/cmake/Modules/Findamd-smi.cmake deleted file mode 100644 index 46965ab4dd..0000000000 --- a/projects/rocprofiler-systems/cmake/Modules/Findamd-smi.cmake +++ /dev/null @@ -1,86 +0,0 @@ -# Distributed under the OSI-approved BSD 3-Clause License. See accompanying file -# Copyright.txt or https://cmake.org/licensing for details. - -include(FindPackageHandleStandardArgs) - -# ----------------------------------------------------------------------------------------# - -if(NOT ROCM_PATH AND NOT "$ENV{ROCM_PATH}" STREQUAL "") - set(ROCM_PATH "$ENV{ROCM_PATH}") -endif() - -foreach(_DIR ${ROCmVersion_DIR} ${ROCM_PATH} /opt/rocm /opt/rocm/amd_smi) - if(EXISTS ${_DIR}) - get_filename_component(_ABS_DIR "${_DIR}" REALPATH) - list(APPEND _AMD_SMI_PATHS ${_ABS_DIR}) - endif() -endforeach() - -# ----------------------------------------------------------------------------------------# - -find_path( - amd-smi_ROOT_DIR - NAMES include/amd_smi/amdsmi.h - HINTS ${_AMD_SMI_PATHS} - PATHS ${_AMD_SMI_PATHS} - PATH_SUFFIXES amd_smi -) - -mark_as_advanced(amd-smi_ROOT_DIR) - -# ----------------------------------------------------------------------------------------# - -find_path( - amd-smi_INCLUDE_DIR - NAMES amd_smi/amdsmi.h - HINTS ${amd-smi_ROOT_DIR} ${_AMD_SMI_PATHS} - PATHS ${amd-smi_ROOT_DIR} ${_AMD_SMI_PATHS} - PATH_SUFFIXES include amd_smi/include -) - -mark_as_advanced(amd-smi_INCLUDE_DIR) - -# ----------------------------------------------------------------------------------------# - -find_library( - amd-smi_LIBRARY - NAMES amd_smi - HINTS ${amd-smi_ROOT_DIR} ${_AMD_SMI_PATHS} - PATHS ${amd-smi_ROOT_DIR} ${_AMD_SMI_PATHS} - PATH_SUFFIXES amd-smi/lib lib -) - -if(amd-smi_LIBRARY) - get_filename_component(amd-smi_LIBRARY_DIR "${amd-smi_LIBRARY}" PATH CACHE) -endif() - -mark_as_advanced(amd-smi_LIBRARY) - -# ----------------------------------------------------------------------------------------# - -find_package_handle_standard_args( - amd-smi - DEFAULT_MSG - amd-smi_ROOT_DIR - amd-smi_INCLUDE_DIR - amd-smi_LIBRARY -) - -# ------------------------------------------------------------------------------# - -if(amd-smi_FOUND) - add_library(amd-smi::amd-smi INTERFACE IMPORTED) - add_library(amd-smi::roctx INTERFACE IMPORTED) - set(amd-smi_INCLUDE_DIRS ${amd-smi_INCLUDE_DIR}) - set(amd-smi_LIBRARIES ${amd-smi_LIBRARY}) - set(amd-smi_LIBRARY_DIRS ${amd-smi_LIBRARY_DIR}) - - target_include_directories(amd-smi::amd-smi INTERFACE ${amd-smi_INCLUDE_DIR}) - target_link_libraries(amd-smi::amd-smi INTERFACE ${amd-smi_LIBRARY}) -endif() - -# ------------------------------------------------------------------------------# - -unset(_AMD_SMI_PATHS) - -# ------------------------------------------------------------------------------# diff --git a/projects/rocprofiler-systems/cmake/Packages.cmake b/projects/rocprofiler-systems/cmake/Packages.cmake index ebb60d267b..9f9e997725 100644 --- a/projects/rocprofiler-systems/cmake/Packages.cmake +++ b/projects/rocprofiler-systems/cmake/Packages.cmake @@ -172,11 +172,7 @@ if(ROCPROFSYS_USE_ROCM) HINTS ${ROCPROFSYS_DEFAULT_ROCM_PATH} PATHS ${ROCPROFSYS_DEFAULT_ROCM_PATH} ) - if(SPACK_BUILD) - find_package(ROCmVersion HINTS ${ROCM_PATH} PATHS ${ROCM_PATH}) - else() - find_package(ROCmVersion REQUIRED HINTS ${ROCM_PATH} PATHS ${ROCM_PATH}) - endif() + find_package(ROCmVersion HINTS ${ROCM_PATH} PATHS ${ROCM_PATH}) endif() if(NOT ROCmVersion_FOUND) @@ -196,7 +192,7 @@ if(ROCPROFSYS_USE_ROCM) list(APPEND CMAKE_PREFIX_PATH ${ROCmVersion_DIR}) endif() - set(ROCPROFSYS_ROCM_VERSION ${ROCmVersion_FULL_VERSION}) + set(ROCPROFSYS_ROCM_VERSION_FULL ${ROCmVersion_FULL_VERSION}) set(ROCPROFSYS_ROCM_VERSION_MAJOR ${ROCmVersion_MAJOR_VERSION}) set(ROCPROFSYS_ROCM_VERSION_MINOR ${ROCmVersion_MINOR_VERSION}) set(ROCPROFSYS_ROCM_VERSION_PATCH ${ROCmVersion_PATCH_VERSION}) @@ -219,6 +215,7 @@ endif() # ----------------------------------------------------------------------------------------# if(ROCPROFSYS_USE_ROCM) + # ROCProfiler SDK find_package(rocprofiler-sdk ${rocprofiler_systems_FIND_QUIETLY} REQUIRED) rocprofiler_systems_target_compile_definitions(rocprofiler-systems-rocm INTERFACE ROCPROFSYS_USE_ROCM @@ -228,8 +225,47 @@ if(ROCPROFSYS_USE_ROCM) INTERFACE rocprofiler-sdk::rocprofiler-sdk ) - find_package(amd-smi ${rocprofiler_systems_FIND_QUIETLY} REQUIRED) - target_link_libraries(rocprofiler-systems-rocm INTERFACE amd-smi::amd-smi) + # AMD SMI + find_package( + amd_smi + ${rocprofiler_systems_FIND_QUIETLY} + HINTS ${ROCMVersion_DIR} ${ROCM_PATH} /opt/amdgpu + PATHS ${ROCMVersion_DIR} ${ROCM_PATH} /opt/amdgpu + REQUIRED + ) + + # amd_smi in ROCm 6.4 requires both drm and drm_amdgpu libraries to be explicitly linked. + # This is no longer the case in ROCm 7.0. + if(ROCPROFSYS_ROCM_VERSION_MAJOR EQUAL 6 AND ROCPROFSYS_ROCM_VERSION_MINOR EQUAL 4) + # Find drm library + find_library( + drm_LIBRARY + NAMES drm + HINTS ${ROCMVersion_DIR} ${ROCM_PATH} /opt/amdgpu + PATHS ${ROCMVersion_DIR} ${ROCM_PATH} /opt/amdgpu + PATH_SUFFIXES lib lib64 + REQUIRED + ) + # Find drm_amdgpu library + find_library( + drm_amdgpu_LIBRARY + NAMES drm_amdgpu + HINTS ${ROCMVersion_DIR} ${ROCM_PATH} /opt/amdgpu + PATHS ${ROCMVersion_DIR} ${ROCM_PATH} /opt/amdgpu + PATH_SUFFIXES lib lib64 + REQUIRED + ) + + get_filename_component(_drm_LIBRARY_DIR "${drm_LIBRARY}" DIRECTORY) + get_filename_component(_drm_amdgpu_LIBRARY_DIR "${drm_amdgpu_LIBRARY}" DIRECTORY) + + set(_drm_LIBRARY_DIRS "${_drm_LIBRARY_DIR};${_drm_amdgpu_LIBRARY_DIR}") + list(REMOVE_DUPLICATES _drm_LIBRARY_DIRS) + + target_link_directories(amd_smi INTERFACE ${_drm_LIBRARY_DIRS}) + endif() + + target_link_libraries(rocprofiler-systems-rocm INTERFACE amd_smi) endif() # ----------------------------------------------------------------------------------------#