From d379fc21faa852b86f8cf8e61a2c24c13bebcde7 Mon Sep 17 00:00:00 2001 From: Gavin Zhao Date: Fri, 26 Dec 2025 09:16:08 -0800 Subject: [PATCH] rocmPackages.clr: add HIP impure tests for generic-arch and isa-compat Co-Authored-By: Luna Nova --- pkgs/development/rocm-modules/clr/default.nix | 27 +++++++ .../rocm-modules/clr/test-isa-compat.nix | 74 +++++++++++++++++++ 2 files changed, 101 insertions(+) create mode 100644 pkgs/development/rocm-modules/clr/test-isa-compat.nix diff --git a/pkgs/development/rocm-modules/clr/default.nix b/pkgs/development/rocm-modules/clr/default.nix index 4861e59fb7e2..79070cb3ffba 100644 --- a/pkgs/development/rocm-modules/clr/default.nix +++ b/pkgs/development/rocm-modules/clr/default.nix @@ -269,6 +269,33 @@ stdenv.mkDerivation (finalAttrs: { opencl-example = callPackage ./test-opencl-example.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" + ]; + }; }; selectGpuTargets = diff --git a/pkgs/development/rocm-modules/clr/test-isa-compat.nix b/pkgs/development/rocm-modules/clr/test-isa-compat.nix new file mode 100644 index 000000000000..2eca8edbff3d --- /dev/null +++ b/pkgs/development/rocm-modules/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 ]; + }; +}