guix_mirror_bot pushed a commit to branch next-master
in repository guix.

commit 08b7cb622d360e39d82193e8fccd94e481afaa65
Author: Jean-Baptiste Note <[email protected]>
AuthorDate: Thu Sep 25 16:15:47 2025 +0200

    gnu: Bump rocm to version 7.1.0
    
    * gnu/packages/llvm.scm (%rocm-llvm-version): New variable.
    (make-llvm-rocm): New procedure.
    (llvm-rocm): New variable.
    (make-clang-runtime-rocm): New procedure.
    (clang-runtime-rocm): New variable.
    (make-clang-rocm): New procedure.
    (clang-rocm): New variable.
    (rocm-device-libs): New variable.
    (rocm-comgr): New variable.
    (rocm-hipcc): New variable.
    (make-lld-rocm): New procedure.
    (lld-rocm): New variable.
    * gnu/packages/rocm.scm: Add perl to imports.
    (%rocm-version): Update to 7.1.0.
    (%rocm-systems-url, %rocm-systems-origin): New variables.
    (rocr-runtime): Use %rocm-systems-origin and update build.
    (rocm-opencl-runtime): Use %rocm-systems-origin and update build.
    (rocm-hip-runtime): New variable.
    (rocminfo): Use %rocm-systems-origin and update build.
    (%default-amdgpu-targets, %default-amdgpu-targets-property): New variables.
    (%amdgpu-targets): New syntax.
    (rocm-bandwidth-test): Update and add comprehensive build support.
    * gnu/local.mk: Add rocm-bandwidth-test patches.
    * 
gnu/packages/patches/rocm-bandwidth-test-fix-external-packages-search.patch,
    gnu/packages/patches/rocm-bandwidth-test-fix-hsa-include-file-lookup.patch,
    
gnu/packages/patches/rocm-bandwidth-test-take-default-gpus-from-environment.patch:
    New files.
    * gnu/packages/patches/rocclr-5.6.0-enable-gfx800.patch,
    gnu/packages/patches/rocm-opencl-runtime-4.3-noclinfo.patch: Update patch 
paths.
    
    Change-Id: I43f162b9f8ab898e25d8ecbe4ea30be84a29eb0d
    Signed-off-by: Ludovic Courtès <[email protected]>
---
 gnu/local.mk                                       |   3 +
 gnu/packages/llvm.scm                              | 306 ++++++++++++-
 .../patches/rocclr-5.6.0-enable-gfx800.patch       |   4 +-
 ...ndwidth-test-fix-external-packages-search.patch |  58 +++
 ...andwidth-test-fix-hsa-include-file-lookup.patch |  16 +
 ...h-test-take-default-gpus-from-environment.patch |  29 ++
 .../patches/rocm-opencl-runtime-4.3-noclinfo.patch |   8 +-
 gnu/packages/rocm.scm                              | 489 +++++++++++++--------
 8 files changed, 702 insertions(+), 211 deletions(-)

diff --git a/gnu/local.mk b/gnu/local.mk
index 17e7ac922c..cf1cdaf879 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -2267,6 +2267,9 @@ dist_patch_DATA =                                         
\
   %D%/packages/patches/rng-tools-revert-build-randstat.patch   \
   %D%/packages/patches/rocclr-5.6.0-enable-gfx800.patch                \
   %D%/packages/patches/rocm-opencl-runtime-4.3-noclinfo.patch  \
+  %D%/packages/patches/rocm-bandwidth-test-fix-external-packages-search.patch  
\
+  %D%/packages/patches/rocm-bandwidth-test-fix-hsa-include-file-lookup.patch   
\
+  
%D%/packages/patches/rocm-bandwidth-test-take-default-gpus-from-environment.patch
    \
   %D%/packages/patches/rottlog-direntry.patch                  \
   %D%/packages/patches/ruby-actionpack-remove-browser-tests.patch      \
   %D%/packages/patches/ruby-activesupport-fix-deprecation-warning.patch        
\
diff --git a/gnu/packages/llvm.scm b/gnu/packages/llvm.scm
index 6a241519de..cdfbaad7b7 100644
--- a/gnu/packages/llvm.scm
+++ b/gnu/packages/llvm.scm
@@ -67,6 +67,7 @@
   #:use-module (gnu packages autotools)
   #:use-module (gnu packages base)
   #:use-module (gnu packages cmake)
+  #:use-module (gnu packages bash)
   #:use-module (gnu packages crypto)
   #:use-module (gnu packages gcc)
   #:use-module (gnu packages bootstrap)           ;glibc-dynamic-linker
@@ -86,6 +87,7 @@
   #:use-module (gnu packages pkg-config)
   #:use-module (gnu packages python)
   #:use-module (gnu packages python-build)
+  #:use-module (gnu packages rocm)
   #:use-module (gnu packages swig)
   #:use-module (gnu packages vulkan)
   #:use-module (gnu packages xml)
@@ -1279,40 +1281,282 @@ Library.")
 (define-public clang clang-13)
 (define-public clang-toolchain clang-toolchain-13)
 
