1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
|
{ lib
, stdenv
, fetchFromGitHub
, rocmUpdateScript
, cmake
, rocm-cmake
, ninja
, clr
, git
, libxml2
, libedit
, zstd
, zlib
, ncurses
, python3Packages
, buildRockCompiler ? false
, buildTests ? false # `argument of type 'NoneType' is not iterable`
}:
# Theoretically, we could have our MLIR have an output
# with the source and built objects so that we can just
# use it as the external LLVM repo for this
let
suffix =
if buildRockCompiler
then "-rock"
else "";
llvmNativeTarget =
if stdenv.isx86_64 then "X86"
else if stdenv.isAarch64 then "AArch64"
else throw "Unsupported ROCm LLVM platform";
in stdenv.mkDerivation (finalAttrs: {
pname = "rocmlir${suffix}";
version = "5.7.1";
outputs = [
"out"
] ++ lib.optionals (!buildRockCompiler) [
"external"
];
src = fetchFromGitHub {
owner = "ROCm";
repo = "rocMLIR";
rev = "rocm-${finalAttrs.version}";
hash = "sha256-vPi4UVljohVAfnwDVQqeOVaJPa6v8aV5uBOtqLddTtc=";
};
nativeBuildInputs = [
cmake
rocm-cmake
ninja
clr
python3Packages.python
python3Packages.tomli
];
buildInputs = [
git
libxml2
libedit
];
propagatedBuildInputs = [
zstd
zlib
ncurses
];
cmakeFlags = [
"-DLLVM_TARGETS_TO_BUILD=AMDGPU;${llvmNativeTarget}"
"-DLLVM_ENABLE_ZSTD=ON"
"-DLLVM_ENABLE_ZLIB=ON"
"-DLLVM_ENABLE_TERMINFO=ON"
"-DROCM_PATH=${clr}"
# Manually define CMAKE_INSTALL_<DIR>
# See: https://github.com/NixOS/nixpkgs/pull/197838
"-DCMAKE_INSTALL_BINDIR=bin"
"-DCMAKE_INSTALL_LIBDIR=lib"
"-DCMAKE_INSTALL_INCLUDEDIR=include"
] ++ lib.optionals buildRockCompiler [
"-DBUILD_FAT_LIBROCKCOMPILER=ON"
] ++ lib.optionals (!buildRockCompiler) [
"-DROCM_TEST_CHIPSET=gfx000"
];
postPatch = ''
patchShebangs mlir
substituteInPlace mlir/utils/performance/common/CMakeLists.txt \
--replace "/opt/rocm" "${clr}"
'';
dontBuild = true;
doCheck = true;
# Certain libs aren't being generated, try enabling tests next update
checkTarget = if buildRockCompiler
then "librockCompiler"
else if buildTests
then "check-rocmlir"
else "check-rocmlir-build-only";
postInstall = let
libPath = lib.makeLibraryPath [ zstd zlib ncurses clr stdenv.cc.cc ];
in lib.optionals (!buildRockCompiler) ''
mkdir -p $external/lib
cp -a external/llvm-project/llvm/lib/{*.a*,*.so*} $external/lib
patchelf --set-rpath $external/lib:$out/lib:${libPath} $external/lib/*.so*
patchelf --set-rpath $out/lib:$external/lib:${libPath} $out/{bin/*,lib/*.so*}
'';
passthru.updateScript = rocmUpdateScript {
name = finalAttrs.pname;
owner = finalAttrs.src.owner;
repo = finalAttrs.src.repo;
page = "tags?per_page=2";
filter = ".[1].name | split(\"-\") | .[1]";
};
meta = with lib; {
description = "MLIR-based convolution and GEMM kernel generator";
homepage = "https://github.com/ROCm/rocMLIR";
license = with licenses; [ asl20 ];
maintainers = teams.rocm.members;
platforms = platforms.linux;
broken = versions.minor finalAttrs.version != versions.minor stdenv.cc.version || versionAtLeast finalAttrs.version "6.0.0";
};
})
|