about summary refs log tree commit diff
path: root/pkgs/development/python-modules/triton/bin.nix
blob: 0189278bc0e9b40a7ba64a0453a2b9f22b0060be (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
{
  lib,
  stdenv,
  addDriverRunpath,
  cudaPackages,
  buildPythonPackage,
  fetchurl,
  isPy38,
  isPy39,
  isPy310,
  isPy311,
  python,
  autoPatchelfHook,
  filelock,
  lit,
  zlib,
}:

buildPythonPackage rec {
  pname = "triton";
  version = "2.1.0";
  format = "wheel";

  src =
    let
      pyVerNoDot = lib.replaceStrings [ "." ] [ "" ] python.pythonVersion;
      unsupported = throw "Unsupported system";
      srcs = (import ./binary-hashes.nix version)."${stdenv.system}-${pyVerNoDot}" or unsupported;
    in
    fetchurl srcs;

  disabled = !(isPy38 || isPy39 || isPy310 || isPy311);

  pythonRemoveDeps = [
    "cmake"
    # torch and triton refer to each other so this hook is included to mitigate that.
    "torch"
  ];

  buildInputs = [ zlib ];

  nativeBuildInputs = [
    autoPatchelfHook
  ];

  propagatedBuildInputs = [
    filelock
    lit
    zlib
  ];

  dontStrip = true;

  # If this breaks, consider replacing with "${cuda_nvcc}/bin/ptxas"
  postFixup =
    ''
      chmod +x "$out/${python.sitePackages}/triton/third_party/cuda/bin/ptxas"
    ''
    + (
      let
        # Bash was getting weird without linting,
        # but basically upstream contains [cc, ..., "-lcuda", ...]
        # and we replace it with [..., "-lcuda", "-L/run/opengl-driver/lib", "-L$stubs", ...]
        old = [ "-lcuda" ];
        new = [
          "-lcuda"
          "-L${addDriverRunpath.driverLink}"
          "-L${cudaPackages.cuda_cudart}/lib/stubs/"
        ];

        quote = x: ''"${x}"'';
        oldStr = lib.concatMapStringsSep ", " quote old;
        newStr = lib.concatMapStringsSep ", " quote new;
      in
      ''
        substituteInPlace $out/${python.sitePackages}/triton/common/build.py \
          --replace '${oldStr}' '${newStr}'
      ''
    );

  meta = with lib; {
    description = "Language and compiler for custom Deep Learning operations";
    homepage = "https://github.com/triton-lang/triton/";
    changelog = "https://github.com/triton-lang/triton/releases/tag/v${version}";
    # Includes NVIDIA's ptxas, but redistributions of the binary are not limited.
    # https://docs.nvidia.com/cuda/eula/index.html
    # triton's license is MIT.
    # triton-bin includes ptxas binary, therefore unfreeRedistributable is set.
    license = with licenses; [
      unfreeRedistributable
      mit
    ];
    sourceProvenance = with sourceTypes; [ binaryNativeCode ];
    platforms = [ "x86_64-linux" ];
    maintainers = with maintainers; [ junjihashimoto ];
  };
}