From fff815c7b10ae315bbc721dceb466eba73b21d6d Mon Sep 17 00:00:00 2001 From: randomizedcoder Date: Fri, 16 Oct 2026 19:45:42 -0700 Subject: [PATCH 01/21] rocmPackages.rocmUpdateScript: take maxMajor and tagPrefixes Prepare the update script for a rocmPackages_10 set built from the TheRock monorepos, whose sources are tagged therock-X.Y[.Z]: - maxMajor (default 7) replaces the hard-coded major cap, so a second set can call it with its own cap. - tagPrefixes (default [ "rocm" ]) selects which tag families count as releases. The current set keeps rocm- only, so the therock-7.x preview tags are not picked up. - setName (default "rocmPackages") is the attribute path passed to update-source-version. - Pick the highest matching version instead of the first release listed: releases are not ordered by version (a rocm-7.2.x maintenance release can be published after a newer series). - Follow GitHub's pagination (100 per page) so the highest version is found even when it is not on the first page, and fail on fetch errors instead of reporting "no valid version". No change to any derivation; passthru.updateScript only. Assisted-by: Claude Code (claude-opus-5-5) --- pkgs/development/rocm-modules/update.nix | 48 +++++++++++++++++------- 1 file changed, 34 insertions(+), 14 deletions(-) diff --git a/pkgs/development/rocm-modules/update.nix b/pkgs/development/rocm-modules/update.nix index 7ffc5f9a7e6cb..71b281e816fa0 100644 --- a/pkgs/development/rocm-modules/update.nix +++ b/pkgs/development/rocm-modules/update.nix @@ -1,6 +1,12 @@ { lib, writeScript, + # Newest major this set accepts; a newer major goes into a new rocmPackages_X. + maxMajor ? 7, + # Tag prefixes this set's versions are published under (rocm-X.Y.Z, therock-X.Y[.Z]). + tagPrefixes ? [ "rocm" ], + # Attribute path of the package set, for update-source-version. + setName ? "rocmPackages", }: { @@ -8,10 +14,17 @@ name ? finalAttrs.pname, owner ? finalAttrs.src.owner, repo ? finalAttrs.src.repo, - page ? "releases?per_page=10", - # input: array of [ { tag_name: "rocm-6.x.x", }, ... ]. some entries may have bad names like rocm-test-date we want to skip - # output: first tag_name/name that's a proper version if any - filter ? "map(.tag_name // .name) | map(select(test(\"^rocm-[0-9]+\\\\.[0-9]+(\\\\.[0-9]+)?$\"))) | first | ltrimstr(\"rocm-\")", + page ? "releases?per_page=100", + # input: array of [ { tag_name: "rocm-7.2.4", }, { tag_name: "therock-10.1" }, ... ]. some entries + # may have bad names like rocm-test-date we want to skip + # output: the highest proper version with an accepted prefix and major <= maxMajor, if any. + # Releases are not ordered by version (a rocm-7.2.x maintenance release can follow therock-10.1). + filter ? lib.concatStringsSep " | " [ + "map(.tag_name // .name)" + "map(select(test(\"^(${lib.concatStringsSep "|" tagPrefixes})-[0-9]+\\\\.[0-9]+(\\\\.[0-9]+)?$\")) | sub(\"^(${lib.concatStringsSep "|" tagPrefixes})-\"; \"\"))" + "map(select((split(\".\")[0] | tonumber) <= ${toString maxMajor}))" + "sort_by(split(\".\") | map(tonumber)) | last // empty" + ], }: let @@ -23,14 +36,21 @@ let #!nix-shell -i bash -p curl jq common-updater-scripts set -euo pipefail - fetch_releases() { + fetch_releases() ( local api_url="https://api.github.com/repos/${owner}/${repo}/${page}" - if [ "${page}" = "releases" ]; then - api_url="$api_url?per_page=4" + local headers + headers="$(mktemp)" + trap 'rm -f "$headers"' EXIT + local -a auth=() + if [[ -n "''${GITHUB_TOKEN:-}" ]]; then + auth=(-H "Authorization: Bearer $GITHUB_TOKEN") fi - >&2 echo $api_url - curl ''${GITHUB_TOKEN:+-u ":$GITHUB_TOKEN"} -sL "$api_url" - } + while [[ -n "$api_url" ]]; do + curl "''${auth[@]}" -fsSL --dump-header "$headers" "$api_url" || return + printf '\n' + api_url="$(tr -d '\r' < "$headers" | sed -nE 's/^link:.*<([^>]+)>; rel="next".*/\1/ip')" + done + ) find_valid_version() { local releases="$1" @@ -40,7 +60,7 @@ let echo "$releases" | jq -r 'if type == "array" then . else [.] end | ${filter}' } - releases="$(fetch_releases)" + releases="$(fetch_releases | jq -s 'map(if type == "array" then . else [.] end) | add')" version="$(find_valid_version "$releases")" if [ -z "$version" ]; then @@ -52,12 +72,12 @@ let >&2 echo parsed version "$version_arr" from "$version" - if (( ''${version_arr[0]} > 7 )); then - echo "'rocmPackages.${pname}' is already at its maximum allowed version.''\nAny further upgrades should go into 'rocmPackages_X.${pname}'." >&2 + if (( ''${version_arr[0]} > ${toString maxMajor} )); then + echo "'${setName}.${pname}' is already at its maximum allowed version.''\nAny further upgrades should go into 'rocmPackages_X.${pname}'." >&2 exit 1 fi - update-source-version rocmPackages.${pname} "$version" --ignore-same-hash + update-source-version ${setName}.${pname} "$version" --ignore-same-hash ''; in [ updateScript ] From f636197cb36c98c59e5bea8e1ffd69245ebb0296 Mon Sep 17 00:00:00 2001 From: aaravrav <37036762+aaravrav@users.noreply.github.com> Date: Fri, 16 Oct 2026 23:20:55 +0530 Subject: [PATCH 02/21] llvmPackages_23.openmp: fix build for LLVM 23+ (cherry picked from commit ab348e2dc2527cb2f052d28b248427eb49689d66) --- .../compilers/llvm/common/openmp/default.nix | 32 +++++++++++++++---- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/pkgs/development/compilers/llvm/common/openmp/default.nix b/pkgs/development/compilers/llvm/common/openmp/default.nix index 2601e294fccfe..d6792fa1a94b5 100644 --- a/pkgs/development/compilers/llvm/common/openmp/default.nix +++ b/pkgs/development/compilers/llvm/common/openmp/default.nix @@ -36,15 +36,28 @@ stdenv.mkDerivation (finalAttrs: { strictDeps = true; __structuredAttrs = true; } - '' - mkdir -p "$out" - cp -r ${monorepoSrc}/cmake "$out" - cp -r ${monorepoSrc}/openmp "$out" - '' + ( + '' + mkdir -p "$out" + cp -r ${monorepoSrc}/cmake "$out" + cp -r ${monorepoSrc}/openmp "$out" + '' + + lib.optionalString (lib.versionAtLeast release_version "23") '' + mkdir -p "$out/llvm" + cp -r ${monorepoSrc}/llvm/cmake "$out/llvm" + cp -r ${monorepoSrc}/llvm/utils "$out/llvm" + cp -r ${monorepoSrc}/third-party "$out" + cp -r ${monorepoSrc}/runtimes "$out" + '' + ) else src; - sourceRoot = "${finalAttrs.src.name}/openmp"; + # LLVM 23 removed OpenMP's standalone build + # https://openmp.llvm.org/Building.html + sourceRoot = + "${finalAttrs.src.name}/" + + (if lib.versionAtLeast release_version "23" then "runtimes" else "openmp"); outputs = [ "out" @@ -89,6 +102,9 @@ stdenv.mkDerivation (finalAttrs: { (lib.cmakeFeature "OPT_TOOL" "${llvm}/bin/opt") (lib.cmakeFeature "LINK_TOOL" "${llvm}/bin/llvm-link") ] + ++ lib.optionals (lib.versionAtLeast release_version "23") [ + (lib.cmakeFeature "LLVM_ENABLE_RUNTIMES" "openmp") + ] ++ devExtraCmakeFlags; doCheck = false; @@ -96,7 +112,9 @@ stdenv.mkDerivation (finalAttrs: { checkTarget = "check-openmp"; preCheck = '' - patchShebangs ../tools/archer/tests/deflake.bash + patchShebangs ${ + if lib.versionAtLeast release_version "23" then "../../openmp" else ".." + }/tools/archer/tests/deflake.bash ''; __structuredAttrs = true; From c6ad124cbca76ee73dfc1c81373e2602c247a49d Mon Sep 17 00:00:00 2001 From: randomizedcoder Date: Thu, 22 Oct 2026 07:18:35 -0700 Subject: [PATCH 03/21] rocmPackages_10: init Add an empty rocmPackages_10 scope next to rocmPackages, sharing its structure (rocm-modules/10/default.nix is derived from rocm-modules/default.nix). The following PRs add the ROCm 10.1 packages to it tier by tier; a final PR on staging switches rocmPackages over. Following the rocmPackages_5/_6 layout. It is deliberately not wrapped in recurseIntoAttrs, so Hydra and the CI rebuild count are unaffected until the switch. The update script runs with maxMajor = 10, the therock- tag prefix, and setName = "rocmPackages_10". Assisted-by: Claude Code (claude-opus-5-5) --- pkgs/development/rocm-modules/10/default.nix | 19 +++++++++++++++++++ pkgs/top-level/all-packages.nix | 2 ++ 2 files changed, 21 insertions(+) create mode 100644 pkgs/development/rocm-modules/10/default.nix diff --git a/pkgs/development/rocm-modules/10/default.nix b/pkgs/development/rocm-modules/10/default.nix new file mode 100644 index 0000000000000..47b10a6e9e7f7 --- /dev/null +++ b/pkgs/development/rocm-modules/10/default.nix @@ -0,0 +1,19 @@ +{ + lib, + newScope, +}: + +let + outer = lib.makeScope newScope (self: { + + rocmUpdateScript = self.callPackage ../update.nix { + maxMajor = 10; + tagPrefixes = [ + "rocm" + "therock" + ]; + setName = "rocmPackages_10"; + }; + }); +in +outer diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index e85402023569b..63d4d6a926e7d 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -1855,6 +1855,8 @@ with pkgs; dvtm-unstable = callPackage ../tools/misc/dvtm/unstable.nix { }; rocmPackages = recurseIntoAttrs (callPackage ../development/rocm-modules { }); + # Kept out of Hydra until the default ROCm scope switches. + rocmPackages_10 = callPackage ../development/rocm-modules/10 { }; tsm-client-withGui = callPackage ../by-name/ts/tsm-client/package.nix { enableGui = true; }; From 0fbffa86e22b11671fbd4aeaf42732e86839ee96 Mon Sep 17 00:00:00 2001 From: randomizedcoder Date: Thu, 22 Oct 2026 07:18:36 -0700 Subject: [PATCH 04/21] rocmPackages_10: copy llvm from rocmPackages Verbatim copies of the rocmPackages (ROCm 7.2.4) expressions for llvm, rocm-device-libs, not yet part of the rocmPackages_10 scope. The following commits update each one to ROCm 10.1, so their diffs read against 7.2.4. Assisted-by: Claude Code (claude-opus-5-5) --- .../clang-bodge-ignore-systemwide-incls.diff | 23 + .../rocm-modules/10/llvm/clang-log-jobs.diff | 40 ++ .../rocm-modules/10/llvm/default.nix | 614 ++++++++++++++++++ .../opt-offload-compress-on-by-default.patch | 22 + .../llvm/perf-increase-namestring-size.patch | 28 + .../perf-shorten-gcclib-include-paths.patch | 59 ++ .../10/rocm-device-libs/cmake.patch | 43 ++ .../10/rocm-device-libs/default.nix | 67 ++ 8 files changed, 896 insertions(+) create mode 100644 pkgs/development/rocm-modules/10/llvm/clang-bodge-ignore-systemwide-incls.diff create mode 100644 pkgs/development/rocm-modules/10/llvm/clang-log-jobs.diff create mode 100644 pkgs/development/rocm-modules/10/llvm/default.nix create mode 100644 pkgs/development/rocm-modules/10/llvm/opt-offload-compress-on-by-default.patch create mode 100644 pkgs/development/rocm-modules/10/llvm/perf-increase-namestring-size.patch create mode 100644 pkgs/development/rocm-modules/10/llvm/perf-shorten-gcclib-include-paths.patch create mode 100644 pkgs/development/rocm-modules/10/rocm-device-libs/cmake.patch create mode 100644 pkgs/development/rocm-modules/10/rocm-device-libs/default.nix diff --git a/pkgs/development/rocm-modules/10/llvm/clang-bodge-ignore-systemwide-incls.diff b/pkgs/development/rocm-modules/10/llvm/clang-bodge-ignore-systemwide-incls.diff new file mode 100644 index 0000000000000..5f44dbe15655c --- /dev/null +++ b/pkgs/development/rocm-modules/10/llvm/clang-bodge-ignore-systemwide-incls.diff @@ -0,0 +1,23 @@ +diff --git a/lib/Driver/ToolChains/Linux.cpp b/lib/Driver/ToolChains/Linux.cpp +index 57368104c914..71c57f72078e 100644 +--- a/lib/Driver/ToolChains/Linux.cpp ++++ b/lib/Driver/ToolChains/Linux.cpp +@@ -640,6 +640,7 @@ void Linux::AddClangSystemIncludeArgs(const ArgList &DriverArgs, + return; + + // LOCAL_INCLUDE_DIR ++ if (!SysRoot.empty()) + addSystemInclude(DriverArgs, CC1Args, concat(SysRoot, "/usr/local/include")); + // TOOL_INCLUDE_DIR + AddMultilibIncludeArgs(DriverArgs, CC1Args); +@@ -672,8 +673,10 @@ void Linux::AddClangSystemIncludeArgs(const ArgList &DriverArgs, + // Add an include of '/include' directly. This isn't provided by default by + // system GCCs, but is often used with cross-compiling GCCs, and harmless to + // add even when Clang is acting as-if it were a system compiler. ++ if (!SysRoot.empty()) + addExternCSystemInclude(DriverArgs, CC1Args, concat(SysRoot, "/include")); + ++ if (!SysRoot.empty()) + addExternCSystemInclude(DriverArgs, CC1Args, concat(SysRoot, "/usr/include")); + + if (!DriverArgs.hasArg(options::OPT_nobuiltininc) && getTriple().isMusl()) diff --git a/pkgs/development/rocm-modules/10/llvm/clang-log-jobs.diff b/pkgs/development/rocm-modules/10/llvm/clang-log-jobs.diff new file mode 100644 index 0000000000000..3a3a712c8bbaf --- /dev/null +++ b/pkgs/development/rocm-modules/10/llvm/clang-log-jobs.diff @@ -0,0 +1,40 @@ +diff --git a/clang/lib/Driver/Compilation.cpp b/clang/lib/Driver/Compilation.cpp +index 06f5e7e7e335..8407d664886a 100644 +--- a/lib/Driver/Compilation.cpp ++++ b/lib/Driver/Compilation.cpp +@@ -340,6 +340,9 @@ private: + void Compilation::ExecuteJobs(const JobList &Jobs, + FailingCommandList &FailingCommands, + bool LogOnly) const { ++ // If >1 job, log as each job finishes so can see progress while building many offloads ++ const bool logJobs = Jobs.size() > 1; ++ auto start_time = std::chrono::steady_clock::now(); + // According to UNIX standard, driver need to continue compiling all the + // inputs on the command line even one of them failed. + // In all but CLMode, execute all the jobs unless the necessary inputs for the +@@ -364,11 +367,25 @@ void Compilation::ExecuteJobs(const JobList &Jobs, + + JS.setJobState(Next, JobScheduler::JS_RUN); + auto Work = [&, Next]() { ++ auto job_start_time = std::chrono::steady_clock::now(); + const Command *FailingCommand = nullptr; + if (int Res = ExecuteCommand(*Next, FailingCommand, LogOnly)) { + FailingCommands.push_back(std::make_pair(Res, FailingCommand)); + JS.setJobState(Next, JobScheduler::JS_FAIL); + } else { ++ if (logJobs && Next) { ++ auto now = std::chrono::steady_clock::now(); ++ auto job_duration = std::chrono::duration_cast(now - job_start_time).count(); ++ auto duration = std::chrono::duration_cast(now - start_time).count(); ++ if (duration > 10 && job_duration > 0) { ++ if (Next->getOutputFilenames().empty()) ++ if (Next->getExecutable()) llvm::errs() << "Job completed: " << Next->getExecutable() << "\n"; ++ else (llvm::errs() << "Job completed: "), Next->Print(llvm::errs(), "\n", true); ++ else ++ llvm::errs() << "Job completed: " << Next->getOutputFilenames().front().c_str() << "\n"; ++ } ++ } ++ + JS.setJobState(Next, JobScheduler::JS_DONE); + } + }; diff --git a/pkgs/development/rocm-modules/10/llvm/default.nix b/pkgs/development/rocm-modules/10/llvm/default.nix new file mode 100644 index 0000000000000..4fbb9fb0d1c92 --- /dev/null +++ b/pkgs/development/rocm-modules/10/llvm/default.nix @@ -0,0 +1,614 @@ +{ + lib, + stdenv, + # LLVM version closest to ROCm fork to override + llvmPackages_22, + overrideCC, + lndir, + rocm-device-libs, + fetchFromGitHub, + runCommand, + symlinkJoin, + rdfind, + zstd, + gcc-unwrapped, + glibc, + libffi, + libxml2, + removeReferencesTo, + fetchpatch, + # Build compilers and stdenv suitable for profiling + # leaving compressed line tables (-g1 -gz) unstripped + # TODO: Should also apply to downstream packages which use rocmClangStdenv? + profilableStdenv ? false, + # FIXME: proper two-stage bootstrap & PGO/BOLT/LTO + # LTO currently disabled due to llvm 22 vs 22.1 bitcode mismatch between + # llvmPackages_22 (22.1) and ROCm LLVM (22.0). Uses new bitcode attr + # 105 nocreateundeforpoison fails to link hipify. + # Whether to use LTO when building the ROCm toolchain + # Slows down this toolchain's build, for typical ROCm usecase + # time saved building composable_kernel and other heavy packages + # will outweight that. ~3-4% speedup multiplied by thousands + # of corehours. + withLto ? false, + # whether rocm stdenv uses libcxx (clang c++ stdlib) instead of gcc stdlibc++ + withLibcxx ? false, +}: + +let + version = "7.2.4"; + # major version of this should be the clang version ROCm forked from + rocmLlvmVersion = "22.0.0-rocm"; + # llvmPackages_base version should match rocmLlvmVersion + # so libllvm's bitcode is compatible with the built toolchain + llvmPackages_base = llvmPackages_22; + llvmPackagesNoBintools = llvmPackages_base.override { + bootBintools = null; + bootBintoolsNoLibc = null; + }; + + stdenvToBuildRocmLlvm = + if withLibcxx then + overrideCC llvmPackagesNoBintools.libcxxStdenv llvmPackagesNoBintools.clangUseLLVM + else + # oddly fuse-ld=lld fails without this override + overrideCC llvmPackagesNoBintools.stdenv ( + llvmPackagesNoBintools.libstdcxxClang.override { + inherit (llvmPackages_base) bintools; + } + ); + + gcc-include = runCommand "gcc-include" { } '' + mkdir -p $out + ln -s ${gcc-unwrapped}/include/ $out/ + ln -s ${gcc-unwrapped}/lib/ $out/ + ''; + + disallowedRefsForToolchain = [ + stdenv.cc + stdenv.cc.cc + stdenv.cc.bintools + gcc-unwrapped + stdenvToBuildRocmLlvm + stdenvToBuildRocmLlvm.cc + stdenvToBuildRocmLlvm.cc.cc + ]; + # A prefix for use as the GCC prefix when building rocm-toolchain + gcc-prefix-headers = symlinkJoin { + name = "gcc-prefix-headers"; + paths = [ + glibc.dev + gcc-unwrapped.out + ]; + disallowedRequisites = [ + glibc.dev + gcc-unwrapped.out + ]; + postBuild = '' + rm -rf $out/{bin,libexec,nix-support,lib64,share,etc} + rm $out/lib/gcc/x86_64-unknown-linux-gnu/*/plugin/include/auto-host.h + + mkdir /build/tmpout + mv $out/* /build/tmpout + cp -Lr --no-preserve=mode /build/tmpout/* $out/ + set -x + versionedIncludePath="$(echo $out/include/c++/*/)" + mv $versionedIncludePath/* $out/include/c++/ + rm -rf $versionedIncludePath/ + ''; + }; + gcc-prefix = symlinkJoin { + name = "gcc-prefix"; + paths = [ + gcc-prefix-headers + glibc + gcc-unwrapped.lib + ]; + disallowedRequisites = [ + glibc.dev + gcc-unwrapped.out + ]; + postBuild = '' + rm -rf $out/{bin,libexec,nix-support,lib64,share,etc} + rm $out/lib/ld-linux-x86-64.so.2 + ln -s $out $out/x86_64-unknown-linux-gnu + ''; + }; + llvmSrc = fetchFromGitHub { + owner = "ROCm"; + repo = "llvm-project"; + tag = "rocm-${version}"; + hash = "sha256-TwFvQimbax2E37ZC/52lNkHXCgyBNfSGDBaqmas2x/s="; + }; + llvmMajorVersion = lib.versions.major rocmLlvmVersion; + # An llvmPackages (pkgs/development/compilers/llvm/) built from ROCm LLVM's source tree + llvmPackagesRocm = llvmPackages_base.override (_old: { + stdenv = stdenvToBuildRocmLlvm; + + # not setting gitRelease = because that causes patch selection logic to use git patches + # ROCm LLVM is closer to 20 official + # gitRelease = {}; officialRelease = null; + officialRelease = { }; # Set but empty because we're overriding everything from it. + # this version determines which patches are applied + version = rocmLlvmVersion; + src = llvmSrc; + monorepoSrc = llvmSrc; + doCheck = false; + }); + refsToRemove = builtins.concatStringsSep " -t " [ + stdenvToBuildRocmLlvm + stdenvToBuildRocmLlvm.cc + stdenvToBuildRocmLlvm.cc.cc + stdenv.cc + stdenv.cc.cc + stdenv.cc.bintools + ]; + # Hacky way to avoid nixfmt indenting the entire scope body suggested by @emilazy + overrideLlvmPackagesRocm = + f: + let + overridenScope = llvmPackagesRocm.overrideScope (final: prev: f { inherit final prev; }); + in + { + inherit (overridenScope) + # Expose only a limited set of packages that we care about for ROCm + bintools + compiler-rt + compiler-rt-libc + clang + clang-unwrapped + libcxx + lld + llvm + rocm-toolchain + rocmClangStdenv + openmp + ; + }; + sysrootCompiler = + { + cc, + name, + paths, + linkPaths, + }: + let + linked = symlinkJoin { inherit name paths; }; + in + runCommand name + { + pname = name; + # If this is erroring, try why-depends --precise on the symlinkJoin of inputs to look for the problem + # nix why-depends --precise .#rocmPackages.llvm.rocm-toolchain.linked /store/path/its/not/allowed + outputChecks.out.disallowedRequisites = disallowedRefsForToolchain; + passthru.linked = linked; + inherit linkPaths; + __structuredAttrs = true; + # TODO(@LunNova): Try to use --sysroot with clang in its original location instead of + # relying on copying the binary? + # $clang/bin/clang++ --sysroot=$rocm-toolchain is not equivalent + # to a clang copied to $rocm-toolchain/bin here, have not yet figured out why + } + '' + mkdir -p $out/ + cp --reflink=auto -rL ${linked}/* $out/ + chmod -R +rw $out + mkdir -p $out/usr + ln -s $out/ $out/usr/local + # we don't need mixed 32 bit, the presence of lib64 is used by LLVM to decide it's a multilib sysroot + rm -rf $out/lib64 + rm -rf $out/lib/cmake $out/lib/lib*.a + mkdir -p $out/lib/clang/${llvmMajorVersion}/lib/linux/ + ln -s $out/lib/linux/libclang_rt.* $out/lib/clang/${llvmMajorVersion}/lib/linux/ + mkdir -p $out/lib/clang/${llvmMajorVersion}/lib/${stdenv.hostPlatform.config}/ + for f in $out/lib/linux/*-${stdenv.hostPlatform.parsed.cpu.name}.*; do + [ -e "$f" ] || continue + base="$(basename "$f" | sed 's/-${stdenv.hostPlatform.parsed.cpu.name}\././')" + ln -sf "$f" "$out/lib/clang/${llvmMajorVersion}/lib/${stdenv.hostPlatform.config}/$base" + done + + find $out -type f -exec sed -i "s|${cc.out}|$out|g" {} + + find $out -type f -exec sed -i "s|${cc.dev}|$out|g" {} + + + # Clang config file: redirect resource dir to the sysroot (where compiler-rt + # lives) and set GCC install prefix for header/library search + cat > $out/bin/${stdenv.hostPlatform.config}.cfg <> $out/nix-support/setup-hook + echo 'export CXX=clang++' >> $out/nix-support/setup-hook + ''; + tablegenUsage = x: !(lib.strings.hasInfix "llvm-tblgen" x); + llvmTargetsFlag = "-DLLVM_TARGETS_TO_BUILD=AMDGPU;${ + { + "x86_64" = "X86"; + "aarch64" = "AArch64"; + } + .${stdenv.targetPlatform.parsed.cpu.name} + or (throw "Unsupported CPU architecture: ${stdenv.targetPlatform.parsed.cpu.name}") + }"; + llvmMeta = { + # TODO(@LunNova): it would be nice to support aarch64 for rocmPackages + platforms = [ "x86_64-linux" ]; + }; + # TODO(@LunNova): Some of this might be worth supporting in llvmPackages, dropping from here + commonCmakeFlags = [ + llvmTargetsFlag + # Compression support is required for compressed offload kernels + # Set FORCE_ON so that failure to find the compression lib will be a build error + (lib.cmakeFeature "LLVM_ENABLE_ZSTD" "FORCE_ON") + # required for threaded ThinLTO to work + (lib.cmakeBool "LLVM_ENABLE_THREADS" true) + # third-party/benchmark is broken in rocm-7.2.0 + # error: '__COUNTER__' is a C2y extension [-Werror,-Wc2y-extensions] + (lib.cmakeBool "LLVM_INCLUDE_BENCHMARKS" false) + # LLVM tries to call git to embed VCS info if FORCE_VC_ aren't set + (lib.cmakeFeature "LLVM_FORCE_VC_REVISION" "rocm-${version}") + (lib.cmakeFeature "LLVM_FORCE_VC_REPOSITORY" "https://github.com/ROCm/llvm-project") + (lib.cmakeFeature "LLVM_VERSION_SUFFIX" "") + (lib.cmakeBool "LLVM_ENABLE_LIBCXX" withLibcxx) + (lib.cmakeFeature "CLANG_DEFAULT_CXX_STDLIB" (if withLibcxx then "libc++" else "libstdc++")) + (lib.cmakeFeature "CLANG_VENDOR" "nixpkgs-AMD") + (lib.cmakeFeature "CLANG_REPOSITORY_STRING" "https://github.com/ROCm/llvm-project/tree/rocm-${version}") + ] + ++ lib.optionals withLibcxx [ + (lib.cmakeFeature "CLANG_DEFAULT_RTLIB" "compiler-rt") + ] + ++ lib.optionals withLto [ + (lib.cmakeBool "CMAKE_INTERPROCEDURAL_OPTIMIZATION" true) + (lib.cmakeBool "LLVM_ENABLE_FATLTO" false) + ] + ++ lib.optionals (withLto && stdenvToBuildRocmLlvm.cc.isClang) [ + (lib.cmakeFeature "LLVM_ENABLE_LTO" "FULL") + (lib.cmakeFeature "LLVM_USE_LINKER" "lld") + ]; + + llvmExtraCflags = lib.concatStringsSep " " ( + lib.optionals (stdenv.hostPlatform.system == "x86_64-linux") [ + # Unprincipled decision to build x86_64 ROCm clang for at least skylake and tune for zen3+ + # In practice building the ROCm package set with anything earlier than zen3 is annoying + # and earlier than skylake is implausible due to too few cores and too little RAM + # Speeds up composable_kernel builds by ~4% + # If this causes trouble in practice we can drop this. Set since 2025-03-24. + "-march=skylake" + "-mtune=znver3" + ] + ++ lib.optionals profilableStdenv [ + # compressed line only debug info for profiling + "-gz" + "-g1" + ] + ); + inherit (llvmPackagesRocm) libcxx; +in +overrideLlvmPackagesRocm (s: { + libllvm = (s.prev.libllvm.override { }).overrideAttrs (old: { + patches = [ + # Backport select ptr combine fixes so our LLVM 22 sdag fix backport can apply + (fetchpatch { + name = "amdgpu-add-baseline-load-select-ptr-combine-test.patch"; + url = "https://github.com/llvm/llvm-project/commit/ac27b2455ad7c89cc1f928de7beb05933a035031.patch"; + relative = "llvm"; + hash = "sha256-1mine1h/oqnn2tKDYW4FntyZXu/foyifrKGkqKOHrPg="; + }) + (fetchpatch { + name = "amdgpu-fix-treating-divergent-loads-as-uniform.patch"; + url = "https://github.com/llvm/llvm-project/commit/d3c3c6bab5df051d9db12ea96add2211df9d81be.patch"; + relative = "llvm"; + hash = "sha256-9VB77d4d+nwX8s+JBq1PXmbmqT7oD6lRC0uDIrTgjjo="; + }) + (fetchpatch { + name = "dag-allow-select-ptr-combine-for-non-0-address-spaces.patch"; + url = "https://github.com/llvm/llvm-project/commit/0e1cb2de90aafa1d5dbd46fc9e6c4e743700fa8b.patch"; + relative = "llvm"; + hash = "sha256-6Pj3pRESaho60YhXWwaQxEKteSuziZseeT4FbZqZANk="; + }) + ] + # https://github.com/NixOS/nixpkgs/pull/564039 introduces minimal-arm64e_x1-support.patch that depends on llvm 22.1.0 + # Patches to clang, compiler-rt-libc, and these patches bridge the gap between llvm 22.0.0 and ~22.1.8 + # arm64e_x1: Can be removed when upgrading to rocm 10 + ++ [ + (fetchpatch { + name = "wasm-add-wasm32-linux-muslwali-target.patch"; + url = "https://github.com/llvm/llvm-project/commit/7e7c923b5890e62f4b5920c2f8a2e51f586a186c.patch"; + relative = "llvm"; + hash = "sha256-KbM7M4osxaaxkn5UN+csNm+aKvaWgJ0KQnKHHpI+Qxo="; + }) + (fetchpatch { + name = "adt-allow-arbitrary-number-of-cases-in-stringswitch.patch"; + url = "https://github.com/llvm/llvm-project/commit/8642762ac356f0b8432b78d7a32c1f5213e494b3.patch"; + relative = "llvm"; + hash = "sha256-aQBmMSJ+aunE7HLpfIizBH7Be1kmcN6nxUk2sV9d3Qo="; + }) + (fetchpatch { + name = "adt-migrate-stringswitch-cases-to-new-overload.patch"; + url = "https://github.com/llvm/llvm-project/commit/2ed7baafc3bf5b4321e3f77dfb1ce291e62bcadc.patch"; + relative = "llvm"; + hash = "sha256-cV9POhuJFCnjCdPL6Lym2cmKLeW/2k34N2rwauxU7MA="; + }) + (fetchpatch { + name = "lfi-introduce-aarch64-lfi-target.patch"; + url = "https://github.com/llvm/llvm-project/commit/2c05ae4b8f85927d55f862fdf61bea564e2ea944.patch"; + relative = "llvm"; + hash = "sha256-yxvmZg3BTlIrNeer90cYnF7yuRyraeVg1nbiaRVr+zc="; + }) + ] + ++ old.patches + ++ [ + ./perf-increase-namestring-size.patch + # v64i8 shuffle lowering inf loop on VBMI targets, hangs whisper-cpp etc + # https://github.com/NixOS/nixpkgs/issues/497745 + (fetchpatch { + # https://github.com/llvm/llvm-project/pull/182832 + name = "llvm-x86-v64i8-add-test-coverage.patch"; + url = "https://github.com/llvm/llvm-project/commit/0e3a96d0ec01e3575674d72c4e23bf98affdca28.patch"; + relative = "llvm"; + hash = "sha256-qhRkB8Fjz/fNacuGv1OFkiTNOQ0/QQ9p4pLFudwrTzM="; + }) + (fetchpatch { + # https://github.com/llvm/llvm-project/pull/182852 + name = "llvm-x86-v64i8-prefer-vpermv3-on-vbmi.patch"; + url = "https://github.com/llvm/llvm-project/commit/8f5880d3ae4e5dfc748985d90e5413671028aa3e.patch"; + relative = "llvm"; + hash = "sha256-4DU6gu/1+iQpzvVYBlTTUKtw77QSRyTja4hdel4D5Cw="; + }) + (fetchpatch { + # https://github.com/llvm/llvm-project/pull/183109 + name = "llvm-x86-v64i8-skip-repeated-mask-lane-permute-on-vbmi.patch"; + url = "https://github.com/llvm/llvm-project/commit/1b9fea021840f17c41ea980300d0fc45e7285909.patch"; + relative = "llvm"; + hash = "sha256-9Akm78QQr8BIMrVWwDG3poWS1HuQ0hpIQWfke3oADgg="; + }) + # TODO: consider reapplying "Don't include aliases in RegisterClassInfo::IgnoreCSRForAllocOrder" + # it was reverted as it's a pessimization for non-GPU archs, but this compiler + # is used mostly for amdgpu + ]; + dontStrip = profilableStdenv; + hardeningDisable = [ "all" ]; + nativeBuildInputs = old.nativeBuildInputs ++ [ removeReferencesTo ]; + buildInputs = old.buildInputs ++ [ + zstd + ]; + preFixup = '' + moveToOutput "lib/lib*.a" "$dev" + moveToOutput "lib/cmake" "$dev" + sed -Ei "s|$lib/lib/(lib[^/]*)\.a|$dev/lib/\1.a|g" $dev/lib/cmake/llvm/*.cmake + ''; + env = (old.env or { }) // { + NIX_CFLAGS_COMPILE = "${(old.env or { }).NIX_CFLAGS_COMPILE or ""} ${llvmExtraCflags}"; + }; + cmakeFlags = (builtins.filter tablegenUsage old.cmakeFlags) ++ commonCmakeFlags; + # Ensure we don't leak refs to compiler that was used to bootstrap this LLVM + disallowedReferences = (old.disallowedReferences or [ ]) ++ disallowedRefsForToolchain; + postFixup = '' + ${old.postFixup or ""} + find $lib -type f -exec remove-references-to -t ${refsToRemove} {} + + ''; + meta = old.meta // llvmMeta; + }); + lld = + (s.prev.lld.override { + }).overrideAttrs + (old: { + dontStrip = profilableStdenv; + hardeningDisable = [ "all" ]; + nativeBuildInputs = old.nativeBuildInputs ++ [ + removeReferencesTo + ]; + buildInputs = old.buildInputs ++ [ + zstd + ]; + env = (old.env or { }) // { + NIX_CFLAGS_COMPILE = "${(old.env or { }).NIX_CFLAGS_COMPILE or ""} ${llvmExtraCflags}"; + }; + cmakeFlags = (builtins.filter tablegenUsage old.cmakeFlags) ++ commonCmakeFlags; + # Ensure we don't leak refs to compiler that was used to bootstrap this LLVM + disallowedReferences = (old.disallowedReferences or [ ]) ++ disallowedRefsForToolchain; + postFixup = '' + ${old.postFixup or ""} + find $lib -type f -exec remove-references-to -t ${refsToRemove} {} + + ''; + meta = old.meta // llvmMeta; + }); + clang-unwrapped = ( + (s.prev.clang-unwrapped.override { + enableClangToolsExtra = false; + }).overrideAttrs + (old: { + passthru = old.passthru // { + inherit gcc-prefix; + }; + patches = [ + (fetchpatch { + # [clang][cmake] Add option to control scan-build-py installation (#172727) + name = "clang-scan-build-py-configurable.patch"; + url = "https://github.com/llvm/llvm-project/commit/f5759eeb63a3a5ce7d555c13c3126cea84e0c7b1.patch"; + relative = "clang"; + hash = "sha256-73IDPGZWKX4vny3x5FJ3/NQw8XRad9UNwfYkvQdMB4s="; + }) + ] + # arm64e_x1: Can be removed when upgrading to rocm 10 + ++ [ + (fetchpatch { + name = "wasm-add-wasm32-linux-muslwali-target.patch"; + url = "https://github.com/llvm/llvm-project/commit/7e7c923b5890e62f4b5920c2f8a2e51f586a186c.patch"; + relative = "clang"; + hash = "sha256-QGqil4rs9wFFa8J25ghWKTE8YG2+AbGG81dt5ReAw9k="; + }) + (fetchpatch { + name = "adt-migrate-stringswitch-cases-to-new-overload.patch"; + url = "https://github.com/llvm/llvm-project/commit/2ed7baafc3bf5b4321e3f77dfb1ce291e62bcadc.patch"; + relative = "clang"; + hash = "sha256-w9sS+pwawHqxGkTAWMinzF1r9ZyWMTmI119X/NdQoc8="; + }) + (fetchpatch { + name = "lfi-introduce-aarch64-lfi-target.patch"; + url = "https://github.com/llvm/llvm-project/commit/2c05ae4b8f85927d55f862fdf61bea564e2ea944.patch"; + relative = "clang"; + hash = "sha256-CcwqLvhDAJSr3dkRDqJKe3pVD2G+w5JMgtGkUx6pUPc="; + }) + ] + ++ old.patches + ++ [ + # Never add FHS include paths + ./clang-bodge-ignore-systemwide-incls.diff + # Prevents builds timing out if a single compiler invocation is very slow but + # per-arch jobs are completing by ensuring there's terminal output + ./clang-log-jobs.diff + ./opt-offload-compress-on-by-default.patch + ./perf-shorten-gcclib-include-paths.patch + (fetchpatch { + # [ClangOffloadBundler]: Add GetBundleIDsInFile to OffloadBundler + hash = "sha256-OsarDZXuJ5vAXTP4i0NBUeK/r6tQPumaqmMWkf29UtM="; + url = "https://github.com/GZGavinZhao/rocm-llvm-project/commit/c7de294b0d1d25f277f9d1cbb2c9e09c7600e210.patch"; + relative = "clang"; + }) + ]; + # ROCm 7.2 commits 4dda51261a6 "Replace hostexec with upstream rpc" + # and 2ca1509d6d2 "Put the RTL, Back!", added CGEmitEmissaryExec.cpp which + # includes ../../openmp/device/include/EmissaryIds.h, breaking + # standalone clang builds. The upstream PR llvm/llvm-project#175265 + # ("[OpenMP] support for Emissary APIs") moves EmissaryIds.h into + # clang/lib/Headers/ so this should not be needed once that lands + # and ROCm rebases onto it. + postUnpack = '' + ${old.postUnpack or ""} + mkdir -p "''${sourceRoot}/openmp/device/include" + ln -s "${llvmSrc}/openmp/device/include/EmissaryIds.h" "''${sourceRoot}/openmp/device/include/" + ''; + hardeningDisable = [ "all" ]; + nativeBuildInputs = old.nativeBuildInputs ++ [ + removeReferencesTo + ]; + buildInputs = old.buildInputs ++ [ + zstd + ]; + env = (old.env or { }) // { + NIX_CFLAGS_COMPILE = "${(old.env or { }).NIX_CFLAGS_COMPILE or ""} ${llvmExtraCflags}"; + }; + dontStrip = profilableStdenv; + # Ensure we don't leak refs to compiler that was used to bootstrap this LLVM + disallowedReferences = (old.disallowedReferences or [ ]) ++ disallowedRefsForToolchain; + # Enable structured attrs for separateDebugInfo, because it is required with disallowedReferences set + __structuredAttrs = true; + # https://github.com/llvm/llvm-project/blob/6976deebafa8e7de993ce159aa6b82c0e7089313/clang/cmake/caches/DistributionExample-stage2.cmake#L9-L11 + cmakeFlags = + # TODO: Remove in followup, tblgen now works correctly but would rebuild + (builtins.filter tablegenUsage old.cmakeFlags) ++ commonCmakeFlags; + preFixup = '' + ${toString old.preFixup or ""} + moveToOutput "lib/lib*.a" "$dev" + moveToOutput "lib/cmake" "$dev" + mkdir -p $dev/lib/clang/ + ln -s $lib/lib/clang/${llvmMajorVersion} $dev/lib/clang/ + sed -Ei "s|$lib/lib/(lib[^/]*)\.a|$dev/lib/\1.a|g" $dev/lib/cmake/clang/*.cmake + ''; + postFixup = '' + ${toString old.postFixup or ""} + find $lib -type f -exec remove-references-to -t ${refsToRemove} {} + + find $dev -type f -exec remove-references-to -t ${refsToRemove} {} + + ''; + meta = old.meta // llvmMeta; + }) + ); + # A clang that understands standard include searching in a GNU sysroot and will put GPU libs in include path + # in the right order + # and expects its libc to be in the sysroot + rocm-toolchain = + with s.final; + (sysrootCompiler { + cc = clang-unwrapped; + name = "rocm-toolchain"; + paths = [ + clang-unwrapped.out + clang-unwrapped.lib + bintools.out + compiler-rt.out + openmp.out + openmp.dev + ] + ++ lib.optionals withLibcxx [ + libcxx + ] + ++ lib.optionals (!withLibcxx) [ + glibc + glibc.dev + ]; + linkPaths = [ + bintools.bintools.out + ] + ++ lib.optionals (!withLibcxx) [ + gcc-include.out + ]; + }) + // { + version = llvmMajorVersion; + cc = rocm-toolchain; + libllvm = llvm; + isClang = true; + isGNU = false; + }; + compiler-rt-libc = s.prev.compiler-rt-libc.overrideAttrs (old: { + patches = [ + # arm64e_x1: Can be removed when upgrading to rocm 10 + (fetchpatch { + name = "lfi-introduce-aarch64-lfi-target.patch"; + url = "https://github.com/llvm/llvm-project/commit/2c05ae4b8f85927d55f862fdf61bea564e2ea944.patch"; + relative = "compiler-rt"; + hash = "sha256-xgvVXG+IGa9qwv60ioER6N5nC7XPRPEDHVUrQ5n9RBI="; + }) + ] + ++ old.patches; + meta = old.meta // llvmMeta; + }); + compiler-rt = s.final.compiler-rt-libc; + clang = s.final.rocm-toolchain; + + rocmClangStdenv = with s.final; overrideCC (if withLibcxx then libcxxStdenv else stdenv) clang; + + # Projects + openmp = + with s.final; + (llvmPackagesRocm.openmp.override { + llvm = llvm; + clang-unwrapped = clang-unwrapped; + }).overrideAttrs + (old: { + disallowedReferences = (old.disallowedReferences or [ ]) ++ disallowedRefsForToolchain; + nativeBuildInputs = (old.nativeBuildInputs or [ ]) ++ [ + removeReferencesTo + ]; + cmakeFlags = + old.cmakeFlags + ++ commonCmakeFlags + ++ [ + "-DDEVICELIBS_ROOT=${rocm-device-libs.src}" + # OMPD support is broken in ROCm 6.3+ Haven't investigated why. + "-DLIBOMP_OMPD_SUPPORT:BOOL=FALSE" + "-DLIBOMP_OMPD_GDB_SUPPORT:BOOL=FALSE" + ]; + buildInputs = old.buildInputs ++ [ + clang-unwrapped + zstd + libxml2 + libffi + ]; + postFixup = '' + ${old.postFixup or ""} + ln -s $out/lib/libomp.so $dev/lib/libomp.so + ''; + }); + # AMD has a separate MLIR impl which we package under rocmPackages.rocmlir + # It would be an error to rely on the original mlir package from this scope + mlir = null; +}) diff --git a/pkgs/development/rocm-modules/10/llvm/opt-offload-compress-on-by-default.patch b/pkgs/development/rocm-modules/10/llvm/opt-offload-compress-on-by-default.patch new file mode 100644 index 0000000000000..d5cb1a363ea5d --- /dev/null +++ b/pkgs/development/rocm-modules/10/llvm/opt-offload-compress-on-by-default.patch @@ -0,0 +1,22 @@ +From 762511ad9c9cac7769a795cc4df888a1559dca02 Mon Sep 17 00:00:00 2001 +From: Luna Nova +Date: Mon, 16 Dec 2024 14:56:57 -0800 +Subject: [PATCH] [AMDGPU] CommonArgs: Enable offload compression by default + +--- + clang/lib/Driver/ToolChains/CommonArgs.cpp | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp b/clang/lib/Driver/ToolChains/CommonArgs.cpp +index 33f12fb2d075d..ba35f65210c7a 100644 +--- a/lib/Driver/ToolChains/CommonArgs.cpp ++++ b/lib/Driver/ToolChains/CommonArgs.cpp +@@ -2914,7 +2914,7 @@ void tools::addHIPRuntimeLibArgs(const ToolChain &TC, Compilation &C, + void tools::addOffloadCompressArgs(const llvm::opt::ArgList &TCArgs, + llvm::opt::ArgStringList &CmdArgs) { + if (TCArgs.hasFlag(options::OPT_offload_compress, +- options::OPT_no_offload_compress, false)) ++ options::OPT_no_offload_compress, true)) + CmdArgs.push_back("--compress"); + if (TCArgs.hasArg(options::OPT_v)) + CmdArgs.push_back("-verbose"); diff --git a/pkgs/development/rocm-modules/10/llvm/perf-increase-namestring-size.patch b/pkgs/development/rocm-modules/10/llvm/perf-increase-namestring-size.patch new file mode 100644 index 0000000000000..84046a588630a --- /dev/null +++ b/pkgs/development/rocm-modules/10/llvm/perf-increase-namestring-size.patch @@ -0,0 +1,28 @@ +From a57eb548d46a37e4aed33eefccc9e6374b579ff9 Mon Sep 17 00:00:00 2001 +From: Luna Nova +Date: Mon, 16 Dec 2024 13:58:54 -0800 +Subject: [PATCH] [AMDGPU] TargetMachine: increase NameString size to 256 + +128 is too small a default for compilers used to build +AMD's rocBLAS, composable_kernel and similar libs because +they use very long symbol names such as +device_gemm_xdl_universal_bf16_bf16_bf16_mk_nk_mn_comp_default_instance + +This fixes spending ~10% of compile time in malloc inside this function. +--- + llvm/lib/Target/TargetMachine.cpp | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/llvm/lib/Target/TargetMachine.cpp b/llvm/lib/Target/TargetMachine.cpp +index abd0fdf2390c0..86ce468b75643 100644 +--- a/lib/Target/TargetMachine.cpp ++++ b/lib/Target/TargetMachine.cpp +@@ -270,7 +270,7 @@ MCSymbol *TargetMachine::getSymbol(const GlobalValue *GV) const { + if (MCSymbol *TargetSymbol = TLOF->getTargetSymbol(GV, *this)) + return TargetSymbol; + +- SmallString<128> NameStr; ++ SmallString<256> NameStr; + getNameWithPrefix(NameStr, GV, TLOF->getMangler()); + return TLOF->getContext().getOrCreateSymbol(NameStr); + } diff --git a/pkgs/development/rocm-modules/10/llvm/perf-shorten-gcclib-include-paths.patch b/pkgs/development/rocm-modules/10/llvm/perf-shorten-gcclib-include-paths.patch new file mode 100644 index 0000000000000..b23a3886c3d00 --- /dev/null +++ b/pkgs/development/rocm-modules/10/llvm/perf-shorten-gcclib-include-paths.patch @@ -0,0 +1,59 @@ +From 8c64deff2a82fcca5b521362193a1fd8b1a0dca7 Mon Sep 17 00:00:00 2001 +From: Luna Nova +Date: Tue, 17 Dec 2024 04:29:11 -0800 +Subject: [PATCH] HACK: Get canonical GCC include path so doesn't have + ../../../../ + +This allows more of the strings used in compilation to fit inside +fixed size stack allocated buffers instead of spilling into the heap +--- + lib/Driver/ToolChains/Gnu.cpp | 16 ++++++++++------ + 1 file changed, 10 insertions(+), 6 deletions(-) + +diff --git a/lib/Driver/ToolChains/Gnu.cpp b/lib/Driver/ToolChains/Gnu.cpp +index 07df9864636..b1201b999f0 100644 +--- a/lib/Driver/ToolChains/Gnu.cpp ++++ b/lib/Driver/ToolChains/Gnu.cpp +@@ -3326,29 +3326,33 @@ static bool addLibStdCXXIncludePaths(llvm::vfs::FileSystem &vfs, + if (!vfs.exists(IncludeDir)) + return false; + ++ SmallString<260> CanonicalIncludeDir; ++ if (vfs.getRealPath(IncludeDir, CanonicalIncludeDir)) ++ return false; ++ + // Debian native gcc uses g++-multiarch-incdir.diff which uses + // include/x86_64-linux-gnu/c++/10$IncludeSuffix instead of + // include/c++/10/x86_64-linux-gnu$IncludeSuffix. +- std::string Dir = IncludeDir.str(); + StringRef Include = +- llvm::sys::path::parent_path(llvm::sys::path::parent_path(Dir)); ++ llvm::sys::path::parent_path(llvm::sys::path::parent_path(CanonicalIncludeDir)); + std::string Path = +- (Include + "/" + Triple + Dir.substr(Include.size()) + IncludeSuffix) ++ (Include + "/" + Triple + CanonicalIncludeDir.substr(Include.size()) + IncludeSuffix) + .str(); + if (DetectDebian && !vfs.exists(Path)) + return false; + + // GPLUSPLUS_INCLUDE_DIR +- ToolChain::addSystemInclude(DriverArgs, CC1Args, IncludeDir); ++ ToolChain::addSystemInclude(DriverArgs, CC1Args, CanonicalIncludeDir); + // GPLUSPLUS_TOOL_INCLUDE_DIR. If Triple is not empty, add a target-dependent + // include directory. + if (DetectDebian) + ToolChain::addSystemInclude(DriverArgs, CC1Args, Path); + else if (!Triple.empty()) + ToolChain::addSystemInclude(DriverArgs, CC1Args, +- IncludeDir + "/" + Triple + IncludeSuffix); ++ CanonicalIncludeDir + "/" + Triple + IncludeSuffix); + // GPLUSPLUS_BACKWARD_INCLUDE_DIR +- ToolChain::addSystemInclude(DriverArgs, CC1Args, IncludeDir + "/backward"); ++ if (vfs.exists(CanonicalIncludeDir + "/backward")) ++ ToolChain::addSystemInclude(DriverArgs, CC1Args, CanonicalIncludeDir + "/backward"); + return true; + } + +-- +2.52.0 + diff --git a/pkgs/development/rocm-modules/10/rocm-device-libs/cmake.patch b/pkgs/development/rocm-modules/10/rocm-device-libs/cmake.patch new file mode 100644 index 0000000000000..500ff37a99052 --- /dev/null +++ b/pkgs/development/rocm-modules/10/rocm-device-libs/cmake.patch @@ -0,0 +1,43 @@ +diff --git a/cmake/Packages.cmake b/cmake/Packages.cmake +index 07c60eb..c736b3e 100644 +--- a/cmake/Packages.cmake ++++ b/cmake/Packages.cmake +@@ -12,24 +12,29 @@ set_target_properties(${target} PROPERTIES + IMPORTED_LOCATION \"${target_path}\")") + endforeach() + configure_file(AMDDeviceLibsConfig.cmake.in +- ${PACKAGE_PREFIX}/AMDDeviceLibsConfig.cmake ++ lib/cmake/AMDDeviceLibs/AMDDeviceLibsConfig.cmake + @ONLY) + + + set(install_path_suffix "amdgcn/bitcode") + + # Generate the install-tree package. +-# We do not know the absolute path to the intall tree until we are installed, +-# so we calculate it dynamically in AMD_DEVICE_LIBS_PREFIX_CODE and use +-# relative paths in the target imports in AMD_DEVICE_LIBS_TARGET_CODE. +-set(AMD_DEVICE_LIBS_PREFIX_CODE " ++if(IS_ABSOLUTE "${CMAKE_INSTALL_PREFIX}") ++ set(AMD_DEVICE_LIBS_PREFIX_CODE "set(AMD_DEVICE_LIBS_PREFIX \"${CMAKE_INSTALL_PREFIX}\")") ++else() ++ # We do not know the absolute path to the install tree until we are installed, ++ # so we calculate it dynamically in AMD_DEVICE_LIBS_PREFIX_CODE and use ++ # relative paths in the target imports in AMD_DEVICE_LIBS_TARGET_CODE. ++ set(AMD_DEVICE_LIBS_PREFIX_CODE " + # Derive absolute install prefix from config file path. + get_filename_component(AMD_DEVICE_LIBS_PREFIX \"\${CMAKE_CURRENT_LIST_FILE}\" PATH)") +-string(REGEX REPLACE "/" ";" count "${PACKAGE_PREFIX}") +-foreach(p ${count}) +- set(AMD_DEVICE_LIBS_PREFIX_CODE "${AMD_DEVICE_LIBS_PREFIX_CODE} ++ string(REGEX REPLACE "/" ";" count "${PACKAGE_PREFIX}") ++ foreach(p ${count}) ++ set(AMD_DEVICE_LIBS_PREFIX_CODE "${AMD_DEVICE_LIBS_PREFIX_CODE} + get_filename_component(AMD_DEVICE_LIBS_PREFIX \"\${AMD_DEVICE_LIBS_PREFIX}\" PATH)") +-endforeach() ++ endforeach() ++endif() ++ + set(AMD_DEVICE_LIBS_TARGET_CODE) + foreach(target ${AMDGCN_LIB_LIST}) + get_target_property(target_name ${target} ARCHIVE_OUTPUT_NAME) diff --git a/pkgs/development/rocm-modules/10/rocm-device-libs/default.nix b/pkgs/development/rocm-modules/10/rocm-device-libs/default.nix new file mode 100644 index 0000000000000..41034d2c64803 --- /dev/null +++ b/pkgs/development/rocm-modules/10/rocm-device-libs/default.nix @@ -0,0 +1,67 @@ +{ + lib, + stdenv, + cmake, + ninja, + zlib, + zstd, + llvm, + python3, +}: + +let + llvmNativeTarget = + if stdenv.hostPlatform.isx86_64 then + "X86" + else if stdenv.hostPlatform.isAarch64 then + "AArch64" + else + throw "Unsupported ROCm LLVM platform"; +in +stdenv.mkDerivation (finalAttrs: { + pname = "rocm-device-libs"; + # In-tree with ROCm LLVM + inherit (llvm.llvm) version; + src = llvm.llvm.monorepoSrc; + sourceRoot = "${finalAttrs.src.name}/amd/device-libs"; + strictDeps = true; + __structuredAttrs = true; + + postPatch = + # Use our sysrooted toolchain instead of direct clang target + '' + substituteInPlace cmake/OCL.cmake \ + --replace-fail '$' "${llvm.rocm-toolchain}/bin/clang" + ''; + + patches = [ + ./cmake.patch + ]; + + nativeBuildInputs = [ + cmake + ninja + python3 + llvm.rocm-toolchain + ]; + + buildInputs = [ + llvm.llvm + llvm.clang-unwrapped + zlib + zstd + ]; + + cmakeFlags = [ + "-DLLVM_TARGETS_TO_BUILD=AMDGPU;${llvmNativeTarget}" + ]; + + meta = { + description = "Set of AMD-specific device-side language runtime libraries"; + homepage = "https://github.com/ROCm/ROCm-Device-Libs"; + license = lib.licenses.ncsa; + maintainers = with lib.maintainers; [ lovesegfault ]; + teams = [ lib.teams.rocm ]; + platforms = lib.platforms.linux; + }; +}) From 417d349dc4a1da04ff2301f6d08ac9f18ce19eb7 Mon Sep 17 00:00:00 2001 From: randomizedcoder Date: Thu, 22 Oct 2026 07:18:37 -0700 Subject: [PATCH 05/21] rocmPackages_10.llvm: init at 10.1 (LLVM 24) Update the rocmPackages.llvm copy from the previous commit to ROCm 10.1 and add it to the rocmPackages_10 scope. From "rocmPackages.llvm: 7.2.4 -> 10.1.0, build LLVM 24 on the llvmPackages_23 base": ROCm 10.1's llvm-project fork is LLVM 24 (LLVMVersion.cmake: LLVM_VERSION_MAJOR 24), sourced from the therock-10.1 tag. nixpkgs has no released llvmPackages_24, and the 24.0.0-git snapshot (llvmPackages_git) is an alias reserved for testing whose package-set splice resolves through that alias, so it cannot be evaluated with allowAliases = false (as CI does). Keep the released llvmPackages_23 as the base: it only supplies the shared compilers/llvm/common packaging and the bootstrap clang/bintools, while rocmLlvmVersion = "24.0.0-rocm" selects the LLVM 24 patch set for ROCm's own source. LTO is off, so the base's bitcode version is moot. Toolchain changes for the LLVM 22 -> 24 jump: - Drop the LLVM 22 backports (select-ptr-combine, arm64e_x1 bridge, v64i8 VBMI shuffle, scan-build-py option): all upstream in LLVM 24. - Drop the CompressedOffloadBundle::decompress postPatch and the EmissaryIds postUnpack symlink: ROCm 10.1 uses the raw_ostream* decompress form and removed CGEmitEmissaryExec.cpp/EmissaryIds.h (llvm#175265). - Replace the GZGavinZhao GetBundleIDsInFile fetchpatch (no longer applies) with a locally rebased clang-add-getbundleidsinfile.diff; it adds the set-returning OffloadBundler::GetBundleIDsInFile the comgr ISA-compat patch calls. - Drop clang-log-jobs.diff: LLVM 24 rewrote Compilation::ExecuteJobs around parallel offload job groups, so the patched loop no longer exists; it was cosmetic CI-progress logging. - Put zstd's lib dir on the toolchain default link path: LLVM 24's clang-linker-wrapper links libzstd when combining compressed offload images (--offload-compress defaults on). - Rebase rocm-device-libs' cmake.patch and guard rocm-comgr's EnvLLVMPath substitution against a null default. Revised during the split review: Set LIBOMP_COPY_EXPORTS to FALSE for openmp: ROCm's llvm-project defaults it to TRUE (upstream LLVM: FALSE), which copies libomp and its generated headers into the source tree. The generic LLVM >= 23 runtimes build of openmp (upstream PR 575569, carried at the bottom of this stack) then needs no writable copy of the source. Assisted-by: Claude Code (claude-opus-5-5) --- pkgs/development/rocm-modules/10/default.nix | 36 +++- .../10/llvm/clang-add-getbundleidsinfile.diff | 75 +++++++ .../rocm-modules/10/llvm/clang-log-jobs.diff | 40 ---- .../rocm-modules/10/llvm/default.nix | 187 +++--------------- 4 files changed, 131 insertions(+), 207 deletions(-) create mode 100644 pkgs/development/rocm-modules/10/llvm/clang-add-getbundleidsinfile.diff delete mode 100644 pkgs/development/rocm-modules/10/llvm/clang-log-jobs.diff diff --git a/pkgs/development/rocm-modules/10/default.nix b/pkgs/development/rocm-modules/10/default.nix index 47b10a6e9e7f7..a82d45132733c 100644 --- a/pkgs/development/rocm-modules/10/default.nix +++ b/pkgs/development/rocm-modules/10/default.nix @@ -1,19 +1,35 @@ { lib, + callPackage, newScope, }: let - outer = lib.makeScope newScope (self: { + outer = lib.makeScope newScope ( + self: + let + inherit (self) llvm; + in + { - rocmUpdateScript = self.callPackage ../update.nix { - maxMajor = 10; - tagPrefixes = [ - "rocm" - "therock" - ]; - setName = "rocmPackages_10"; - }; - }); + rocmUpdateScript = self.callPackage ../update.nix { + maxMajor = 10; + tagPrefixes = [ + "rocm" + "therock" + ]; + setName = "rocmPackages_10"; + }; + + ## ROCm ## + llvm = lib.recurseIntoAttrs ( + callPackage ./llvm/default.nix { + # rocm-device-libs is used for .src only + # otherwise would cause infinite recursion + inherit (self) rocm-device-libs; + } + ); + } + ); in outer diff --git a/pkgs/development/rocm-modules/10/llvm/clang-add-getbundleidsinfile.diff b/pkgs/development/rocm-modules/10/llvm/clang-add-getbundleidsinfile.diff new file mode 100644 index 0000000000000..ea6c9193ef34a --- /dev/null +++ b/pkgs/development/rocm-modules/10/llvm/clang-add-getbundleidsinfile.diff @@ -0,0 +1,75 @@ +--- a/include/clang/Driver/OffloadBundler.h 2026-10-07 22:36:18.030705685 -0700 ++++ b/include/clang/Driver/OffloadBundler.h 2026-10-07 22:36:50.353394217 -0700 +@@ -23,6 +23,7 @@ + #include "llvm/TargetParser/Triple.h" + #include + #include ++#include + + namespace clang { + +@@ -64,6 +65,13 @@ + ListBundleIDsInFile(llvm::StringRef InputFileName, + const OffloadBundlerConfig &BundlerConfig); + ++ // Collect available bundle IDs into a std::set. Return true if an error was ++ // found. ++ static llvm::Error ++ GetBundleIDsInFile(llvm::StringRef InputFileName, ++ const OffloadBundlerConfig &BundlerConfig, ++ std::set &BundleIds); ++ + llvm::Error BundleFiles(); + llvm::Error UnbundleFiles(); + llvm::Error UnbundleArchive(); +--- a/lib/Driver/OffloadBundler.cpp 2026-10-07 22:36:18.033306744 -0700 ++++ b/lib/Driver/OffloadBundler.cpp 2026-10-07 22:36:50.372606013 -0700 +@@ -1087,6 +1087,48 @@ + return Error::success(); + } + ++// Collect available bundle IDs into a std::set. Return true if an error was ++// found. ++Error OffloadBundler::GetBundleIDsInFile(StringRef InputFileName, ++ const OffloadBundlerConfig &BundlerConfig, ++ std::set &BundleIDs) { ++ // Open Input file. ++ ErrorOr> CodeOrErr = ++ MemoryBuffer::getFileOrSTDIN(InputFileName); ++ if (std::error_code EC = CodeOrErr.getError()) ++ return createFileError(InputFileName, EC); ++ ++ // Decompress the input if necessary. ++ Expected> DecompressedBufferOrErr = ++ CompressedOffloadBundle::decompress( ++ **CodeOrErr, BundlerConfig.Verbose ? &llvm::errs() : nullptr); ++ if (!DecompressedBufferOrErr) ++ return createStringError( ++ inconvertibleErrorCode(), ++ "Failed to decompress input: " + ++ llvm::toString(DecompressedBufferOrErr.takeError())); ++ ++ MemoryBuffer &DecompressedInput = **DecompressedBufferOrErr; ++ ++ // Select the right files handler. ++ Expected> FileHandlerOrErr = ++ CreateFileHandler(DecompressedInput, BundlerConfig); ++ if (!FileHandlerOrErr) ++ return FileHandlerOrErr.takeError(); ++ ++ std::unique_ptr &FH = *FileHandlerOrErr; ++ assert(FH); ++ ++ std::set BundleIDsRefs; ++ if (auto Error = FH->getBundleIDs(DecompressedInput, BundleIDsRefs)) ++ return Error; ++ ++ for (auto bundle_id : BundleIDsRefs) ++ BundleIDs.insert(bundle_id.str()); ++ ++ return Error::success(); ++} ++ + /// @brief Checks if a code object \p CodeObjectInfo is compatible with a given + /// target \p TargetInfo. + /// @link https://clang.llvm.org/docs/ClangOffloadBundler.html#bundle-entry-id diff --git a/pkgs/development/rocm-modules/10/llvm/clang-log-jobs.diff b/pkgs/development/rocm-modules/10/llvm/clang-log-jobs.diff deleted file mode 100644 index 3a3a712c8bbaf..0000000000000 --- a/pkgs/development/rocm-modules/10/llvm/clang-log-jobs.diff +++ /dev/null @@ -1,40 +0,0 @@ -diff --git a/clang/lib/Driver/Compilation.cpp b/clang/lib/Driver/Compilation.cpp -index 06f5e7e7e335..8407d664886a 100644 ---- a/lib/Driver/Compilation.cpp -+++ b/lib/Driver/Compilation.cpp -@@ -340,6 +340,9 @@ private: - void Compilation::ExecuteJobs(const JobList &Jobs, - FailingCommandList &FailingCommands, - bool LogOnly) const { -+ // If >1 job, log as each job finishes so can see progress while building many offloads -+ const bool logJobs = Jobs.size() > 1; -+ auto start_time = std::chrono::steady_clock::now(); - // According to UNIX standard, driver need to continue compiling all the - // inputs on the command line even one of them failed. - // In all but CLMode, execute all the jobs unless the necessary inputs for the -@@ -364,11 +367,25 @@ void Compilation::ExecuteJobs(const JobList &Jobs, - - JS.setJobState(Next, JobScheduler::JS_RUN); - auto Work = [&, Next]() { -+ auto job_start_time = std::chrono::steady_clock::now(); - const Command *FailingCommand = nullptr; - if (int Res = ExecuteCommand(*Next, FailingCommand, LogOnly)) { - FailingCommands.push_back(std::make_pair(Res, FailingCommand)); - JS.setJobState(Next, JobScheduler::JS_FAIL); - } else { -+ if (logJobs && Next) { -+ auto now = std::chrono::steady_clock::now(); -+ auto job_duration = std::chrono::duration_cast(now - job_start_time).count(); -+ auto duration = std::chrono::duration_cast(now - start_time).count(); -+ if (duration > 10 && job_duration > 0) { -+ if (Next->getOutputFilenames().empty()) -+ if (Next->getExecutable()) llvm::errs() << "Job completed: " << Next->getExecutable() << "\n"; -+ else (llvm::errs() << "Job completed: "), Next->Print(llvm::errs(), "\n", true); -+ else -+ llvm::errs() << "Job completed: " << Next->getOutputFilenames().front().c_str() << "\n"; -+ } -+ } -+ - JS.setJobState(Next, JobScheduler::JS_DONE); - } - }; diff --git a/pkgs/development/rocm-modules/10/llvm/default.nix b/pkgs/development/rocm-modules/10/llvm/default.nix index 4fbb9fb0d1c92..f235f751a9ee2 100644 --- a/pkgs/development/rocm-modules/10/llvm/default.nix +++ b/pkgs/development/rocm-modules/10/llvm/default.nix @@ -1,8 +1,9 @@ { lib, stdenv, - # LLVM version closest to ROCm fork to override - llvmPackages_22, + # Packaging base only; there is no llvmPackages_24, and the llvmPackages_git + # alias fails with allowAliases = false. + llvmPackages_23, overrideCC, lndir, rocm-device-libs, @@ -16,14 +17,13 @@ libffi, libxml2, removeReferencesTo, - fetchpatch, # Build compilers and stdenv suitable for profiling # leaving compressed line tables (-g1 -gz) unstripped # TODO: Should also apply to downstream packages which use rocmClangStdenv? profilableStdenv ? false, # FIXME: proper two-stage bootstrap & PGO/BOLT/LTO - # LTO currently disabled due to llvm 22 vs 22.1 bitcode mismatch between - # llvmPackages_22 (22.1) and ROCm LLVM (22.0). Uses new bitcode attr + # LTO currently disabled due to bitcode mismatch between the nixpkgs + # llvmPackages_23 and ROCm LLVM (24.0.0git). Uses new bitcode attr # 105 nocreateundeforpoison fails to link hipify. # Whether to use LTO when building the ROCm toolchain # Slows down this toolchain's build, for typical ROCm usecase @@ -36,12 +36,14 @@ }: let - version = "7.2.4"; + version = "10.1"; + # ROCm/TheRock two-component tag (therock-.) for all monorepo/llvm sources + srcTag = "therock-${version}"; # major version of this should be the clang version ROCm forked from - rocmLlvmVersion = "22.0.0-rocm"; - # llvmPackages_base version should match rocmLlvmVersion - # so libllvm's bitcode is compatible with the built toolchain - llvmPackages_base = llvmPackages_22; + rocmLlvmVersion = "24.0.0-rocm"; + # The base's own libllvm is used only to bootstrap (LTO is off, see withLto), + # so a released base one major behind ROCm's LLVM is fine. + llvmPackages_base = llvmPackages_23; llvmPackagesNoBintools = llvmPackages_base.override { bootBintools = null; bootBintoolsNoLibc = null; @@ -117,18 +119,17 @@ let llvmSrc = fetchFromGitHub { owner = "ROCm"; repo = "llvm-project"; - tag = "rocm-${version}"; - hash = "sha256-TwFvQimbax2E37ZC/52lNkHXCgyBNfSGDBaqmas2x/s="; + tag = srcTag; + hash = "sha256-WkgJF0D4XsrWKbJO+vKow9CrNIKL/PqOXRwrB3ECsQE="; }; llvmMajorVersion = lib.versions.major rocmLlvmVersion; # An llvmPackages (pkgs/development/compilers/llvm/) built from ROCm LLVM's source tree llvmPackagesRocm = llvmPackages_base.override (_old: { stdenv = stdenvToBuildRocmLlvm; - # not setting gitRelease = because that causes patch selection logic to use git patches - # ROCm LLVM is closer to 20 official - # gitRelease = {}; officialRelease = null; - officialRelease = { }; # Set but empty because we're overriding everything from it. + # Keep the official (not git) patch-selection path: ROCm LLVM tracks official + # releases closely. Set but empty because we're overriding everything from it. + officialRelease = { }; # this version determines which patches are applied version = rocmLlvmVersion; src = llvmSrc; @@ -212,8 +213,10 @@ let # Clang config file: redirect resource dir to the sysroot (where compiler-rt # lives) and set GCC install prefix for header/library search + # -L zstd: clang-linker-wrapper links -lzstd for compressed offload images. cat > $out/bin/${stdenv.hostPlatform.config}.cfg < Date: Thu, 22 Oct 2026 07:18:37 -0700 Subject: [PATCH 06/21] rocmPackages_10.rocm-device-libs: init at 24.0.0-rocm Update the rocmPackages.rocm-device-libs copy from the previous commit to ROCm 10.1 and add it to the rocmPackages_10 scope. From "rocmPackages.llvm: 7.2.4 -> 10.1.0, build LLVM 24 on the llvmPackages_23 base": ROCm 10.1's llvm-project fork is LLVM 24 (LLVMVersion.cmake: LLVM_VERSION_MAJOR 24), sourced from the therock-10.1 tag. nixpkgs has no released llvmPackages_24, and the 24.0.0-git snapshot (llvmPackages_git) is an alias reserved for testing whose package-set splice resolves through that alias, so it cannot be evaluated with allowAliases = false (as CI does). Keep the released llvmPackages_23 as the base: it only supplies the shared compilers/llvm/common packaging and the bootstrap clang/bintools, while rocmLlvmVersion = "24.0.0-rocm" selects the LLVM 24 patch set for ROCm's own source. LTO is off, so the base's bitcode version is moot. Toolchain changes for the LLVM 22 -> 24 jump: - Drop the LLVM 22 backports (select-ptr-combine, arm64e_x1 bridge, v64i8 VBMI shuffle, scan-build-py option): all upstream in LLVM 24. - Drop the CompressedOffloadBundle::decompress postPatch and the EmissaryIds postUnpack symlink: ROCm 10.1 uses the raw_ostream* decompress form and removed CGEmitEmissaryExec.cpp/EmissaryIds.h (llvm#175265). - Replace the GZGavinZhao GetBundleIDsInFile fetchpatch (no longer applies) with a locally rebased clang-add-getbundleidsinfile.diff; it adds the set-returning OffloadBundler::GetBundleIDsInFile the comgr ISA-compat patch calls. - Drop clang-log-jobs.diff: LLVM 24 rewrote Compilation::ExecuteJobs around parallel offload job groups, so the patched loop no longer exists; it was cosmetic CI-progress logging. - Put zstd's lib dir on the toolchain default link path: LLVM 24's clang-linker-wrapper links libzstd when combining compressed offload images (--offload-compress defaults on). - Rebase rocm-device-libs' cmake.patch and guard rocm-comgr's EnvLLVMPath substitution against a null default. Assisted-by: Claude Code (claude-opus-5-5) --- pkgs/development/rocm-modules/10/default.nix | 7 +++++++ .../10/rocm-device-libs/cmake.patch | 21 ++++++------------- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/pkgs/development/rocm-modules/10/default.nix b/pkgs/development/rocm-modules/10/default.nix index a82d45132733c..07d5e6bca5694 100644 --- a/pkgs/development/rocm-modules/10/default.nix +++ b/pkgs/development/rocm-modules/10/default.nix @@ -2,6 +2,7 @@ lib, callPackage, newScope, + stdenv, }: let @@ -9,8 +10,11 @@ let self: let inherit (self) llvm; + rocmClangStdenv = llvm.rocmClangStdenv; in { + inherit rocmClangStdenv; + stdenv = rocmClangStdenv; rocmUpdateScript = self.callPackage ../update.nix { maxMajor = 10; @@ -29,6 +33,9 @@ let inherit (self) rocm-device-libs; } ); + inherit (self.llvm) rocm-toolchain clang openmp; + + rocm-device-libs = self.callPackage ./rocm-device-libs { }; } ); in diff --git a/pkgs/development/rocm-modules/10/rocm-device-libs/cmake.patch b/pkgs/development/rocm-modules/10/rocm-device-libs/cmake.patch index 500ff37a99052..89160e66970e3 100644 --- a/pkgs/development/rocm-modules/10/rocm-device-libs/cmake.patch +++ b/pkgs/development/rocm-modules/10/rocm-device-libs/cmake.patch @@ -1,8 +1,6 @@ -diff --git a/cmake/Packages.cmake b/cmake/Packages.cmake -index 07c60eb..c736b3e 100644 ---- a/cmake/Packages.cmake -+++ b/cmake/Packages.cmake -@@ -12,24 +12,29 @@ set_target_properties(${target} PROPERTIES +--- a/cmake/Packages.cmake 2026-09-20 19:45:16.236395164 -0700 ++++ b/cmake/Packages.cmake 2026-09-20 19:45:16.252171984 -0700 +@@ -12,21 +12,25 @@ IMPORTED_LOCATION \"${target_path}\")") endforeach() configure_file(AMDDeviceLibsConfig.cmake.in @@ -10,20 +8,14 @@ index 07c60eb..c736b3e 100644 + lib/cmake/AMDDeviceLibs/AMDDeviceLibsConfig.cmake @ONLY) - - set(install_path_suffix "amdgcn/bitcode") - # Generate the install-tree package. --# We do not know the absolute path to the intall tree until we are installed, --# so we calculate it dynamically in AMD_DEVICE_LIBS_PREFIX_CODE and use --# relative paths in the target imports in AMD_DEVICE_LIBS_TARGET_CODE. + # We do not know the absolute path to the intall tree until we are installed, + # so we calculate it dynamically in AMD_DEVICE_LIBS_PREFIX_CODE and use + # relative paths in the target imports in AMD_DEVICE_LIBS_TARGET_CODE. -set(AMD_DEVICE_LIBS_PREFIX_CODE " +if(IS_ABSOLUTE "${CMAKE_INSTALL_PREFIX}") + set(AMD_DEVICE_LIBS_PREFIX_CODE "set(AMD_DEVICE_LIBS_PREFIX \"${CMAKE_INSTALL_PREFIX}\")") +else() -+ # We do not know the absolute path to the install tree until we are installed, -+ # so we calculate it dynamically in AMD_DEVICE_LIBS_PREFIX_CODE and use -+ # relative paths in the target imports in AMD_DEVICE_LIBS_TARGET_CODE. + set(AMD_DEVICE_LIBS_PREFIX_CODE " # Derive absolute install prefix from config file path. get_filename_component(AMD_DEVICE_LIBS_PREFIX \"\${CMAKE_CURRENT_LIST_FILE}\" PATH)") @@ -37,7 +29,6 @@ index 07c60eb..c736b3e 100644 -endforeach() + endforeach() +endif() -+ set(AMD_DEVICE_LIBS_TARGET_CODE) foreach(target ${AMDGCN_LIB_LIST}) get_target_property(target_name ${target} ARCHIVE_OUTPUT_NAME) From ab8f71a8f46295aab46dcf202d323fa4c17a8af5 Mon Sep 17 00:00:00 2001 From: randomizedcoder Date: Thu, 22 Oct 2026 07:18:41 -0700 Subject: [PATCH 07/21] rocmPackages_10: copy runtime from rocmPackages Verbatim copies of the rocmPackages (ROCm 7.2.4) expressions for rocm-core, rocm-cmake, rocprofiler-register, rocm-runtime, rocm-comgr, rocminfo, amdsmi, rocm-smi, hip-common, roctracer, clr, hipify, half, not yet part of the rocmPackages_10 scope. The following commits update each one to ROCm 10.1, so their diffs read against 7.2.4. Assisted-by: Claude Code (claude-opus-5-5) --- .../rocm-modules/10/amdsmi/default.nix | 96 +++++ .../amdsmi/drm-struct-redefinition-fix.patch | 35 ++ .../10/clr/cmake-find-x11-libgl.patch | 40 ++ .../rocm-modules/10/clr/default.nix | 345 ++++++++++++++++++ .../10/clr/test-hiprtc-type-traits.cpp | 68 ++++ .../10/clr/test-hiprtc-type-traits.nix | 57 +++ .../rocm-modules/10/clr/test-isa-compat.nix | 74 ++++ .../rocm-modules/10/clr/test-opencl-cts.nix | 28 ++ .../rocm-modules/10/clr/test-rocm-smi.nix | 27 ++ .../rocm-modules/10/half/default.nix | 35 ++ .../rocm-modules/10/hip-common/default.nix | 46 +++ .../rocm-modules/10/hipify/default.nix | 66 ++++ .../rocm-modules/10/rocm-cmake/default.nix | 34 ++ .../rocm-modules/10/rocm-comgr/default.nix | 88 +++++ .../fix-ccob-compat-output-filename.patch | 11 + .../rocm-modules/10/rocm-core/default.nix | 95 +++++ .../10/rocm-core/env-rocm-path.patch | 22 ++ .../rocm-modules/10/rocm-runtime/default.nix | 109 ++++++ .../10/rocm-runtime/queue-failure.patch | 71 ++++ .../remove-hsa-aqlprofile-dep.patch | 27 ++ .../rocm-modules/10/rocm-smi/default.nix | 78 ++++ .../rocm-modules/10/rocminfo/default.nix | 57 +++ .../10/rocprofiler-register/default.nix | 97 +++++ .../rocm-modules/10/roctracer/default.nix | 118 ++++++ 24 files changed, 1724 insertions(+) create mode 100644 pkgs/development/rocm-modules/10/amdsmi/default.nix create mode 100644 pkgs/development/rocm-modules/10/amdsmi/drm-struct-redefinition-fix.patch create mode 100644 pkgs/development/rocm-modules/10/clr/cmake-find-x11-libgl.patch create mode 100644 pkgs/development/rocm-modules/10/clr/default.nix create mode 100644 pkgs/development/rocm-modules/10/clr/test-hiprtc-type-traits.cpp create mode 100644 pkgs/development/rocm-modules/10/clr/test-hiprtc-type-traits.nix create mode 100644 pkgs/development/rocm-modules/10/clr/test-isa-compat.nix create mode 100644 pkgs/development/rocm-modules/10/clr/test-opencl-cts.nix create mode 100644 pkgs/development/rocm-modules/10/clr/test-rocm-smi.nix create mode 100644 pkgs/development/rocm-modules/10/half/default.nix create mode 100644 pkgs/development/rocm-modules/10/hip-common/default.nix create mode 100644 pkgs/development/rocm-modules/10/hipify/default.nix create mode 100644 pkgs/development/rocm-modules/10/rocm-cmake/default.nix create mode 100644 pkgs/development/rocm-modules/10/rocm-comgr/default.nix create mode 100644 pkgs/development/rocm-modules/10/rocm-comgr/fix-ccob-compat-output-filename.patch create mode 100644 pkgs/development/rocm-modules/10/rocm-core/default.nix create mode 100644 pkgs/development/rocm-modules/10/rocm-core/env-rocm-path.patch create mode 100644 pkgs/development/rocm-modules/10/rocm-runtime/default.nix create mode 100644 pkgs/development/rocm-modules/10/rocm-runtime/queue-failure.patch create mode 100644 pkgs/development/rocm-modules/10/rocm-runtime/remove-hsa-aqlprofile-dep.patch create mode 100644 pkgs/development/rocm-modules/10/rocm-smi/default.nix create mode 100644 pkgs/development/rocm-modules/10/rocminfo/default.nix create mode 100644 pkgs/development/rocm-modules/10/rocprofiler-register/default.nix create mode 100644 pkgs/development/rocm-modules/10/roctracer/default.nix diff --git a/pkgs/development/rocm-modules/10/amdsmi/default.nix b/pkgs/development/rocm-modules/10/amdsmi/default.nix new file mode 100644 index 0000000000000..d483dde8b6e8a --- /dev/null +++ b/pkgs/development/rocm-modules/10/amdsmi/default.nix @@ -0,0 +1,96 @@ +{ + lib, + stdenv, + fetchFromGitHub, + rocmUpdateScript, + cmake, + pkg-config, + libdrm, + python, + wrapPython, + autoPatchelfHook, +}: + +let + esmi_ib_src = fetchFromGitHub { + owner = "amd"; + repo = "esmi_ib_library"; + tag = "esmi_pkg_ver-4.2"; + hash = "sha256-czF9ezkAO0PuDkXh8y639AcOZH+KVcWiXPX74H5W/nw="; + }; +in +stdenv.mkDerivation (finalAttrs: { + pname = "amdsmi"; + version = "7.2.4"; + src = fetchFromGitHub { + owner = "ROCm"; + repo = "rocm-systems"; + tag = "rocm-${finalAttrs.version}"; + sparseCheckout = [ + "projects/amdsmi" + "shared" + ]; + hash = "sha256-TFi+3txemvV6K827e8S3hZOd9jcj4Qzop6V9CdKrpLg="; + }; + sourceRoot = "${finalAttrs.src.name}/projects/amdsmi"; + + postPatch = '' + substituteInPlace goamdsmi_shim/CMakeLists.txt \ + --replace-fail "amd_smi)" ${"'"}''${AMD_SMI_TARGET})' \ + --replace-fail 'target_link_libraries(''${GOAMDSMI_SHIM_TARGET} -L' '#' + substituteInPlace CMakeLists.txt \ + --replace-fail "if(NOT latest_esmi_tag STREQUAL current_esmi_tag)" "if(OFF)" + + # Manually unpack esmi_ib_src and add amd_hsmp.h so execute-process git clone doesn't run + cp -rf --no-preserve=mode ${esmi_ib_src} ./esmi_ib_library + mkdir -p ./esmi_ib_library/include/asm + cp ./include/amd_smi/impl/amd_hsmp.h ./esmi_ib_library/include/asm/amd_hsmp.h + ''; + + patches = [ + # Fix error: redefinition of 'struct drm_color_ctm_3x4' + # https://github.com/ROCm/amdsmi/pull/165 + ./drm-struct-redefinition-fix.patch + ]; + + nativeBuildInputs = [ + cmake + pkg-config + wrapPython + autoPatchelfHook + ]; + + buildInputs = [ + libdrm + ]; + + cmakeFlags = [ + # Manually define CMAKE_INSTALL_ + # See: https://github.com/NixOS/nixpkgs/pull/197838 + "-DCMAKE_INSTALL_BINDIR=bin" + "-DCMAKE_INSTALL_LIBDIR=lib" + "-DCMAKE_INSTALL_INCLUDEDIR=include" + ]; + + postInstall = '' + mkdir -p $out/${python.sitePackages} + ln -s $out/share/amd_smi/amdsmi $out/${python.sitePackages}/amdsmi + + makeWrapperArgs=(--prefix LD_LIBRARY_PATH : ${lib.makeLibraryPath [ libdrm ]}) + wrapPythonProgramsIn $out + rm $out/bin/amd-smi + ln -sf $out/libexec/amdsmi_cli/amdsmi_cli.py $out/bin/amd-smi + ''; + + passthru.updateScript = rocmUpdateScript { inherit finalAttrs; }; + + meta = { + description = "System management interface for AMD GPUs supported by ROCm"; + homepage = "https://github.com/ROCm/rocm-systems/tree/develop/projects/amdsmi"; + license = lib.licenses.mit; + maintainers = with lib.maintainers; [ lovesegfault ]; + teams = [ lib.teams.rocm ]; + platforms = [ "x86_64-linux" ]; + mainProgram = "amd-smi"; + }; +}) diff --git a/pkgs/development/rocm-modules/10/amdsmi/drm-struct-redefinition-fix.patch b/pkgs/development/rocm-modules/10/amdsmi/drm-struct-redefinition-fix.patch new file mode 100644 index 0000000000000..caf23edcef57a --- /dev/null +++ b/pkgs/development/rocm-modules/10/amdsmi/drm-struct-redefinition-fix.patch @@ -0,0 +1,35 @@ +From b8b4a6bcfe35ba9539a120cfd16573123ddd9241 Mon Sep 17 00:00:00 2001 +From: "Sv. Lockal" +Date: Mon, 15 Dec 2025 03:46:35 +0800 +Subject: [PATCH] Fix compilation with libdrm-2.4.130 + +Fix error: redefinition of 'struct drm_color_ctm_3x4'. + +drm_color_ctm_3x4 structure is now defined in https://github.com/torvalds/linux/commit/e5719e7f19009d4fbedf685fc22eec9cd8de154f#diff-4c51fb416ec7cc69566cd7b795ee57eb070aa1006ad65d6962081f039ffb2718 + +As this structure is unused and not a part of amdsmi public interface, +it is safe to remove it. +--- + include/amd_smi/impl/amdgpu_drm.h | 9 --------- + 1 file changed, 9 deletions(-) + +diff --git a/include/amd_smi/impl/amdgpu_drm.h b/include/amd_smi/impl/amdgpu_drm.h +index b56a5ac4b..0e483d13b 100644 +--- a/include/amd_smi/impl/amdgpu_drm.h ++++ b/include/amd_smi/impl/amdgpu_drm.h +@@ -1625,15 +1625,6 @@ struct drm_amdgpu_info_uq_metadata { + #define AMDGPU_FAMILY_GC_11_5_0 150 /* GC 11.5.0 */ + #define AMDGPU_FAMILY_GC_12_0_0 152 /* GC 12.0.0 */ + +-/* FIXME wrong namespace! */ +-struct drm_color_ctm_3x4 { +- /* +- * Conversion matrix with 3x4 dimensions in S31.32 sign-magnitude +- * (not two's complement!) format. +- */ +- __u64 matrix[12]; +-}; +- + #if defined(__cplusplus) + } + #endif diff --git a/pkgs/development/rocm-modules/10/clr/cmake-find-x11-libgl.patch b/pkgs/development/rocm-modules/10/clr/cmake-find-x11-libgl.patch new file mode 100644 index 0000000000000..5a36a2c2c74d0 --- /dev/null +++ b/pkgs/development/rocm-modules/10/clr/cmake-find-x11-libgl.patch @@ -0,0 +1,40 @@ +diff --git a/rocclr/cmake/ROCclr.cmake b/rocclr/cmake/ROCclr.cmake +index 3f233b72f..67bdc62ee 100644 +--- a/rocclr/cmake/ROCclr.cmake ++++ b/rocclr/cmake/ROCclr.cmake +@@ -44,6 +44,19 @@ find_package(Threads REQUIRED) + + find_package(AMD_OPENCL) + ++# Find X11 package ++find_package(X11 REQUIRED) ++if(NOT X11_FOUND) ++ message(FATAL_ERROR "X11 libraries not found") ++endif() ++ ++# Find OpenGL package ++find_package(OpenGL REQUIRED) ++if(NOT OpenGL_FOUND) ++ message(FATAL_ERROR "OpenGL not found") ++endif() ++ ++ + add_library(rocclr STATIC) + + include(ROCclrCompilerOptions) +@@ -123,9 +136,14 @@ target_include_directories(rocclr PUBLIC + ${ROCCLR_SRC_DIR}/device + ${ROCCLR_SRC_DIR}/elf + ${ROCCLR_SRC_DIR}/include ++ ${X11_INCLUDE_DIR} ++ ${OPENGL_INCLUDE_DIR} + ${AMD_OPENCL_INCLUDE_DIRS}) + +-target_link_libraries(rocclr PUBLIC Threads::Threads) ++target_link_libraries(rocclr PUBLIC ++ Threads::Threads ++ ${X11_LIBRARIES} ++ ${OPENGL_LIBRARIES}) + # IPC on Windows is not supported + if(UNIX) + target_link_libraries(rocclr PUBLIC rt) diff --git a/pkgs/development/rocm-modules/10/clr/default.nix b/pkgs/development/rocm-modules/10/clr/default.nix new file mode 100644 index 0000000000000..554c76d845c04 --- /dev/null +++ b/pkgs/development/rocm-modules/10/clr/default.nix @@ -0,0 +1,345 @@ +{ + lib, + stdenv, + callPackage, + fetchFromGitHub, + fetchpatch, + rocmUpdateScript, + makeWrapper, + cmake, + perl, + hip-common, + hipcc, + rocm-device-libs, + rocm-comgr, + rocm-runtime, + rocm-core, + roctracer, + rocminfo, + rocm-smi, + rocprofiler-register, + symlinkJoin, + numactl, + libffi, + zstd, + zlib, + libGL, + libxml2, + libx11, + python3Packages, + llvm, + khronos-ocl-icd-loader, + gcc-unwrapped, + writeShellScriptBin, + localGpuTargets ? null, +}: + +let + inherit (rocm-core) ROCM_LIBPATCH_VERSION; + # HIP_CLANG_PATH or ROCM_PATH/llvm + # Note: relying on ROCM_PATH/llvm is bad for cross + hipClang = symlinkJoin { + name = "hipClang"; + paths = [ + # FIXME: if we don't put this first aotriton build fails with ld.lld: -flavor gnu + # Probably wrapper jank + llvm.bintools.bintools + llvm.rocm-toolchain + ]; + postBuild = '' + rm -rf $out/{include,lib,share,etc,nix-support,usr} + ''; + }; + hipClangPath = "${hipClang}/bin"; + wrapperArgs = [ + "--prefix PATH : $out/bin" + "--prefix LD_LIBRARY_PATH : ${rocm-runtime}" + "--set HIP_PLATFORM amd" + "--set HIP_PATH $out" + "--set HIP_CLANG_PATH ${hipClangPath}" + "--set DEVICE_LIB_PATH ${rocm-device-libs}/amdgcn/bitcode" + "--set HSA_PATH ${rocm-runtime}" + "--set ROCM_PATH $out" + ]; + amdclang = writeShellScriptBin "amdclang" '' + exec ${hipClang}/bin/clang "$@" + ''; + amdclangxx = writeShellScriptBin "amdclang++" '' + exec ${hipClang}/bin/clang++ "$@" + ''; +in +stdenv.mkDerivation (finalAttrs: { + pname = "clr"; + version = "7.2.4"; + + outputs = [ + "out" + "icd" + ]; + + __structuredAttrs = true; + strictDeps = true; + + src = fetchFromGitHub { + owner = "ROCm"; + repo = "rocm-systems"; + tag = "rocm-${finalAttrs.version}"; + sparseCheckout = [ + "projects/clr" + "shared" + ]; + hash = "sha256-//cQBKlSB9uSP4fBgJpI1FxnqlzyQN913CHVGa2tqv8="; + }; + sourceRoot = "${finalAttrs.src.name}/projects/clr"; + + nativeBuildInputs = [ + makeWrapper + cmake + perl + python3Packages.python + python3Packages.cppheaderparser + amdclang + amdclangxx + ]; + + buildInputs = [ + llvm.llvm + numactl + libGL + libxml2 + libx11 + khronos-ocl-icd-loader + hipClang + libffi + zstd + zlib + rocprofiler-register + ]; + + propagatedBuildInputs = [ + rocm-core + rocm-device-libs + rocm-comgr + rocm-runtime + rocminfo + hipClangPath + ]; + + cmakeBuildType = "RelWithDebInfo"; + separateDebugInfo = true; + + cmakeFlags = [ + (lib.cmakeFeature "CMAKE_POLICY_DEFAULT_CMP0072" "NEW") # Prefer newer OpenGL libraries + (lib.cmakeBool "CLR_BUILD_HIP" true) + (lib.cmakeBool "CLR_BUILD_OCL" true) + (lib.cmakeFeature "HIP_COMMON_DIR" hip-common.outPath) + (lib.cmakeFeature "HIPCC_BIN_DIR" "${hipcc}/bin") + (lib.cmakeFeature "HIP_PLATFORM" "amd") + (lib.cmakeFeature "PROF_API_HEADER_PATH" "${roctracer.src}/inc/ext") + (lib.cmakeFeature "ROCM_PATH" rocminfo.outPath) + (lib.cmakeBool "BUILD_ICD" true) + (lib.cmakeFeature "AMD_ICD_LIBRARY_DIR" khronos-ocl-icd-loader.outPath) + + # Temporarily set variables to work around upstream CMakeLists issue + # Can be removed once https://github.com/ROCm/rocm-cmake/issues/121 is fixed + (lib.cmakeFeature "CMAKE_INSTALL_BINDIR" "bin") + (lib.cmakeFeature "CMAKE_INSTALL_INCLUDEDIR" "include") + (lib.cmakeFeature "CMAKE_INSTALL_LIBDIR" "lib") + ]; + + env.LLVM_DIR = ""; + + patches = [ + ./cmake-find-x11-libgl.patch + (fetchpatch { + # [PATCH] rocclr: Extend HIP ISA compatibility checks + hash = "sha256-3MsDL+OQg24wH1RDhbao74RuIbzEAmduwla9KOPzQ/M="; + url = "https://github.com/GZGavinZhao/rocm-systems/commit/039cb23b24d739adb8c0f9de8b550d9f557de031.patch"; + relative = "projects/clr"; + }) + ]; + + postPatch = '' + patchShebangs hipamd/*.sh + patchShebangs hipamd/src + '' + # We're not on Windows so these are never installed to hipcc... + + '' + substituteInPlace hipamd/CMakeLists.txt \ + --replace-fail "install(PROGRAMS \''${HIPCC_BIN_DIR}/hipcc.bat DESTINATION bin)" "" \ + --replace-fail "install(PROGRAMS \''${HIPCC_BIN_DIR}/hipconfig.bat DESTINATION bin)" "" + '' + + '' + substituteInPlace hipamd/src/hip_embed_pch.sh \ + --replace-fail "\''$LLVM_DIR/bin/clang" "${hipClangPath}/clang" \ + --replace-fail "\''$LLVM_DIR/bin/llvm-mc" "${lib.getExe' llvm.bintools.bintools "llvm-mc"}" + '' + + '' + substituteInPlace opencl/khronos/icd/loader/icd_platform.h \ + --replace-fail '#define ICD_VENDOR_PATH "/etc/OpenCL/vendors/";' \ + '#define ICD_VENDOR_PATH "/run/opengl-driver/etc/OpenCL/vendors/";' + '' + # HIP defines __noinline__ as an empty macro for host compilers, which breaks + # [[__gnu__::__noinline__]] in libstdc++ 16's + # https://github.com/ROCm/rocm-systems/pull/12596 + + '' + substituteInPlace hipamd/include/hip/amd_detail/host_defines.h \ + --replace-fail $'#define __noinline__\n' "" + ''; + + postInstall = '' + chmod +x $out/bin/* + patchShebangs $out/bin + + cp ${amdclang}/bin/* $out/bin/ + cp ${amdclangxx}/bin/* $out/bin/ + + for prog in hip{cc,config}; do + wrapProgram $out/bin/$prog ${lib.concatStringsSep " " wrapperArgs} + done + + mkdir -p $out/nix-support/ + echo ' + export HIP_PATH="${placeholder "out"}" + export HIP_PLATFORM=amd + export HIP_DEVICE_LIB_PATH="${rocm-device-libs}/amdgcn/bitcode" + export NIX_CC_USE_RESPONSE_FILE=0 + export HIP_CLANG_PATH="${hipClangPath}" + export ROCM_LIBPATCH_VERSION="${ROCM_LIBPATCH_VERSION}" + export HSA_PATH="${rocm-runtime}"' > $out/nix-support/setup-hook + + # Just link rocminfo, it's easier + ln -s ${rocminfo}/bin/* $out/bin + ln -s ${rocm-core}/include/* $out/include/ + + # Replace rocm-opencl-icd functionality + mkdir -p $icd/etc/OpenCL/vendors + echo "$out/lib/libamdocl64.so" > $icd/etc/OpenCL/vendors/amdocl64.icd + + # add version info to output (downstream rocmPackages look for this) + ln -s ${rocm-core}/.info/ $out/.info + + ln -s ${hipClang} $out/llvm + ''; + + # libamdhip64.so dlopens its own bare name for hipGetProcAddress symbol resolution, + # same pattern with libhiprtc.so, so add own lib directory to all .so's + # RPATHs so they can find themselves and neighbouring libs + # Must be in postFixup so it runs after patchelf --shrink-rpath which removes + # the apparently useless rpath + postFixup = '' + patchelf --add-rpath "$out/lib" "$out"/lib/*.so + ''; + + disallowedRequisites = [ + gcc-unwrapped + ]; + + passthru = { + # All known and valid general GPU targets + # We cannot use this for each ROCm library, as each defines their own supported targets + # See: https://github.com/ROCm/ROCm/blob/77cbac4abab13046ee93d8b5bf410684caf91145/README.md#library-target-matrix + gpuTargets = lib.forEach [ + # "9-generic" # can handle all Vega variants + "900" # MI25, Vega 56/64 + # "902" # Vega 8 + # "909" # Renoir Vega APU + # "90c" # Renoir Vega APU + # Past this point cards need their own kernels for perf despite gfx9-generic compat + "906" # MI50/60, Radeon VII - adds dot product & mixed precision FMA ops + "908" # MI100 - adds MFMA (matrix fused multiply-add) ops + "90a" # MI210/MI250 - additional MFMA variants + # "9-4-generic" - since only 942 is valid for 6.4 target it directly + # 940/1 - never released publicly, maybe HPE cray specific MI3xx? + "942" # MI300A/X, MI325X + "950" # MI350X, MI355X + # "10-1-generic" # fine for all RDNA1 cards + "1010" + # "10-3-generic" + "1030" # W6800, various Radeon cards + # 1100 through 1103 = RDNA3 + # "11-generic" # will handle 7600, hopefully ryzen AI series iGPUs + "1100" + "1101" + "1102" + "1103" # RDNA3 iGPU like Radeon 780M + "1150" # Strix Point + "1151" # Strix Halo + # "12-generic" + "1200" # RX 9060 + "1201" # RX 9070 + XT + ] (target: "gfx${target}"); + + inherit hipClangPath; + + updateScript = rocmUpdateScript { inherit finalAttrs; }; + + impureTests = { + # bash $(nix-build -A rocmPackages.clr.impureTests.rocm-smi) + rocm-smi = callPackage ./test-rocm-smi.nix { + inherit rocm-smi; + clr = finalAttrs.finalPackage; + }; + # Simple subset of opencl-cts test_basic + opencl-cts = callPackage ./test-opencl-cts.nix { + clr = finalAttrs.finalPackage; + }; + generic-arch = callPackage ./test-isa-compat.nix { + clr = finalAttrs.finalPackage; + name = "generic-arch"; + offloadArches = [ + "gfx9-generic" + "gfx10-1-generic" + "gfx10-3-generic" + "gfx11-generic" + "gfx12-generic" + ]; + }; + isa-compat = callPackage ./test-isa-compat.nix { + clr = finalAttrs.finalPackage; + name = "isa-compat"; + offloadArches = [ + "gfx900" + "gfx1010" + "gfx1030" + ]; + }; + spirv = callPackage ./test-isa-compat.nix { + clr = finalAttrs.finalPackage; + name = "spirv"; + offloadArches = [ + "amdgcnspirv" + ]; + }; + hiprtc-type-traits = callPackage ./test-hiprtc-type-traits.nix { + clr = finalAttrs.finalPackage; + inherit rocm-smi; + }; + }; + + selectGpuTargets = + { + supported ? [ ], + }: + supported; + gpuArchSuffix = ""; + } + // lib.optionalAttrs (localGpuTargets != null) { + inherit localGpuTargets; + gpuArchSuffix = "-" + (builtins.concatStringsSep "-" localGpuTargets); + selectGpuTargets = + { + supported ? [ ], + }: + if supported == [ ] then localGpuTargets else lib.lists.intersectLists localGpuTargets supported; + }; + + meta = { + description = "AMD Common Language Runtime for hipamd, opencl, and rocclr"; + homepage = "https://github.com/ROCm/rocm-systems/tree/develop/projects/clr"; + license = lib.licenses.mit; + maintainers = with lib.maintainers; [ lovesegfault ]; + teams = [ lib.teams.rocm ]; + platforms = lib.platforms.linux; + }; +}) diff --git a/pkgs/development/rocm-modules/10/clr/test-hiprtc-type-traits.cpp b/pkgs/development/rocm-modules/10/clr/test-hiprtc-type-traits.cpp new file mode 100644 index 0000000000000..39a99f39eae11 --- /dev/null +++ b/pkgs/development/rocm-modules/10/clr/test-hiprtc-type-traits.cpp @@ -0,0 +1,68 @@ +#include +#include +#include +#include + +#define CHECK_HIP(expr) do { \ + if ((expr) != hipSuccess) { \ + std::cerr << #expr << " failed" << std::endl; \ + return 1; \ + } \ +} while(0) + +#define CHECK_HIPRTC(expr) do { \ + hiprtcResult _res = (expr); \ + if (_res != HIPRTC_SUCCESS) { \ + std::cerr << #expr << " failed: " << hiprtcGetErrorString(_res) << std::endl; \ + hiprtcGetProgramLogSize(prog, &log_size); \ + if (log_size > 0) { \ + std::string log(log_size, '\0'); \ + hiprtcGetProgramLog(prog, log.data()); \ + std::cerr << "Compile log:\n" << log << std::endl; \ + } \ + return 1; \ + } \ +} while(0) + +static const char* kernelSource = R"( + #include + + extern "C" __global__ void test_kernel(int* out) { + static_assert(std::is_same::type>::value, + "type_traits not working"); + out[0] = 5; + } +)"; + +int main() { + hiprtcProgram prog; + size_t log_size = 0; + CHECK_HIPRTC(hiprtcCreateProgram(&prog, kernelSource, "test.hip", 0, nullptr, nullptr)); + CHECK_HIPRTC(hiprtcCompileProgram(prog, 0, nullptr)); + + size_t code_size; + CHECK_HIPRTC(hiprtcGetCodeSize(prog, &code_size)); + std::string code(code_size, '\0'); + CHECK_HIPRTC(hiprtcGetCode(prog, code.data())); + hiprtcDestroyProgram(&prog); + + hipModule_t module; + hipFunction_t kernel; + CHECK_HIP(hipModuleLoadData(&module, code.data())); + CHECK_HIP(hipModuleGetFunction(&kernel, module, "test_kernel")); + + int* d_out; + int h_out = 0; + CHECK_HIP(hipMalloc(&d_out, sizeof(int))); + void* args[] = { &d_out }; + CHECK_HIP(hipModuleLaunchKernel(kernel, 1, 1, 1, 1, 1, 1, 0, nullptr, args, nullptr)); + CHECK_HIP(hipMemcpy(&h_out, d_out, sizeof(int), hipMemcpyDeviceToHost)); + + if (h_out != 5) { + std::cerr << "Kernel output mismatch: expected 5, got " << h_out << std::endl; + return 1; + } + + std::cout << "HIPRTC type_traits test passed (output=" << h_out << ")" << std::endl; + return 0; +} diff --git a/pkgs/development/rocm-modules/10/clr/test-hiprtc-type-traits.nix b/pkgs/development/rocm-modules/10/clr/test-hiprtc-type-traits.nix new file mode 100644 index 0000000000000..f0f3628fcdaa3 --- /dev/null +++ b/pkgs/development/rocm-modules/10/clr/test-hiprtc-type-traits.nix @@ -0,0 +1,57 @@ +{ + lib, + stdenv, + makeImpureTest, + clr, + rocm-smi, +}: +# minimal hiprtc test that compiles a kernel using at runtime +# mirrors an migraphx workload, better test/iteration UX to be able to confirm +# with just a build up to clr +let + hiprtc-test = stdenv.mkDerivation { + pname = "hiprtc-type-traits-test"; + version = "0"; + + dontUnpack = true; + + nativeBuildInputs = [ clr ]; + + buildPhase = '' + runHook preBuild + hipcc -o hiprtc-test ${./test-hiprtc-type-traits.cpp} -lhiprtc + runHook postBuild + ''; + + installPhase = '' + runHook preInstall + mkdir -p $out/bin + cp hiprtc-test $out/bin/ + runHook postInstall + ''; + }; +in +makeImpureTest { + name = "hiprtc-type-traits"; + testedPackage = "rocmPackages.clr"; + + sandboxPaths = [ + "/sys" + "/dev/dri" + "/dev/kfd" + ]; + + nativeBuildInputs = [ + hiprtc-test + rocm-smi + ]; + + testScript = '' + rocm-smi + hiprtc-test + ''; + + meta = { + teams = [ lib.teams.rocm ]; + }; +} diff --git a/pkgs/development/rocm-modules/10/clr/test-isa-compat.nix b/pkgs/development/rocm-modules/10/clr/test-isa-compat.nix new file mode 100644 index 0000000000000..2eca8edbff3d5 --- /dev/null +++ b/pkgs/development/rocm-modules/10/clr/test-isa-compat.nix @@ -0,0 +1,74 @@ +{ + lib, + stdenv, + makeImpureTest, + fetchFromGitHub, + clr, + rocm-smi, + name, + offloadArches, +}: + +let + # TODO: swap to another tiny test if this breaks; upstream is archived but fine for now + vectoradd = stdenv.mkDerivation { + pname = "rocm-hip-vectoradd"; + version = "2024-04-11"; + + src = fetchFromGitHub { + owner = "ROCm"; + repo = "HIP-Examples"; + rev = "cdf9d101acd9a3fc89ee750f73c1f1958cbd5cc3"; + hash = "sha256-/I1KmOBFbEZIjA1vRE+2tPTtEKtOgazjCbnZtr+87E0="; + }; + + nativeBuildInputs = [ + clr + ]; + + installPhase = '' + runHook preInstall + + mkdir -p $out/bin + amdclang++ -x hip -o $out/bin/vectoradd \ + ${lib.concatMapStringsSep " " (arch: "--offload-arch=${arch}") offloadArches} \ + vectorAdd/vectoradd_hip.cpp + + runHook postInstall + ''; + + meta = { + description = "vectorAdd HIP example for ROCm"; + homepage = "https://github.com/ROCm/HIP-Examples"; + license = lib.licenses.unfree; + platforms = lib.platforms.linux; + teams = [ lib.teams.rocm ]; + }; + }; + +in +makeImpureTest { + inherit name; + testedPackage = "rocmPackages.clr"; + + sandboxPaths = [ + "/sys" + "/dev/dri" + "/dev/kfd" + ]; + + nativeBuildInputs = [ + vectoradd + rocm-smi + ]; + + testScript = '' + rocm-smi + + vectoradd + ''; + + meta = { + teams = [ lib.teams.rocm ]; + }; +} diff --git a/pkgs/development/rocm-modules/10/clr/test-opencl-cts.nix b/pkgs/development/rocm-modules/10/clr/test-opencl-cts.nix new file mode 100644 index 0000000000000..77929531f9009 --- /dev/null +++ b/pkgs/development/rocm-modules/10/clr/test-opencl-cts.nix @@ -0,0 +1,28 @@ +{ + lib, + makeImpureTest, + opencl-cts, + clr, +}: + +makeImpureTest { + name = "opencl-cts"; + testedPackage = "rocmPackages.clr"; + + sandboxPaths = [ + "/sys" + "/dev/dri" + "/dev/kfd" + ]; + + nativeBuildInputs = [ opencl-cts ]; + OCL_ICD_VENDORS = "${clr.icd}/etc/OpenCL/vendors"; + + testScript = '' + test_basic arraycopy arrayreadwrite astype barrier vector_swizzle work_item_functions + ''; + + meta = { + teams = [ lib.teams.rocm ]; + }; +} diff --git a/pkgs/development/rocm-modules/10/clr/test-rocm-smi.nix b/pkgs/development/rocm-modules/10/clr/test-rocm-smi.nix new file mode 100644 index 0000000000000..e03655907c7b1 --- /dev/null +++ b/pkgs/development/rocm-modules/10/clr/test-rocm-smi.nix @@ -0,0 +1,27 @@ +{ + lib, + makeImpureTest, + clinfo, + clr, + rocm-smi, +}: + +makeImpureTest { + name = "rocm-smi"; + testedPackage = "rocmPackages.clr"; + nativeBuildInputs = [ + clinfo + rocm-smi + ]; + OCL_ICD_VENDORS = "${clr.icd}/etc/OpenCL/vendors"; + + testScript = '' + # Test fails if the number of platforms is 0 + clinfo | grep -E 'Number of platforms * [1-9]' + rocm-smi | grep -A1 GPU + ''; + + meta = { + teams = [ lib.teams.rocm ]; + }; +} diff --git a/pkgs/development/rocm-modules/10/half/default.nix b/pkgs/development/rocm-modules/10/half/default.nix new file mode 100644 index 0000000000000..8541b82d596fe --- /dev/null +++ b/pkgs/development/rocm-modules/10/half/default.nix @@ -0,0 +1,35 @@ +{ + lib, + stdenv, + fetchFromGitHub, + rocmUpdateScript, + cmake, + rocm-cmake, +}: + +stdenv.mkDerivation (finalAttrs: { + pname = "half"; + version = "7.2.4"; + + src = fetchFromGitHub { + owner = "ROCm"; + repo = "half"; + tag = "rocm-${finalAttrs.version}"; + hash = "sha256-If9O5BEeymsLN+C0drZsPSxEWXpJTxeDBGNHNXSumm4="; + }; + + nativeBuildInputs = [ + cmake + rocm-cmake + ]; + + passthru.updateScript = rocmUpdateScript { inherit finalAttrs; }; + + meta = { + description = "C++ library for half precision floating point arithmetics"; + homepage = "https://github.com/ROCm/half"; + license = lib.licenses.mit; + teams = [ lib.teams.rocm ]; + platforms = lib.platforms.unix; + }; +}) diff --git a/pkgs/development/rocm-modules/10/hip-common/default.nix b/pkgs/development/rocm-modules/10/hip-common/default.nix new file mode 100644 index 0000000000000..f2415ab549c33 --- /dev/null +++ b/pkgs/development/rocm-modules/10/hip-common/default.nix @@ -0,0 +1,46 @@ +{ + lib, + stdenv, + fetchFromGitHub, + rocmUpdateScript, +}: + +stdenv.mkDerivation (finalAttrs: { + pname = "hip-common"; + version = "7.2.4"; + + src = fetchFromGitHub { + owner = "ROCm"; + repo = "rocm-systems"; + tag = "rocm-${finalAttrs.version}"; + sparseCheckout = [ + "projects/hip" + "shared" + ]; + hash = "sha256-orfTXKjcZJ5E73cmXEyltZVYhCQo8FLExVHM3J/rqUM="; + }; + sourceRoot = "${finalAttrs.src.name}/projects/hip"; + + dontConfigure = true; + dontBuild = true; + + installPhase = '' + runHook preInstall + + mkdir -p $out + mv * $out + + runHook postInstall + ''; + + passthru.updateScript = rocmUpdateScript { inherit finalAttrs; }; + + meta = { + description = "C++ Heterogeneous-Compute Interface for Portability"; + homepage = "https://github.com/ROCm/rocm-systems/tree/develop/projects/hip"; + license = lib.licenses.mit; + maintainers = with lib.maintainers; [ lovesegfault ]; + teams = [ lib.teams.rocm ]; + platforms = lib.platforms.linux; + }; +}) diff --git a/pkgs/development/rocm-modules/10/hipify/default.nix b/pkgs/development/rocm-modules/10/hipify/default.nix new file mode 100644 index 0000000000000..b121f0859dce6 --- /dev/null +++ b/pkgs/development/rocm-modules/10/hipify/default.nix @@ -0,0 +1,66 @@ +{ + lib, + stdenv, + fetchFromGitHub, + rocmUpdateScript, + cmake, + llvm, + zlib, + zstd, + perl, +}: + +stdenv.mkDerivation (finalAttrs: { + pname = "hipify"; + version = "7.2.4"; + + src = fetchFromGitHub { + owner = "ROCm"; + repo = "HIPIFY"; + tag = "rocm-${finalAttrs.version}"; + hash = "sha256-LC0lnYetV7RPVw92zew6za6bDH4zmnERXUM4MVaRVtc="; + }; + + strictDeps = true; + + nativeBuildInputs = [ + cmake + perl + llvm.rocm-toolchain + ]; + + buildInputs = [ + llvm.llvm + llvm.clang-unwrapped + perl + zlib + zstd + ]; + + env.CXXFLAGS = "-I${lib.getInclude llvm.llvm}/include -I${lib.getInclude llvm.clang-unwrapped}/include"; + + postPatch = '' + substituteInPlace CMakeLists.txt \ + --replace-fail "\''${LLVM_TOOLS_BINARY_DIR}/clang" "${llvm.rocm-toolchain}/bin/clang" + chmod +x bin/* + ''; + + passthru.updateScript = rocmUpdateScript { inherit finalAttrs; }; + + postInstall = '' + rm $out/bin/hipify-perl + chmod +x $out/bin/* + chmod +x $out/libexec/* + patchShebangs $out/bin/ + patchShebangs $out/libexec/ + ln -s $out/{libexec/hipify,bin}/hipify-perl + ''; + + meta = { + description = "Convert CUDA to Portable C++ Code"; + homepage = "https://github.com/ROCm/HIPIFY"; + license = lib.licenses.mit; + teams = [ lib.teams.rocm ]; + platforms = lib.platforms.linux; + }; +}) diff --git a/pkgs/development/rocm-modules/10/rocm-cmake/default.nix b/pkgs/development/rocm-modules/10/rocm-cmake/default.nix new file mode 100644 index 0000000000000..dac12d5d0fccc --- /dev/null +++ b/pkgs/development/rocm-modules/10/rocm-cmake/default.nix @@ -0,0 +1,34 @@ +{ + lib, + stdenv, + fetchFromGitHub, + rocmUpdateScript, + rocm-core, + cmake, +}: + +stdenv.mkDerivation (finalAttrs: { + pname = "rocm-cmake"; + version = "7.2.4"; + + src = fetchFromGitHub { + owner = "ROCm"; + repo = "rocm-cmake"; + tag = "rocm-${finalAttrs.version}"; + hash = "sha256-gY6jzIIN1pSXGbCMN6y35Q/VJgbIqWDRjD8aI/fc1L0="; + }; + + nativeBuildInputs = [ cmake ]; + + buildInputs = [ rocm-core ]; + + passthru.updateScript = rocmUpdateScript { inherit finalAttrs; }; + + meta = { + description = "CMake modules for common build tasks for the ROCm stack"; + homepage = "https://github.com/ROCm/rocm-cmake"; + license = lib.licenses.mit; + teams = [ lib.teams.rocm ]; + platforms = lib.platforms.unix; + }; +}) diff --git a/pkgs/development/rocm-modules/10/rocm-comgr/default.nix b/pkgs/development/rocm-modules/10/rocm-comgr/default.nix new file mode 100644 index 0000000000000..e7663a1f7130a --- /dev/null +++ b/pkgs/development/rocm-modules/10/rocm-comgr/default.nix @@ -0,0 +1,88 @@ +{ + lib, + stdenv, + fetchpatch, + cmake, + llvm, + python3, + rocm-device-libs, + zlib, + zstd, +}: + +let + llvmNativeTarget = + if stdenv.hostPlatform.isx86_64 then + "X86" + else if stdenv.hostPlatform.isAarch64 then + "AArch64" + else + throw "Unsupported ROCm LLVM platform"; +in +stdenv.mkDerivation (finalAttrs: { + pname = "rocm-comgr"; + # In-tree with ROCm LLVM + inherit (llvm.llvm) version; + src = llvm.llvm.monorepoSrc; + sourceRoot = "${finalAttrs.src.name}/amd/comgr"; + strictDeps = true; + + patches = [ + # [Comgr] Extend ISA compatibility + (fetchpatch { + hash = "sha256-X2VPGigK582J+a/u2Kg74w25/+CTpVWU9D3Eqgnb2PU="; + url = "https://github.com/GZGavinZhao/rocm-llvm-project/commit/7002dc04863d38c57cfd2e6fc60a1cf5a613fd8e.patch"; + relative = "amd/comgr"; + }) + # [Comgr] Extend ISA compatibility for CCOB + (fetchpatch { + hash = "sha256-/50I+PqxL3oaQMqg5vR7+ibUcXO1SvfXBdw/sybRt1o="; + url = "https://github.com/GZGavinZhao/rocm-llvm-project/commit/2c1e44fc3eacadcafdd4ada3e3184a092b6f26c5.patch"; + relative = "amd/comgr"; + }) + # Fix: CCOB compat patch used coerced (featureless) name for output filename, + # causing CLR's code_obj_map key to miss when looking up device ISA with features + ./fix-ccob-compat-output-filename.patch + ]; + + postPatch = + # Fix relative path assumption for libllvm + '' + substituteInPlace cmake/opencl_header.cmake \ + --replace-fail "\''${CLANG_CMAKE_DIR}/../../../" "${llvm.clang-unwrapped.lib}" + '' + # Bake LLVM root for cfg/includes or HIPRTC can't find C++ stdlib headers (e.g. ). + + '' + substituteInPlace src/comgr-env.cpp \ + --replace-fail \ + 'return EnvLLVMPath;' \ + 'return EnvLLVMPath ? EnvLLVMPath : "${llvm.rocm-toolchain}";' + ''; + + nativeBuildInputs = [ + cmake + python3 + ]; + + buildInputs = [ + llvm.llvm + llvm.clang-unwrapped + llvm.lld + rocm-device-libs + zlib + zstd + ]; + + cmakeFlags = [ + "-DLLVM_TARGETS_TO_BUILD=AMDGPU;${llvmNativeTarget}" + ]; + + meta = { + description = "APIs for compiling and inspecting AMDGPU code objects"; + homepage = "https://github.com/ROCm/ROCm-CompilerSupport/tree/amd-stg-open/lib/comgr"; + license = lib.licenses.ncsa; + maintainers = with lib.maintainers; [ lovesegfault ]; + teams = [ lib.teams.rocm ]; + platforms = lib.platforms.linux; + }; +}) diff --git a/pkgs/development/rocm-modules/10/rocm-comgr/fix-ccob-compat-output-filename.patch b/pkgs/development/rocm-modules/10/rocm-comgr/fix-ccob-compat-output-filename.patch new file mode 100644 index 0000000000000..813f419ef3a9b --- /dev/null +++ b/pkgs/development/rocm-modules/10/rocm-comgr/fix-ccob-compat-output-filename.patch @@ -0,0 +1,11 @@ +--- a/src/comgr-compiler.cpp ++++ b/src/comgr-compiler.cpp +@@ -1425,7 +1425,7 @@ + // Add an output file for each target + SmallString<128> OutputFilePath = OutputDir; + sys::path::append(OutputFilePath, +- OutputPrefix + "-" + CompatEntry + "." + FileExtension); ++ OutputPrefix + "-" + Entry + "." + FileExtension); + + BundlerConfig.TargetNames.emplace_back(CompatEntry); + BundlerConfig.OutputFileNames.emplace_back(OutputFilePath); diff --git a/pkgs/development/rocm-modules/10/rocm-core/default.nix b/pkgs/development/rocm-modules/10/rocm-core/default.nix new file mode 100644 index 0000000000000..861c6107935ee --- /dev/null +++ b/pkgs/development/rocm-modules/10/rocm-core/default.nix @@ -0,0 +1,95 @@ +{ + lib, + stdenv, + fetchFromGitHub, + rocmUpdateScript, + cmake, + writeText, +}: + +# rocm-core is used by most distros for a few purposes: +# - meta package that all rocm packages depend so `apt-get remove rocm-core` removes all rocm packages +# - provide overall ROCM_PATH +# - provide rocm version info and path to rocm version headers +# only the last usage makes sense in nixpkgs +let + padIfSingle = s: if lib.stringLength s == 1 then "0${s}" else s; +in +stdenv.mkDerivation (finalAttrs: { + pname = "rocm-core"; + version = "7.2.4"; + + src = fetchFromGitHub { + owner = "ROCm"; + repo = "rocm-systems"; + tag = "rocm-${finalAttrs.version}"; + sparseCheckout = [ + "projects/rocm-core" + "shared" + ]; + hash = "sha256-Y3WuDwruD5zKN2epwfUCZAGq5vgxCT27awJN8JxmOsY="; + }; + sourceRoot = "${finalAttrs.src.name}/projects/rocm-core"; + + patches = [ + ./env-rocm-path.patch + ]; + + nativeBuildInputs = [ cmake ]; + env = { + ROCM_LIBPATCH_VERSION = "${lib.versions.major finalAttrs.version}${padIfSingle (lib.versions.minor finalAttrs.version)}${padIfSingle (lib.versions.patch finalAttrs.version)}"; + BUILD_ID = "nixpkgs-${finalAttrs.env.ROCM_LIBPATCH_VERSION}"; + ROCM_BUILD_ID = "${finalAttrs.env.BUILD_ID}"; + }; + cmakeFlags = [ + "-DROCM_LIBPATCH_VERSION=${finalAttrs.env.ROCM_LIBPATCH_VERSION}" + "-DROCM_VERSION=${finalAttrs.version}" + "-DBUILD_ID=${finalAttrs.env.BUILD_ID}" + "-DCMAKE_INSTALL_LIBDIR=lib" + "-DCMAKE_INSTALL_LIBEXECDIR=libexec" + "-DCMAKE_INSTALL_INCLUDEDIR=include" + "-DCMAKE_INSTALL_BINDIR=bin" + ]; + + setupHook = writeText "setupHook.sh" '' + export ROCM_VERSION="${finalAttrs.version}" + export ROCM_LIBPATCH_VERSION="${finalAttrs.env.ROCM_LIBPATCH_VERSION}" + export ROCM_BUILD_ID="${finalAttrs.env.ROCM_BUILD_ID}" + ''; + + doInstallCheck = true; + preInstallCheck = + # Test that the CMake config file can be included and sets expected vars + '' + mkdir test_project + pushd test_project + + echo ' + cmake_minimum_required(VERSION 3.16) + project(test_rocm_core) + find_package(rocm-core REQUIRED) + if(NOT DEFINED ROCM_CORE_INCLUDE_DIR) + message(FATAL_ERROR "ROCM_CORE_INCLUDE_DIR not set") + endif() + message(STATUS "Found ROCM_CORE_INCLUDE_DIR: ''${ROCM_CORE_INCLUDE_DIR}") + message(STATUS "Found ROCM_PATH: ''${ROCM_PATH}") + ' > CMakeLists.txt + + CMAKE_PREFIX_PATH="$out" cmake . + popd + + . $out/nix-support/setup-hook + env | grep '^ROCM' + ''; + + passthru.ROCM_LIBPATCH_VERSION = finalAttrs.env.ROCM_LIBPATCH_VERSION; + passthru.updateScript = rocmUpdateScript { inherit finalAttrs; }; + + meta = { + description = "Utility for getting the ROCm release version"; + homepage = "https://github.com/ROCm/rocm-systems/tree/develop/projects/rocm-core"; + license = lib.licenses.mit; + teams = [ lib.teams.rocm ]; + platforms = lib.platforms.linux; + }; +}) diff --git a/pkgs/development/rocm-modules/10/rocm-core/env-rocm-path.patch b/pkgs/development/rocm-modules/10/rocm-core/env-rocm-path.patch new file mode 100644 index 0000000000000..a40fa33b90cec --- /dev/null +++ b/pkgs/development/rocm-modules/10/rocm-core/env-rocm-path.patch @@ -0,0 +1,22 @@ +In FHS distros rocm-core expects to be installed colocated with a full set of ROCM packages. +In nixpkgs contexts, we don't want rocm-core to be a ROCM_PATH root. +diff --git a/cmake_modules/rocm-core-config.cmake.in b/cmake_modules/rocm-core-config.cmake.in +index f5fe07c..9d72c9c 100644 +--- a/cmake_modules/rocm-core-config.cmake.in ++++ b/cmake_modules/rocm-core-config.cmake.in +@@ -11,7 +11,14 @@ set_and_check(rocm_core_INCLUDE_DIR "@PACKAGE_INCLUDE_INSTALL_DIR@") + set_and_check(ROCM_CORE_INCLUDE_DIR "@PACKAGE_INCLUDE_INSTALL_DIR@") + set_and_check(rocm_core_LIB_DIR "@PACKAGE_LIB_INSTALL_DIR@") + set_and_check(ROCM_CORE_LIB_DIR "@PACKAGE_LIB_INSTALL_DIR@") +-set_and_check(ROCM_PATH "${PACKAGE_PREFIX_DIR}") ++# Set ROCM_PATH with priority: existing value > environment variable > package prefix ++if(NOT DEFINED ROCM_PATH) ++ if(DEFINED ENV{ROCM_PATH}) ++ set(ROCM_PATH "$ENV{ROCM_PATH}") ++ else() ++ set_and_check(ROCM_PATH "${PACKAGE_PREFIX_DIR}") ++ endif() ++endif() + + get_filename_component(ROCM_CORE_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH) + include("${ROCM_CORE_CMAKE_DIR}/rocmCoreTargets.cmake") diff --git a/pkgs/development/rocm-modules/10/rocm-runtime/default.nix b/pkgs/development/rocm-modules/10/rocm-runtime/default.nix new file mode 100644 index 0000000000000..255fce0eb24ec --- /dev/null +++ b/pkgs/development/rocm-modules/10/rocm-runtime/default.nix @@ -0,0 +1,109 @@ +{ + lib, + stdenv, + fetchFromGitHub, + fetchpatch, + rocmUpdateScript, + pkg-config, + cmake, + xxd, + rocm-device-libs, + rocprofiler-register, + elfutils, + libdrm, + numactl, + llvm, +}: + +stdenv.mkDerivation (finalAttrs: { + pname = "rocm-runtime"; + version = "7.2.4"; + + src = fetchFromGitHub { + owner = "ROCm"; + repo = "rocm-systems"; + tag = "rocm-${finalAttrs.version}"; + sparseCheckout = [ + "projects/rocr-runtime" + "shared" + ]; + hash = "sha256-hcyjOLMtoBX/p6r6R9Bl9635DuvI6rTn1KziHMeyYM0="; + }; + sourceRoot = "${finalAttrs.src.name}/projects/rocr-runtime"; + + cmakeBuildType = "RelWithDebInfo"; + separateDebugInfo = true; + __structuredAttrs = true; + strictDeps = true; + + nativeBuildInputs = [ + pkg-config + cmake + xxd # used by create_hsaco_ascii_file.sh + llvm.rocm-toolchain + ]; + + buildInputs = [ + llvm.clang-unwrapped + llvm.llvm + elfutils + libdrm + numactl + rocprofiler-register + ]; + + cmakeFlags = [ + "-DBUILD_SHARED_LIBS=ON" + "-DCMAKE_INSTALL_BINDIR=bin" + "-DCMAKE_INSTALL_LIBDIR=lib" + "-DCMAKE_INSTALL_INCLUDEDIR=include" + ]; + + patches = [ + # Vendored upstream PR for fix for segfault when queue allocation fails + # https://github.com/ROCm/rocm-systems/pull/2850 + ./queue-failure.patch + (fetchpatch { + # [PATCH] rocr: Extend HIP ISA compatibility check + hash = "sha256-8r2Lb5lBfFaZC3knCxfXGcnkzNv6JxOKyJn2rD5gus4="; + url = "https://github.com/GZGavinZhao/rocm-systems/commit/dcef23cf896f4dcbc7ed81abeaa4ec2208dcdd8c.patch"; + relative = "projects/rocr-runtime"; + }) + (fetchpatch { + # [PATCH] kfd_ioctl: fix UB due to 1 << 31 + url = "https://github.com/ROCm/ROCR-Runtime/commit/41bfc66aef437a5b349f71105fa4b907cc7e17d5.patch"; + hash = "sha256-A7VhPR3eSsmjq2cTBSjBIz9i//WiNjoXm0EsRKtF+ns="; + }) + # This causes a circular dependency, aqlprofile relies on hsa-runtime64 + # which is part of rocm-runtime + # Worked around by having rocprofiler load aqlprofile directly + ./remove-hsa-aqlprofile-dep.patch + ]; + + postPatch = '' + patchShebangs --build \ + runtime/hsa-runtime/core/runtime/trap_handler/create_trap_handler_header.sh \ + runtime/hsa-runtime/core/runtime/blit_shaders/create_blit_shader_header.sh \ + runtime/hsa-runtime/image/blit_src/create_hsaco_ascii_file.sh + patchShebangs --host image core runtime + + substituteInPlace CMakeLists.txt \ + --replace 'hsa/include/hsa' 'include/hsa' + + substituteInPlace runtime/hsa-runtime/image/blit_src/CMakeLists.txt \ + --replace-fail 'COMMAND clang' "COMMAND ${llvm.rocm-toolchain}/bin/clang" + + export HIP_DEVICE_LIB_PATH="${rocm-device-libs}/amdgcn/bitcode" + ''; + + passthru.updateScript = rocmUpdateScript { inherit finalAttrs; }; + + meta = { + description = "Platform runtime for ROCm"; + homepage = "https://github.com/ROCm/rocm-systems/tree/develop/projects/rocr-runtime"; + license = lib.licenses.ncsa; + maintainers = with lib.maintainers; [ lovesegfault ]; + teams = [ lib.teams.rocm ]; + platforms = lib.platforms.linux; + }; +}) diff --git a/pkgs/development/rocm-modules/10/rocm-runtime/queue-failure.patch b/pkgs/development/rocm-modules/10/rocm-runtime/queue-failure.patch new file mode 100644 index 0000000000000..f9087144bc229 --- /dev/null +++ b/pkgs/development/rocm-modules/10/rocm-runtime/queue-failure.patch @@ -0,0 +1,71 @@ +From b7717446c85d08b2d7c0c60ba3ac0eff11ee6120 Mon Sep 17 00:00:00 2001 +From: Luna Nova +Date: Tue, 20 Jan 2026 12:55:45 -0800 +Subject: [PATCH 1/2] rocm-runtime: fix crash in QueueCreate due to trying to + free non allocated scratch + +if (scratch.main_queue_base != nullptr) before calling ReleaseQueueMainScratch +because ReleaseQueueMainScratch is only valid if main_queue_base is set +and the scope guard can fire for an error allocating the queue. +--- + .../runtime/hsa-runtime/core/runtime/amd_gpu_agent.cpp | 4 +++- + 1 file changed, 3 insertions(+), 1 deletion(-) + +diff --git a/runtime/hsa-runtime/core/runtime/amd_gpu_agent.cpp b/runtime/hsa-runtime/core/runtime/amd_gpu_agent.cpp +index 01b01fe869..83db40dacc 100644 +--- a/runtime/hsa-runtime/core/runtime/amd_gpu_agent.cpp ++++ b/runtime/hsa-runtime/core/runtime/amd_gpu_agent.cpp +@@ -1792,7 +1792,9 @@ hsa_status_t GpuAgent::QueueCreate(size_t size, hsa_queue_type32_t queue_type, u + scratch.main_queue_base = nullptr; + scratch.main_queue_process_offset = 0; + +- MAKE_NAMED_SCOPE_GUARD(scratchGuard, [&]() { ReleaseQueueMainScratch(scratch); }); ++ MAKE_NAMED_SCOPE_GUARD(scratchGuard, [&]() { ++ if (scratch.main_queue_base != nullptr) ReleaseQueueMainScratch(scratch); ++ }); + + if (scratch.main_size != 0) { + AcquireQueueMainScratch(scratch); +-- +2.52.0 + + +From 9c1746cd76a703e4d2321dc2ffe85fc61bfd2f21 Mon Sep 17 00:00:00 2001 +From: Luna Nova +Date: Tue, 20 Jan 2026 13:00:32 -0800 +Subject: [PATCH 2/2] rocm-runtime: log for errors in QueueCreate + +--- + .../runtime/hsa-runtime/core/runtime/amd_gpu_agent.cpp | 9 ++++++++- + 1 file changed, 8 insertions(+), 1 deletion(-) + +diff --git a/runtime/hsa-runtime/core/runtime/amd_gpu_agent.cpp b/runtime/hsa-runtime/core/runtime/amd_gpu_agent.cpp +index 83db40dacc..ae68732eb5 100644 +--- a/runtime/hsa-runtime/core/runtime/amd_gpu_agent.cpp ++++ b/runtime/hsa-runtime/core/runtime/amd_gpu_agent.cpp +@@ -1799,6 +1799,9 @@ hsa_status_t GpuAgent::QueueCreate(size_t size, hsa_queue_type32_t queue_type, u + if (scratch.main_size != 0) { + AcquireQueueMainScratch(scratch); + if (scratch.main_queue_base == nullptr) { ++ LogPrint(HSA_AMD_LOG_FLAG_INFO, ++ "Failed to allocate scratch memory for queue, size=%zu, node=%u", ++ scratch.main_size, node_id()); + return HSA_STATUS_ERROR_OUT_OF_RESOURCES; + } + } +@@ -1827,7 +1830,11 @@ hsa_status_t GpuAgent::QueueCreate(size_t size, hsa_queue_type32_t queue_type, u + node_id())); + } + +- if (!shared_queue) return HSA_STATUS_ERROR_OUT_OF_RESOURCES; ++ if (!shared_queue) { ++ LogPrint(HSA_AMD_LOG_FLAG_INFO, ++ "Failed to allocate shared queue descriptor memory, node=%u", node_id()); ++ return HSA_STATUS_ERROR_OUT_OF_RESOURCES; ++ } + + auto aql_queue = new AqlQueue(shared_queue, this, size, node_id(), scratch, event_callback, data, + flags); +-- +2.52.0 + diff --git a/pkgs/development/rocm-modules/10/rocm-runtime/remove-hsa-aqlprofile-dep.patch b/pkgs/development/rocm-modules/10/rocm-runtime/remove-hsa-aqlprofile-dep.patch new file mode 100644 index 0000000000000..b8ed57d049bc9 --- /dev/null +++ b/pkgs/development/rocm-modules/10/rocm-runtime/remove-hsa-aqlprofile-dep.patch @@ -0,0 +1,27 @@ +libhsa-amd-aqlprofile64 library is unfree +Bug: https://github.com/ROCm/ROCm/issues/1781 +--- a/runtime/hsa-runtime/core/runtime/amd_gpu_agent.cpp ++++ b/runtime/hsa-runtime/core/runtime/amd_gpu_agent.cpp +@@ -1333,11 +1333,6 @@ hsa_status_t GpuAgent::GetInfo(hsa_agent_info_t attribute, void* value) const { + setFlag(HSA_EXTENSION_AMD_PC_SAMPLING); + } + +- if (os::LibHandle lib = os::LoadLib(kAqlProfileLib)) { +- os::CloseLib(lib); +- setFlag(HSA_EXTENSION_AMD_AQLPROFILE); +- } +- + setFlag(HSA_EXTENSION_AMD_PROFILER); + + break; +--- a/runtime/hsa-runtime/core/runtime/hsa.cpp ++++ b/runtime/hsa-runtime/core/runtime/hsa.cpp +@@ -490,7 +490,7 @@ hsa_status_t hsa_system_get_major_extension_table(uint16_t extension, uint16_t v + return HSA_STATUS_SUCCESS; + } + +- if (extension == HSA_EXTENSION_AMD_AQLPROFILE) { ++ if (0) { + if (version_major != hsa_ven_amd_aqlprofile_VERSION_MAJOR) { + debug_print("aqlprofile API incompatible ver %d, current ver %d\n", + version_major, hsa_ven_amd_aqlprofile_VERSION_MAJOR); diff --git a/pkgs/development/rocm-modules/10/rocm-smi/default.nix b/pkgs/development/rocm-modules/10/rocm-smi/default.nix new file mode 100644 index 0000000000000..ad53094199161 --- /dev/null +++ b/pkgs/development/rocm-modules/10/rocm-smi/default.nix @@ -0,0 +1,78 @@ +{ + lib, + stdenv, + fetchFromGitHub, + rocmUpdateScript, + pkg-config, + libdrm, + cmake, + wrapPython, +}: + +stdenv.mkDerivation (finalAttrs: { + pname = "rocm-smi"; + version = "7.2.4"; + + src = fetchFromGitHub { + owner = "ROCm"; + repo = "rocm-systems"; + tag = "rocm-${finalAttrs.version}"; + sparseCheckout = [ + "projects/rocm-smi-lib" + "shared" + ]; + hash = "sha256-Si8SbeVKUBtqk6h2QJ9ssQV68bLq6TvESrYXJuArHd8="; + }; + sourceRoot = "${finalAttrs.src.name}/projects/rocm-smi-lib"; + + __structuredAttrs = true; + strictDeps = true; + + propagatedBuildInputs = [ + libdrm + ]; + + nativeBuildInputs = [ + cmake + wrapPython + pkg-config + ]; + + cmakeFlags = [ + # Manually define CMAKE_INSTALL_ + # See: https://github.com/NixOS/nixpkgs/pull/197838 + (lib.cmakeFeature "CMAKE_INSTALL_BINDIR" "bin") + (lib.cmakeFeature "CMAKE_INSTALL_LIBDIR" "lib") + (lib.cmakeFeature "CMAKE_INSTALL_LIBEXECDIR" "libexec") + (lib.cmakeFeature "CMAKE_INSTALL_INCLUDEDIR" "include") + ]; + + postInstall = + # wrap python programs, but undo two that need to be importable at that path + '' + wrapPythonProgramsIn $out + mv $out/libexec/rocm_smi/.rsmiBindingsInit.py-wrapped $out/libexec/rocm_smi/rsmiBindingsInit.py + mv $out/libexec/rocm_smi/.rsmiBindings.py-wrapped $out/libexec/rocm_smi/rsmiBindings.py + '' + # workaround: propagate libdrm/ manually + # rocm-toolchain doesn't automatically add buildInputs to isystem include path like + # wrapper based toolchains, cmake files often don't find_package(rocm-smi) so + # can't rely on cmake propagated interface + # upstream have been shipping libdrm copied into /opt/rocm + + '' + ln -s ${libdrm.dev}/include/libdrm/ $out/include/ + ''; + + passthru.updateScript = rocmUpdateScript { inherit finalAttrs; }; + + meta = { + description = "System management interface for AMD GPUs supported by ROCm"; + homepage = "https://github.com/ROCm/rocm-systems/tree/develop/projects/rocm-smi-lib"; + changelog = "https://github.com/ROCm/rocm-systems/releases/tag/${finalAttrs.src.tag}"; + license = lib.licenses.mit; + mainProgram = "rocm-smi"; + maintainers = with lib.maintainers; [ lovesegfault ]; + teams = [ lib.teams.rocm ]; + platforms = [ "x86_64-linux" ]; + }; +}) diff --git a/pkgs/development/rocm-modules/10/rocminfo/default.nix b/pkgs/development/rocm-modules/10/rocminfo/default.nix new file mode 100644 index 0000000000000..1cfbe4ddc9b7e --- /dev/null +++ b/pkgs/development/rocm-modules/10/rocminfo/default.nix @@ -0,0 +1,57 @@ +{ + lib, + stdenv, + fetchFromGitHub, + rocmUpdateScript, + cmake, + rocm-cmake, + rocm-runtime, + busybox, + python3, + gnugrep, +}: + +stdenv.mkDerivation (finalAttrs: { + version = "7.2.4"; + pname = "rocminfo"; + + src = fetchFromGitHub { + owner = "ROCm"; + repo = "rocm-systems"; + tag = "rocm-${finalAttrs.version}"; + sparseCheckout = [ + "projects/rocminfo" + "shared" + ]; + hash = "sha256-0esRBEXVibC2uzyonpc0ABNNHQ2NAWZrBmmg6p1zP0c="; + }; + sourceRoot = "${finalAttrs.src.name}/projects/rocminfo"; + + strictDeps = true; + + nativeBuildInputs = [ + cmake + rocm-cmake + python3 + ]; + + buildInputs = [ rocm-runtime ]; + cmakeFlags = [ "-DROCRTST_BLD_TYPE=Release" ]; + + prePatch = '' + patchShebangs rocm_agent_enumerator + sed 's,lsmod | grep ,${busybox}/bin/lsmod | ${gnugrep}/bin/grep ,' -i rocminfo.cc + ''; + + passthru.updateScript = rocmUpdateScript { inherit finalAttrs; }; + + meta = { + description = "ROCm Application for Reporting System Info"; + homepage = "https://github.com/ROCm/rocm-systems/tree/develop/projects/rocminfo"; + license = lib.licenses.ncsa; + mainProgram = "rocminfo"; + maintainers = with lib.maintainers; [ lovesegfault ]; + teams = [ lib.teams.rocm ]; + platforms = lib.platforms.linux; + }; +}) diff --git a/pkgs/development/rocm-modules/10/rocprofiler-register/default.nix b/pkgs/development/rocm-modules/10/rocprofiler-register/default.nix new file mode 100644 index 0000000000000..710985790d708 --- /dev/null +++ b/pkgs/development/rocm-modules/10/rocprofiler-register/default.nix @@ -0,0 +1,97 @@ +{ + lib, + stdenv, + numactl, + libpciaccess, + libxml2, + elfutils, + glog, + fmt, + fetchFromGitHub, + rocmUpdateScript, + cmake, + clang, + python3Packages, + fetchpatch, +}: + +stdenv.mkDerivation (finalAttrs: { + pname = "rocprofiler-register"; + version = "7.2.4"; + + src = fetchFromGitHub { + owner = "ROCm"; + repo = "rocm-systems"; + tag = "rocm-${finalAttrs.version}"; + sparseCheckout = [ + "projects/rocprofiler-register" + "shared" + ]; + hash = "sha256-XhxED3LHIjxBcSVyyEC3pgg0fyKyfKtHkF7umExSboM="; + }; + sourceRoot = "${finalAttrs.src.name}/projects/rocprofiler-register"; + + patches = [ + (fetchpatch { + # [rocprofiler-sdk][rocprofiler-register] add CPackComponent + url = "https://github.com/ROCm/rocm-systems/commit/ef7253365c420ca486f074b9e9119a222e30fea0.patch"; + hash = "sha256-dwqvZ4AaTcOk2mSnxgHp/NbhjlD8W6KVz1H5ZF4i/Tw="; + relative = "projects/rocprofiler-register"; + }) + (fetchpatch { + # [rocprofiler-register] Fix compilation with system fmt/glog + url = "https://github.com/ROCm/rocm-systems/commit/c8ad2522083c6e00539ce5c1c22df766c20084fb.patch"; + hash = "sha256-VloRKV6kUzIfIInltx/bV1EM0FUfeQZrVAx6qgdsLyg="; + relative = "projects/rocprofiler-register"; + }) + (fetchpatch { + # fix(rocprofiler-sdk): include fmt/format.h instead of fmt/core.h for fmt::format + # fmt 12.2.0 changes the meaning of fmt/core.h so it no longer includes + # fmt::format, so this upstream commit switches to the correct header. + url = "https://github.com/ROCm/rocm-systems/commit/e2f588592ecfb0653ed5b3078753186325adf70a.patch"; + hash = "sha256-ip/s7tmUptcXMen3fyQJYKiZKwoe3SH0XqTVb0YBA7k="; + relative = "projects/rocprofiler-register"; + }) + ]; + + nativeBuildInputs = [ + cmake + clang + ]; + + buildInputs = [ + numactl + libpciaccess + libxml2 + elfutils + glog + fmt + + python3Packages.lxml + python3Packages.cppheaderparser + python3Packages.pyyaml + python3Packages.barectf + python3Packages.pandas + ]; + cmakeFlags = [ + "-DROCPROFILER_REGISTER_BUILD_TESTS=0" + "-DROCPROFILER_REGISTER_BUILD_SAMPLES=0" + "-DROCPROFILER_REGISTER_BUILD_GLOG=OFF" + "-DROCPROFILER_REGISTER_BUILD_FMT=OFF" + # Manually define CMAKE_INSTALL_ + # See: https://github.com/NixOS/nixpkgs/pull/197838 + "-DCMAKE_INSTALL_BINDIR=bin" + "-DCMAKE_INSTALL_LIBDIR=lib" + "-DCMAKE_INSTALL_INCLUDEDIR=include" + ]; + + passthru.updateScript = rocmUpdateScript { inherit finalAttrs; }; + + meta = { + description = "Profiling with perf-counters and derived metrics"; + homepage = "https://github.com/ROCm/rocm-systems/tree/develop/projects/rocprofiler-register"; + license = lib.licenses.mit; # mitx11 + teams = [ lib.teams.rocm ]; + platforms = lib.platforms.linux; + }; +}) diff --git a/pkgs/development/rocm-modules/10/roctracer/default.nix b/pkgs/development/rocm-modules/10/roctracer/default.nix new file mode 100644 index 0000000000000..6cc979eb3648e --- /dev/null +++ b/pkgs/development/rocm-modules/10/roctracer/default.nix @@ -0,0 +1,118 @@ +{ + lib, + stdenv, + fetchFromGitHub, + rocmUpdateScript, + cmake, + clr, + rocm-device-libs, + libxml2, + doxygen, + graphviz, + gcc-unwrapped, + libbacktrace, + rocm-runtime, + python3Packages, + buildDocs ? false, # Nothing seems to be generated, so not making the output + buildTests ? false, +}: + +stdenv.mkDerivation (finalAttrs: { + pname = "roctracer"; + version = "7.2.4"; + + outputs = [ + "out" + ] + ++ lib.optionals buildDocs [ + "doc" + ] + ++ lib.optionals buildTests [ + "test" + ]; + + src = fetchFromGitHub { + owner = "ROCm"; + repo = "rocm-systems"; + tag = "rocm-${finalAttrs.version}"; + sparseCheckout = [ + "projects/roctracer" + "shared" + ]; + hash = "sha256-Ps9b/MMdxXthGV96ZDg0kZGPdmn7Sy5if1a/Fjx2fEE="; + }; + sourceRoot = "${finalAttrs.src.name}/projects/roctracer"; + + nativeBuildInputs = [ + cmake + clr + ] + ++ lib.optionals buildDocs [ + doxygen + graphviz + ]; + + buildInputs = [ + libxml2 + libbacktrace + python3Packages.python + python3Packages.cppheaderparser + ]; + + cmakeFlags = [ + "-DCMAKE_MODULE_PATH=${clr}/hip/cmake" + # Manually define CMAKE_INSTALL_ + # See: https://github.com/NixOS/nixpkgs/pull/197838 + "-DCMAKE_INSTALL_BINDIR=bin" + "-DCMAKE_INSTALL_LIBDIR=lib" + "-DCMAKE_INSTALL_INCLUDEDIR=include" + ]; + + env.NIX_CFLAGS_COMPILE = toString [ + # Needed with GCC 12 + "-Wno-error=array-bounds" + ]; + + postPatch = '' + export HIP_DEVICE_LIB_PATH=${rocm-device-libs}/amdgcn/bitcode + '' + + lib.optionalString (!buildTests) '' + substituteInPlace CMakeLists.txt \ + --replace "add_subdirectory(test)" "" + ''; + + # Tests always fail, probably need GPU + # doCheck = buildTests; + + postInstall = + lib.optionalString buildDocs '' + mkdir -p $doc + '' + + lib.optionalString buildTests '' + mkdir -p $test/bin + # Not sure why this is an install target + find $out/test -executable -type f -exec mv {} $test/bin \; + rm $test/bin/{*.sh,*.py} + patchelf --set-rpath $out/lib:${ + lib.makeLibraryPath ( + finalAttrs.buildInputs + ++ [ + clr + gcc-unwrapped.lib + rocm-runtime + ] + ) + } $test/bin/* + rm -rf $out/test + ''; + + passthru.updateScript = rocmUpdateScript { inherit finalAttrs; }; + + meta = { + description = "Tracer callback/activity library"; + homepage = "https://github.com/ROCm/rocm-systems/tree/develop/projects/roctracer"; + license = lib.licenses.mit; # mitx11 + teams = [ lib.teams.rocm ]; + platforms = lib.platforms.linux; + }; +}) From 33512497088ff39fd3b29c4b30758fe0859d9ed5 Mon Sep 17 00:00:00 2001 From: randomizedcoder Date: Thu, 22 Oct 2026 07:18:41 -0700 Subject: [PATCH 08/21] rocmPackages_10: share hipcc, rocm-docs-core with rocmPackages hipcc, rocm-docs-core are unchanged between ROCm 7.2.4 and 10.1 (no 10.x upstream release, or versioned independently of ROCm), so the rocmPackages_10 scope calls the existing expression instead of copying it. Assisted-by: Claude Code (claude-opus-5-5) --- pkgs/development/rocm-modules/10/default.nix | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pkgs/development/rocm-modules/10/default.nix b/pkgs/development/rocm-modules/10/default.nix index 07d5e6bca5694..22be4a41f52ed 100644 --- a/pkgs/development/rocm-modules/10/default.nix +++ b/pkgs/development/rocm-modules/10/default.nix @@ -2,6 +2,7 @@ lib, callPackage, newScope, + python3Packages, stdenv, }: @@ -10,6 +11,7 @@ let self: let inherit (self) llvm; + origStdenv = stdenv; rocmClangStdenv = llvm.rocmClangStdenv; in { @@ -36,6 +38,10 @@ let inherit (self.llvm) rocm-toolchain clang openmp; rocm-device-libs = self.callPackage ./rocm-device-libs { }; + + rocm-docs-core = python3Packages.callPackage ../rocm-docs-core { }; + + hipcc = self.callPackage ../hipcc { stdenv = origStdenv; }; } ); in From 05c1a15114af3e0c05d96eef7f6babff5038cec0 Mon Sep 17 00:00:00 2001 From: randomizedcoder Date: Thu, 22 Oct 2026 07:18:42 -0700 Subject: [PATCH 09/21] rocmPackages_10.rocm-core: init at 10.1 Update the rocmPackages.rocm-core copy from the previous commit to ROCm 10.1 and add it to the rocmPackages_10 scope. Revised during the split review: Report the padded version (10.1.0) in the setup hook as well, the three-part form 7.2.4 exported; ROCM_VERSION is only read from the environment as a CPack fallback in comgr and hipcc. Keep the version helper in the outer let. Assisted-by: Claude Code (claude-opus-5-5) --- pkgs/development/rocm-modules/10/default.nix | 2 ++ .../rocm-modules/10/rocm-core/default.nix | 14 ++++++++------ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/pkgs/development/rocm-modules/10/default.nix b/pkgs/development/rocm-modules/10/default.nix index 22be4a41f52ed..03cf5ad7aa6dc 100644 --- a/pkgs/development/rocm-modules/10/default.nix +++ b/pkgs/development/rocm-modules/10/default.nix @@ -37,6 +37,8 @@ let ); inherit (self.llvm) rocm-toolchain clang openmp; + rocm-core = self.callPackage ./rocm-core { stdenv = origStdenv; }; + rocm-device-libs = self.callPackage ./rocm-device-libs { }; rocm-docs-core = python3Packages.callPackage ../rocm-docs-core { }; diff --git a/pkgs/development/rocm-modules/10/rocm-core/default.nix b/pkgs/development/rocm-modules/10/rocm-core/default.nix index 861c6107935ee..d28c0668477bf 100644 --- a/pkgs/development/rocm-modules/10/rocm-core/default.nix +++ b/pkgs/development/rocm-modules/10/rocm-core/default.nix @@ -14,20 +14,22 @@ # only the last usage makes sense in nixpkgs let padIfSingle = s: if lib.stringLength s == 1 then "0${s}" else s; + # TheRock tags are two-component (therock-10.1); ROCm reports X.Y.Z. + rocmVersion = version: lib.versions.pad 3 version; in stdenv.mkDerivation (finalAttrs: { pname = "rocm-core"; - version = "7.2.4"; + version = "10.1"; src = fetchFromGitHub { owner = "ROCm"; repo = "rocm-systems"; - tag = "rocm-${finalAttrs.version}"; + tag = "therock-${finalAttrs.version}"; sparseCheckout = [ "projects/rocm-core" "shared" ]; - hash = "sha256-Y3WuDwruD5zKN2epwfUCZAGq5vgxCT27awJN8JxmOsY="; + hash = "sha256-3bEmFF4jivCslDINOTA5nIu1/nreGWZuIMYMxaUgd18="; }; sourceRoot = "${finalAttrs.src.name}/projects/rocm-core"; @@ -37,13 +39,13 @@ stdenv.mkDerivation (finalAttrs: { nativeBuildInputs = [ cmake ]; env = { - ROCM_LIBPATCH_VERSION = "${lib.versions.major finalAttrs.version}${padIfSingle (lib.versions.minor finalAttrs.version)}${padIfSingle (lib.versions.patch finalAttrs.version)}"; + ROCM_LIBPATCH_VERSION = "${lib.versions.major (rocmVersion finalAttrs.version)}${padIfSingle (lib.versions.minor (rocmVersion finalAttrs.version))}${padIfSingle (lib.versions.patch (rocmVersion finalAttrs.version))}"; BUILD_ID = "nixpkgs-${finalAttrs.env.ROCM_LIBPATCH_VERSION}"; ROCM_BUILD_ID = "${finalAttrs.env.BUILD_ID}"; }; cmakeFlags = [ "-DROCM_LIBPATCH_VERSION=${finalAttrs.env.ROCM_LIBPATCH_VERSION}" - "-DROCM_VERSION=${finalAttrs.version}" + "-DROCM_VERSION=${rocmVersion finalAttrs.version}" "-DBUILD_ID=${finalAttrs.env.BUILD_ID}" "-DCMAKE_INSTALL_LIBDIR=lib" "-DCMAKE_INSTALL_LIBEXECDIR=libexec" @@ -52,7 +54,7 @@ stdenv.mkDerivation (finalAttrs: { ]; setupHook = writeText "setupHook.sh" '' - export ROCM_VERSION="${finalAttrs.version}" + export ROCM_VERSION="${rocmVersion finalAttrs.version}" export ROCM_LIBPATCH_VERSION="${finalAttrs.env.ROCM_LIBPATCH_VERSION}" export ROCM_BUILD_ID="${finalAttrs.env.ROCM_BUILD_ID}" ''; From 6019ee572f047cd827fc469970f74faa3afa1d96 Mon Sep 17 00:00:00 2001 From: randomizedcoder Date: Thu, 22 Oct 2026 07:18:43 -0700 Subject: [PATCH 10/21] rocmPackages_10.rocm-cmake: init at 10.1 Update the rocmPackages.rocm-cmake copy from the previous commit to ROCm 10.1 and add it to the rocmPackages_10 scope. Source/version bump only. Assisted-by: Claude Code (claude-opus-5-5) --- pkgs/development/rocm-modules/10/default.nix | 2 ++ pkgs/development/rocm-modules/10/rocm-cmake/default.nix | 6 +++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/pkgs/development/rocm-modules/10/default.nix b/pkgs/development/rocm-modules/10/default.nix index 03cf5ad7aa6dc..0b51f8101a9f9 100644 --- a/pkgs/development/rocm-modules/10/default.nix +++ b/pkgs/development/rocm-modules/10/default.nix @@ -39,6 +39,8 @@ let rocm-core = self.callPackage ./rocm-core { stdenv = origStdenv; }; + rocm-cmake = self.callPackage ./rocm-cmake { stdenv = origStdenv; }; + rocm-device-libs = self.callPackage ./rocm-device-libs { }; rocm-docs-core = python3Packages.callPackage ../rocm-docs-core { }; diff --git a/pkgs/development/rocm-modules/10/rocm-cmake/default.nix b/pkgs/development/rocm-modules/10/rocm-cmake/default.nix index dac12d5d0fccc..1c0a5e4e7a220 100644 --- a/pkgs/development/rocm-modules/10/rocm-cmake/default.nix +++ b/pkgs/development/rocm-modules/10/rocm-cmake/default.nix @@ -9,13 +9,13 @@ stdenv.mkDerivation (finalAttrs: { pname = "rocm-cmake"; - version = "7.2.4"; + version = "10.1"; src = fetchFromGitHub { owner = "ROCm"; repo = "rocm-cmake"; - tag = "rocm-${finalAttrs.version}"; - hash = "sha256-gY6jzIIN1pSXGbCMN6y35Q/VJgbIqWDRjD8aI/fc1L0="; + tag = "therock-${finalAttrs.version}"; + hash = "sha256-im6UO0crO0Jc27zkTsdvJYPHit8IGlw/vDPGrmP1XqY="; }; nativeBuildInputs = [ cmake ]; From b6a21406da3dbaef515d1b1d16c3ecee2c95b82f Mon Sep 17 00:00:00 2001 From: randomizedcoder Date: Thu, 22 Oct 2026 07:18:43 -0700 Subject: [PATCH 11/21] rocmPackages_10.rocprofiler-register: init at 10.1 Update the rocmPackages.rocprofiler-register copy from the previous commit to ROCm 10.1 and add it to the rocmPackages_10 scope. From the mass bump: - rocprofiler-register: drop 3 fetchpatches now upstream. Assisted-by: Claude Code (claude-opus-5-5) --- pkgs/development/rocm-modules/10/default.nix | 3 ++ .../10/rocprofiler-register/default.nix | 29 ++----------------- 2 files changed, 6 insertions(+), 26 deletions(-) diff --git a/pkgs/development/rocm-modules/10/default.nix b/pkgs/development/rocm-modules/10/default.nix index 0b51f8101a9f9..037a55b1cb309 100644 --- a/pkgs/development/rocm-modules/10/default.nix +++ b/pkgs/development/rocm-modules/10/default.nix @@ -46,6 +46,9 @@ let rocm-docs-core = python3Packages.callPackage ../rocm-docs-core { }; hipcc = self.callPackage ../hipcc { stdenv = origStdenv; }; + rocprofiler-register = self.callPackage ./rocprofiler-register { + inherit (llvm) clang; + }; } ); in diff --git a/pkgs/development/rocm-modules/10/rocprofiler-register/default.nix b/pkgs/development/rocm-modules/10/rocprofiler-register/default.nix index 710985790d708..7effd89bd26fd 100644 --- a/pkgs/development/rocm-modules/10/rocprofiler-register/default.nix +++ b/pkgs/development/rocm-modules/10/rocprofiler-register/default.nix @@ -17,43 +17,20 @@ stdenv.mkDerivation (finalAttrs: { pname = "rocprofiler-register"; - version = "7.2.4"; + version = "10.1"; src = fetchFromGitHub { owner = "ROCm"; repo = "rocm-systems"; - tag = "rocm-${finalAttrs.version}"; + tag = "therock-${finalAttrs.version}"; sparseCheckout = [ "projects/rocprofiler-register" "shared" ]; - hash = "sha256-XhxED3LHIjxBcSVyyEC3pgg0fyKyfKtHkF7umExSboM="; + hash = "sha256-/y+ZerbaSKyHfEttomNtmF5zccnpqsQFNw/5gjGBuyA="; }; sourceRoot = "${finalAttrs.src.name}/projects/rocprofiler-register"; - patches = [ - (fetchpatch { - # [rocprofiler-sdk][rocprofiler-register] add CPackComponent - url = "https://github.com/ROCm/rocm-systems/commit/ef7253365c420ca486f074b9e9119a222e30fea0.patch"; - hash = "sha256-dwqvZ4AaTcOk2mSnxgHp/NbhjlD8W6KVz1H5ZF4i/Tw="; - relative = "projects/rocprofiler-register"; - }) - (fetchpatch { - # [rocprofiler-register] Fix compilation with system fmt/glog - url = "https://github.com/ROCm/rocm-systems/commit/c8ad2522083c6e00539ce5c1c22df766c20084fb.patch"; - hash = "sha256-VloRKV6kUzIfIInltx/bV1EM0FUfeQZrVAx6qgdsLyg="; - relative = "projects/rocprofiler-register"; - }) - (fetchpatch { - # fix(rocprofiler-sdk): include fmt/format.h instead of fmt/core.h for fmt::format - # fmt 12.2.0 changes the meaning of fmt/core.h so it no longer includes - # fmt::format, so this upstream commit switches to the correct header. - url = "https://github.com/ROCm/rocm-systems/commit/e2f588592ecfb0653ed5b3078753186325adf70a.patch"; - hash = "sha256-ip/s7tmUptcXMen3fyQJYKiZKwoe3SH0XqTVb0YBA7k="; - relative = "projects/rocprofiler-register"; - }) - ]; - nativeBuildInputs = [ cmake clang From 05b4e342ae88e138e097d5c26044f8cf66b14adf Mon Sep 17 00:00:00 2001 From: randomizedcoder Date: Thu, 22 Oct 2026 07:18:44 -0700 Subject: [PATCH 12/21] rocmPackages_10.rocm-runtime: init at 10.1 Update the rocmPackages.rocm-runtime copy from the previous commit to ROCm 10.1 and add it to the rocmPackages_10 scope. From "rocmPackages.rocm-runtime: drop patches upstreamed in ROCr 1.21": ROCm 10 ships ROCr 1.21, which carries the queue-failure fix (PR #2850), the kfd_ioctl 1<<31 UB fix, and refactors aqlprofile to a runtime dlopen (removing the build-time circular dependency). Drop the three now-obsolete patches and add python3 for the new trap_handler find_package(Python3). Assisted-by: Claude Code (claude-opus-5-5) --- pkgs/development/rocm-modules/10/default.nix | 4 ++ .../rocm-modules/10/rocm-runtime/default.nix | 20 ++---- .../10/rocm-runtime/queue-failure.patch | 71 ------------------- .../remove-hsa-aqlprofile-dep.patch | 27 ------- 4 files changed, 9 insertions(+), 113 deletions(-) delete mode 100644 pkgs/development/rocm-modules/10/rocm-runtime/queue-failure.patch delete mode 100644 pkgs/development/rocm-modules/10/rocm-runtime/remove-hsa-aqlprofile-dep.patch diff --git a/pkgs/development/rocm-modules/10/default.nix b/pkgs/development/rocm-modules/10/default.nix index 037a55b1cb309..a4b612431bb56 100644 --- a/pkgs/development/rocm-modules/10/default.nix +++ b/pkgs/development/rocm-modules/10/default.nix @@ -43,6 +43,10 @@ let rocm-device-libs = self.callPackage ./rocm-device-libs { }; + rocm-runtime = self.callPackage ./rocm-runtime { + stdenv = origStdenv; + }; + rocm-docs-core = python3Packages.callPackage ../rocm-docs-core { }; hipcc = self.callPackage ../hipcc { stdenv = origStdenv; }; diff --git a/pkgs/development/rocm-modules/10/rocm-runtime/default.nix b/pkgs/development/rocm-modules/10/rocm-runtime/default.nix index 255fce0eb24ec..4bcecc40cd034 100644 --- a/pkgs/development/rocm-modules/10/rocm-runtime/default.nix +++ b/pkgs/development/rocm-modules/10/rocm-runtime/default.nix @@ -6,6 +6,7 @@ rocmUpdateScript, pkg-config, cmake, + python3, xxd, rocm-device-libs, rocprofiler-register, @@ -17,17 +18,17 @@ stdenv.mkDerivation (finalAttrs: { pname = "rocm-runtime"; - version = "7.2.4"; + version = "10.1"; src = fetchFromGitHub { owner = "ROCm"; repo = "rocm-systems"; - tag = "rocm-${finalAttrs.version}"; + tag = "therock-${finalAttrs.version}"; sparseCheckout = [ "projects/rocr-runtime" "shared" ]; - hash = "sha256-hcyjOLMtoBX/p6r6R9Bl9635DuvI6rTn1KziHMeyYM0="; + hash = "sha256-fY6/ofaZe94ZK7An6bSHcLj0T92OCQCflnBk5onVzzo="; }; sourceRoot = "${finalAttrs.src.name}/projects/rocr-runtime"; @@ -39,6 +40,7 @@ stdenv.mkDerivation (finalAttrs: { nativeBuildInputs = [ pkg-config cmake + python3 # trap_handler/CMakeLists.txt: find_package(Python3 Interpreter) xxd # used by create_hsaco_ascii_file.sh llvm.rocm-toolchain ]; @@ -60,24 +62,12 @@ stdenv.mkDerivation (finalAttrs: { ]; patches = [ - # Vendored upstream PR for fix for segfault when queue allocation fails - # https://github.com/ROCm/rocm-systems/pull/2850 - ./queue-failure.patch (fetchpatch { # [PATCH] rocr: Extend HIP ISA compatibility check hash = "sha256-8r2Lb5lBfFaZC3knCxfXGcnkzNv6JxOKyJn2rD5gus4="; url = "https://github.com/GZGavinZhao/rocm-systems/commit/dcef23cf896f4dcbc7ed81abeaa4ec2208dcdd8c.patch"; relative = "projects/rocr-runtime"; }) - (fetchpatch { - # [PATCH] kfd_ioctl: fix UB due to 1 << 31 - url = "https://github.com/ROCm/ROCR-Runtime/commit/41bfc66aef437a5b349f71105fa4b907cc7e17d5.patch"; - hash = "sha256-A7VhPR3eSsmjq2cTBSjBIz9i//WiNjoXm0EsRKtF+ns="; - }) - # This causes a circular dependency, aqlprofile relies on hsa-runtime64 - # which is part of rocm-runtime - # Worked around by having rocprofiler load aqlprofile directly - ./remove-hsa-aqlprofile-dep.patch ]; postPatch = '' diff --git a/pkgs/development/rocm-modules/10/rocm-runtime/queue-failure.patch b/pkgs/development/rocm-modules/10/rocm-runtime/queue-failure.patch deleted file mode 100644 index f9087144bc229..0000000000000 --- a/pkgs/development/rocm-modules/10/rocm-runtime/queue-failure.patch +++ /dev/null @@ -1,71 +0,0 @@ -From b7717446c85d08b2d7c0c60ba3ac0eff11ee6120 Mon Sep 17 00:00:00 2001 -From: Luna Nova -Date: Tue, 20 Jan 2026 12:55:45 -0800 -Subject: [PATCH 1/2] rocm-runtime: fix crash in QueueCreate due to trying to - free non allocated scratch - -if (scratch.main_queue_base != nullptr) before calling ReleaseQueueMainScratch -because ReleaseQueueMainScratch is only valid if main_queue_base is set -and the scope guard can fire for an error allocating the queue. ---- - .../runtime/hsa-runtime/core/runtime/amd_gpu_agent.cpp | 4 +++- - 1 file changed, 3 insertions(+), 1 deletion(-) - -diff --git a/runtime/hsa-runtime/core/runtime/amd_gpu_agent.cpp b/runtime/hsa-runtime/core/runtime/amd_gpu_agent.cpp -index 01b01fe869..83db40dacc 100644 ---- a/runtime/hsa-runtime/core/runtime/amd_gpu_agent.cpp -+++ b/runtime/hsa-runtime/core/runtime/amd_gpu_agent.cpp -@@ -1792,7 +1792,9 @@ hsa_status_t GpuAgent::QueueCreate(size_t size, hsa_queue_type32_t queue_type, u - scratch.main_queue_base = nullptr; - scratch.main_queue_process_offset = 0; - -- MAKE_NAMED_SCOPE_GUARD(scratchGuard, [&]() { ReleaseQueueMainScratch(scratch); }); -+ MAKE_NAMED_SCOPE_GUARD(scratchGuard, [&]() { -+ if (scratch.main_queue_base != nullptr) ReleaseQueueMainScratch(scratch); -+ }); - - if (scratch.main_size != 0) { - AcquireQueueMainScratch(scratch); --- -2.52.0 - - -From 9c1746cd76a703e4d2321dc2ffe85fc61bfd2f21 Mon Sep 17 00:00:00 2001 -From: Luna Nova -Date: Tue, 20 Jan 2026 13:00:32 -0800 -Subject: [PATCH 2/2] rocm-runtime: log for errors in QueueCreate - ---- - .../runtime/hsa-runtime/core/runtime/amd_gpu_agent.cpp | 9 ++++++++- - 1 file changed, 8 insertions(+), 1 deletion(-) - -diff --git a/runtime/hsa-runtime/core/runtime/amd_gpu_agent.cpp b/runtime/hsa-runtime/core/runtime/amd_gpu_agent.cpp -index 83db40dacc..ae68732eb5 100644 ---- a/runtime/hsa-runtime/core/runtime/amd_gpu_agent.cpp -+++ b/runtime/hsa-runtime/core/runtime/amd_gpu_agent.cpp -@@ -1799,6 +1799,9 @@ hsa_status_t GpuAgent::QueueCreate(size_t size, hsa_queue_type32_t queue_type, u - if (scratch.main_size != 0) { - AcquireQueueMainScratch(scratch); - if (scratch.main_queue_base == nullptr) { -+ LogPrint(HSA_AMD_LOG_FLAG_INFO, -+ "Failed to allocate scratch memory for queue, size=%zu, node=%u", -+ scratch.main_size, node_id()); - return HSA_STATUS_ERROR_OUT_OF_RESOURCES; - } - } -@@ -1827,7 +1830,11 @@ hsa_status_t GpuAgent::QueueCreate(size_t size, hsa_queue_type32_t queue_type, u - node_id())); - } - -- if (!shared_queue) return HSA_STATUS_ERROR_OUT_OF_RESOURCES; -+ if (!shared_queue) { -+ LogPrint(HSA_AMD_LOG_FLAG_INFO, -+ "Failed to allocate shared queue descriptor memory, node=%u", node_id()); -+ return HSA_STATUS_ERROR_OUT_OF_RESOURCES; -+ } - - auto aql_queue = new AqlQueue(shared_queue, this, size, node_id(), scratch, event_callback, data, - flags); --- -2.52.0 - diff --git a/pkgs/development/rocm-modules/10/rocm-runtime/remove-hsa-aqlprofile-dep.patch b/pkgs/development/rocm-modules/10/rocm-runtime/remove-hsa-aqlprofile-dep.patch deleted file mode 100644 index b8ed57d049bc9..0000000000000 --- a/pkgs/development/rocm-modules/10/rocm-runtime/remove-hsa-aqlprofile-dep.patch +++ /dev/null @@ -1,27 +0,0 @@ -libhsa-amd-aqlprofile64 library is unfree -Bug: https://github.com/ROCm/ROCm/issues/1781 ---- a/runtime/hsa-runtime/core/runtime/amd_gpu_agent.cpp -+++ b/runtime/hsa-runtime/core/runtime/amd_gpu_agent.cpp -@@ -1333,11 +1333,6 @@ hsa_status_t GpuAgent::GetInfo(hsa_agent_info_t attribute, void* value) const { - setFlag(HSA_EXTENSION_AMD_PC_SAMPLING); - } - -- if (os::LibHandle lib = os::LoadLib(kAqlProfileLib)) { -- os::CloseLib(lib); -- setFlag(HSA_EXTENSION_AMD_AQLPROFILE); -- } -- - setFlag(HSA_EXTENSION_AMD_PROFILER); - - break; ---- a/runtime/hsa-runtime/core/runtime/hsa.cpp -+++ b/runtime/hsa-runtime/core/runtime/hsa.cpp -@@ -490,7 +490,7 @@ hsa_status_t hsa_system_get_major_extension_table(uint16_t extension, uint16_t v - return HSA_STATUS_SUCCESS; - } - -- if (extension == HSA_EXTENSION_AMD_AQLPROFILE) { -+ if (0) { - if (version_major != hsa_ven_amd_aqlprofile_VERSION_MAJOR) { - debug_print("aqlprofile API incompatible ver %d, current ver %d\n", - version_major, hsa_ven_amd_aqlprofile_VERSION_MAJOR); From 3ae4d90afecc56eb4972e11fd0442e1dc9345782 Mon Sep 17 00:00:00 2001 From: randomizedcoder Date: Thu, 22 Oct 2026 07:18:44 -0700 Subject: [PATCH 13/21] rocmPackages_10.rocm-comgr: init at 24.0.0-rocm Update the rocmPackages.rocm-comgr copy from the previous commit to ROCm 10.1 and add it to the rocmPackages_10 scope. From "rocmPackages.rocm-comgr: rebase ISA-compat CCOB patch for LLVM 24": The "[Comgr] Extend ISA compatibility for CCOB" change (GZGavinZhao 2c1e44fc) no longer applies as a fetchpatch: LLVM 24's comgr inserted comgr-unpackage-command.h into comgr-compiler.cpp's include block (shifting the comgr-metadata.h include past patch's default fuzz) and moved the unbundle() body ~477 lines down. Rebase it locally as comgr-isa-compat-ccob.patch against therock-10.1. The OffloadBundler::GetBundleIDsInFile it calls is provided clang-side by clang-add-getbundleidsinfile.diff in the llvm module. Assisted-by: Claude Code (claude-opus-5-5) --- pkgs/development/rocm-modules/10/default.nix | 2 + .../10/rocm-comgr/comgr-isa-compat-ccob.patch | 97 +++++++++++++++++++ .../rocm-modules/10/rocm-comgr/default.nix | 14 +-- 3 files changed, 106 insertions(+), 7 deletions(-) create mode 100644 pkgs/development/rocm-modules/10/rocm-comgr/comgr-isa-compat-ccob.patch diff --git a/pkgs/development/rocm-modules/10/default.nix b/pkgs/development/rocm-modules/10/default.nix index a4b612431bb56..16120eabf2833 100644 --- a/pkgs/development/rocm-modules/10/default.nix +++ b/pkgs/development/rocm-modules/10/default.nix @@ -47,6 +47,8 @@ let stdenv = origStdenv; }; + rocm-comgr = self.callPackage ./rocm-comgr { }; + rocm-docs-core = python3Packages.callPackage ../rocm-docs-core { }; hipcc = self.callPackage ../hipcc { stdenv = origStdenv; }; diff --git a/pkgs/development/rocm-modules/10/rocm-comgr/comgr-isa-compat-ccob.patch b/pkgs/development/rocm-modules/10/rocm-comgr/comgr-isa-compat-ccob.patch new file mode 100644 index 0000000000000..f2c93adf45a26 --- /dev/null +++ b/pkgs/development/rocm-modules/10/rocm-comgr/comgr-isa-compat-ccob.patch @@ -0,0 +1,97 @@ +--- a/src/comgr-compiler.cpp ++++ b/src/comgr-compiler.cpp +@@ -20,6 +20,7 @@ + #include "comgr-diagnostic-handler.h" + #include "comgr-env.h" + #include "comgr-libcxx-headers.h" ++#include "comgr-metadata.h" + #include "comgr-resource-directory.h" + #include "comgr-spirv-command.h" + #include "comgr-unbundle-command.h" +@@ -1855,17 +1856,72 @@ + size_t Index = OutputPrefix.find_last_of("."); + OutputPrefix = OutputPrefix.substr(0, Index); + ++ std::set CoEntryIds; ++ if (auto Error = OffloadBundler::GetBundleIDsInFile(InputFilePath, BundlerConfig, CoEntryIds)) { ++ if (env::shouldEmitVerboseLogs()) { ++ LogS << "Failed to get bundle IDs in " ++ << InputFilePath ++ << ", not trying to coerce compatible archs\n"; ++ LogS.flush(); ++ } ++ } ++ std::set> entry_ids_with_idents; ++ for (const auto& CoEntryId : CoEntryIds) { ++ std::string TargetIdent; ++ size_t Pos = std::string::npos; ++ for (const auto& Prefix : {"hipv4-", "hip-"}) { ++ if ((Pos = CoEntryId.find(Prefix)) == 0) { ++ TargetIdent = CoEntryId.substr(std::char_traits::length(Prefix)); ++ break; ++ } ++ } ++ ++ if (TargetIdent.empty()) { ++ continue; ++ } ++ ++ entry_ids_with_idents.emplace(CoEntryId, TargetIdent); ++ } ++ ++ // Bundler target and output names + for (StringRef Entry : ActionInfo->BundleEntryIDs) { ++ std::string CompatEntry = Entry.str(); ++ ++ std::string EntryIdent; ++ size_t Pos = std::string::npos; ++ for (const auto& Prefix : {"hipv4-", "hip-"}) { ++ if ((Pos = Entry.find(Prefix)) == 0) { ++ EntryIdent = Entry.substr(std::char_traits::length(Prefix)); ++ break; ++ } ++ } ++ ++ if (!EntryIdent.empty()) { ++ std::string BestEntry; ++ for (const auto& [CoEntry, CoIdent] : entry_ids_with_idents) { ++ if (EntryIdent == CoIdent) { ++ BestEntry = CoEntry; ++ break; ++ } else if (metadata::isCompatibleIsaName(EntryIdent, CoIdent)) { ++ BestEntry = CoEntry; ++ } ++ } ++ ++ if (!BestEntry.empty()) { ++ CompatEntry = BestEntry; ++ } ++ } ++ + // Add an output file for each target + SmallString<128> OutputFilePath = OutputDir; + sys::path::append(OutputFilePath, +- OutputPrefix + "-" + Entry + "." + FileExtension); ++ OutputPrefix + "-" + CompatEntry + "." + FileExtension); + +- BundlerConfig.TargetNames.emplace_back(Entry); ++ BundlerConfig.TargetNames.emplace_back(CompatEntry); + BundlerConfig.OutputFileNames.emplace_back(OutputFilePath); + + if (env::shouldEmitVerboseLogs()) { +- LogS << "\tBundle Entry ID: " << Entry << "\n" ++ LogS << "\tBundle (Compat)Entry ID: " << CompatEntry << "\n" + << "\tOutput Filename: " << OutputFilePath << "\n"; + LogS.flush(); + } +--- a/src/comgr-metadata.h ++++ b/src/comgr-metadata.h +@@ -37,6 +37,8 @@ + + bool isValidIsaName(llvm::StringRef IsaName); + ++bool isCompatibleIsaName(llvm::StringRef IsaName, llvm::StringRef CodeObjectIsaName); ++ + amd_comgr_status_t getElfIsaName(DataObject *DataP, std::string &IsaName); + + amd_comgr_status_t lookUpCodeObject(DataObject *DataP, diff --git a/pkgs/development/rocm-modules/10/rocm-comgr/default.nix b/pkgs/development/rocm-modules/10/rocm-comgr/default.nix index e7663a1f7130a..fa6640d5c1f33 100644 --- a/pkgs/development/rocm-modules/10/rocm-comgr/default.nix +++ b/pkgs/development/rocm-modules/10/rocm-comgr/default.nix @@ -34,12 +34,12 @@ stdenv.mkDerivation (finalAttrs: { url = "https://github.com/GZGavinZhao/rocm-llvm-project/commit/7002dc04863d38c57cfd2e6fc60a1cf5a613fd8e.patch"; relative = "amd/comgr"; }) - # [Comgr] Extend ISA compatibility for CCOB - (fetchpatch { - hash = "sha256-/50I+PqxL3oaQMqg5vR7+ibUcXO1SvfXBdw/sybRt1o="; - url = "https://github.com/GZGavinZhao/rocm-llvm-project/commit/2c1e44fc3eacadcafdd4ada3e3184a092b6f26c5.patch"; - relative = "amd/comgr"; - }) + # [Comgr] Extend ISA compatibility for CCOB. + # Rebased from GZGavinZhao/rocm-llvm-project 2c1e44fc onto the LLVM 24 comgr + # (comgr-compiler.cpp's include block and unbundle() body moved). The + # OffloadBundler::GetBundleIDsInFile it calls is provided by the clang-side + # clang-add-getbundleidsinfile.diff in the llvm module. + ./comgr-isa-compat-ccob.patch # Fix: CCOB compat patch used coerced (featureless) name for output filename, # causing CLR's code_obj_map key to miss when looking up device ISA with features ./fix-ccob-compat-output-filename.patch @@ -55,7 +55,7 @@ stdenv.mkDerivation (finalAttrs: { + '' substituteInPlace src/comgr-env.cpp \ --replace-fail \ - 'return EnvLLVMPath;' \ + 'return EnvLLVMPath ? EnvLLVMPath : "";' \ 'return EnvLLVMPath ? EnvLLVMPath : "${llvm.rocm-toolchain}";' ''; From 3166d74391bf7f6e5927fbe524106df793195699 Mon Sep 17 00:00:00 2001 From: randomizedcoder Date: Thu, 22 Oct 2026 07:18:45 -0700 Subject: [PATCH 14/21] rocmPackages_10.rocminfo: init at 10.1 Update the rocmPackages.rocminfo copy from the previous commit to ROCm 10.1 and add it to the rocmPackages_10 scope. Source/version bump only. Assisted-by: Claude Code (claude-opus-5-5) --- pkgs/development/rocm-modules/10/default.nix | 2 ++ pkgs/development/rocm-modules/10/rocminfo/default.nix | 6 +++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/pkgs/development/rocm-modules/10/default.nix b/pkgs/development/rocm-modules/10/default.nix index 16120eabf2833..834bdb6efef81 100644 --- a/pkgs/development/rocm-modules/10/default.nix +++ b/pkgs/development/rocm-modules/10/default.nix @@ -49,6 +49,8 @@ let rocm-comgr = self.callPackage ./rocm-comgr { }; + rocminfo = self.callPackage ./rocminfo { stdenv = origStdenv; }; + rocm-docs-core = python3Packages.callPackage ../rocm-docs-core { }; hipcc = self.callPackage ../hipcc { stdenv = origStdenv; }; diff --git a/pkgs/development/rocm-modules/10/rocminfo/default.nix b/pkgs/development/rocm-modules/10/rocminfo/default.nix index 1cfbe4ddc9b7e..2da6d54f403de 100644 --- a/pkgs/development/rocm-modules/10/rocminfo/default.nix +++ b/pkgs/development/rocm-modules/10/rocminfo/default.nix @@ -12,18 +12,18 @@ }: stdenv.mkDerivation (finalAttrs: { - version = "7.2.4"; + version = "10.1"; pname = "rocminfo"; src = fetchFromGitHub { owner = "ROCm"; repo = "rocm-systems"; - tag = "rocm-${finalAttrs.version}"; + tag = "therock-${finalAttrs.version}"; sparseCheckout = [ "projects/rocminfo" "shared" ]; - hash = "sha256-0esRBEXVibC2uzyonpc0ABNNHQ2NAWZrBmmg6p1zP0c="; + hash = "sha256-oK9fUtHb2qvFTpQ/9KE6LfiopDUvoreApZtsDb9aGvA="; }; sourceRoot = "${finalAttrs.src.name}/projects/rocminfo"; From d35f8f2e1bc82c7afd79a0e87ae9c5efdc7c1c3d Mon Sep 17 00:00:00 2001 From: randomizedcoder Date: Thu, 22 Oct 2026 07:18:46 -0700 Subject: [PATCH 15/21] rocmPackages_10.amdsmi: init at 10.1 Update the rocmPackages.amdsmi copy from the previous commit to ROCm 10.1 and add it to the rocmPackages_10 scope. From "rocmPackages.amdsmi: adapt to 27.0.0 ABI": amdsmi 27.0.0 (SONAME libamd_smi.so.27) requires libnl-3/libnl-genl-3 and libmnl; add them. py-interface/CMakeLists.txt now FATAL_ERRORs at configure time if it cannot locate a system python3 (it probes /usr/bin/python3 and /usr/libexec/platform-python, neither in the sandbox) unless AMDSMI_SYSTEM_PYTHON_SITELIB is set. The install it guards is DESTDIR-gated (nix uses CMAKE_INSTALL_PREFIX) and thus skipped anyway, so pass nix's sitePackages to satisfy the guard. Revised during the split review: Drop the drm_color_ctm_3x4 patch: amdsmi 10.1 builds without it against libdrm 2.4.134, whose drm_mode.h shares the bundled copy's include guard. Pin esmi_ib_library by the commit amdsmi pins. Link libamd_smi.so with -Bsymbolic-functions: with librocm_smi64 loaded (as after import torch) its exported rsmi_init was interposed and amdsmi enumerated no GPUs, so torch.cuda.device_count() was 0. Assisted-by: Claude Code (claude-opus-5-5) --- .../rocm-modules/10/amdsmi/default.nix | 40 ++++++++++--------- .../amdsmi/drm-struct-redefinition-fix.patch | 35 ---------------- pkgs/development/rocm-modules/10/default.nix | 5 +++ 3 files changed, 27 insertions(+), 53 deletions(-) delete mode 100644 pkgs/development/rocm-modules/10/amdsmi/drm-struct-redefinition-fix.patch diff --git a/pkgs/development/rocm-modules/10/amdsmi/default.nix b/pkgs/development/rocm-modules/10/amdsmi/default.nix index d483dde8b6e8a..abb1ecd74e48e 100644 --- a/pkgs/development/rocm-modules/10/amdsmi/default.nix +++ b/pkgs/development/rocm-modules/10/amdsmi/default.nix @@ -6,62 +6,57 @@ cmake, pkg-config, libdrm, + libnl, + libmnl, python, wrapPython, autoPatchelfHook, + binutils, }: let esmi_ib_src = fetchFromGitHub { owner = "amd"; repo = "esmi_ib_library"; - tag = "esmi_pkg_ver-4.2"; - hash = "sha256-czF9ezkAO0PuDkXh8y639AcOZH+KVcWiXPX74H5W/nw="; + # The commit amdsmi pins (tag esmi_pkg_ver-5.2.1.1) + rev = "d494a3194ceb4cc4dbb2debf9fcbe8773c6d3bef"; + hash = "sha256-StSYzyIujaH8UJIRpfJC0lf+oVT9fWflJgQONvRqu70="; }; in stdenv.mkDerivation (finalAttrs: { pname = "amdsmi"; - version = "7.2.4"; + version = "10.1"; src = fetchFromGitHub { owner = "ROCm"; repo = "rocm-systems"; - tag = "rocm-${finalAttrs.version}"; + tag = "therock-${finalAttrs.version}"; sparseCheckout = [ "projects/amdsmi" "shared" ]; - hash = "sha256-TFi+3txemvV6K827e8S3hZOd9jcj4Qzop6V9CdKrpLg="; + hash = "sha256-CmCVPmqgU0HtqIBuJUs+Nr7LRKtngOaNNsWFek9Nino="; }; sourceRoot = "${finalAttrs.src.name}/projects/amdsmi"; postPatch = '' - substituteInPlace goamdsmi_shim/CMakeLists.txt \ - --replace-fail "amd_smi)" ${"'"}''${AMD_SMI_TARGET})' \ - --replace-fail 'target_link_libraries(''${GOAMDSMI_SHIM_TARGET} -L' '#' - substituteInPlace CMakeLists.txt \ - --replace-fail "if(NOT latest_esmi_tag STREQUAL current_esmi_tag)" "if(OFF)" - - # Manually unpack esmi_ib_src and add amd_hsmp.h so execute-process git clone doesn't run + # Pre-populate esmi_ib_library so CMake does not FetchContent it. cp -rf --no-preserve=mode ${esmi_ib_src} ./esmi_ib_library mkdir -p ./esmi_ib_library/include/asm cp ./include/amd_smi/impl/amd_hsmp.h ./esmi_ib_library/include/asm/amd_hsmp.h ''; - patches = [ - # Fix error: redefinition of 'struct drm_color_ctm_3x4' - # https://github.com/ROCm/amdsmi/pull/165 - ./drm-struct-redefinition-fix.patch - ]; - nativeBuildInputs = [ cmake pkg-config wrapPython autoPatchelfHook + binutils # CMake resolves link-lib SONAMEs via `objdump -p` ]; buildInputs = [ libdrm + libnl # pkg_check_modules libnl-3.0 + libnl-genl-3.0 + libmnl # pkg_check_modules libmnl ]; cmakeFlags = [ @@ -70,6 +65,15 @@ stdenv.mkDerivation (finalAttrs: { "-DCMAKE_INSTALL_BINDIR=bin" "-DCMAKE_INSTALL_LIBDIR=lib" "-DCMAKE_INSTALL_INCLUDEDIR=include" + # py-interface/CMakeLists.txt fails without a system python3 unless this is set. + "-DAMDSMI_SYSTEM_PYTHON_SITELIB=${placeholder "out"}/${python.sitePackages}" + # libamd_smi.so still exports rsmi_init, and its own call to it goes + # through the PLT. Once librocm_smi64 is loaded globally (torch's + # libtorch_hip needs it), that call binds to rocm_smi's copy, amdsmi's own + # state is never initialised, and enumeration returns no processors: + # torch.cuda.device_count() is then 0. Upstream links only the wheel's + # libamd_smi_python.so this way; do the same for the system library. + "-DCMAKE_SHARED_LINKER_FLAGS=-Wl,-Bsymbolic-functions" ]; postInstall = '' diff --git a/pkgs/development/rocm-modules/10/amdsmi/drm-struct-redefinition-fix.patch b/pkgs/development/rocm-modules/10/amdsmi/drm-struct-redefinition-fix.patch deleted file mode 100644 index caf23edcef57a..0000000000000 --- a/pkgs/development/rocm-modules/10/amdsmi/drm-struct-redefinition-fix.patch +++ /dev/null @@ -1,35 +0,0 @@ -From b8b4a6bcfe35ba9539a120cfd16573123ddd9241 Mon Sep 17 00:00:00 2001 -From: "Sv. Lockal" -Date: Mon, 15 Dec 2025 03:46:35 +0800 -Subject: [PATCH] Fix compilation with libdrm-2.4.130 - -Fix error: redefinition of 'struct drm_color_ctm_3x4'. - -drm_color_ctm_3x4 structure is now defined in https://github.com/torvalds/linux/commit/e5719e7f19009d4fbedf685fc22eec9cd8de154f#diff-4c51fb416ec7cc69566cd7b795ee57eb070aa1006ad65d6962081f039ffb2718 - -As this structure is unused and not a part of amdsmi public interface, -it is safe to remove it. ---- - include/amd_smi/impl/amdgpu_drm.h | 9 --------- - 1 file changed, 9 deletions(-) - -diff --git a/include/amd_smi/impl/amdgpu_drm.h b/include/amd_smi/impl/amdgpu_drm.h -index b56a5ac4b..0e483d13b 100644 ---- a/include/amd_smi/impl/amdgpu_drm.h -+++ b/include/amd_smi/impl/amdgpu_drm.h -@@ -1625,15 +1625,6 @@ struct drm_amdgpu_info_uq_metadata { - #define AMDGPU_FAMILY_GC_11_5_0 150 /* GC 11.5.0 */ - #define AMDGPU_FAMILY_GC_12_0_0 152 /* GC 12.0.0 */ - --/* FIXME wrong namespace! */ --struct drm_color_ctm_3x4 { -- /* -- * Conversion matrix with 3x4 dimensions in S31.32 sign-magnitude -- * (not two's complement!) format. -- */ -- __u64 matrix[12]; --}; -- - #if defined(__cplusplus) - } - #endif diff --git a/pkgs/development/rocm-modules/10/default.nix b/pkgs/development/rocm-modules/10/default.nix index 834bdb6efef81..486046756902b 100644 --- a/pkgs/development/rocm-modules/10/default.nix +++ b/pkgs/development/rocm-modules/10/default.nix @@ -12,6 +12,7 @@ let let inherit (self) llvm; origStdenv = stdenv; + pyPackages = python3Packages; rocmClangStdenv = llvm.rocmClangStdenv; in { @@ -51,6 +52,10 @@ let rocminfo = self.callPackage ./rocminfo { stdenv = origStdenv; }; + amdsmi = pyPackages.callPackage ./amdsmi { + inherit (self) rocmUpdateScript; + }; + rocm-docs-core = python3Packages.callPackage ../rocm-docs-core { }; hipcc = self.callPackage ../hipcc { stdenv = origStdenv; }; From b592665fb563656d7eb8de0ff7eb2286982be77a Mon Sep 17 00:00:00 2001 From: randomizedcoder Date: Thu, 22 Oct 2026 07:18:46 -0700 Subject: [PATCH 16/21] rocmPackages_10.rocm-smi: init at 10.1 Update the rocmPackages.rocm-smi copy from the previous commit to ROCm 10.1 and add it to the rocmPackages_10 scope. Source/version bump only. Assisted-by: Claude Code (claude-opus-5-5) --- pkgs/development/rocm-modules/10/default.nix | 4 ++++ pkgs/development/rocm-modules/10/rocm-smi/default.nix | 6 +++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/pkgs/development/rocm-modules/10/default.nix b/pkgs/development/rocm-modules/10/default.nix index 486046756902b..b96aa6b235f13 100644 --- a/pkgs/development/rocm-modules/10/default.nix +++ b/pkgs/development/rocm-modules/10/default.nix @@ -56,6 +56,10 @@ let inherit (self) rocmUpdateScript; }; + rocm-smi = pyPackages.callPackage ./rocm-smi { + inherit (self) rocmUpdateScript; + }; + rocm-docs-core = python3Packages.callPackage ../rocm-docs-core { }; hipcc = self.callPackage ../hipcc { stdenv = origStdenv; }; diff --git a/pkgs/development/rocm-modules/10/rocm-smi/default.nix b/pkgs/development/rocm-modules/10/rocm-smi/default.nix index ad53094199161..35fc58c037bfa 100644 --- a/pkgs/development/rocm-modules/10/rocm-smi/default.nix +++ b/pkgs/development/rocm-modules/10/rocm-smi/default.nix @@ -11,17 +11,17 @@ stdenv.mkDerivation (finalAttrs: { pname = "rocm-smi"; - version = "7.2.4"; + version = "10.1"; src = fetchFromGitHub { owner = "ROCm"; repo = "rocm-systems"; - tag = "rocm-${finalAttrs.version}"; + tag = "therock-${finalAttrs.version}"; sparseCheckout = [ "projects/rocm-smi-lib" "shared" ]; - hash = "sha256-Si8SbeVKUBtqk6h2QJ9ssQV68bLq6TvESrYXJuArHd8="; + hash = "sha256-t5yMLdDaylgdhreVzWBmhY5rFvNSGRs3v2bZcRQyqI0="; }; sourceRoot = "${finalAttrs.src.name}/projects/rocm-smi-lib"; From f409337ca0b729ef9711d50803b98663ddddc5ba Mon Sep 17 00:00:00 2001 From: randomizedcoder Date: Thu, 22 Oct 2026 07:18:47 -0700 Subject: [PATCH 17/21] rocmPackages_10.hip-common: init at 10.1 Update the rocmPackages.hip-common copy from the previous commit to ROCm 10.1 and add it to the rocmPackages_10 scope. Source/version bump only. Assisted-by: Claude Code (claude-opus-5-5) --- pkgs/development/rocm-modules/10/default.nix | 2 ++ pkgs/development/rocm-modules/10/hip-common/default.nix | 6 +++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/pkgs/development/rocm-modules/10/default.nix b/pkgs/development/rocm-modules/10/default.nix index b96aa6b235f13..63fd18ac140c9 100644 --- a/pkgs/development/rocm-modules/10/default.nix +++ b/pkgs/development/rocm-modules/10/default.nix @@ -62,6 +62,8 @@ let rocm-docs-core = python3Packages.callPackage ../rocm-docs-core { }; + hip-common = self.callPackage ./hip-common { }; + hipcc = self.callPackage ../hipcc { stdenv = origStdenv; }; rocprofiler-register = self.callPackage ./rocprofiler-register { inherit (llvm) clang; diff --git a/pkgs/development/rocm-modules/10/hip-common/default.nix b/pkgs/development/rocm-modules/10/hip-common/default.nix index f2415ab549c33..c791e60f5b31a 100644 --- a/pkgs/development/rocm-modules/10/hip-common/default.nix +++ b/pkgs/development/rocm-modules/10/hip-common/default.nix @@ -7,17 +7,17 @@ stdenv.mkDerivation (finalAttrs: { pname = "hip-common"; - version = "7.2.4"; + version = "10.1"; src = fetchFromGitHub { owner = "ROCm"; repo = "rocm-systems"; - tag = "rocm-${finalAttrs.version}"; + tag = "therock-${finalAttrs.version}"; sparseCheckout = [ "projects/hip" "shared" ]; - hash = "sha256-orfTXKjcZJ5E73cmXEyltZVYhCQo8FLExVHM3J/rqUM="; + hash = "sha256-MP92iAemtjBLt9hy4JJpud+UfT2xolfm7mtLknrU5EE="; }; sourceRoot = "${finalAttrs.src.name}/projects/hip"; From e48aa86745d9ddf6670829c52d20b7a6a816fab4 Mon Sep 17 00:00:00 2001 From: randomizedcoder Date: Thu, 22 Oct 2026 07:18:48 -0700 Subject: [PATCH 18/21] rocmPackages_10.roctracer: init at 10.1 Update the rocmPackages.roctracer copy from the previous commit to ROCm 10.1 and add it to the rocmPackages_10 scope. Source/version bump only. Assisted-by: Claude Code (claude-opus-5-5) --- pkgs/development/rocm-modules/10/default.nix | 2 ++ pkgs/development/rocm-modules/10/roctracer/default.nix | 6 +++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/pkgs/development/rocm-modules/10/default.nix b/pkgs/development/rocm-modules/10/default.nix index 63fd18ac140c9..f8da269205aef 100644 --- a/pkgs/development/rocm-modules/10/default.nix +++ b/pkgs/development/rocm-modules/10/default.nix @@ -68,6 +68,8 @@ let rocprofiler-register = self.callPackage ./rocprofiler-register { inherit (llvm) clang; }; + + roctracer = self.callPackage ./roctracer { }; } ); in diff --git a/pkgs/development/rocm-modules/10/roctracer/default.nix b/pkgs/development/rocm-modules/10/roctracer/default.nix index 6cc979eb3648e..0fd5b25342c38 100644 --- a/pkgs/development/rocm-modules/10/roctracer/default.nix +++ b/pkgs/development/rocm-modules/10/roctracer/default.nix @@ -19,7 +19,7 @@ stdenv.mkDerivation (finalAttrs: { pname = "roctracer"; - version = "7.2.4"; + version = "10.1"; outputs = [ "out" @@ -34,12 +34,12 @@ stdenv.mkDerivation (finalAttrs: { src = fetchFromGitHub { owner = "ROCm"; repo = "rocm-systems"; - tag = "rocm-${finalAttrs.version}"; + tag = "therock-${finalAttrs.version}"; sparseCheckout = [ "projects/roctracer" "shared" ]; - hash = "sha256-Ps9b/MMdxXthGV96ZDg0kZGPdmn7Sy5if1a/Fjx2fEE="; + hash = "sha256-1pXWl8yUlfw5C3PFhrLxXPwHxscu1+AHx+lEqhl59vk="; }; sourceRoot = "${finalAttrs.src.name}/projects/roctracer"; From 0204dbfba8f5a14b0b37cbbfa943721fced8bad2 Mon Sep 17 00:00:00 2001 From: randomizedcoder Date: Thu, 22 Oct 2026 07:18:48 -0700 Subject: [PATCH 19/21] rocmPackages_10.clr: init at 10.1 Update the rocmPackages.clr copy from the previous commit to ROCm 10.1 and add it to the rocmPackages_10 scope. Source/version bump only. Assisted-by: Claude Code (claude-opus-5-5) --- .../rocm-modules/10/clr/default.nix | 11 ++++-- pkgs/development/rocm-modules/10/default.nix | 36 +++++++++++++++++++ 2 files changed, 44 insertions(+), 3 deletions(-) diff --git a/pkgs/development/rocm-modules/10/clr/default.nix b/pkgs/development/rocm-modules/10/clr/default.nix index 554c76d845c04..238c9ae4ba023 100644 --- a/pkgs/development/rocm-modules/10/clr/default.nix +++ b/pkgs/development/rocm-modules/10/clr/default.nix @@ -70,7 +70,7 @@ let in stdenv.mkDerivation (finalAttrs: { pname = "clr"; - version = "7.2.4"; + version = "10.1"; outputs = [ "out" @@ -83,12 +83,12 @@ stdenv.mkDerivation (finalAttrs: { src = fetchFromGitHub { owner = "ROCm"; repo = "rocm-systems"; - tag = "rocm-${finalAttrs.version}"; + tag = "therock-${finalAttrs.version}"; sparseCheckout = [ "projects/clr" "shared" ]; - hash = "sha256-//cQBKlSB9uSP4fBgJpI1FxnqlzyQN913CHVGa2tqv8="; + hash = "sha256-uK/JD5p72os15+n6Jw6aU0xELphBHdYnVu7NmXC3BA4="; }; sourceRoot = "${finalAttrs.src.name}/projects/clr"; @@ -212,6 +212,11 @@ stdenv.mkDerivation (finalAttrs: { ln -s ${rocminfo}/bin/* $out/bin ln -s ${rocm-core}/include/* $out/include/ + # Installed by opencl/CMakeLists.txt; the ICD file would collide with $icd's. + # https://github.com/ROCm/rocm-systems/blob/therock-10.1/projects/clr/opencl/CMakeLists.txt#L124-L143 + rm $out/etc/OpenCL/vendors/amdocl64.icd $out/etc/ld.so.conf.d/10-rocm-opencl.conf + rmdir $out/etc/OpenCL/vendors $out/etc/OpenCL $out/etc/ld.so.conf.d $out/etc + # Replace rocm-opencl-icd functionality mkdir -p $icd/etc/OpenCL/vendors echo "$out/lib/libamdocl64.so" > $icd/etc/OpenCL/vendors/amdocl64.icd diff --git a/pkgs/development/rocm-modules/10/default.nix b/pkgs/development/rocm-modules/10/default.nix index f8da269205aef..75f32e901a185 100644 --- a/pkgs/development/rocm-modules/10/default.nix +++ b/pkgs/development/rocm-modules/10/default.nix @@ -65,6 +65,9 @@ let hip-common = self.callPackage ./hip-common { }; hipcc = self.callPackage ../hipcc { stdenv = origStdenv; }; + + # Replaces hip, opencl-runtime, and rocclr + clr = self.callPackage ./clr { }; rocprofiler-register = self.callPackage ./rocprofiler-register { inherit (llvm) clang; }; @@ -72,5 +75,38 @@ let roctracer = self.callPackage ./roctracer { }; } ); + scopeForArches = + arches: + outer.overrideScope ( + _final: prev: { + clr = prev.clr.override { + localGpuTargets = arches; + }; + } + ); in outer +// lib.genAttrs outer.clr.gpuTargets (arch: scopeForArches [ arch ]) +// { + gfx9 = scopeForArches [ + "gfx906" + "gfx908" + "gfx90a" + "gfx942" + ]; + gfx10 = scopeForArches [ + "gfx1010" + "gfx1030" + ]; + gfx11 = scopeForArches [ + "gfx1100" + "gfx1101" + "gfx1102" + "gfx1150" + "gfx1151" + ]; + gfx12 = scopeForArches [ + "gfx1200" + "gfx1201" + ]; +} From 5271f129886fa6da7f08874969cbe59d216c57e9 Mon Sep 17 00:00:00 2001 From: randomizedcoder Date: Thu, 22 Oct 2026 07:18:49 -0700 Subject: [PATCH 20/21] rocmPackages_10.hipify: init at 10.1 Update the rocmPackages.hipify copy from the previous commit to ROCm 10.1 and add it to the rocmPackages_10 scope. Source/version bump only. Assisted-by: Claude Code (claude-opus-5-5) --- pkgs/development/rocm-modules/10/default.nix | 4 ++++ pkgs/development/rocm-modules/10/hipify/default.nix | 6 +++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/pkgs/development/rocm-modules/10/default.nix b/pkgs/development/rocm-modules/10/default.nix index 75f32e901a185..3356c1c61fdf2 100644 --- a/pkgs/development/rocm-modules/10/default.nix +++ b/pkgs/development/rocm-modules/10/default.nix @@ -68,6 +68,10 @@ let # Replaces hip, opencl-runtime, and rocclr clr = self.callPackage ./clr { }; + + hipify = self.callPackage ./hipify { + stdenv = origStdenv; + }; rocprofiler-register = self.callPackage ./rocprofiler-register { inherit (llvm) clang; }; diff --git a/pkgs/development/rocm-modules/10/hipify/default.nix b/pkgs/development/rocm-modules/10/hipify/default.nix index b121f0859dce6..5f35a82d79f46 100644 --- a/pkgs/development/rocm-modules/10/hipify/default.nix +++ b/pkgs/development/rocm-modules/10/hipify/default.nix @@ -12,13 +12,13 @@ stdenv.mkDerivation (finalAttrs: { pname = "hipify"; - version = "7.2.4"; + version = "10.1"; src = fetchFromGitHub { owner = "ROCm"; repo = "HIPIFY"; - tag = "rocm-${finalAttrs.version}"; - hash = "sha256-LC0lnYetV7RPVw92zew6za6bDH4zmnERXUM4MVaRVtc="; + tag = "therock-${finalAttrs.version}"; + hash = "sha256-Ayw+jfXmeK9XDy1C+cmalTIDStvr6kGY2n78x5b2KYk="; }; strictDeps = true; From 00b0bf3ccf636d5f6ab539e379785b86375363c7 Mon Sep 17 00:00:00 2001 From: randomizedcoder Date: Thu, 22 Oct 2026 07:18:50 -0700 Subject: [PATCH 21/21] rocmPackages_10.half: init at 10.1 Update the rocmPackages.half copy from the previous commit to ROCm 10.1 and add it to the rocmPackages_10 scope. Source/version bump only. Assisted-by: Claude Code (claude-opus-5-5) --- pkgs/development/rocm-modules/10/default.nix | 29 +++++++++++++++++++ .../rocm-modules/10/half/default.nix | 4 +-- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/pkgs/development/rocm-modules/10/default.nix b/pkgs/development/rocm-modules/10/default.nix index 3356c1c61fdf2..fc71188cf36b6 100644 --- a/pkgs/development/rocm-modules/10/default.nix +++ b/pkgs/development/rocm-modules/10/default.nix @@ -1,8 +1,10 @@ { lib, + config, callPackage, newScope, python3Packages, + openmpi, stdenv, }: @@ -13,6 +15,7 @@ let inherit (self) llvm; origStdenv = stdenv; pyPackages = python3Packages; + openmpi-orig = openmpi; rocmClangStdenv = llvm.rocmClangStdenv; in { @@ -72,11 +75,37 @@ let hipify = self.callPackage ./hipify { stdenv = origStdenv; }; + + # hsakmt was merged into rocm-runtime + hsakmt = self.rocm-runtime; rocprofiler-register = self.callPackage ./rocprofiler-register { inherit (llvm) clang; }; roctracer = self.callPackage ./roctracer { }; + + half = self.callPackage ./half { }; + + # Even if config.rocmSupport is false we need rocmSupport true + # version of ucc/ucx in openmpi in this package set + openmpi = openmpi-orig.override ( + prev: + let + ucx = prev.ucx.override { + enableCuda = false; + enableRocm = true; + rocmPackages = self; + }; + in + { + inherit ucx; + ucc = prev.ucc.override { + enableCuda = false; + inherit ucx; + }; + } + ); + mpi = self.openmpi; } ); scopeForArches = diff --git a/pkgs/development/rocm-modules/10/half/default.nix b/pkgs/development/rocm-modules/10/half/default.nix index 8541b82d596fe..ae57c10d2caeb 100644 --- a/pkgs/development/rocm-modules/10/half/default.nix +++ b/pkgs/development/rocm-modules/10/half/default.nix @@ -9,12 +9,12 @@ stdenv.mkDerivation (finalAttrs: { pname = "half"; - version = "7.2.4"; + version = "10.1"; src = fetchFromGitHub { owner = "ROCm"; repo = "half"; - tag = "rocm-${finalAttrs.version}"; + tag = "therock-${finalAttrs.version}"; hash = "sha256-If9O5BEeymsLN+C0drZsPSxEWXpJTxeDBGNHNXSumm4="; };