biome: 1.9.2 -> 1.9.3 (#349335)
[NixPkgs.git] / pkgs / development / rocm-modules / 5 / miopen / default.nix
blob1c072ef1a304d3d765106e23491a71011050d2d0
1 { lib
2 , stdenv
3 , fetchFromGitHub
4 , fetchpatch
5 , rocmUpdateScript
6 , runCommand
7 , pkg-config
8 , cmake
9 , rocm-cmake
10 , rocblas
11 , rocmlir
12 , clr
13 , clang-tools-extra
14 , clang-ocl
15 , miopengemm
16 , composable_kernel
17 , frugally-deep
18 , rocm-docs-core
19 , half
20 , boost
21 , sqlite
22 , bzip2
23 , lbzip2
24 , nlohmann_json
25 , texliveSmall
26 , doxygen
27 , sphinx
28 , zlib
29 , gtest
30 , rocm-comgr
31 , python3Packages
32 , buildDocs ? false # Needs internet because of rocm-docs-core
33 , buildTests ? false
34 , useOpenCL ? false
37 let
38   version = "5.7.1";
40   src = fetchFromGitHub {
41     owner = "ROCm";
42     repo = "MIOpen";
43     rev = "rocm-${version}";
44     hash = "sha256-xcKmFI8HcRA9bbh6EQGElKykIQ3RJX/q5f4IxXvM1Is=";
45     fetchLFS = true;
46     leaveDotGit = true;
48     # If you're reading this, it's gonna take a bit of time.
49     # fetchSubModules doesn't work with postFetch???
50     # fetchLFS isn't actually fetching the LFS files...
51     postFetch = ''
52       export HOME=$(mktemp -d)
53       cd $out
55       # We need more history to fetch LFS files
56       git remote add origin $url
57       git fetch origin
58       git clean -fdx
59       git checkout rocm-${version}
61       # We need to do this manually since using leaveDotGit and fetchSubmodules errors
62       git submodule update --init
64       # Fetch the LFS files
65       git lfs install
66       git lfs fetch --all
67       git lfs checkout
69       # Remove the defunct .git folder
70       rm -rf .git
71     '';
72   };
74   latex = lib.optionalAttrs buildDocs (texliveSmall.withPackages (ps: with ps; [
75     latexmk
76     tex-gyre
77     fncychap
78     wrapfig
79     capt-of
80     framed
81     needspace
82     tabulary
83     varwidth
84     titlesec
85   ]));
87   gfx900 = runCommand "miopen-gfx900.kdb" { preferLocalBuild = true; } ''
88     ${lbzip2}/bin/lbzip2 -ckd ${src}/src/kernels/gfx900.kdb.bz2 > $out
89   '';
91   gfx906 = runCommand "miopen-gfx906.kdb" { preferLocalBuild = true; } ''
92     ${lbzip2}/bin/lbzip2 -ckd ${src}/src/kernels/gfx906.kdb.bz2 > $out
93   '';
95   gfx908 = runCommand "miopen-gfx908.kdb" { preferLocalBuild = true; } ''
96     ${lbzip2}/bin/lbzip2 -ckd ${src}/src/kernels/gfx908.kdb.bz2 > $out
97   '';
99   gfx90a = runCommand "miopen-gfx90a.kdb" { preferLocalBuild = true; } ''
100     ${lbzip2}/bin/lbzip2 -ckd ${src}/src/kernels/gfx90a.kdb.bz2 > $out
101   '';
103   gfx1030 = runCommand "miopen-gfx1030.kdb" { preferLocalBuild = true; } ''
104     ${lbzip2}/bin/lbzip2 -ckd ${src}/src/kernels/gfx1030.kdb.bz2 > $out
105   '';
106 in stdenv.mkDerivation (finalAttrs: {
107   inherit version src;
108   pname = "miopen";
110   # Find zstd and add to target. Mainly for torch.
111   patches = [
112     (fetchpatch {
113       url = "https://github.com/ROCm/MIOpen/commit/e608b4325646afeabb5e52846997b926d2019d19.patch";
114       hash = "sha256-oxa3qlIC2bzbwGxrQOZXoY/S7CpLsMrnWRB7Og0tk0M=";
115     })
116     (fetchpatch {
117       url = "https://github.com/ROCm/MIOpen/commit/3413d2daaeb44b7d6eadcc03033a5954a118491e.patch";
118       hash = "sha256-ST4snUcTmmSI1Ogx815KEX9GdMnmubsavDzXCGJkiKs=";
119     })
120   ];
122   outputs = [
123     "out"
124   ] ++ lib.optionals buildDocs [
125     "doc"
126   ] ++ lib.optionals buildTests [
127     "test"
128   ];
130   nativeBuildInputs = [
131     pkg-config
132     cmake
133     rocm-cmake
134     clr
135     clang-tools-extra
136   ];
138   buildInputs = [
139     rocblas
140     rocmlir
141     clang-ocl
142     miopengemm
143     composable_kernel
144     half
145     boost
146     sqlite
147     bzip2
148     nlohmann_json
149     frugally-deep
150   ] ++ lib.optionals buildDocs [
151     latex
152     doxygen
153     sphinx
154     rocm-docs-core
155     python3Packages.sphinx-rtd-theme
156     python3Packages.breathe
157     python3Packages.myst-parser
158   ] ++ lib.optionals buildTests [
159     gtest
160     zlib
161   ];
163   cmakeFlags = [
164     "-DCMAKE_CXX_FLAGS=-Wno-#warnings" # <half> -> <half/half.hpp>
165     "-DMIOPEN_USE_MIOPENGEMM=ON"
166     "-DUNZIPPER=${bzip2}/bin/bunzip2"
167     # Manually define CMAKE_INSTALL_<DIR>
168     # See: https://github.com/NixOS/nixpkgs/pull/197838
169     "-DCMAKE_INSTALL_BINDIR=bin"
170     "-DCMAKE_INSTALL_LIBDIR=lib"
171     "-DCMAKE_INSTALL_INCLUDEDIR=include"
172   ] ++ lib.optionals (!useOpenCL) [
173     "-DCMAKE_C_COMPILER=hipcc"
174     "-DCMAKE_CXX_COMPILER=hipcc"
175     "-DMIOPEN_BACKEND=HIP"
176   ] ++ lib.optionals useOpenCL [
177     "-DMIOPEN_BACKEND=OpenCL"
178   ] ++ lib.optionals buildTests [
179     "-DBUILD_TESTS=ON"
180     "-DMIOPEN_TEST_ALL=ON"
181   ];
183   postPatch = ''
184     patchShebangs test src/composable_kernel fin utils install_deps.cmake
186     substituteInPlace CMakeLists.txt \
187       --replace "unpack_db(\"\''${CMAKE_SOURCE_DIR}/src/kernels/\''${FILE_NAME}.kdb.bz2\")" "" \
188       --replace "MIOPEN_HIP_COMPILER MATCHES \".*clang\\\\+\\\\+$\"" "true" \
189       --replace "set(MIOPEN_TIDY_ERRORS ALL)" "" # error: missing required key 'key'
191     substituteInPlace test/gtest/CMakeLists.txt \
192       --replace "include(googletest)" ""
194     substituteInPlace test/gtest/CMakeLists.txt \
195       --replace-fail " gtest_main " " ${gtest}/lib/libgtest.so ${gtest}/lib/libgtest_main.so "
197     ln -sf ${gfx900} src/kernels/gfx900.kdb
198     ln -sf ${gfx906} src/kernels/gfx906.kdb
199     ln -sf ${gfx908} src/kernels/gfx908.kdb
200     ln -sf ${gfx90a} src/kernels/gfx90a.kdb
201     ln -sf ${gfx1030} src/kernels/gfx1030.kdb
202   '';
204   # Unfortunately, it seems like we have to call make on these manually
205   postBuild = lib.optionalString buildDocs ''
206     python -m sphinx -T -E -b html -d _build/doctrees -D language=en ../docs _build/html
207   '' + lib.optionalString buildTests ''
208     make -j$NIX_BUILD_CORES check
209   '';
211   postInstall = ''
212     rm $out/bin/install_precompiled_kernels.sh
213     ln -sf ${gfx900} $out/share/miopen/db/gfx900.kdb
214     ln -sf ${gfx906} $out/share/miopen/db/gfx906.kdb
215     ln -sf ${gfx908} $out/share/miopen/db/gfx908.kdb
216     ln -sf ${gfx90a} $out/share/miopen/db/gfx90a.kdb
217     ln -sf ${gfx1030} $out/share/miopen/db/gfx1030.kdb
218   '' + lib.optionalString buildDocs ''
219     mv ../doc/html $out/share/doc/miopen-${if useOpenCL then "opencl" else "hip"}
220   '' + lib.optionalString buildTests ''
221     mkdir -p $test/bin
222     mv bin/test_* $test/bin
223     patchelf --set-rpath $out/lib:${lib.makeLibraryPath (finalAttrs.buildInputs ++
224       [ clr rocm-comgr ])} $test/bin/*
225   '';
227   requiredSystemFeatures = [ "big-parallel" ];
229   passthru.updateScript = rocmUpdateScript {
230     name = finalAttrs.pname;
231     owner = finalAttrs.src.owner;
232     repo = finalAttrs.src.repo;
233   };
235   meta = with lib; {
236     description = "Machine intelligence library for ROCm";
237     homepage = "https://github.com/ROCm/MIOpen";
238     license = with licenses; [ mit ];
239     maintainers = teams.rocm.members;
240     platforms = platforms.linux;
241     broken = versions.minor finalAttrs.version != versions.minor stdenv.cc.version || versionAtLeast finalAttrs.version "6.0.0";
242   };