nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{
2 lib,
3 stdenv,
4 fetchFromGitHub,
5 rocmUpdateScript,
6 pkg-config,
7 cmake,
8 rocm-cmake,
9 clr,
10 openmp,
11 rocblas,
12 hipblas-common,
13 hipblas,
14 hipblaslt,
15 rocmlir,
16 miopen,
17 protobuf,
18 abseil-cpp,
19 half,
20 nlohmann_json,
21 boost,
22 msgpack-cxx,
23 sqlite,
24 # TODO(@LunNova): Swap to `oneDNN` once v3 is supported
25 # Upstream issue: https://github.com/ROCm/AMDMIGraphX/issues/4351
26 oneDNN_2,
27 blaze,
28 texliveSmall,
29 doxygen,
30 sphinx,
31 docutils,
32 ghostscript,
33 python3Packages,
34 writableTmpDirAsHomeHook,
35 buildDocs ? false,
36 buildTests ? false,
37 gpuTargets ? clr.gpuTargets,
38}:
39
40let
41 latex = lib.optionalAttrs buildDocs (
42 texliveSmall.withPackages (
43 ps: with ps; [
44 latexmk
45 tex-gyre
46 fncychap
47 wrapfig
48 capt-of
49 framed
50 needspace
51 tabulary
52 varwidth
53 titlesec
54 epstopdf
55 ]
56 )
57 );
58in
59stdenv.mkDerivation (finalAttrs: {
60 pname = "migraphx";
61 version = "7.1.1";
62
63 outputs = [
64 "out"
65 ]
66 ++ lib.optionals buildDocs [
67 "doc"
68 ]
69 ++ lib.optionals buildTests [
70 "test"
71 ];
72
73 src = fetchFromGitHub {
74 owner = "ROCm";
75 repo = "AMDMIGraphX";
76 rev = "rocm-${finalAttrs.version}";
77 hash = "sha256-s6w4bF7koK4wnf6leVKBzwIB4X2ROHa3EgX6XuJIAew=";
78 };
79
80 nativeBuildInputs = [
81 pkg-config
82 cmake
83 rocm-cmake
84 clr
85 python3Packages.python
86 ]
87 ++ lib.optionals buildDocs [
88 latex
89 doxygen
90 sphinx
91 docutils
92 ghostscript
93 python3Packages.sphinx-rtd-theme
94 python3Packages.breathe
95 writableTmpDirAsHomeHook
96 ];
97
98 buildInputs = [
99 openmp
100 rocblas
101 hipblas-common
102 hipblas
103 hipblaslt
104 rocmlir
105 miopen
106 protobuf
107 half
108 nlohmann_json
109 boost
110 msgpack-cxx
111 sqlite
112 oneDNN_2
113 blaze
114 python3Packages.pybind11
115 python3Packages.onnx
116 ];
117
118 env.LDFLAGS = "-Wl,--allow-shlib-undefined";
119
120 cmakeFlags = [
121 "-DMIGRAPHX_ENABLE_GPU=ON"
122 "-DMIGRAPHX_ENABLE_CPU=ON"
123 "-DMIGRAPHX_ENABLE_FPGA=ON"
124 "-DMIGRAPHX_ENABLE_MLIR=OFF" # LLVM or rocMLIR mismatch?
125 "-DCMAKE_C_COMPILER=amdclang"
126 "-DCMAKE_CXX_COMPILER=amdclang++"
127 "-DCMAKE_VERBOSE_MAKEFILE=ON"
128 "-DEMBED_USE=CArrays" # Fixes error with lld
129 "-DDMIGRAPHX_ENABLE_PYTHON=ON"
130 "-DROCM_PATH=${clr}"
131 "-DHIP_ROOT_DIR=${clr}"
132 # migraphx relies on an incompatible fork of composable_kernel
133 # migraphxs relies on miopen which relies on current composable_kernel
134 # impossible to build with this ON; we can't link both of them even if we package both
135 "-DMIGRAPHX_USE_COMPOSABLEKERNEL=OFF"
136 # Manually define CMAKE_INSTALL_<DIR>
137 # See: https://github.com/NixOS/nixpkgs/pull/197838
138 "-DCMAKE_INSTALL_BINDIR=bin"
139 "-DCMAKE_INSTALL_LIBDIR=lib"
140 "-DCMAKE_INSTALL_INCLUDEDIR=include"
141 "-DGPU_TARGETS=${lib.concatStringsSep ";" gpuTargets}"
142 ];
143
144 postPatch = ''
145 export CXXFLAGS+=" -w -isystem${rocmlir}/include/rocmlir -I${half}/include -I${lib.getInclude abseil-cpp}/include -I${hipblas-common}/include -I${lib.getInclude protobuf}/include"
146 patchShebangs tools
147
148 # `error: '__clang_hip_runtime_wrapper.h' file not found [clang-diagnostic-error]`
149 substituteInPlace CMakeLists.txt \
150 --replace "set(MIGRAPHX_TIDY_ERRORS ALL)" ""
151
152 # Fix Unicode minus sign (U+2212) in comment that breaks EMBED_USE=CArrays
153 # The embed mechanism generates char[] arrays that can't store unicode −
154 # which has values >127
155 substituteInPlace src/targets/gpu/kernels/include/migraphx/kernels/bit.hpp \
156 --replace-fail "// popcount(~(x | −x))" "// popcount(~(x | -x))"
157 ''
158 + lib.optionalString (!buildDocs) ''
159 substituteInPlace CMakeLists.txt \
160 --replace "add_subdirectory(doc)" ""
161 ''
162 + lib.optionalString (!buildTests) ''
163 substituteInPlace CMakeLists.txt \
164 --replace "add_subdirectory(test)" ""
165 '';
166
167 # Unfortunately, it seems like we have to call make on this manually
168 preInstall = lib.optionalString buildDocs ''
169 make -j$NIX_BUILD_CORES doc
170 cd ../doc/pdf
171 make -j$NIX_BUILD_CORES
172 cd -
173 '';
174
175 postInstall =
176 lib.optionalString buildDocs ''
177 mv ../doc/html $out/share/doc/migraphx
178 mv ../doc/pdf/MIGraphX.pdf $out/share/doc/migraphx
179 ''
180 + lib.optionalString buildTests ''
181 mkdir -p $test/bin
182 mv bin/test_* $test/bin
183 patchelf $test/bin/test_* --shrink-rpath --allowed-rpath-prefixes "$NIX_STORE"
184 '';
185
186 passthru.updateScript = rocmUpdateScript {
187 name = finalAttrs.pname;
188 inherit (finalAttrs.src) owner;
189 inherit (finalAttrs.src) repo;
190 };
191
192 meta = {
193 description = "AMD's graph optimization engine";
194 homepage = "https://github.com/ROCm/AMDMIGraphX";
195 license = with lib.licenses; [ mit ];
196 teams = [ lib.teams.rocm ];
197 platforms = lib.platforms.linux;
198 };
199})