2023-11-13 13:58:12 +01:00
|
|
|
{ lib
|
2023-10-07 01:18:24 +02:00
|
|
|
, stdenv
|
|
|
|
, fetchFromGitHub
|
2023-11-13 13:58:12 +01:00
|
|
|
, pkgsBuildBuild
|
2023-10-07 01:18:24 +02:00
|
|
|
, pkg-config
|
|
|
|
, cmake
|
|
|
|
, ninja
|
|
|
|
, git
|
|
|
|
, libxml2
|
|
|
|
, libxcrypt
|
|
|
|
, libedit
|
|
|
|
, libffi
|
2023-11-13 13:58:12 +01:00
|
|
|
, libpfm
|
2023-10-07 01:18:24 +02:00
|
|
|
, mpfr
|
|
|
|
, zlib
|
|
|
|
, ncurses
|
2023-11-13 13:58:12 +01:00
|
|
|
, doxygen
|
|
|
|
, sphinx
|
|
|
|
, which
|
|
|
|
, sysctl
|
2023-10-07 01:18:24 +02:00
|
|
|
, python3Packages
|
|
|
|
, buildDocs ? true
|
|
|
|
, buildMan ? true
|
|
|
|
, buildTests ? true
|
2023-11-13 13:58:12 +01:00
|
|
|
, llvmTargetsToBuild ? [ "NATIVE" ] # "NATIVE" resolves into x86 or aarch64 depending on stdenv
|
|
|
|
, llvmProjectsToBuild ? [ "llvm" "mlir" ]
|
2023-10-07 01:18:24 +02:00
|
|
|
}:
|
|
|
|
|
2023-11-13 13:58:12 +01:00
|
|
|
let
|
|
|
|
llvmNativeTarget =
|
|
|
|
if stdenv.hostPlatform.isx86_64 then "X86"
|
|
|
|
else if stdenv.hostPlatform.isAarch64 then "AArch64"
|
|
|
|
else throw "Currently unsupported LLVM platform '${stdenv.hostPlatform.config}'";
|
|
|
|
|
|
|
|
inferNativeTarget = t: if t == "NATIVE" then llvmNativeTarget else t;
|
|
|
|
llvmTargetsToBuild' = [ "AMDGPU" "NVPTX" ] ++ builtins.map inferNativeTarget llvmTargetsToBuild;
|
|
|
|
|
|
|
|
# This LLVM version can't seem to find pygments/pyyaml,
|
|
|
|
# but a later update will likely fix this (openai-triton-2.1.0)
|
|
|
|
python =
|
|
|
|
if buildTests
|
|
|
|
then python3Packages.python.withPackages (p: with p; [ psutil pygments pyyaml ])
|
|
|
|
else python3Packages.python;
|
|
|
|
|
|
|
|
isNative = stdenv.hostPlatform == stdenv.buildPlatform;
|
|
|
|
in stdenv.mkDerivation (finalAttrs: {
|
2023-10-24 01:39:33 +02:00
|
|
|
pname = "openai-triton-llvm";
|
2023-12-05 21:57:10 +01:00
|
|
|
version = "17.0.0-c5dede880d17";
|
2023-10-07 01:18:24 +02:00
|
|
|
|
|
|
|
outputs = [
|
|
|
|
"out"
|
|
|
|
] ++ lib.optionals buildDocs [
|
|
|
|
"doc"
|
|
|
|
] ++ lib.optionals buildMan [
|
|
|
|
"man"
|
|
|
|
];
|
|
|
|
|
2023-11-13 13:58:12 +01:00
|
|
|
# See https://github.com/openai/triton/blob/main/python/setup.py
|
|
|
|
# and https://github.com/ptillet/triton-llvm-releases/releases
|
2023-10-07 01:18:24 +02:00
|
|
|
src = fetchFromGitHub {
|
|
|
|
owner = "llvm";
|
|
|
|
repo = "llvm-project";
|
2023-12-05 21:57:10 +01:00
|
|
|
rev = "c5dede880d175f7229c9b2923f4753e12702305d";
|
|
|
|
hash = "sha256-v4r3+7XVFK+Dzxt/rErZNJ9REqFO3JmGN4X4vZ+77ew=";
|
2023-10-07 01:18:24 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
nativeBuildInputs = [
|
|
|
|
pkg-config
|
|
|
|
cmake
|
|
|
|
ninja
|
|
|
|
git
|
2023-11-13 13:58:12 +01:00
|
|
|
python
|
2023-10-07 01:18:24 +02:00
|
|
|
] ++ lib.optionals (buildDocs || buildMan) [
|
|
|
|
doxygen
|
|
|
|
sphinx
|
|
|
|
python3Packages.recommonmark
|
|
|
|
];
|
|
|
|
|
|
|
|
buildInputs = [
|
|
|
|
libxml2
|
|
|
|
libxcrypt
|
|
|
|
libedit
|
|
|
|
libffi
|
2023-11-13 13:58:12 +01:00
|
|
|
libpfm
|
2023-10-07 01:18:24 +02:00
|
|
|
mpfr
|
|
|
|
];
|
|
|
|
|
|
|
|
propagatedBuildInputs = [
|
|
|
|
zlib
|
|
|
|
ncurses
|
|
|
|
];
|
|
|
|
|
|
|
|
sourceRoot = "${finalAttrs.src.name}/llvm";
|
|
|
|
|
|
|
|
cmakeFlags = [
|
2023-11-13 13:58:12 +01:00
|
|
|
(lib.cmakeFeature "LLVM_TARGETS_TO_BUILD" (lib.concatStringsSep ";" llvmTargetsToBuild'))
|
|
|
|
(lib.cmakeFeature "LLVM_ENABLE_PROJECTS" (lib.concatStringsSep ";" llvmProjectsToBuild))
|
|
|
|
(lib.cmakeFeature "LLVM_HOST_TRIPLE" stdenv.hostPlatform.config)
|
|
|
|
(lib.cmakeFeature "LLVM_DEFAULT_TARGET_TRIPLE" stdenv.hostPlatform.config)
|
|
|
|
(lib.cmakeBool "LLVM_INSTALL_UTILS" true)
|
|
|
|
(lib.cmakeBool "LLVM_INCLUDE_DOCS" (buildDocs || buildMan))
|
|
|
|
(lib.cmakeBool "MLIR_INCLUDE_DOCS" (buildDocs || buildMan))
|
|
|
|
(lib.cmakeBool "LLVM_BUILD_DOCS" (buildDocs || buildMan))
|
|
|
|
# Way too slow, only uses one core
|
|
|
|
# (lib.cmakeBool "LLVM_ENABLE_DOXYGEN" (buildDocs || buildMan))
|
|
|
|
(lib.cmakeBool "LLVM_ENABLE_SPHINX" (buildDocs || buildMan))
|
|
|
|
(lib.cmakeBool "SPHINX_OUTPUT_HTML" buildDocs)
|
|
|
|
(lib.cmakeBool "SPHINX_OUTPUT_MAN" buildMan)
|
|
|
|
(lib.cmakeBool "SPHINX_WARNINGS_AS_ERRORS" false)
|
|
|
|
(lib.cmakeBool "LLVM_INCLUDE_TESTS" buildTests)
|
|
|
|
(lib.cmakeBool "MLIR_INCLUDE_TESTS" buildTests)
|
|
|
|
(lib.cmakeBool "LLVM_BUILD_TESTS" buildTests)
|
|
|
|
# Cross compilation code taken/modified from LLVM 16 derivation
|
|
|
|
] ++ lib.optionals (!isNative) (let
|
|
|
|
nativeToolchainFlags = let
|
|
|
|
nativeCC = pkgsBuildBuild.targetPackages.stdenv.cc;
|
|
|
|
nativeBintools = nativeCC.bintools.bintools;
|
|
|
|
in [
|
|
|
|
(lib.cmakeFeature "CMAKE_C_COMPILER" "${nativeCC}/bin/${nativeCC.targetPrefix}cc")
|
|
|
|
(lib.cmakeFeature "CMAKE_CXX_COMPILER" "${nativeCC}/bin/${nativeCC.targetPrefix}c++")
|
|
|
|
(lib.cmakeFeature "CMAKE_AR" "${nativeBintools}/bin/${nativeBintools.targetPrefix}ar")
|
|
|
|
(lib.cmakeFeature "CMAKE_STRIP" "${nativeBintools}/bin/${nativeBintools.targetPrefix}strip")
|
|
|
|
(lib.cmakeFeature "CMAKE_RANLIB" "${nativeBintools}/bin/${nativeBintools.targetPrefix}ranlib")
|
|
|
|
];
|
|
|
|
|
|
|
|
# We need to repass the custom GNUInstallDirs values, otherwise CMake
|
|
|
|
# will choose them for us, leading to wrong results in llvm-config-native
|
|
|
|
nativeInstallFlags = [
|
|
|
|
(lib.cmakeFeature "CMAKE_INSTALL_PREFIX" (placeholder "out"))
|
|
|
|
(lib.cmakeFeature "CMAKE_INSTALL_BINDIR" "${placeholder "out"}/bin")
|
|
|
|
(lib.cmakeFeature "CMAKE_INSTALL_INCLUDEDIR" "${placeholder "out"}/include")
|
|
|
|
(lib.cmakeFeature "CMAKE_INSTALL_LIBDIR" "${placeholder "out"}/lib")
|
|
|
|
(lib.cmakeFeature "CMAKE_INSTALL_LIBEXECDIR" "${placeholder "out"}/libexec")
|
|
|
|
];
|
|
|
|
in [
|
|
|
|
(lib.cmakeBool "CMAKE_CROSSCOMPILING" true)
|
|
|
|
(lib.cmakeFeature "CROSS_TOOLCHAIN_FLAGS_NATIVE" (lib.concatStringsSep ";"
|
|
|
|
(lib.concatLists [ nativeToolchainFlags nativeInstallFlags ])))
|
|
|
|
]);
|
2023-10-07 01:18:24 +02:00
|
|
|
|
|
|
|
postPatch = ''
|
|
|
|
# `CMake Error: cannot write to file "/build/source/llvm/build/lib/cmake/mlir/MLIRTargets.cmake": Permission denied`
|
|
|
|
chmod +w -R ../mlir
|
2023-11-13 13:58:12 +01:00
|
|
|
patchShebangs ../mlir/test/mlir-reduce
|
2023-10-07 01:18:24 +02:00
|
|
|
|
|
|
|
# FileSystem permissions tests fail with various special bits
|
|
|
|
rm test/tools/llvm-objcopy/ELF/mirror-permissions-unix.test
|
|
|
|
rm unittests/Support/Path.cpp
|
|
|
|
|
|
|
|
substituteInPlace unittests/Support/CMakeLists.txt \
|
|
|
|
--replace "Path.cpp" ""
|
2023-11-13 13:58:12 +01:00
|
|
|
'' + lib.optionalString stdenv.isAarch64 ''
|
|
|
|
# Not sure why this fails
|
|
|
|
rm test/tools/llvm-exegesis/AArch64/latency-by-opcode-name.s
|
|
|
|
'';
|
|
|
|
|
|
|
|
postInstall = lib.optionalString (!isNative) ''
|
|
|
|
cp -a NATIVE/bin/llvm-config $out/bin/llvm-config-native
|
2023-10-07 01:18:24 +02:00
|
|
|
'';
|
|
|
|
|
|
|
|
doCheck = buildTests;
|
2023-11-13 13:58:12 +01:00
|
|
|
|
|
|
|
nativeCheckInputs = [ which ]
|
|
|
|
++ lib.optionals stdenv.isDarwin [ sysctl ];
|
|
|
|
|
|
|
|
checkTarget = "check-all";
|
2023-10-07 01:18:24 +02:00
|
|
|
requiredSystemFeatures = [ "big-parallel" ];
|
|
|
|
|
|
|
|
meta = with lib; {
|
|
|
|
description = "Collection of modular and reusable compiler and toolchain technologies";
|
|
|
|
homepage = "https://github.com/llvm/llvm-project";
|
|
|
|
license = with licenses; [ ncsa ];
|
|
|
|
maintainers = with maintainers; [ SomeoneSerge Madouura ];
|
2023-11-13 13:58:12 +01:00
|
|
|
platforms = with platforms; aarch64 ++ x86;
|
2023-10-07 01:18:24 +02:00
|
|
|
};
|
|
|
|
})
|