32 , buildDocs ? false # Needs internet because of rocm-docs-core
40 src = fetchFromGitHub {
43 rev = "rocm-${version}";
44 hash = "sha256-xcKmFI8HcRA9bbh6EQGElKykIQ3RJX/q5f4IxXvM1Is=";
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...
52 export HOME=$(mktemp -d)
55 # We need more history to fetch LFS files
56 git remote add origin $url
59 git checkout rocm-${version}
61 # We need to do this manually since using leaveDotGit and fetchSubmodules errors
62 git submodule update --init
69 # Remove the defunct .git folder
74 latex = lib.optionalAttrs buildDocs (texliveSmall.withPackages (ps: with ps; [
87 gfx900 = runCommand "miopen-gfx900.kdb" { preferLocalBuild = true; } ''
88 ${lbzip2}/bin/lbzip2 -ckd ${src}/src/kernels/gfx900.kdb.bz2 > $out
91 gfx906 = runCommand "miopen-gfx906.kdb" { preferLocalBuild = true; } ''
92 ${lbzip2}/bin/lbzip2 -ckd ${src}/src/kernels/gfx906.kdb.bz2 > $out
95 gfx908 = runCommand "miopen-gfx908.kdb" { preferLocalBuild = true; } ''
96 ${lbzip2}/bin/lbzip2 -ckd ${src}/src/kernels/gfx908.kdb.bz2 > $out
99 gfx90a = runCommand "miopen-gfx90a.kdb" { preferLocalBuild = true; } ''
100 ${lbzip2}/bin/lbzip2 -ckd ${src}/src/kernels/gfx90a.kdb.bz2 > $out
103 gfx1030 = runCommand "miopen-gfx1030.kdb" { preferLocalBuild = true; } ''
104 ${lbzip2}/bin/lbzip2 -ckd ${src}/src/kernels/gfx1030.kdb.bz2 > $out
106 in stdenv.mkDerivation (finalAttrs: {
110 # Find zstd and add to target. Mainly for torch.
113 url = "https://github.com/ROCm/MIOpen/commit/e608b4325646afeabb5e52846997b926d2019d19.patch";
114 hash = "sha256-oxa3qlIC2bzbwGxrQOZXoY/S7CpLsMrnWRB7Og0tk0M=";
117 url = "https://github.com/ROCm/MIOpen/commit/3413d2daaeb44b7d6eadcc03033a5954a118491e.patch";
118 hash = "sha256-ST4snUcTmmSI1Ogx815KEX9GdMnmubsavDzXCGJkiKs=";
124 ] ++ lib.optionals buildDocs [
126 ] ++ lib.optionals buildTests [
130 nativeBuildInputs = [
150 ] ++ lib.optionals buildDocs [
155 python3Packages.sphinx-rtd-theme
156 python3Packages.breathe
157 python3Packages.myst-parser
158 ] ++ lib.optionals buildTests [
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 [
180 "-DMIOPEN_TEST_ALL=ON"
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
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
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 ''
222 mv bin/test_* $test/bin
223 patchelf --set-rpath $out/lib:${lib.makeLibraryPath (finalAttrs.buildInputs ++
224 [ clr rocm-comgr ])} $test/bin/*
227 requiredSystemFeatures = [ "big-parallel" ];
229 passthru.updateScript = rocmUpdateScript {
230 name = finalAttrs.pname;
231 owner = finalAttrs.src.owner;
232 repo = finalAttrs.src.repo;
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";