-(define-public llvm-for-rocm
+
+
+;; ROCm compiler infrastructure elements are compiled from a monorepo at
+;; https://github.com/ROCm/llvm-project.  Due to some of these parts
+;; referencing both a common origin and llvm helpers (in particular related to
+;; patches and base packages).  Other ROCm elements are part of rocm.scm
+
+;; This must match '%rocm-version' in rocm.scm.  They cannot be shared because
+;; toplevel variables cannot be called from one file to another.
+(define %rocm-llvm-version "7.1.0")
+
+(define (make-llvm-rocm llvm-base)
   (package
-    ;; Currently based on LLVM 19.
-    (inherit llvm-19)
-    (name "llvm-for-rocm")
-    (version "6.4.2")                         ;this must match '%rocm-version'
+    (inherit llvm-base)
+    ;; XXX A lot of llvm package phases are dependent on llvm version.  Are
+    ;; these resolved early, so that we can override the package version 
easily?
+    (version %rocm-llvm-version)
+    (name "llvm-rocm")
     (source (origin
               (method git-fetch)
               (uri (git-reference
-                    (url "https://github.com/ROCm/llvm-project.git";)
-                    (commit (string-append "rocm-" version))))
-              (file-name (git-file-name name version))
+                     (url "https://github.com/ROCm/llvm-project";)
+                     (commit (string-append "rocm-" %rocm-llvm-version))))
+              (file-name (git-file-name "rocm-llvm" %rocm-llvm-version))
               (sha256
                (base32
-                "1j2cr362k7snsh5c1z38ikyihmjvy0088rj0f0dhng6cjwgysryp"))))
+                "1nwbj2cz99psgq9s9l4wbsxj41l2d2dga5l9rw9jndk05jsn4n7s"))
+              ;; Some of these patches require a further dynamic substitution 
during
+              ;; package build.  Therefore, it is important to derive from the 
base
+              ;; packages or to duplicate such substitutions.  Additionally, 
some of
+              ;; those substitutions are only applied on specific subcomponents
+              ;; (llvm-clang), so duplicating the base-llvm structure with 
subcomponents
+              ;; is necessary.
+              (patches
+               (map search-patch
+                    (assoc-ref %llvm-patches (package-version llvm-base))))))
     (arguments
-     (substitute-keyword-arguments (package-arguments llvm-19)
+     (substitute-keyword-arguments (package-arguments llvm-base)
        ((#:configure-flags flags)
-        #~(list "-DLLVM_ENABLE_PROJECTS=llvm;clang;lld"
-                "-DLLVM_TARGETS_TO_BUILD=AMDGPU;X86"
-                "-DCMAKE_SKIP_BUILD_RPATH=FALSE"
-                "-DCMAKE_BUILD_WITH_INSTALL_RPATH=FALSE"
-                "-DBUILD_SHARED_LIBS:BOOL=TRUE"
-                "-DLLVM_VERSION_SUFFIX="))))
+        #~(append #$flags
+                  (list "-DLLVM_TARGETS_TO_BUILD=AMDGPU;X86"
+                        "-DLLVM_VERSION_SUFFIX=")))))
     (properties `((hidden? . #t)
-                  ,@(package-properties llvm-19)))
+                  ,@(package-properties llvm-base)))
     (home-page "https://github.com/ROCm/llvm-project";)
     (synopsis
-     (string-append (package-synopsis llvm-19) " (AMD fork)"))
+     (string-append (package-synopsis llvm-base) " (AMD fork)"))
     (description
-     (string-append (package-description llvm-19) "
+     (string-append (package-description llvm-base) "
 
 This AMD fork includes AMD-specific additions."))))
 
+(define-public llvm-rocm (make-llvm-rocm llvm-20))
+
+(define (make-clang-runtime-rocm clang-runtime-base)
+  (package
+    (inherit clang-runtime-base)
+    (name "clang-runtime-rocm")
+    (version (package-version llvm-rocm))
+    (source (package-source llvm-rocm))
+    (inputs (modify-inputs (package-inputs clang-runtime-base)
+              (replace "llvm" llvm-rocm)))))
+
+(define-public clang-runtime-rocm (make-clang-runtime-rocm clang-runtime-20))
+
+(define (make-clang-rocm clang-base)
+  ;; note: tools-extra is embedded in the checkout
+  (package
+    (inherit clang-base)
+    (name "clang-rocm")
+    (version (package-version llvm-rocm))
+    (source (package-source llvm-rocm))
+    (inputs (modify-inputs (package-inputs clang-base)
+              (delete "clang-tools-extra")))
+    (propagated-inputs
+     (modify-inputs (package-propagated-inputs clang-base)
+       (replace "llvm" llvm-rocm)
+       (replace "clang-runtime" clang-runtime-rocm)
+       (append python-lit)))
+    (arguments
+     (substitute-keyword-arguments (package-arguments clang-base)
+       ;;  The tests can be run, as allowed by check phase rewrite and
+       ;;  LLVM_EXTERNAL_LIT setting.  However, 84/46171 are failing. Most
+       ;;  should probably be disabled.
+       ;;
+       ;;  - CUDA tests are failing.
+       ;;
+       ;;  - Checking for some -L[[SYSROOT]] is failing, which I guess is
+       ;;  expected, given the patches we apply, which are mangling directory
+       ;;  searching for libraries.
+       ;;
+       ;;  Getting the test suite to pass doesn't seem out of reach.  We
+       ;;  probably should start with the standard llvm-clang-20x package.
+       ((#:tests? _ #t) #f)
+       ((#:configure-flags flags)
+        #~(append #$flags
+                  (list
+                   "-DLLVM_TARGETS_TO_BUILD=AMDGPU;X86"
+                   ;; WARNING: we could patch
+                   ;; #$llvm-rocm/lib/cmake/llvm/AddLLVM.cmake to simplify, by
+                   ;; substituting set(LIT_COMMAND
+                   ;; "${Python3_EXECUTABLE};${lit_base_dir}/${lit_file_name}")
+                   ;; pending this, having a correct python script here is a
+                   ;; must-have.
+                   ;; TODO: test this on llvm-rocm.
+                   (string-append
+                    "-DLLVM_EXTERNAL_LIT="
+                    (search-input-file %build-inputs "bin/.lit-real"))
+                   ;; Disable clang wrapper which depends on lld as well.
+                   "-DCLANG_ENABLE_AMDCLANG=OFF")))
+       ((#:phases phases '%standard-phases)
+        #~(modify-phases #$phases
+            (replace 'check
+              (lambda* (#:rest args)
+                (setenv "HOME" "/tmp")
+                (apply (assoc-ref
+                        (@ (guix build gnu-build-system) %standard-phases)
+                        'check)
+                       #:test-target "check-clang" args)))
+            (replace 'add-tools-extra
+              (lambda _
+                (copy-recursively "../clang-tools-extra" "tools/extra")))))))))
+
+(define-public clang-rocm (make-clang-rocm clang-20))
+
+(define-public rocm-device-libs
+  (package
+    (name "rocm-device-libs")
+    (version (package-version llvm-rocm))
+    (source (package-source llvm-rocm))
+    (build-system cmake-build-system)
+    (arguments
+     (list
+      #:tests? #f ; Not sure how to run them.
+      #:build-type "Release"
+      #:phases
+      #~(modify-phases %standard-phases
+          (add-after 'unpack 'chdir
+            (lambda _
+              (chdir "amd/device-libs")))
+          (add-after 'install 'copy-include-directories
+            (lambda _
+              ;; at this point we're within amd/build; i guess the build
+              ;; directory should be at the same level as source, but due to
+              ;; the chdir above...
+              (with-directory-excursion "../device-libs"
+                (for-each
+                 (lambda (directory)
+                   (let ((include-directory (string-append directory "/inc")))
+                     (copy-recursively
+                      include-directory
+                      (string-append #$output "/" include-directory))))
+                 (list "irif" "oclc" "ockl" "ocml"))))))))
+    (inputs (list clang-rocm))
+    (home-page "https://github.com/ROCm/llvm-project/";)
+    (synopsis "ROCm Device libraries")
+    (description "ROCm device libraries provide AMD-specific device-side 
language runtime
+libraries, namely oclc, ocml, ockl, opencl, hip and hc.")
+    (license license:ncsa)))
+
+;; Usage note from amd/comgr/src/comgr-env.cpp: at runtime, comgr either needs
+;; the awful ROCM_PATH set, or the more palatable LLVM_PATH and HIP_PATH, set.
+(define-public rocm-comgr
+  (package
+    (name "rocm-comgr")
+    (version (package-version llvm-rocm))
+    (source (package-source llvm-rocm))
+    (build-system cmake-build-system)
+    (arguments
+     (list
+      #:build-type "Release"
+      #:phases
+      #~(modify-phases %standard-phases
+          (add-after 'unpack 'prepare-to-build
+            (lambda _
+              (chdir "amd/comgr")
+              (setenv "ROCM_PATH"
+                      #$(this-package-input "rocm-device-libs")))))))
+    (inputs (list libffi rocm-device-libs))
+    (native-inputs (list
+                    clang-rocm
+                    lld-rocm
+                    python))
+    (home-page "https://github.com/ROCm/ROCm-CompilerSupport";)
+    (synopsis "ROCm Code Object Manager")
+    (description "The Comgr library provides APIs for compiling and inspecting
+AMDGPU code objects.")
+    (license license:ncsa)))
+
+(define-public rocm-hipcc
+  (package
+    (name "rocm-hipcc")
+    (version (package-version llvm-rocm))
+    (source (package-source llvm-rocm))
+    (build-system cmake-build-system)
+    (arguments
+     (list
+      #:tests? #f                       ; Not sure how to run them.
+      #:build-type "Release"
+      #:phases
+      #~(modify-phases %standard-phases
+          (add-after 'unpack 'chdir
+            (lambda _
+              (chdir "amd/hipcc")))
+          (add-after 'chdir 'patch-rocm-path
+            (lambda* (#:key inputs #:allow-other-keys)
+              (substitute* (find-files "src" "\\.h$")
+                (("roccmPath \\+ \"/bin/rocm_agent_enumerator\"")
+                 (format #f "~s" (search-input-file
+                                  inputs
+                                  "/bin/rocm_agent_enumerator"))))))
+          ;; This version file very important, as it is parsed under
+          ;; $#{llvm-rocm}/clang/lib/Driver/ToolChains/AMDGPU.cpp and its
+          ;; contents decides on some includes for hipcc.
+          (add-after 'install 'info-version
+            (lambda _
+              (let ((hip-version-dir (string-append #$output "/share/hip")))
+                (mkdir hip-version-dir)
+                (with-directory-excursion hip-version-dir
+                  (with-output-to-file "version"
+                    (lambda _
+                      (apply format #t
+                             "HIP_VERSION_MAJOR=~a~%~
+                              HIP_VERSION_MINOR=~a~%~
+                              HIP_VERSION_PATCH=~a~%~
+                              HIP_VERSION_GITHASH=0~%"
+                             (string-split
+                              #$(version-major+minor+point version) #\.))))))))
+          (add-after 'install 'wrap-programs
+            (lambda* (#:key inputs outputs #:allow-other-keys)
+              (let ((output-bindir (string-append (assoc-ref outputs "out") 
"/bin")))
+                (for-each
+                 (lambda (file)
+                   (wrap-program (string-append output-bindir "/" file)
+                     ;; The following definitions and their meaning can be
+                     ;; found in hibBin_base.h.  We've defined neither
+                     ;; HIP_RUNTIME nor HIP_ROCCLR_HOME.
+
+                     ;; HIP_ROCCLR_HOME unfortunately cannot be set here
+                     ;; (circular dependency problem) -- it should be set to
+                     ;; #$rocm-hip-runtime.
+
+                     ;;(list "HIP_ROCCLR_HOME" '= (list #$rocm-hip-runtime))
+                     (list "HIP_PATH" '= (list #$output))
+                     (list "HIP_CLANG_PATH"
+                           '=
+                           (list (string-append
+                                  #$(this-package-input "clang-rocm")
+                                  "/bin")))
+                     (list "DEVICE_LIB_PATH"
+                           '=
+                           (list (string-append
+                                  #$(this-package-input "rocm-device-libs")
+                                  "/amdgcn/bitcode")))
+
+                     ;; This is done in order to please check_config, which
+                     ;; checks that HSA_PATH is in LD_LIBRARY_PATH
+                     (list "LD_LIBRARY_PATH"
+                           'suffix
+                           (list #$(this-package-input "rocr-runtime")))
+                     ;; checks hipconfig is in PATH
+                     (list "PATH" 'suffix (list output-bindir))))
+                 '( "hipcc" "hipconfig" ))))))))
+    (inputs (list clang-rocm
+                  rocm-device-libs
+                  rocr-runtime
+                  rocminfo
+                  perl
+                  bash-minimal))
+    (home-page "https://github.com/ROCm/llvm-project/";)
+    (synopsis "ROCm HIP compiler driver (@command{hipcc})")
+    (description "The HIP compiler driver (@command{hipcc}) is a compiler 
utility that will
+call @command{clang} and pass the appropriate include and library options for
+the target compiler and HIP infrastructure.")
+    (license license:expat)))
+
 
 
 (define-public libunwind-headers
@@ -1723,6 +1967,26 @@ existing compilers together.")
 (define-public python-clang-13
   (clang-python-bindings clang-13))
 
+;; XXX
+;; I would move all of rocm packages here and define a ROCm section.
+
+(define (make-lld-rocm lld-base)
+  (package
+    (inherit lld-base)
+    (name "lld-rocm")
+    (version (package-version llvm-rocm))
+    (source (package-source llvm-rocm))
+    (inputs (list llvm-rocm))
+    (arguments
+     (substitute-keyword-arguments (package-arguments lld-base)
+       ((#:configure-flags flags)
+        #~(append #$flags
+                  '("-DLLVM_TARGETS_TO_BUILD=AMDGPU;X86")))))))
+
+(define-public lld-rocm (make-lld-rocm lld-20))
+
+
+
 (define-public include-what-you-use
   (package
     (name "include-what-you-use")
@@ -1733,8 +1997,8 @@ existing compilers together.")
      (origin
        (method git-fetch)
        (uri (git-reference
-             (url 
"https://github.com/include-what-you-use/include-what-you-use";)
-             (commit version)))
+              (url 
"https://github.com/include-what-you-use/include-what-you-use";)
+              (commit version)))
        (file-name (git-file-name name version))
        (sha256
         (base32 "0dkk65y6abf7bzv10q1ch3dyzj4d5y89qhh43jn189l861d6pzs0"))))
diff --git a/gnu/packages/patches/rocclr-5.6.0-enable-gfx800.patch 
b/gnu/packages/patches/rocclr-5.6.0-enable-gfx800.patch
index 21fd88b82e..1233fac2c6 100644
--- a/gnu/packages/patches/rocclr-5.6.0-enable-gfx800.patch
+++ b/gnu/packages/patches/rocclr-5.6.0-enable-gfx800.patch
@@ -17,8 +17,8 @@ Signed-off-by: Jeremy Newton <[email protected]>
 
 diff --git a/rocclr/device/device.hpp b/rocclr/device/device.hpp
 index ef82630325..6409cebc90 100644
---- a/rocclr/device/device.hpp
-+++ b/rocclr/device/device.hpp
+--- a/projects/clr/rocclr/device/device.hpp
++++ b/projects/clr/rocclr/device/device.hpp
 @@ -1431,8 +1431,5 @@ class Isa {
  
    /// @returns If the ROCm runtime supports the ISA.
diff --git 
a/gnu/packages/patches/rocm-bandwidth-test-fix-external-packages-search.patch 
b/gnu/packages/patches/rocm-bandwidth-test-fix-external-packages-search.patch
new file mode 100644
index 0000000000..74091f11b5
--- /dev/null
+++ 
b/gnu/packages/patches/rocm-bandwidth-test-fix-external-packages-search.patch
@@ -0,0 +1,58 @@
+diff --git a/cmake/build_utils.cmake b/cmake/build_utils.cmake
+index 83db1be..6f62931 100644
+--- a/cmake/build_utils.cmake
++++ b/cmake/build_utils.cmake
+@@ -1010,7 +1010,7 @@ macro(add_bundled_libraries)
+         add_subdirectory(${FMT_SOURCE_DIR} EXCLUDE_FROM_ALL)
+         set(FMT_LIBRARIES fmt::fmt-header-only)
+     else()
+-        find_package(${FMT_PACKAGE_NAME} REQUIRED 
${FMT_PKG_MINIMUM_REQUIRED_VERSION})
++        find_package(${FMT_PACKAGE_NAME} ${FMT_PKG_MINIMUM_REQUIRED_VERSION} 
REQUIRED)
+         set(FMT_LIBRARIES fmt::fmt)
+     endif()
+     list(APPEND 3RD_PARTY_TARGET_LIST ${FMT_LIBRARIES})
+@@ -1020,8 +1020,8 @@ macro(add_bundled_libraries)
+     #   Note:   C++23+ we can use std::stacktrace for the traces.
+     #           Some older compilers/systems will not allow that. We will 
force/use boost::stacktrace for now.
+     #           Check for 'Boost'
+-    set(BOOST_PACKAGE_NAME "boost")
+-    set(BOOST_LIBRARY_NAME "boost")
++    set(BOOST_PACKAGE_NAME "Boost")
++    set(BOOST_LIBRARY_NAME "Boost")
+     set(BOOST_REPO_URL "https://github.com/boostorg/boost.git";)
+     set(BOOST_PKG_MINIMUM_REQUIRED_VERSION "1.74.0")
+     set(BOOST_REPO_VERSION "boost-1.88.0")
+@@ -1128,7 +1128,7 @@ macro(add_bundled_libraries)
+         add_subdirectory(${SPDLOG_SOURCE_DIR} EXCLUDE_FROM_ALL)
+         set(SPDLOG_LIBRARIES spdlog::spdlog_header_only)
+     else()
+-        find_package(${SPDLOG_PACKAGE_NAME} REQUIRED 
${SPDLOG_PKG_MINIMUM_REQUIRED_VERSION})
++        find_package(${SPDLOG_PACKAGE_NAME} 
${SPDLOG_PKG_MINIMUM_REQUIRED_VERSION} REQUIRED)
+         set(SPDLOG_LIBRARIES spdlog::spdlog)
+     endif()
+     list(APPEND 3RD_PARTY_TARGET_LIST ${SPDLOG_LIBRARIES})
+@@ -1162,7 +1162,7 @@ macro(add_bundled_libraries)
+     #    find_package(Boost 1.74 REQUIRED COMPONENTS stacktrace_basic)
+     #    set(BOOST_LIBRARIES boost::boost)
+     #endif()
+-    set(CATCH2_PACKAGE_NAME "catch2")
++    set(CATCH2_PACKAGE_NAME "Catch2")
+     set(CATCH2_LIBRARY_NAME "Catch2")
+     set(CATCH2_REPO_URL "https://github.com/catchorg/Catch2.git";)
+     set(CATCH2_PKG_MINIMUM_REQUIRED_VERSION "3.5.1")
+diff --git a/main/cmdline/CMakeLists.txt b/main/cmdline/CMakeLists.txt
+index ad8219e..f507a2b 100644
+--- a/main/cmdline/CMakeLists.txt
++++ b/main/cmdline/CMakeLists.txt
+@@ -54,7 +54,7 @@ if(NOT USE_LOCAL_CLI11)
+     set(CLI11_LIBRARIES CLI11::CLI11)
+     set(CLI11_INCLUDE_DIRS)
+ else()
+-    find_package(CLI11 CONFIG QUIT)
++    find_package(CLI11 CONFIG QUIET)
+ endif()
+ 
+ 
+-- 
+2.51.0
+
diff --git 
a/gnu/packages/patches/rocm-bandwidth-test-fix-hsa-include-file-lookup.patch 
b/gnu/packages/patches/rocm-bandwidth-test-fix-hsa-include-file-lookup.patch
new file mode 100644
index 0000000000..9b0501e65c
--- /dev/null
+++ b/gnu/packages/patches/rocm-bandwidth-test-fix-hsa-include-file-lookup.patch
@@ -0,0 +1,16 @@
+diff --git a/plugins/tb/transferbench/CMakeLists.txt 
b/plugins/tb/transferbench/CMakeLists.txt
+index 98e4bc4..8e4588e 100644
+--- a/plugins/tb/transferbench/CMakeLists.txt
++++ b/plugins/tb/transferbench/CMakeLists.txt
+@@ -153,7 +153,7 @@ endif()
+ 
+ ## Check for hsa support
+ find_library(HSA_LIBRARY hsa-runtime64 PATHS ${ROCM_PATH} ${ROCM_PATH}/lib)
+-find_path(HSA_INCLUDE_DIR hsa.h PATHS ${ROCM_PATH}/include 
${ROCM_PATH}/include/hsa)
++find_path(HSA_INCLUDE_DIR has/hsa.h PATHS ${ROCM_PATH}/include 
${ROCM_PATH}/include/hsa)
+ if(HSA_LIBRARY AND HSA_INCLUDE_DIR)
+     add_library(hsa-runtime64 SHARED IMPORTED)
+     set_target_properties(hsa-runtime64 PROPERTIES 
INTERFACE_INCLUDE_DIRECTORIES "${HSA_INCLUDE_DIR}" IMPORTED_LOCATION 
"${HSA_LIBRARY}" INTERFACE_SYSTEM_INCLUDE_DIRECTORIES "${HSA_INCLUDE_DIR}")
+-- 
+2.51.0
+
diff --git 
a/gnu/packages/patches/rocm-bandwidth-test-take-default-gpus-from-environment.patch
 
b/gnu/packages/patches/rocm-bandwidth-test-take-default-gpus-from-environment.patch
new file mode 100644
index 0000000000..7fc1bb96af
--- /dev/null
+++ 
b/gnu/packages/patches/rocm-bandwidth-test-take-default-gpus-from-environment.patch
@@ -0,0 +1,29 @@
+diff --git a/plugins/tb/transferbench/CMakeLists.txt 
b/plugins/tb/transferbench/CMakeLists.txt
+index 8e4588e..1d0e12f 100644
+--- a/plugins/tb/transferbench/CMakeLists.txt
++++ b/plugins/tb/transferbench/CMakeLists.txt
+@@ -61,20 +61,7 @@ option(ENABLE_NIC_EXEC             "Enable RDMA NIC 
Executor in TransferBench"
+ 
+ # Default GPU architectures to build
+ 
#==================================================================================================
+-set(DEFAULT_GPUS
+-      gfx906
+-      gfx908
+-      gfx90a
+-      gfx942
+-      gfx950
+-      gfx1030
+-      gfx1100
+-      gfx1101
+-      gfx1102
+-      gfx1150
+-      gfx1151
+-      gfx1200
+-      gfx1201)
++set(DEFAULT_GPUS ENV{AMDGPU_TARGETS})
+ 
+ # Build only for local GPU architecture
+ if (BUILD_LOCAL_GPU_TARGET_ONLY)
+-- 
+2.51.0
+
diff --git a/gnu/packages/patches/rocm-opencl-runtime-4.3-noclinfo.patch 
b/gnu/packages/patches/rocm-opencl-runtime-4.3-noclinfo.patch
index da96b3ade8..3c80b024b1 100644
--- a/gnu/packages/patches/rocm-opencl-runtime-4.3-noclinfo.patch
+++ b/gnu/packages/patches/rocm-opencl-runtime-4.3-noclinfo.patch
@@ -2,8 +2,8 @@ Do not build and install clinfo.
 
 diff --git a/opencl/CMakeLists.txt b/opencl/CMakeLists.txt
 index 7b97cfdef..23eec15b2 100644
---- a/opencl/CMakeLists.txt
-+++ b/opencl/CMakeLists.txt
+--- a/projects/clr/opencl/CMakeLists.txt
++++ b/projects/clr/opencl/CMakeLists.txt
 @@ -33,7 +33,7 @@ if(BUILD_ICD)
    add_subdirectory(khronos/icd)
  endif()
@@ -15,8 +15,8 @@ index 7b97cfdef..23eec15b2 100644
    add_subdirectory(tests/ocltst)
 diff --git a/opencl/packaging/CMakeLists.txt b/opencl/packaging/CMakeLists.txt
 index 7d9e6366f..f8d08e0fc 100644
---- a/opencl/packaging/CMakeLists.txt
-+++ b/opencl/packaging/CMakeLists.txt
+--- a/projects/clr/opencl/packaging/CMakeLists.txt
++++ b/projects/clr/opencl/packaging/CMakeLists.txt
 @@ -16,7 +16,7 @@ endif()
  set(CPACK_DEB_COMPONENT_INSTALL ON)
  set(CPACK_RPM_COMPONENT_INSTALL ON)
diff --git a/gnu/packages/rocm.scm b/gnu/packages/rocm.scm
index 3adb1e381d..6d168ce04d 100644
--- a/gnu/packages/rocm.scm
+++ b/gnu/packages/rocm.scm
@@ -1,6 +1,7 @@
 ;;; GNU Guix --- Functional package management for GNU
 ;;; Copyright © 2021 Lars-Dominik Braun <[email protected]>
 ;;; Copyright © 2022, 2023, 2025 John Kehayias <[email protected]>
+;;; Copyright © 2026 Jean-Baptiste Note <[email protected]>
 ;;;
 ;;; This program is free software; you can redistribute it and/or modify it
 ;;; under the terms of the GNU General Public License as published by
@@ -24,178 +25,65 @@
   #:use-module (guix git-download)
   #:use-module (guix build-system cmake)
   #:use-module (gnu packages)
+  #:use-module (gnu packages boost)
+  #:use-module (gnu packages check)
+  #:use-module (gnu packages cpp)
+  #:use-module (gnu packages curl)
   #:use-module (gnu packages elf)
   #:use-module (gnu packages gcc)
   #:use-module (gnu packages gl)
   #:use-module (gnu packages linux)
   #:use-module (gnu packages llvm)
+  #:use-module (gnu packages logging)
   #:use-module (gnu packages opencl)
   #:use-module (gnu packages pkg-config)
+  #:use-module (gnu packages pretty-print)
   #:use-module (gnu packages python)
   #:use-module (gnu packages version-control)
   #:use-module (gnu packages vim)
-  #:use-module (gnu packages xdisorg))
+  #:use-module (gnu packages perl)
+  #:use-module (gnu packages xdisorg)
+  #:use-module (gnu packages libffi)
+  #:use-module (ice-9 match))
 
 ;; The components are tightly integrated and can only be upgraded as a unit. If
 ;; you want to upgrade ROCm, bump this version number and update hashes below.
-(define %rocm-version "6.4.2")
 
-;; As of version 6.1.0 several of the ROCm projects are contained within their
-;; forked LLVM repository.  This is the same as the source for llvm-for-rocm.
-(define %rocm-llvm-origin
+(define %rocm-version "7.1.0")
+
+;; ROCm-systems derived packages belong here.
+
+(define %rocm-systems-url "https://github.com/ROCm/rocm-systems";)
+(define %rocm-systems-origin
   (origin
     (method git-fetch)
     (uri (git-reference
-           (url "https://github.com/ROCm/llvm-project/";)
+           (url (string-append %rocm-systems-url))
            (commit (string-append "rocm-" %rocm-version))))
-    (file-name (git-file-name "llvm-for-rocm" %rocm-version))
+    (file-name (git-file-name "rocm-systems" %rocm-version))
     (sha256
      (base32
-      "1j2cr362k7snsh5c1z38ikyihmjvy0088rj0f0dhng6cjwgysryp"))))
-
-(define-public rocm-cmake
-  (package
-    (name "rocm-cmake")
-    (version %rocm-version)
-    (source (origin
-              (method git-fetch)
-              (uri (git-reference
-                    (url "https://github.com/ROCm/rocm-cmake/";)
-                    (commit (string-append "rocm-" version))))
-              (file-name (git-file-name name version))
-              (sha256
-               (base32
-                "1af9z59bm8pj577x43q614v3ff039wijvcdpgw6sdsq1c0ssj260"))))
-    (build-system cmake-build-system)
-    (arguments `(#:tests? #f)) ; Tests try to use git commit
-    (native-inputs (list git))
-    (home-page "https://rocm.docs.amd.com/projects/ROCmCMakeBuildTools/";)
-    (synopsis "ROCm cmake modules")
-    (description "ROCm cmake modules provides cmake modules for common build
-tasks needed for the ROCM software stack.")
-    (license license:ncsa)))
-
-(define-public rocm-device-libs
-  (package
-    (name "rocm-device-libs")
-    (version %rocm-version)
-    (source %rocm-llvm-origin)
-    (build-system cmake-build-system)
-    (arguments
-     (list
-      #:tests? #f ; Not sure how to run them.
-      #:build-type "Release"
-      #:configure-flags
-      #~(list "-DCMAKE_SKIP_BUILD_RPATH=FALSE"
-              "-DCMAKE_BUILD_WITH_INSTALL_RPATH=FALSE")
-      #:phases
-      #~(modify-phases %standard-phases
-          (add-after 'unpack 'chdir
-            (lambda _
-              (chdir "amd/device-libs"))))))
-    (inputs (list llvm-for-rocm))
-    (home-page "https://github.com/ROCm/llvm-project/";)
-    (synopsis "ROCm Device libraries")
-    (description "AMD-specific device-side language runtime libraries, namely
-oclc, ocml, ockl, opencl, hip and hc.")
-    (license license:ncsa)))
-
-(define-public rocm-hip-cpu
-  ;; There are no releases or tags.
-  (let ((commit "e112c935057434897bb12d9ab3910380a8bd5f58")
-        (release "0"))
-    (package
-      (name "rocm-hip-cpu")
-      (version "0.1.4142")              ;from CMakeLists.txt
-      (source
-       (origin
-         (method git-fetch)
-         (uri (git-reference
-                (url "https://github.com/ROCm/HIP-CPU/";)
-                (commit commit)))
-         (file-name (git-file-name name version))
-         (sha256
-          (base32
-           "1rbih56kfry7scvww54dwx8ph11ddzc5bf4ww1vs1vmhi3r05gpa"))))
-      (build-system cmake-build-system)
-      (arguments
-       (list
-        #:configure-flags #~(list "-DBUILD_EXAMPLES=ON")))
-      (home-page "https://github.com/ROCm/HIP-CPU/";)
-      (synopsis "An implementation of HIP that works on CPUs")
-      (description "The HIP CPU Runtime is a header-only library that allows
-CPUs to execute unmodified HIP code.  It is generic and does not assume a
-particular CPU vendor or architecture.")
-      (license license:expat))))
-
-(define-public rocm-comgr
-  (package
-    (name "rocm-comgr")
-    (version %rocm-version)
-    (source %rocm-llvm-origin)
-    (build-system cmake-build-system)
-    (arguments
-     (list
-      #:build-type "Release"
-      #:phases
-      #~(modify-phases %standard-phases
-          (add-after 'unpack 'prepare-to-build
-            (lambda _
-              (chdir "amd/comgr")
-              (setenv "ROCM_PATH"
-                      #$(this-package-input "rocm-device-libs")))))))
-    (inputs (list rocm-device-libs))
-    (native-inputs (list llvm-for-rocm python))
-    (home-page "https://github.com/ROCm/ROCm-CompilerSupport";)
-    (synopsis "ROCm Code Object Manager")
-    (description "The Comgr library provides APIs for compiling and inspecting
-AMDGPU code objects.")
-    (license license:ncsa)))
-
-;; This package is deprecated; this is the last version released.
-(define-public roct-thunk-interface
-  (package
-    (name "roct-thunk-interface")
-    (version "6.2.4")
-    (source (origin
-              (method git-fetch)
-              (uri (git-reference
-                    (url "https://github.com/ROCm/ROCT-Thunk-Interface.git";)
-                    (commit (string-append "rocm-" version))))
-              (file-name (git-file-name name version))
-              (sha256
-               (base32
-                "1y3mn4860z7ca71cv4hhag7racpc208acy8rws8ldw5k8yjc68m0"))))
-    (build-system cmake-build-system)
-    (arguments `(#:tests? #f)) ; Not sure how to run tests.
-    (inputs (list libdrm numactl))
-    (native-inputs (list `(,gcc "lib") pkg-config))
-    (home-page "https://github.com/ROCm/ROCT-Thunk-Interface";)
-    (synopsis "Radeon Open Compute Thunk Interface")
-    (description "User-mode API interfaces used to interact with the ROCk
-driver.")
-    (license (list license:expat license:ncsa))))
+      "16h88j5440csz69s7gpcbmiwn72bz4zjlkdm2c7wcyp73m2knnm2"))
+    (patches
+     (search-patches
+      "rocclr-5.6.0-enable-gfx800.patch"
+      "rocm-opencl-runtime-4.3-noclinfo.patch"))))
 
 (define-public rocr-runtime
   (package
     (name "rocr-runtime")
     (version %rocm-version)
-    (source (origin
-              (method git-fetch)
-              (uri (git-reference
-                    (url "https://github.com/ROCm/ROCR-Runtime.git";)
-                    (commit (string-append "rocm-" version))))
-              (file-name (git-file-name name version))
-              (sha256
-               (base32
-                "01gqbzqm5m28dw9b2calrbp9a23w2cc2gwi3pay8yl8qvk4jgkff"))))
+    (source %rocm-systems-origin)
     (build-system cmake-build-system)
     (arguments
      (list
-      #:tests? #f ; No tests.
+      #:tests? #f                       ; No tests.
       #:build-type "Release"
       #:phases
       #~(modify-phases %standard-phases
+          (add-after 'unpack 'chdir
+            (lambda _
+              (chdir "projects/rocr-runtime")))
           (add-after 'unpack 'add-rocm-device-lib-path
             (lambda _
               (setenv "ROCM_PATH"
@@ -203,12 +91,12 @@ driver.")
     (inputs
      (list libdrm
            libelf-shared
-           llvm-for-rocm
+           clang-rocm
+           lld-rocm
            numactl
-           rocm-device-libs ; For bitcode.
-           roct-thunk-interface))
+           rocm-device-libs))           ; For bitcode.
     (native-inputs (list pkg-config xxd))
-    (home-page "https://github.com/ROCm/ROCR-Runtime";)
+    (home-page %rocm-systems-url)
     (synopsis "ROCm Platform Runtime")
     (description "User-mode API interfaces and libraries necessary for host
 applications to launch compute kernels to available HSA ROCm kernel agents.")
@@ -218,25 +106,12 @@ applications to launch compute kernels to available HSA 
ROCm kernel agents.")
   (package
     (name "rocm-opencl-runtime")
     (version %rocm-version)
-    (home-page "https://github.com/ROCm/clr";)
-    (source (origin
-              (method git-fetch)
-              (uri (git-reference
-                    (url home-page)
-                    (commit (string-append "rocm-" version))))
-              (file-name (git-file-name name version))
-              (sha256
-               (base32
-                "00zr1fw84nifn2b2zd4wxf00f1171hjmz1lypzzmydsk5yw01q0c"))
-              (patches
-               (search-patches
-                "rocclr-5.6.0-enable-gfx800.patch"
-                ;; Guix includes a program clinfo already.
-                "rocm-opencl-runtime-4.3-noclinfo.patch"))))
+    (home-page %rocm-systems-url)
+    (source %rocm-systems-origin)
     (build-system cmake-build-system)
     (arguments
      (list
-      #:tests? #f ; Not sure how to run them.
+      #:tests? #f                       ; Not sure how to run them.
       #:build-type "Release"
       #:configure-flags
       #~(list
@@ -250,11 +125,13 @@ applications to launch compute kernels to available HSA 
ROCm kernel agents.")
          "-DFILE_REORG_BACKWARD_COMPATIBILITY=OFF")
       #:phases
       #~(modify-phases %standard-phases
-          (add-after 'unpack 'no-os-release
+          (add-after 'unpack 'chdir
+            (lambda _
+              (chdir "projects/clr")))
+          (add-after 'chdir 'no-os-release
             (lambda _
               (substitute* "opencl/packaging/CMakeLists.txt"
-                (("\"/etc/os-release\"")
-                 "\"/dev/null\""))))
+                (("/etc/os-release") "/dev/null"))))
           (add-after 'install 'create-icd
             ;; Manually install ICD, which simply consists of dumping
             ;; the path of the .so into the correct file.
@@ -270,6 +147,7 @@ applications to launch compute kernels to available HSA 
ROCm kernel agents.")
            numactl
            opencl-headers
            opencl-icd-loader
+           libffi
            rocm-comgr
            rocr-runtime))
     (synopsis "ROCm OpenCL Runtime")
@@ -277,39 +155,178 @@ applications to launch compute kernels to available HSA 
ROCm kernel agents.")
 and in-process/in-memory compilation.")
     (license license:expat)))
 
+;; this runtime includes the hipcc and hip-config present in rocm-hipcc
+;; wrapping them in rocm-hipcc allows the copies that are made here to be
+;; wrapped also.
+(define-public rocm-hip-runtime
+  (package
+    (name "rocm-hip-runtime")
+    (version %rocm-version)
+    (home-page %rocm-systems-url)
+    (source %rocm-systems-origin)
+    (build-system cmake-build-system)
+    (arguments
+     (list
+      #:tests? #f                       ; Not sure how to run them.
+      #:build-type "Release"
+      #:configure-flags
+      #~(list
+         (string-append "-DAMD_OPENCL_PATH=" #$(package-source this-package))
+         "-DCLR_BUILD_HIP=ON"
+         "-DCLR_BUILD_OCL=OFF"
+         (string-append "-DROCM_PATH=" #$output)
+         "-DHIP_PLATFORM=amd"
+         (string-append
+          "-DHIPCC_BIN_DIR=" #$(this-package-native-input "rocm-hipcc") "/bin")
+         (string-append
+          "-DHIP_COMMON_DIR=" #$(package-source this-package) "/projects/hip")
+         ;; for now
+         "-DUSE_PROF_API=OFF"
+         "-DHIP_ENABLE_ROCPROFILER_REGISTER=OFF")
+      #:phases
+      #~(modify-phases %standard-phases
+          (add-after 'unpack 'chdir
+            (lambda _
+              (chdir "projects/clr")))
+          (add-after 'chdir 'no-os-release
+            (lambda _
+              (substitute* '("hipamd/packaging/CMakeLists.txt"
+                             "hipamd/CMakeLists.txt")
+                (("/etc/os-release") "/dev/null"))))
+          (add-after 'chdir 'less-cmake-warnings
+            (lambda _
+              (substitute* "rocclr/cmake/ROCclrLC.cmake"
+                (("2\\.9") "3.0"))))
+          (add-after 'chdir 'fix-clang-location-for-embed-pch
+            (lambda _
+              (substitute* "hipamd/src/CMakeLists.txt"
+                ;; differentiate between CLANG and LLVM packages
+                (("\\$\\{HIP_LLVM_ROOT\\}")
+                 (string-append  "${HIP_LLVM_ROOT} "
+                                 #$(this-package-input "clang-rocm"))))
+              (substitute* "hipamd/src/hip_embed_pch.sh"
+                (("\\$5") "$6")
+                (("LLVM_DIR=\"\\$4\"")
+                 "LLVM_DIR=\"$4\"; CLANG_DIR=\"$5\";")
+                (("\\$LLVM_DIR/bin/clang")
+                 (string-append "$CLANG_DIR/bin/clang"))))))))
+    (inputs
+     (list glew
+           mesa
+           numactl
+           perl
+           opencl-headers
+           rocm-comgr
+           rocr-runtime
+           rocm-device-libs
+           libffi
+           clang-rocm))
+    (native-inputs
+     (list rocm-hipcc))
+    (synopsis "ROCm HIP Runtime")
+    (description "HIP language runtime, allowing execution of HIP kernels
+on AMD harware, with library support for in-process/in-memory
+compilation (hipclr) of HIP kernel code, and its execution on AMD hardware.")
+    (license license:expat)))
+
 (define-public rocminfo
   (package
     (name "rocminfo")
     (version %rocm-version)
-    (source (origin
-              (method git-fetch)
-              (uri (git-reference
-                    (url "https://github.com/ROCm/rocminfo.git";)
-                    (commit (string-append "rocm-" version))))
-              (file-name (git-file-name name version))
-              (sha256
-               (base32
-                "15mzmxz011sg42jg0dbxz57f4fagmxzdjc6zhd0yab3cq7k1kiv2"))))
+    (source %rocm-systems-origin)
     (build-system cmake-build-system)
     (arguments
      (list
-      #:tests? #f ; No tests.
+      #:tests? #f                       ; No tests.
       #:phases
       #~(modify-phases %standard-phases
-          (add-after 'unpack 'patch-binary-paths
+          (add-after 'unpack 'chdir
+            (lambda _
+              (chdir "projects/rocminfo")))
+          (add-after 'chdir 'patch-binary-paths
             (lambda* (#:key inputs #:allow-other-keys)
               (substitute* "rocminfo.cc"
                 (("lsmod")
                  (search-input-file inputs "bin/lsmod"))
-                (("grep") (search-input-file inputs "bin/grep"))))))))
+                (("grep")
+                 (search-input-file inputs "bin/grep"))))))))
     (inputs
-     (list rocr-runtime kmod))
-    (home-page "https://github.com/ROCm/rocminfo";)
+     (list rocr-runtime kmod python))
+    (home-page %rocm-systems-url)
     (synopsis "ROCm Application for Reporting System Info")
     (description "List @acronym{HSA,Heterogeneous System Architecture} Agents
 available to ROCm and show their properties.")
     (license license:ncsa)))
 
+
+
+;; ROCm base helpers.
+
+(define-public rocm-cmake
+  (package
+    (name "rocm-cmake")
+    (version %rocm-version)
+    (source (origin
+              (method git-fetch)
+              (uri (git-reference
+                     (url "https://github.com/ROCm/rocm-cmake/";)
+                     (commit (string-append "rocm-" version))))
+              (file-name (git-file-name name version))
+              (sha256
+               (base32
+                "19jyymisxiikphzmq6h8vy5cg0r5dz3lxr5wvdf44frb8wxr8vla"))))
+    (build-system cmake-build-system)
+    (arguments `(#:tests? #f))          ; Tests try to use git commit
+    (native-inputs (list git))
+    (home-page "https://rocm.docs.amd.com/projects/ROCmCMakeBuildTools/";)
+    (synopsis "ROCm cmake modules")
+    (description "ROCm cmake modules provides cmake modules for common build
+tasks needed for the ROCM software stack.")
+    (license license:ncsa)))
+
+(define-public rocm-hip-cpu
+  ;; There are no releases or tags.
+  (let ((commit "e112c935057434897bb12d9ab3910380a8bd5f58")
+        (release "0"))
+    (package
+      (name "rocm-hip-cpu")
+      (version "0.1.4142")              ;from CMakeLists.txt
+      (source
+       (origin
+         (method git-fetch)
+         (uri (git-reference
+                (url "https://github.com/ROCm/HIP-CPU/";)
+                (commit commit)))
+         (file-name (git-file-name name version))
+         (sha256
+          (base32
+           "1rbih56kfry7scvww54dwx8ph11ddzc5bf4ww1vs1vmhi3r05gpa"))))
+      (build-system cmake-build-system)
+      (arguments
+       (list
+        #:configure-flags #~(list "-DBUILD_EXAMPLES=ON")))
+      (home-page "https://github.com/ROCm/HIP-CPU/";)
+      (synopsis "Implementation of HIP that works on CPUs")
+      (description "The HIP CPU Runtime is a header-only library that allows
+CPUs to execute unmodified HIP code.  It is generic and does not assume a
+particular CPU vendor or architecture.")
+      (license license:expat))))
+
+(define %default-amdgpu-targets
+  '("gfx908" "gfx90a" "gfx942" "gfx1030" "gfx1100" "gfx1101" "gfx1200" 
"gfx1201"))
+
+;; I guess the intent would be to have this overridable with a package
+;; transform akin to --with-property=amdgpu-target="gfx1100;gfx1101"
+(define %default-amdgpu-targets-property
+  `(amdgpu-targets
+    .
+    ,(string-join %default-amdgpu-targets ";")))
+
+(define-syntax-rule (%amdgpu-targets)
+  (string-split
+   (assoc-ref (package-properties this-package) 'amdgpu-targets)
+   #\;))
+
 (define-public rocm-bandwidth-test
   (package
     (name "rocm-bandwidth-test")
@@ -317,15 +334,120 @@ available to ROCm and show their properties.")
     (source (origin
               (method git-fetch)
               (uri (git-reference
-                    (url "https://github.com/ROCm/rocm_bandwidth_test.git";)
-                    (commit (string-append "rocm-" version))))
+                     (url "https://github.com/ROCm/rocm_bandwidth_test";)
+                     (commit (string-append "rocm-" version))))
               (file-name (git-file-name name version))
               (sha256
                (base32
-                "1afmyx0dkif7djdcm5rfhnsibbrkj4py6dvh0gw4x3v750ms69wv"))))
+                "09ssn8lkjaypq8qy3v28z25qvxsyha4cv4dk6xmfxmgfy8252yqy"))
+              (patches
+               (search-patches
+                "rocm-bandwidth-test-take-default-gpus-from-environment.patch"
+                "rocm-bandwidth-test-fix-hsa-include-file-lookup.patch"
+                "rocm-bandwidth-test-fix-external-packages-search.patch"))))
     (build-system cmake-build-system)
-    (arguments `(#:tests? #f)) ; No tests.
-    (inputs (list rocr-runtime))
+    (arguments
+     (list
+      #:tests? #f
+      #:build-type "Release"
+      #:configure-flags
+      #~(list
+         "-DAMD_APP_TREAT_WARNINGS_AS_ERRORS=FALSE"
+         "-DAMD_APP_ROCM_BUILD_PACKAGE=ON"
+         ;; The rocm build system is very opiniated about the rpath and
+         ;; mangles it beyond recognition, stripping all inputs from it.
+         ;; Avoid the breakage.
+         "-DAMD_APP_ROCM_BUILD_TRY_RPATH=OFF"
+         ;; Allows the plugin files to be correctly rpathed to $#output/lib
+         ;; where shared libraries reside.
+         "-DAMD_WORK_BENCH_PLUGIN_ADD_INSTALL_PREFIX_TO_RPATH=TRUE"
+         ;; Unfortunately this also needs to be patched everywhere, as the
+         ;; value is individually set to OFF for a lot of targets, and not
+         ;; propagated from the top. So set it here, and use substitutions
+         ;; below.
+         "-DCMAKE_INSTALL_RPATH_USE_LINK_PATH=TRUE"
+         (string-append "-DROCM_PATH=" #$output)
+         "-DUSE_LOCAL_FMT_LIB=ON"
+         "-DUSE_LOCAL_NLOHMANN_JSON=ON"
+         "-DUSE_LOCAL_SPDLOG=ON"
+         "-DUSE_LOCAL_BOOST=ON"
+         "-DUSE_LOCAL_CLI11=ON"
+         "-DUSE_LOCAL_CATCH2=ON")
+      #:phases
+      #~(modify-phases %standard-phases
+          (add-after 'unpack 'patch-out-bogus-git-requirement
+            (lambda _
+              (substitute* "CMakeLists.txt"
+                (("find_package\\(Git QUIET\\)")
+                 "set(GIT_FOUND ON)"))))
+          ;; This converts the amdgpu-targets property to its proper entry
+          ;; point in this package; this relies on the patch
+          ;; rocm-bandwidth-test-take-default-gpus-from-environment.patch
+          ;; above, as I can't seem to find a way to do multiline matches.
+          ;; Note that compiling for all GPUs architectures is sequential, and
+          ;; will run for a very long time.
+          (add-after 'unpack 'inject-amdgpu-targets
+            (lambda _
+              (substitute* "plugins/tb/transferbench/CMakeLists.txt"
+                (("set\\(DEFAULT_GPUS[^)]*\\)")
+                 (string-append
+                  "set(DEFAULT_GPUS " #$(string-join (%amdgpu-targets)) ")" 
)))))
+          ;; See configure-flags above.
+          (add-after 'unpack 'fix-use-link-path
+            (lambda _
+              (substitute* (find-files "." "CMakeLists\\.txt$|\\.cmake$")
+                ;; NB: this will also catch instances of
+                ;; CMAKE_INSTALL_RPATH_USE_LINK_PATH
+                (("INSTALL_RPATH_USE_LINK_PATH FALSE")
+                 "INSTALL_RPATH_USE_LINK_PATH TRUE"))))
+          ;; For the same reason, just in case patchelf ends up in the inputs
+          ;; (the build system may require it), we remove a hardcoded rpath in
+          ;; a bash build script which triggers if patchelf is detected.
+          (add-after 'unpack 'remove-hardcoded-patchelf
+            (lambda _
+              (substitute* "plugins/tb/transferbench/build_libamd_tb.sh"
+                (("command -v patchelf") "false"))))
+          ;; XXX The build system uses -fuse-ld=lld flag for c++ linking if it
+          ;; finds ld.lld in any way.  Unfortunately, for some reason, ld.lld
+          ;; does not correctly setup the rpath when compiling the
+          ;; rocm_bandwidth_test binary (the only executable which shows the
+          ;; problem).  We do need ld.lld from lld-rocm in the path for
+          ;; ROCm-specific linking however.  Therefore, just disable ld.lld
+          ;; lookup for standard binaries.
+          ;; I guess there's a standard Guix way to have lld behave for rpath
+          ;; -- which should be applied to lld-rocm, probably.
+          (add-after 'unpack 'dont-use-lld-for-executables
+            (lambda _
+              (substitute* "cmake/build_utils.cmake"
+                (("find_program\\(LD_LLD_PATH ld\\.lld\\)")
+                 "#find_program(LD_LLD_PATH ld.lld)"))))
+          ;; This is just cosmetic and removes superfluous rpath entries
+          ;; involving a nonexistant relative llvm/lib path.
+          ;; XXX: RUNPATH checks are okay with $ORIGIN, but it looks like
+          ;; other packages are removing it altogether -- what to do?
+          (add-after 'unpack 'remove-dubious-rpath
+            (lambda _
+              (substitute* (find-files "." "CMakeLists\\.txt$|\\.cmake$")
+                ((":\\\\\\$ORIGIN(/\\.\\./lib)?/llvm/lib") "")))))))
+    (inputs (list rocr-runtime
+                  rocm-hip-runtime
+                  rocm-cmake
+                  rocm-device-libs
+                  rocm-comgr
+                  numactl
+                  curl
+                  fmt-11
+                  nlohmann-json
+                  spdlog-1.15
+                  boost
+                  cli11
+                  catch2-3.8))
+    (properties
+     (list %default-amdgpu-targets-property))
+    (native-inputs (list
+                    rocm-hipcc
+                    clang-rocm
+                    lld-rocm))
     (home-page "https://github.com/ROCm/rocm_bandwidth_test";)
     (synopsis "Bandwidth test for ROCm")
     (description "RocBandwidthTest is designed to capture the performance
@@ -335,7 +457,6 @@ cop/read/writer operations.  In addition one can also query 
the topology of
 the system in terms of memory pools and their agents.")
     (license license:expat)))
 
-
 ;; e-smi looks hard to unbundle correctly from amd-smi
 ;; the required esmi version is hardcoded in CMakeLists.txt
 (define (make-esmi-source version hash)

Reply via email to