2022-11-04 12:27:35 +00:00
|
|
|
{ lib
|
|
|
|
, stdenv
|
|
|
|
, fetchFromGitHub
|
2022-12-17 10:02:37 +00:00
|
|
|
, rocmUpdateScript
|
2022-11-04 12:27:35 +00:00
|
|
|
, cmake
|
2023-10-19 13:55:26 +00:00
|
|
|
, rocm-cmake
|
2023-01-20 10:41:00 +00:00
|
|
|
, ninja
|
2023-10-19 13:55:26 +00:00
|
|
|
, clr
|
2022-12-17 10:02:37 +00:00
|
|
|
, git
|
|
|
|
, libxml2
|
|
|
|
, libedit
|
2023-10-19 13:55:26 +00:00
|
|
|
, zstd
|
2023-01-20 10:41:00 +00:00
|
|
|
, zlib
|
|
|
|
, ncurses
|
2023-10-19 13:55:26 +00:00
|
|
|
, python3Packages
|
2023-01-20 10:41:00 +00:00
|
|
|
, buildRockCompiler ? false
|
2023-10-19 13:55:26 +00:00
|
|
|
, buildTests ? false # `argument of type 'NoneType' is not iterable`
|
2022-11-04 12:27:35 +00:00
|
|
|
}:
|
|
|
|
|
2023-01-20 10:41:00 +00:00
|
|
|
# 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
|
2023-10-19 13:55:26 +00:00
|
|
|
suffix =
|
|
|
|
if buildRockCompiler
|
|
|
|
then "-rock"
|
|
|
|
else "";
|
|
|
|
|
2023-01-20 10:41:00 +00:00
|
|
|
llvmNativeTarget =
|
|
|
|
if stdenv.isx86_64 then "X86"
|
|
|
|
else if stdenv.isAarch64 then "AArch64"
|
|
|
|
else throw "Unsupported ROCm LLVM platform";
|
|
|
|
in stdenv.mkDerivation (finalAttrs: {
|
2023-10-19 13:55:26 +00:00
|
|
|
pname = "rocmlir${suffix}";
|
2023-11-16 04:20:00 +00:00
|
|
|
version = "5.7.1";
|
2023-01-20 10:41:00 +00:00
|
|
|
|
|
|
|
outputs = [
|
|
|
|
"out"
|
|
|
|
] ++ lib.optionals (!buildRockCompiler) [
|
|
|
|
"external"
|
|
|
|
];
|
2022-11-04 12:27:35 +00:00
|
|
|
|
|
|
|
src = fetchFromGitHub {
|
|
|
|
owner = "ROCmSoftwarePlatform";
|
|
|
|
repo = "rocMLIR";
|
2022-12-02 08:20:57 +00:00
|
|
|
rev = "rocm-${finalAttrs.version}";
|
2023-10-19 13:55:26 +00:00
|
|
|
hash = "sha256-vPi4UVljohVAfnwDVQqeOVaJPa6v8aV5uBOtqLddTtc=";
|
2022-11-04 12:27:35 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
nativeBuildInputs = [
|
|
|
|
cmake
|
2023-10-19 13:55:26 +00:00
|
|
|
rocm-cmake
|
2023-01-20 10:41:00 +00:00
|
|
|
ninja
|
2023-10-19 13:55:26 +00:00
|
|
|
clr
|
|
|
|
python3Packages.python
|
|
|
|
python3Packages.tomli
|
2022-11-04 12:27:35 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
buildInputs = [
|
2022-12-17 10:02:37 +00:00
|
|
|
git
|
|
|
|
libxml2
|
|
|
|
libedit
|
2022-11-04 12:27:35 +00:00
|
|
|
];
|
|
|
|
|
2023-01-20 10:41:00 +00:00
|
|
|
propagatedBuildInputs = [
|
2023-10-19 13:55:26 +00:00
|
|
|
zstd
|
2023-01-20 10:41:00 +00:00
|
|
|
zlib
|
|
|
|
ncurses
|
|
|
|
];
|
|
|
|
|
2022-11-04 12:27:35 +00:00
|
|
|
cmakeFlags = [
|
2023-01-20 10:41:00 +00:00
|
|
|
"-DLLVM_TARGETS_TO_BUILD=AMDGPU;${llvmNativeTarget}"
|
2023-10-19 13:55:26 +00:00
|
|
|
"-DLLVM_ENABLE_ZSTD=ON"
|
2023-01-20 10:41:00 +00:00
|
|
|
"-DLLVM_ENABLE_ZLIB=ON"
|
|
|
|
"-DLLVM_ENABLE_TERMINFO=ON"
|
2023-10-19 13:55:26 +00:00
|
|
|
"-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"
|
2023-01-20 10:41:00 +00:00
|
|
|
] ++ lib.optionals buildRockCompiler [
|
2022-12-17 10:02:37 +00:00
|
|
|
"-DBUILD_FAT_LIBROCKCOMPILER=ON"
|
2023-01-20 10:41:00 +00:00
|
|
|
] ++ lib.optionals (!buildRockCompiler) [
|
|
|
|
"-DROCM_TEST_CHIPSET=gfx000"
|
2022-11-04 12:27:35 +00:00
|
|
|
];
|
|
|
|
|
2023-10-19 13:55:26 +00:00
|
|
|
postPatch = ''
|
|
|
|
patchShebangs mlir
|
|
|
|
|
|
|
|
substituteInPlace mlir/utils/performance/common/CMakeLists.txt \
|
|
|
|
--replace "/opt/rocm" "${clr}"
|
|
|
|
'';
|
|
|
|
|
2023-01-20 10:41:00 +00:00
|
|
|
dontBuild = true;
|
|
|
|
doCheck = true;
|
|
|
|
|
|
|
|
# Certain libs aren't being generated, try enabling tests next update
|
|
|
|
checkTarget = if buildRockCompiler
|
|
|
|
then "librockCompiler"
|
2023-10-19 13:55:26 +00:00
|
|
|
else if buildTests
|
|
|
|
then "check-rocmlir"
|
|
|
|
else "check-rocmlir-build-only";
|
2023-01-20 10:41:00 +00:00
|
|
|
|
|
|
|
postInstall = let
|
2023-10-19 13:55:26 +00:00
|
|
|
libPath = lib.makeLibraryPath [ zstd zlib ncurses clr stdenv.cc.cc ];
|
2023-01-20 10:41:00 +00:00
|
|
|
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*}
|
|
|
|
'';
|
|
|
|
|
2022-12-17 10:02:37 +00:00
|
|
|
passthru.updateScript = rocmUpdateScript {
|
|
|
|
name = finalAttrs.pname;
|
|
|
|
owner = finalAttrs.src.owner;
|
|
|
|
repo = finalAttrs.src.repo;
|
|
|
|
page = "tags?per_page=2";
|
|
|
|
filter = ".[1].name | split(\"-\") | .[1]";
|
|
|
|
};
|
2022-11-27 09:42:12 +00:00
|
|
|
|
2022-11-04 12:27:35 +00:00
|
|
|
meta = with lib; {
|
|
|
|
description = "MLIR-based convolution and GEMM kernel generator";
|
|
|
|
homepage = "https://github.com/ROCmSoftwarePlatform/rocMLIR";
|
|
|
|
license = with licenses; [ asl20 ];
|
2022-11-27 09:42:12 +00:00
|
|
|
maintainers = teams.rocm.members;
|
2023-01-20 10:41:00 +00:00
|
|
|
platforms = platforms.linux;
|
|
|
|
broken = versions.minor finalAttrs.version != versions.minor stdenv.cc.version;
|
2022-11-04 12:27:35 +00:00
|
|
|
};
|
2022-11-27 09:42:12 +00:00
|
|
|
})
|