biome: 1.9.2 -> 1.9.3 (#349335)
[NixPkgs.git] / pkgs / development / rocm-modules / 5 / clr / default.nix
blob49857e9d26f5ac42a8f1a52dc1474ba20a3a9f9c
1 { lib
2 , stdenv
3 , callPackage
4 , fetchFromGitHub
5 , fetchurl
6 , rocmUpdateScript
7 , makeWrapper
8 , cmake
9 , perl
10 , clang
11 , hip-common
12 , hipcc
13 , rocm-device-libs
14 , rocm-comgr
15 , rocm-runtime
16 , roctracer
17 , rocminfo
18 , rocm-smi
19 , numactl
20 , libGL
21 , libxml2
22 , libX11
23 , python3Packages
26 let
27   wrapperArgs = [
28     "--prefix PATH : $out/bin"
29     "--prefix LD_LIBRARY_PATH : ${rocm-runtime}"
30     "--set HIP_PLATFORM amd"
31     "--set HIP_PATH $out"
32     "--set HIP_CLANG_PATH ${clang}/bin"
33     "--set DEVICE_LIB_PATH ${rocm-device-libs}/amdgcn/bitcode"
34     "--set HSA_PATH ${rocm-runtime}"
35     "--set ROCM_PATH $out"
36   ];
38   # https://github.com/NixOS/nixpkgs/issues/305641
39   # Not needed when 3.29.2 is in unstable
40   cmake' = cmake.overrideAttrs(old: rec {
41     version = "3.29.2";
42     src = fetchurl {
43       url = "https://cmake.org/files/v${lib.versions.majorMinor version}/cmake-${version}.tar.gz";
44       hash = "sha256-NttLaSaqt0G6bksuotmckZMiITIwi03IJNQSPLcwNS4=";
45     };
46   });
47 in stdenv.mkDerivation (finalAttrs: {
48   pname = "clr";
49   version = "5.7.1";
51   outputs = [
52     "out"
53     "icd"
54   ];
56   src = fetchFromGitHub {
57     owner = "ROCm";
58     repo = "clr";
59     rev = "rocm-${finalAttrs.version}";
60     hash = "sha256-1gZJhvBbUFdKH9p/7SRfzEV/fM+gIN2Qvlxf2VbmAIw=";
61   };
63   nativeBuildInputs = [
64     makeWrapper
65     cmake'
66     perl
67     python3Packages.python
68     python3Packages.cppheaderparser
69   ];
71   buildInputs = [
72     numactl
73     libGL
74     libxml2
75     libX11
76   ];
78   propagatedBuildInputs = [
79     rocm-device-libs
80     rocm-comgr
81     rocm-runtime
82     rocminfo
83   ];
85   cmakeFlags = [
86     "-DCMAKE_POLICY_DEFAULT_CMP0072=NEW" # Prefer newer OpenGL libraries
87     "-DCLR_BUILD_HIP=ON"
88     "-DCLR_BUILD_OCL=ON"
89     "-DHIP_COMMON_DIR=${hip-common}"
90     "-DHIPCC_BIN_DIR=${hipcc}/bin"
91     "-DHIP_PLATFORM=amd"
92     "-DPROF_API_HEADER_PATH=${roctracer.src}/inc/ext"
93     "-DROCM_PATH=${rocminfo}"
95     # Temporarily set variables to work around upstream CMakeLists issue
96     # Can be removed once https://github.com/ROCm/rocm-cmake/issues/121 is fixed
97     "-DCMAKE_INSTALL_BINDIR=bin"
98     "-DCMAKE_INSTALL_INCLUDEDIR=include"
99     "-DCMAKE_INSTALL_LIBDIR=lib"
100   ];
102   patches = [
103     ./add-missing-operators.patch
104     ./static-functions.patch
105   ];
107   postPatch = ''
108     patchShebangs hipamd/src
110     # We're not on Windows so these are never installed to hipcc...
111     substituteInPlace hipamd/CMakeLists.txt \
112       --replace "install(PROGRAMS \''${HIPCC_BIN_DIR}/hipcc.bat DESTINATION bin)" "" \
113       --replace "install(PROGRAMS \''${HIPCC_BIN_DIR}/hipconfig.bat DESTINATION bin)" ""
115     substituteInPlace hipamd/src/hip_embed_pch.sh \
116       --replace "\''$LLVM_DIR/bin/clang" "${clang}/bin/clang"
118     substituteInPlace opencl/khronos/icd/loader/icd_platform.h \
119       --replace-fail '#define ICD_VENDOR_PATH "/etc/OpenCL/vendors/";' \
120                      '#define ICD_VENDOR_PATH "/run/opengl-driver/etc/OpenCL/vendors/";'
121   '';
123   postInstall = ''
124     patchShebangs $out/bin
126     # hipcc.bin and hipconfig.bin is mysteriously never installed
127     cp -a ${hipcc}/bin/{hipcc.bin,hipconfig.bin} $out/bin
129     wrapProgram $out/bin/hipcc.bin ${lib.concatStringsSep " " wrapperArgs}
130     wrapProgram $out/bin/hipconfig.bin ${lib.concatStringsSep " " wrapperArgs}
131     wrapProgram $out/bin/hipcc.pl ${lib.concatStringsSep " " wrapperArgs}
132     wrapProgram $out/bin/hipconfig.pl ${lib.concatStringsSep " " wrapperArgs}
134     # Just link rocminfo, it's easier
135     ln -s ${rocminfo}/bin/* $out/bin
137     # Replace rocm-opencl-icd functionality
138     mkdir -p $icd/etc/OpenCL/vendors
139     echo "$out/lib/libamdocl64.so" > $icd/etc/OpenCL/vendors/amdocl64.icd
140   '';
142   passthru = {
143     # All known and valid general GPU targets
144     # We cannot use this for each ROCm library, as each defines their own supported targets
145     # See: https://github.com/ROCm/ROCm/blob/77cbac4abab13046ee93d8b5bf410684caf91145/README.md#library-target-matrix
146     gpuTargets = lib.forEach [
147       "803"
148       "900"
149       "906"
150       "908"
151       "90a"
152       "940"
153       "941"
154       "942"
155       "1010"
156       "1012"
157       "1030"
158       "1100"
159       "1101"
160       "1102"
161     ] (target: "gfx${target}");
163     updateScript = rocmUpdateScript {
164       name = finalAttrs.pname;
165       owner = finalAttrs.src.owner;
166       repo = finalAttrs.src.repo;
167       page = "tags?per_page=1";
168       filter = ".[0].name | split(\"-\") | .[1]";
169     };
171     impureTests = {
172       rocm-smi = callPackage ./test-rocm-smi.nix {
173         inherit rocm-smi;
174         clr = finalAttrs.finalPackage;
175       };
176       opencl-example = callPackage ./test-opencl-example.nix {
177         clr = finalAttrs.finalPackage;
178       };
179     };
180   };
182   meta = with lib; {
183     description = "AMD Common Language Runtime for hipamd, opencl, and rocclr";
184     homepage = "https://github.com/ROCm/clr";
185     license = with licenses; [ mit ];
186     maintainers = with maintainers; [ lovesegfault ] ++ teams.rocm.members;
187     platforms = platforms.linux;
188     broken = versions.minor finalAttrs.version != versions.minor stdenv.cc.version || versionAtLeast finalAttrs.version "6.0.0";
189   };