2024-06-05 15:53:02 +00:00
|
|
|
{
|
|
|
|
lib,
|
|
|
|
stdenv,
|
|
|
|
addOpenGLRunpath,
|
|
|
|
cudaPackages,
|
|
|
|
buildPythonPackage,
|
|
|
|
fetchurl,
|
|
|
|
isPy38,
|
|
|
|
isPy39,
|
|
|
|
isPy310,
|
|
|
|
isPy311,
|
|
|
|
python,
|
|
|
|
autoPatchelfHook,
|
|
|
|
filelock,
|
|
|
|
lit,
|
|
|
|
pythonRelaxDepsHook,
|
|
|
|
zlib,
|
2023-05-24 13:37:59 +00:00
|
|
|
}:
|
|
|
|
|
|
|
|
buildPythonPackage rec {
|
|
|
|
pname = "triton";
|
2024-01-02 11:29:13 +00:00
|
|
|
version = "2.1.0";
|
2023-05-24 13:37:59 +00:00
|
|
|
format = "wheel";
|
|
|
|
|
|
|
|
src =
|
2024-06-05 15:53:02 +00:00
|
|
|
let
|
|
|
|
pyVerNoDot = lib.replaceStrings [ "." ] [ "" ] python.pythonVersion;
|
|
|
|
unsupported = throw "Unsupported system";
|
|
|
|
srcs = (import ./binary-hashes.nix version)."${stdenv.system}-${pyVerNoDot}" or unsupported;
|
|
|
|
in
|
|
|
|
fetchurl srcs;
|
2023-05-24 13:37:59 +00:00
|
|
|
|
|
|
|
disabled = !(isPy38 || isPy39 || isPy310 || isPy311);
|
|
|
|
|
2024-06-05 15:53:02 +00:00
|
|
|
pythonRemoveDeps = [
|
|
|
|
"cmake"
|
|
|
|
"torch"
|
|
|
|
];
|
2023-05-24 13:37:59 +00:00
|
|
|
|
|
|
|
buildInputs = [ zlib ];
|
|
|
|
|
|
|
|
nativeBuildInputs = [
|
|
|
|
pythonRelaxDepsHook # torch and triton refer to each other so this hook is included to mitigate that.
|
|
|
|
autoPatchelfHook
|
|
|
|
];
|
|
|
|
|
|
|
|
propagatedBuildInputs = [
|
|
|
|
filelock
|
|
|
|
lit
|
|
|
|
zlib
|
|
|
|
];
|
|
|
|
|
|
|
|
dontStrip = true;
|
|
|
|
|
|
|
|
# If this breaks, consider replacing with "${cuda_nvcc}/bin/ptxas"
|
2024-06-05 15:53:02 +00:00
|
|
|
postFixup =
|
2023-05-24 13:37:59 +00:00
|
|
|
''
|
2024-06-05 15:53:02 +00:00
|
|
|
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${addOpenGLRunpath.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}'
|
|
|
|
''
|
|
|
|
);
|
2023-05-24 13:37:59 +00:00
|
|
|
|
|
|
|
meta = with lib; {
|
|
|
|
description = "A language and compiler for custom Deep Learning operations";
|
|
|
|
homepage = "https://github.com/openai/triton/";
|
|
|
|
changelog = "https://github.com/openai/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.
|
|
|
|
# openai-triton-bin includes ptxas binary, therefore unfreeRedistributable is set.
|
2024-06-05 15:53:02 +00:00
|
|
|
license = with licenses; [
|
|
|
|
unfreeRedistributable
|
|
|
|
mit
|
|
|
|
];
|
2023-05-24 13:37:59 +00:00
|
|
|
sourceProvenance = with sourceTypes; [ binaryNativeCode ];
|
|
|
|
platforms = [ "x86_64-linux" ];
|
|
|
|
maintainers = with maintainers; [ junjihashimoto ];
|
|
|
|
};
|
|
|
|
}
|