Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 52 additions & 30 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -474,41 +474,63 @@ if(MIGRAPHX_PACKAGE_BACKEND STREQUAL "therock")
set(MIGRAPHX_THEROCK_ROCM_VERSION "" CACHE STRING
"TheRock ROCm major.minor version suffix for package dependencies (e.g. 7.13)")
set(MIGRAPHX_THEROCK_GPU_ARCH "" CACHE STRING
"TheRock GPU arch(es) for per-GPU package dependencies. \
Semicolon-separated list (e.g. gfx90a;gfx942;gfx950) for per-GPU deps, \
or empty for device-all meta-package deps.")
"Optional TheRock package architecture override, as a semicolon-separated \
list (e.g. gfx90a;gfx942;gfx950). Defaults to GPU_TARGETS; use this override to \
adapt to TheRock <=7.14 package naming conventions (e.g. gfx94x).")
set(_MGX_PACKAGE_GPU_ARCHES "${MIGRAPHX_THEROCK_GPU_ARCH}")
if(NOT _MGX_PACKAGE_GPU_ARCHES AND GPU_TARGETS)
foreach(mgx_gpu_target IN LISTS GPU_TARGETS)
string(REGEX REPLACE ":.*$" "" mgx_gpu_arch "${mgx_gpu_target}")
list(APPEND _MGX_PACKAGE_GPU_ARCHES "${mgx_gpu_arch}")
endforeach()
list(REMOVE_DUPLICATES _MGX_PACKAGE_GPU_ARCHES)
endif()
set(DEPENDS_HIP_RUNTIME "amdrocm-runtime${MIGRAPHX_THEROCK_ROCM_VERSION}")
if(MIGRAPHX_THEROCK_GPU_ARCH)
# Collect per-GPU dependencies: one amdrocm-dnn/blas per arch
set(_MGX_GPU_DEPS "")
foreach(mgx_gpu_arch IN LISTS MIGRAPHX_THEROCK_GPU_ARCH)
if(MIGRAPHX_USE_MIOPEN)
list(APPEND _MGX_GPU_DEPS "amdrocm-dnn${MIGRAPHX_THEROCK_ROCM_VERSION}-${mgx_gpu_arch}")
endif()
if(MIGRAPHX_USE_ROCBLAS OR MIGRAPHX_USE_HIPBLASLT)
list(APPEND _MGX_GPU_DEPS "amdrocm-blas${MIGRAPHX_THEROCK_ROCM_VERSION}-${mgx_gpu_arch}")
endif()
# TheRock GPU libraries this build calls into
set(_MGX_GPU_LIBS "")
if(MIGRAPHX_USE_MIOPEN)
list(APPEND _MGX_GPU_LIBS "dnn")
endif()
if(MIGRAPHX_USE_ROCBLAS OR MIGRAPHX_USE_HIPBLASLT)
list(APPEND _MGX_GPU_LIBS "blas")
endif()

# Boolean dependencies were added in rpm 4.13 where rpmbuild supports 'or' operators
rocm_find_program_version(rpmbuild GREATER_EQUAL 4.13.0 QUIET
OUTPUT_VARIABLE MIGRAPHX_RPMBUILD_VERSION)

foreach(mgx_gpu_lib IN LISTS _MGX_GPU_LIBS)
set(_MGX_LIB "amdrocm-${mgx_gpu_lib}${MIGRAPHX_THEROCK_ROCM_VERSION}")
set(_MGX_ARCH_DEPS "")
foreach(mgx_gpu_arch IN LISTS _MGX_PACKAGE_GPU_ARCHES)
list(APPEND _MGX_ARCH_DEPS "${_MGX_LIB}-${mgx_gpu_arch}")
endforeach()
list(LENGTH MIGRAPHX_THEROCK_GPU_ARCH _MGX_NUM_ARCHS)
if(_MGX_NUM_ARCHS GREATER 1)
# Multi-arch fat binary: per-GPU libs are Recommends (only the
# libs for the GPU actually present are needed at runtime).
string(REPLACE ";" ", " _MGX_GPU_DEPS_CSV "${_MGX_GPU_DEPS}")
set(CPACK_DEBIAN_RUNTIME_PACKAGE_RECOMMENDS "${_MGX_GPU_DEPS_CSV}")
set(CPACK_RPM_RUNTIME_PACKAGE_SUGGESTS "${_MGX_GPU_DEPS_CSV}")
list(LENGTH _MGX_ARCH_DEPS _MGX_NUM_ARCH_DEPS)

