diff --git a/gnu/local.mk b/gnu/local.mk index e1c837d30c..6234258db1 100644 --- a/gnu/local.mk +++ b/gnu/local.mk @@ -987,6 +987,7 @@ dist_patch_DATA = \ %D%/packages/patches/akonadi-not-relocatable.patch \ %D%/packages/patches/akonadi-timestamps.patch \ %D%/packages/patches/alure-dumb-2.patch \ + %D%/packages/patches/amd-smi-python.patch \ %D%/packages/patches/ibus-anthy-fix-tests.patch \ %D%/packages/patches/ibus-table-paths.patch \ %D%/packages/patches/anki-mpv-args.patch \ diff --git a/gnu/packages/patches/amd-smi-python.patch b/gnu/packages/patches/amd-smi-python.patch new file mode 100644 index 0000000000..4e8f0985d8 --- /dev/null +++ b/gnu/packages/patches/amd-smi-python.patch @@ -0,0 +1,101 @@ +From 7501e5f980854996a9f411642f619fda806e6420 Mon Sep 17 00:00:00 2001 +From: Jean-Baptiste Note +Date: Tue, 23 Sep 2025 09:33:13 +0200 +Subject: [PATCH] [python] Guix support patch. + +* Remove bundled library in python wrapper. + +* Make library lookup consistent with something that can easily be +patched for guix. +--- + py-interface/CMakeLists.txt | 7 +------ + py-interface/amdsmi_wrapper.py | 2 ++ + py-interface/pyproject.toml.in | 4 ---- + py-interface/setup.py.in | 4 ---- + tools/generator.py | 2 ++ + 5 files changed, 5 insertions(+), 14 deletions(-) + +diff --git a/py-interface/CMakeLists.txt b/py-interface/CMakeLists.txt +index 6aaa5056..4bc0150e 100644 +--- a/py-interface/CMakeLists.txt ++++ b/py-interface/CMakeLists.txt +@@ -80,10 +80,6 @@ add_custom_command( + COMMAND ln -Pf ${CMAKE_CURRENT_SOURCE_DIR}/README.md ${PY_PACKAGE_DIR}/ + COMMAND ln -Pf ${PROJECT_SOURCE_DIR}/LICENSE ${PY_PACKAGE_DIR}/) + +-# copy libamd_smi.so to allow for a self-contained python package +-add_custom_command(OUTPUT ${PY_PACKAGE_DIR}/libamd_smi.so DEPENDS ${PROJECT_BINARY_DIR}/src/libamd_smi.so +- COMMAND cp "${PROJECT_BINARY_DIR}/src/libamd_smi.so" ${PY_PACKAGE_DIR}/) +- + add_custom_target( + python_package ALL + DEPENDS ${PY_BUILD_DIR}/pyproject.toml +@@ -93,8 +89,7 @@ add_custom_target( + ${PY_PACKAGE_DIR}/amdsmi_exception.py + ${PY_PACKAGE_DIR}/amdsmi_interface.py + ${PY_PACKAGE_DIR}/README.md +- ${PY_PACKAGE_DIR}/LICENSE +- ${PY_PACKAGE_DIR}/libamd_smi.so) ++ ${PY_PACKAGE_DIR}/LICENSE) + + install( + FILES ${CMAKE_CURRENT_BINARY_DIR}/${PY_BUILD_DIR}/pyproject.toml +diff --git a/py-interface/amdsmi_wrapper.py b/py-interface/amdsmi_wrapper.py +index b52d7fa3..f19fbc73 100644 +--- a/py-interface/amdsmi_wrapper.py ++++ b/py-interface/amdsmi_wrapper.py +@@ -183,6 +183,8 @@ def find_smi_library(): + rocm_path = os.getenv("ROCM_HOME", os.getenv("ROCM_PATH")) + if rocm_path: + possible_locations.append(os.path.join(rocm_path, "lib/libamd_smi.so")) ++ if os.path.exists("/opt/rocm/lib/libamd_smi.so"): ++ possible_locations.append("/opt/rocm/lib/libamd_smi.so") + # 2. + possible_locations.append("libamd_smi.so") + # 3. +diff --git a/py-interface/pyproject.toml.in b/py-interface/pyproject.toml.in +index 38dc13f1..c80a76df 100644 +--- a/py-interface/pyproject.toml.in ++++ b/py-interface/pyproject.toml.in +@@ -24,10 +24,6 @@ classifiers = [ + [tool.setuptools] + packages = ["amdsmi"] + zip-safe = false +-include-package-data = true +- +-[tool.setuptools.package-data] +-amdsmi = ["*.so"] + + [tool.pytest.ini_options] + pythonpath = "/opt/rocm/share/amd_smi" +diff --git a/py-interface/setup.py.in b/py-interface/setup.py.in +index dbd98e2b..8d5f283d 100644 +--- a/py-interface/setup.py.in ++++ b/py-interface/setup.py.in +@@ -13,10 +13,6 @@ setup( + "Programming Language :: Python :: 3", + ], + python_requires=">=3.6", +- include_package_data=True, +- package_data={ +- '': ['*.so'], +- }, + zip_safe=False, + license='amdsmi/LICENSE', + ) +diff --git a/tools/generator.py b/tools/generator.py +index 2882f494..24454bca 100644 +--- a/tools/generator.py ++++ b/tools/generator.py +@@ -198,6 +198,8 @@ def find_smi_library(): + rocm_path = os.getenv("ROCM_HOME", os.getenv("ROCM_PATH")) + if rocm_path: + possible_locations.append(os.path.join(rocm_path, "lib/{library_name}")) ++ if os.path.exists("/opt/rocm/lib/{library_name}"): ++ possible_locations.append("/opt/rocm/lib/{library_name}") + # 2. + possible_locations.append("{library_name}") + # 3. +-- +2.51.0 + diff --git a/gnu/packages/rocm.scm b/gnu/packages/rocm.scm index ea73239f59..3fe9484706 100644 --- a/gnu/packages/rocm.scm +++ b/gnu/packages/rocm.scm @@ -335,3 +335,82 @@ 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:ncsa))) + +;; 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) + (origin + (method git-fetch) + (uri (git-reference + (url "https://github.com/amd/esmi_ib_library.git") + (commit version))) + (file-name (git-file-name "esmi_ib_library" version)) + (sha256 hash))) + +(define %e-smi-version-for-rocm "esmi_pkg_ver-4.1.2") +(define e-smi-for-amd-smi + (make-esmi-source + %e-smi-version-for-rocm + (base32 "1lj35gsa5pgfpsv0bl5y3xpk3xhk8kgsi4nkl2kxj0gsiyny8gf2"))) + +(define-public amd-smi + (package + (name "amd-smi") + (version "25.5.1") + (source (origin + (method git-fetch) + (uri (git-reference + (url "https://github.com/ROCm/amdsmi") + (commit (string-append "rocm-" %rocm-version)))) + (file-name (git-file-name name version)) + (sha256 + (base32 + "0cfsj91pwzvc3c306ivvkzp819g4mxr88h091r2hr4f6h4xvvvgl")) + (patches + (search-patches "amd-smi-python.patch")))) + (build-system cmake-build-system) + (arguments (list + #:tests? #f ;; The test suite is empty and failing as of 25.5.1 + #:configure-flags + #~(list + "-DBUILD_SHARED_LIBS=ON" + ;; this requires ctypeslib2 packaging + ;; "-DBUILD_WRAPPER=ON" + "-DENABLE_ESMI_LIB=ON" + "-DBUILD_CLI=ON") + #:phases + #~(modify-phases %standard-phases + (add-after 'unpack 'add-e-smi + (lambda* _ + (copy-recursively + #$(this-package-input + (origin-file-name e-smi-for-amd-smi)) + "esmi_ib_library") + ;; Fool cmake, which uses failing git calls above this. + (substitute* "CMakeLists.txt" + (("# Update to latest tags if not matched") + (format #f "set(latest_esmi_tag ~s)" + #$%e-smi-version-for-rocm))))) + (add-after 'add-e-smi 'patch-dlopen + (lambda* (#:key inputs #:allow-other-keys) + (substitute* (find-files "src" "\\.cc$") + (("libdrm.so.2") + (search-input-file inputs "/lib/libdrm.so.2")) + (("libdrm_amdgpu.so") + (search-input-file inputs "/lib/libdrm_amdgpu.so"))))) + (add-after 'add-e-smi 'patch-python + (lambda* _ + (substitute* (find-files "py-interface" "\\.py$") + (("/opt/rocm") #$output))))))) + (inputs (list libdrm + python + e-smi-for-amd-smi)) + (home-page "https://github.com/ROCm/amdsmi") + (synopsis "ROCm library and application for managing AMD devices") + (description "The AMD @acronym{SMI,System Management Interface} allows +managing and monitoring AMD devices, particularly in high-performance +computing environments. It provides a user-space interface that allows +applications to control GPU operations, monitor performance, and retrieve +information about the system's drivers and GPUs. It also provides a +command-line tool, @command{amd-smi}, which can be used to do the same.") + (license (list license:expat license:ncsa))))