summary refs log tree commit diff
path: root/pkgs/by-name/op/openai-triton-llvm/package.nix
blob: 2fb56d0a6352203efee69d4dee23a398cd7b8ab7 (plain) (blame)
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
{ config
, lib
, stdenv
, fetchFromGitHub
, pkg-config
, cmake
, ninja
, git
, doxygen
, sphinx
, libxml2
, libxcrypt
, libedit
, libffi
, mpfr
, zlib
, ncurses
, python3Packages
, buildDocs ? true
, buildMan ? true
, buildTests ? true
}:

stdenv.mkDerivation (finalAttrs: {
  pname = "openai-triton-llvm";
  version = "14.0.6-f28c006a5895";

  outputs = [
    "out"
  ] ++ lib.optionals buildDocs [
    "doc"
  ] ++ lib.optionals buildMan [
    "man"
  ];

  # See https://github.com/openai/triton/blob/main/python/setup.py and https://github.com/ptillet/triton-llvm-releases/releases
  src = fetchFromGitHub {
    owner = "llvm";
    repo = "llvm-project";
    rev = "f28c006a5895fc0e329fe15fead81e37457cb1d1";
    hash = "sha256-vffu4HilvYwtzwgq+NlS26m65DGbp6OSSne2aje1yJE=";
  };

  nativeBuildInputs = [
    pkg-config
    cmake
    ninja
    git
    python3Packages.python
  ] ++ lib.optionals (buildDocs || buildMan) [
    doxygen
    sphinx
    python3Packages.recommonmark
  ];

  buildInputs = [
    libxml2
    libxcrypt
    libedit
    libffi
    mpfr
  ];

  propagatedBuildInputs = [
    zlib
    ncurses
  ];

  sourceRoot = "${finalAttrs.src.name}/llvm";

  cmakeFlags = [
    "-DLLVM_TARGETS_TO_BUILD=${
      let
        # Targets can be found in
        # https://github.com/llvm/llvm-project/tree/f28c006a5895fc0e329fe15fead81e37457cb1d1/clang/lib/Basic/Targets
        # NOTE: Unsure of how "host" would function, especially given that we might be cross-compiling.
        llvmTargets = [ "AMDGPU" "NVPTX" ]
        ++ lib.optionals stdenv.isAarch64 [ "AArch64" ]
        ++ lib.optionals stdenv.isx86_64 [ "X86" ];
      in
      lib.concatStringsSep ";" llvmTargets
    }"
    "-DLLVM_ENABLE_PROJECTS=llvm;mlir"
    "-DLLVM_INSTALL_UTILS=ON"
  ] ++ lib.optionals (buildDocs || buildMan) [
    "-DLLVM_INCLUDE_DOCS=ON"
    "-DMLIR_INCLUDE_DOCS=ON"
    "-DLLVM_BUILD_DOCS=ON"
    # "-DLLVM_ENABLE_DOXYGEN=ON" Way too slow, only uses one core
    "-DLLVM_ENABLE_SPHINX=ON"
    "-DSPHINX_OUTPUT_HTML=ON"
    "-DSPHINX_OUTPUT_MAN=ON"
    "-DSPHINX_WARNINGS_AS_ERRORS=OFF"
  ] ++ lib.optionals buildTests [
    "-DLLVM_INCLUDE_TESTS=ON"
    "-DMLIR_INCLUDE_TESTS=ON"
    "-DLLVM_BUILD_TESTS=ON"
  ];

  postPatch = ''
    # `CMake Error: cannot write to file "/build/source/llvm/build/lib/cmake/mlir/MLIRTargets.cmake": Permission denied`
    chmod +w -R ../mlir

    # 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" ""
  '';

  doCheck = buildTests;
  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 ];
    platforms = platforms.linux;
    # Consider the derivation broken if we're not building for CUDA or ROCm, or if we're building for aarch64
    # and ROCm is enabled. See https://github.com/RadeonOpenCompute/ROCm/issues/1831#issuecomment-1278205344.
    broken = stdenv.isAarch64 && !config.cudaSupport;
  };
})