set(_MGX_DEB_ALTS "${_MGX_LIB}")
list(APPEND _MGX_DEB_ALTS ${_MGX_ARCH_DEPS})
if(_MGX_NUM_ARCH_DEPS GREATER 0)
string(REPLACE ";" " | " _MGX_DEB_DEP "${_MGX_DEB_ALTS}")
else()
# Single-arch: hard dependency (user explicitly targets one GPU).
list(APPEND PACKAGE_DEPENDS ${_MGX_GPU_DEPS})
endif()
else()
# Device-all: depend on arch-independent meta packages
if(MIGRAPHX_USE_MIOPEN)
list(APPEND PACKAGE_DEPENDS "amdrocm-dnn${MIGRAPHX_THEROCK_ROCM_VERSION}")
set(_MGX_DEB_DEP "${_MGX_LIB}")
endif()
if(MIGRAPHX_USE_ROCBLAS OR MIGRAPHX_USE_HIPBLASLT)
list(APPEND PACKAGE_DEPENDS "amdrocm-blas${MIGRAPHX_THEROCK_ROCM_VERSION}")
rocm_package_add_deb_dependencies(DEPENDS "${_MGX_DEB_DEP}")

# RPM solvers do not guarantee operand preference. Keep the device
# alternatives useful for provisioned environments, with meta as a
# valid fallback, but do not rely on their order for GPU detection.
set(_MGX_RPM_ALTS ${_MGX_ARCH_DEPS})
list(APPEND _MGX_RPM_ALTS "${_MGX_LIB}")
if(_MGX_NUM_ARCH_DEPS GREATER 0 AND MIGRAPHX_RPMBUILD_VERSION_OK)
string(REPLACE ";" " or " _MGX_RPM_DEP "${_MGX_RPM_ALTS}")
set(_MGX_RPM_DEP "(${_MGX_RPM_DEP})")
else()
# Without boolean dependency support the meta package is all we can
# ask for; it is correct, just larger than necessary.
set(_MGX_RPM_DEP "${_MGX_LIB}")
endif()
endif()
rocm_package_add_rpm_dependencies(DEPENDS "${_MGX_RPM_DEP}")
endforeach()
rocm_package_add_deb_dependencies(SHARED_DEPENDS "amdrocm-runtime-dev${MIGRAPHX_THEROCK_ROCM_VERSION}")
rocm_package_add_rpm_dependencies(SHARED_DEPENDS "amdrocm-runtime-devel${MIGRAPHX_THEROCK_ROCM_VERSION}")

Expand Down
41 changes: 11 additions & 30 deletions cmake/DetectPackageBackend.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -29,27 +29,29 @@
# package against TheRock so that a bare `rbuild package` (or
# `cmake --build build --target package`) works without extra -D flags.
#
# Preferred usage:
# cmake -DMIGRAPHX_PACKAGE_BACKEND=therock -DGPU_TARGETS="gfx942;gfx950" ..
#
# It sets these cache variables (each only when not already provided):
# MIGRAPHX_PACKAGE_BACKEND - "therock" if any installed package name
# starts with "amdrocm", else "default".
# MIGRAPHX_THEROCK_ROCM_VERSION - ROCm version suffix parsed from an installed
# amdrocm-blas<ver>-<arch> package (e.g. 7.13).
# MIGRAPHX_THEROCK_GPU_ARCH - the first detected per-GPU arch (e.g. gfx942),
# used to select the per-GPU package dependency.
# amdrocm-blas<ver>[-<arch>] package (e.g. 10.0).
# GPU_TARGETS - semicolon list of ALL detected arches
# (e.g. gfx942;gfx950), used for compilation.
#
# Precedence per variable: an explicit -D / already-set value wins, then the
# GPU_ARCH_FOR_THEROCK env fallback (GPU arch only), then the detected value.
# Package dependency arches default to GPU_TARGETS. An explicit
# MIGRAPHX_THEROCK_GPU_ARCH cache value can override them for repositories whose
# package suffix differs from the GPU target (e.g. TheRock <=7.14 gfx94x).
#
# Explicit usage still works and overrides detection, e.g.:
# MIGRAPHX_THEROCK_ROCM_VERSION normally comes from installed packages. Set it
# explicitly when packaging for a version that cannot be detected locally, e.g.:
# cmake -DMIGRAPHX_PACKAGE_BACKEND=therock -DMIGRAPHX_THEROCK_GPU_ARCH=gfx942 \
# -DMIGRAPHX_THEROCK_ROCM_VERSION=7.13 -DGPU_TARGETS="gfx942;gfx950" ..
# -DMIGRAPHX_THEROCK_ROCM_VERSION=7.14 -DGPU_TARGETS="gfx942;gfx950" ..

