[rocprofiler-systems] Add build option for "examples" to specify gfx-arch (#2626)

## Motivation
 - Added `check_rocminfo` function that returns true if the provided regex was found, false otherwise. Can also use `GET_OUTPUT` to get the raw output filtered with or without a regex.
 - Moved `rocprofiler_systems_get_gfx_archs()` to `MacroUtilities.cmake` 
 - Added `rocprofiler_systems_lookup_gfx()`, which detects whether a given `gfx` is from the `instinct`, `radeon` or `apu` family.
 - Added `ROCPROFSYS_GFX_TARGETS` as a build argument. Used to specify the offloading architectures that GPU examples should compile for. If empty, defaults to whatever your system has.
 - GPU examples now check if the given `gfx` targets (from `ROCPROFSYS_GFX_TARGETS`) are supported.
 - OMPVV offload tests now only compile if `amdflang` version is `>= 20`
 - Improve link time by reducing the number of GFX targets that binaries need to support.
   - RCCL is now passed a `GPU_TARGETS` var specifying the architectures to build/link against.
This commit is contained in:
Kian Cossettini
2026-01-20 12:13:21 -05:00
committed by GitHub
orang tua 4a5cbbfba5
melakukan 698ac6b8bc
13 mengubah file dengan 352 tambahan dan 162 penghapusan
@@ -58,6 +58,35 @@ if(ROCPROFSYS_INSTALL_EXAMPLES)
include(GNUInstallDirs)
endif()
# GPU architectures to compile for
# If not set, auto-detects from system GPU (or empty if no GPU present)
if(
NOT DEFINED ROCPROFSYS_GFX_TARGETS
OR ROCPROFSYS_GFX_TARGETS STREQUAL ""
OR ROCPROFSYS_GFX_TARGETS STREQUAL "default"
)
rocprofiler_systems_get_gfx_archs(ROCPROFSYS_GFX_TARGETS)
endif()
set(ROCPROFSYS_GFX_TARGETS
"${ROCPROFSYS_GFX_TARGETS}"
CACHE STRING
"GPU architectures to compile for (semicolon-separated)"
FORCE
)
if(ROCPROFSYS_GFX_TARGETS)
message(STATUS "")
rocprofiler_systems_message(STATUS "Detected targets:")
foreach(arch IN LISTS ROCPROFSYS_GFX_TARGETS)
rocprofiler_systems_lookup_gfx(${arch} _GFX_TYPE)
message(STATUS " ${arch} (categories: ${_GFX_TYPE})")
endforeach()
message(STATUS "")
else()
rocprofiler_systems_message(STATUS "No GPU targets detected/set")
endif()
set(ROCPROFSYS_EXAMPLE_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR} CACHE INTERNAL "")
# defines function for creating causal profiling exes
include(${CMAKE_CURRENT_LIST_DIR}/causal-helpers.cmake)
@@ -20,14 +20,12 @@ target_link_libraries(
)
target_compile_options(fork-example PRIVATE ${_FLAGS})
if(ROCPROFSYS_INSTALL_EXAMPLES)
if(TARGET fork-example)
install(
TARGETS fork-example
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/rocprofiler-systems/examples
COMPONENT rocprofiler-systems-examples
)
endif()
if(ROCPROFSYS_INSTALL_EXAMPLES AND TARGET fork-example)
install(
TARGETS fork-example
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/rocprofiler-systems/examples
COMPONENT rocprofiler-systems-examples
)
endif()
# HIP fork example (multi-process concurrency test)
@@ -64,6 +62,18 @@ if(HIPCC_EXECUTABLE)
)
add_executable(hipMallocConcurrencyMproc hipMallocConcurrencyMproc.cpp)
target_link_libraries(hipMallocConcurrencyMproc PRIVATE Threads::Threads)
set_target_properties(
hipMallocConcurrencyMproc
PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/fork"
)
# Specify GPU architectures to compile for
foreach(arch IN LISTS ROCPROFSYS_GFX_TARGETS)
target_compile_options(
hipMallocConcurrencyMproc
PRIVATE --offload-arch=${arch}
)
target_link_options(hipMallocConcurrencyMproc PUBLIC --offload-arch=${arch})
endforeach()
if(
CMAKE_CXX_COMPILER_ID MATCHES "Clang"
@@ -101,22 +101,6 @@ foreach(OPENMP_EXAMPLE IN LISTS OPENMP_EXAMPLES)
endif()
endforeach()
set(DEFAULT_GPU_TARGETS
"gfx900"
"gfx906"
"gfx908"
"gfx90a"
"gfx942"
"gfx950"
"gfx1030"
"gfx1010"
"gfx1100"
"gfx1101"
"gfx1102"
)
set(GPU_TARGETS "${DEFAULT_GPU_TARGETS}" CACHE STRING "GPU targets to compile for")
if(ROCPROFSYS_USE_ROCM)
add_subdirectory(external)
else()
@@ -25,6 +25,11 @@ endif()
rocprofiler_systems_message(STATUS "Configuring OMPVV...")
if(NOT ROCPROFSYS_GFX_TARGETS)
rocprofiler_systems_message(WARNING "No GPU targets detected/set. Disabling OMPVV offload tests...")
set(OMPVV_USE_OFFLOAD_TESTS FALSE)
endif()
# Master branch contains stable releases
rocprofiler_systems_checkout_git_submodule(
RELATIVE_PATH
@@ -63,9 +68,6 @@ function(configure_ompvv_tests TEST_TYPE TEST_LIST_VAR)
elseif(TEST_TYPE STREQUAL "OFFLOAD")
set(TARGET_PREFIX "openmp-vv-offload")
set(FOFFLOADING_FLAGS "-fopenmp")
foreach(arch IN LISTS DEFAULT_GPU_TARGETS)
set(FOFFLOADING_FLAGS "${FOFFLOADING_FLAGS} --offload-arch=${arch}")
endforeach()
else()
rocprofiler_systems_message(FATAL_ERROR "Unknown TEST_TYPE - Only HOST and OFFLOAD supported")
endif()
@@ -77,6 +79,12 @@ function(configure_ompvv_tests TEST_TYPE TEST_LIST_VAR)
string(REPLACE "_" "-" TARGET_NAME ${TEST_NAME})
set(TARGET_NAME "${TARGET_PREFIX}-${TARGET_NAME}")
if(TARGET_PREFIX STREQUAL "openmp-vv-offload")
foreach(arch IN LISTS ROCPROFSYS_GFX_TARGETS)
set(FOFFLOADING_FLAGS "${FOFFLOADING_FLAGS} --offload-arch=${arch}")
endforeach()
endif()
set(CUSTOM_FFLAGS "-lm ${FOFFLOADING_FLAGS}")
set(CUSTOM_FLINKFLAGS "-lm ${FOFFLOADING_FLAGS}")
@@ -184,7 +192,7 @@ set(OMPVV_COMPILER
CACHE FILEPATH
"Fortran compiler used for OMPVV tests"
)
set(OMPVV_FC "amdflang")
set(OMPVV_FC "${amdflang_EXECUTABLE}")
execute_process(
COMMAND ${amdflang_EXECUTABLE} --version
@@ -237,7 +245,7 @@ set(OMPVV_HOST_TESTS_TO_COMPILE
# Set of offloading tests to be compiled (excluding reduction and simd_atomic
# tests due to OMPVV test failure)
set(OMPVV_OFFLOAD_TESTS_TO_COMPILE "")
if(OMPVV_USE_OFFLOAD_TESTS)
if(OMPVV_USE_OFFLOAD_TESTS AND AMDFLANG_VERSION_MAJOR GREATER_EQUAL 20)
set(OMPVV_OFFLOAD_TESTS_TO_COMPILE
"${OMPVV_TDIR}/target_simd/test_target_simd_if.F90"
"${OMPVV_TDIR}/target_teams_distribute_parallel_for/test_target_teams_distribute_parallel_for_collapse.F90"
@@ -3,6 +3,11 @@
cmake_minimum_required(VERSION 3.21 FATAL_ERROR)
if(NOT ROCPROFSYS_GFX_TARGETS)
rocprofiler_systems_message(WARNING "No GPU targets detected/set. Disabling OpenMP target example...")
return()
endif()
if(NOT OMP_TARGET_COMPILER)
find_program(
amdclangpp_EXECUTABLE
@@ -36,7 +41,7 @@ set(CMAKE_BUILD_TYPE "RelWithDebInfo")
find_package(Threads REQUIRED)
function(add_offload_flags tgt)
foreach(arch IN LISTS GPU_TARGETS)
foreach(arch IN LISTS ROCPROFSYS_GFX_TARGETS)
target_compile_options(${tgt} PRIVATE --offload-arch=${arch})
target_link_options(${tgt} PUBLIC --offload-arch=${arch})
endforeach()
@@ -1,24 +1,5 @@
# MIT License
#
# 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
# copies 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
# IMPLIED, 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 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
# Copyright (c) Advanced Micro Devices, Inc.
# SPDX-License-Identifier: MIT
cmake_minimum_required(VERSION 3.21 FATAL_ERROR)
list(APPEND CMAKE_MESSAGE_CONTEXT "rccl-tests")
@@ -68,6 +49,33 @@ if(hip_FOUND AND rccl_FOUND)
return()
endif()
# Parse comment describing supported gfx targets from rccl src/Makefile
execute_process(
COMMAND grep "Currently, supports" ${rccl-tests_SOURCE_DIR}/src/Makefile
OUTPUT_VARIABLE _supported_line
OUTPUT_STRIP_TRAILING_WHITESPACE
RESULT_VARIABLE _rccl_grep_ret
)
if(NOT _rccl_grep_ret EQUAL 0)
message(
FATAL_ERROR
"This grep should never fail unless rccl-tests/src/Makefile was modified in an incompatible way"
)
endif()
# Extract just the gfx architectures
string(REGEX MATCHALL "gfx[0-9a-z]+" RCCL_SUPPORTED_TARGETS "${_supported_line}")
set(RCCL_GPU_TARGETS "")
foreach(arch IN LISTS ROCPROFSYS_GFX_TARGETS)
if(arch IN_LIST RCCL_SUPPORTED_TARGETS)
list(APPEND RCCL_GPU_TARGETS ${arch})
endif()
endforeach()
if(RCCL_GPU_TARGETS STREQUAL "")
message(AUTHOR_WARNING "rccl-tests skipped. No supported GPU targets found.")
return()
endif()
# Copy source to build directory
file(COPY ${rccl-tests_SOURCE_DIR}/ DESTINATION ${rccl-tests_BUILD_DIR})
@@ -78,7 +86,9 @@ if(hip_FOUND AND rccl_FOUND)
add_custom_target(
build-rccl-tests
ALL
COMMAND make HIP_HOME=${ROCM_PATH} RCCL_HOME=${rccl_ROOT_DIR} -j
COMMAND
make HIP_HOME=${ROCM_PATH} RCCL_HOME=${rccl_ROOT_DIR}
GPU_TARGETS=${RCCL_GPU_TARGETS} -j
WORKING_DIRECTORY ${rccl-tests_BUILD_DIR}
COMMENT
"Building rccl-tests with HIP_HOME=${ROCM_PATH} RCCL_HOME=${rccl_ROOT_DIR} ..."
@@ -89,6 +89,12 @@ if("${CMAKE_BUILD_TYPE}" MATCHES "Release")
target_compile_options(roctx PRIVATE -g1)
endif()
# Specify GPU architectures to compile for
foreach(arch IN LISTS ROCPROFSYS_GFX_TARGETS)
target_compile_options(roctx PRIVATE --offload-arch=${arch})
target_link_options(roctx PUBLIC --offload-arch=${arch})
endforeach()
if(NOT CMAKE_CXX_COMPILER_IS_HIPCC AND HIPCC_EXECUTABLE)
# defined in MacroUtilities.cmake
rocprofiler_systems_custom_compilation(COMPILER ${HIPCC_EXECUTABLE} TARGET roctx)
@@ -118,6 +118,16 @@ if("${CMAKE_BUILD_TYPE}" MATCHES "Release")
target_compile_options(transferBench PRIVATE -g1)
endif()
# Specify GPU architectures to compile for
foreach(arch IN LISTS ROCPROFSYS_GFX_TARGETS)
rocprofiler_systems_lookup_gfx(${arch} GPU_CATEGORIES)
if("apu" IN_LIST GPU_CATEGORIES AND NOT "instinct" IN_LIST GPU_CATEGORIES)
continue()
endif()
target_compile_options(transferBench PRIVATE --offload-arch=${arch})
target_link_options(transferBench PUBLIC --offload-arch=${arch})
endforeach()
if(NOT CMAKE_CXX_COMPILER_IS_HIPCC AND HIPCC_EXECUTABLE)
# defined in MacroUtilities.cmake
rocprofiler_systems_custom_compilation(COMPILER ${HIPCC_EXECUTABLE} TARGET transferBench)
@@ -66,6 +66,12 @@ endif()
add_executable(transpose transpose.cpp)
target_link_libraries(transpose PRIVATE Threads::Threads)
# Specify GPU architectures to compile for
foreach(arch IN LISTS ROCPROFSYS_GFX_TARGETS)
target_compile_options(transpose PRIVATE --offload-arch=${arch})
target_link_options(transpose PUBLIC --offload-arch=${arch})
endforeach()
if(
CMAKE_CXX_COMPILER_ID MATCHES "Clang"
AND NOT CMAKE_CXX_COMPILER_IS_HIPCC