# Probe installed packages via dpkg/rpm. Returns (in PARENT_SCOPE):
# _AMDROCM_ANY - TRUE if any installed package name starts with amdrocm
# _THEROCK_VERSION - version suffix from the first amdrocm-blas<ver>[-<arch>]
# _THEROCK_FIRST_ARCH - arch suffix from the first amdrocm-blas<ver>-<arch>
# _THEROCK_ALL_ARCHS - deduped, sorted list of all detected arches
function(_probe_amdrocm_packages)
set(_names "")
Expand Down Expand Up @@ -100,7 +102,6 @@ function(_probe_amdrocm_packages)

set(_any FALSE)
set(_version "")
set(_first_arch "")
set(_all_archs "")
set(_version_no_arch "")
if(_names)
Expand All @@ -114,9 +115,6 @@ function(_probe_amdrocm_packages)
if(NOT _version)
set(_version "${CMAKE_MATCH_1}")
endif()
if(NOT _first_arch)
set(_first_arch "${CMAKE_MATCH_2}")
endif()
list(APPEND _all_archs "${CMAKE_MATCH_2}")
# Non-arch blas package: amdrocm-blas<ver> (version fallback only)
elseif(_name MATCHES "^amdrocm-blas([0-9][0-9.]*)$")
Expand All @@ -139,7 +137,6 @@ function(_probe_amdrocm_packages)

set(_AMDROCM_ANY ${_any} PARENT_SCOPE)
set(_THEROCK_VERSION "${_version}" PARENT_SCOPE)
set(_THEROCK_FIRST_ARCH "${_first_arch}" PARENT_SCOPE)
set(_THEROCK_ALL_ARCHS "${_all_archs}" PARENT_SCOPE)
endfunction()

Expand Down Expand Up @@ -174,19 +171,6 @@ function(detect_package_backend)
"TheRock ROCm major.minor version suffix for package dependencies (e.g. 7.13)")
endif()

# Per-GPU arch used to select the per-GPU package dependency (first only).
if(NOT DEFINED CACHE{MIGRAPHX_THEROCK_GPU_ARCH})
if(DEFINED ENV{GPU_ARCH_FOR_THEROCK})
# Env name drops MIGRAPHX_ prefix to avoid the "unused MIGRAPHX_* env" warning.
set(_default_gpu_arch "$ENV{GPU_ARCH_FOR_THEROCK}")
else()
set(_default_gpu_arch "${_THEROCK_FIRST_ARCH}")
endif()
set(MIGRAPHX_THEROCK_GPU_ARCH "${_default_gpu_arch}" CACHE STRING
"TheRock GPU arch(es) for per-GPU package dependencies (e.g. gfx942). \
Semicolon-separated list for per-GPU deps, or empty for device-all meta-package deps.")
endif()

# GPU_TARGETS (what to compile) defaults to ALL detected arches. Only set
# when not already provided by -D, the HIP package, or env so we never
# clobber an explicit choice.
Expand All @@ -195,10 +179,7 @@ Semicolon-separated list for per-GPU deps, or empty for device-all meta-package
"GPU architectures to compile for (auto-detected from TheRock amdrocm-blas packages)")
endif()

message(STATUS "MIGraphX package backend: therock "
"(ROCm version: '${MIGRAPHX_THEROCK_ROCM_VERSION}', "
"package GPU arch: '${MIGRAPHX_THEROCK_GPU_ARCH}', "
"GPU_TARGETS: '${GPU_TARGETS}')")
message(STATUS "MIGraphX package backend: therock")
else()
message(STATUS "MIGraphX package backend: default (traditional ROCm)")
endif()
Expand Down
Loading