From 5ed0e25be8c2a0ad23fea55515b7ac01f419beaa Mon Sep 17 00:00:00 2001 From: Dennis Wuitz Date: Fri, 19 Jul 2024 16:54:19 +0200 Subject: [PATCH] python312Packages.triton*: repair package --- pkgs/by-name/tr/triton-llvm/package.nix | 14 +- .../triton/0000-dont-download-ptxas.patch | 74 ++++++++-- ...ble-version-key-for-non-cuda-targets.patch | 27 ---- .../development/python-modules/triton/bin.nix | 7 +- .../python-modules/triton/default.nix | 138 ++++++------------ .../python-modules/triton/prefetch.sh | 40 ----- 6 files changed, 120 insertions(+), 180 deletions(-) delete mode 100644 pkgs/development/python-modules/triton/0001-ptxas-disable-version-key-for-non-cuda-targets.patch delete mode 100755 pkgs/development/python-modules/triton/prefetch.sh diff --git a/pkgs/by-name/tr/triton-llvm/package.nix b/pkgs/by-name/tr/triton-llvm/package.nix index d45aa2fafe65..f7e12ba32c11 100644 --- a/pkgs/by-name/tr/triton-llvm/package.nix +++ b/pkgs/by-name/tr/triton-llvm/package.nix @@ -11,6 +11,7 @@ , libedit , libffi , libpfm +, lit , mpfr , zlib , ncurses @@ -45,7 +46,7 @@ let isNative = stdenv.hostPlatform == stdenv.buildPlatform; in stdenv.mkDerivation (finalAttrs: { pname = "triton-llvm"; - version = "17.0.0-c5dede880d17"; + version = "19.1.0-rc1"; # One of the tags at https://github.com/llvm/llvm-project/commit/10dc3a8e916d73291269e5e2b82dd22681489aa1 outputs = [ "out" @@ -60,8 +61,8 @@ in stdenv.mkDerivation (finalAttrs: { src = fetchFromGitHub { owner = "llvm"; repo = "llvm-project"; - rev = "c5dede880d175f7229c9b2923f4753e12702305d"; - hash = "sha256-v4r3+7XVFK+Dzxt/rErZNJ9REqFO3JmGN4X4vZ+77ew="; + rev = "10dc3a8e916d73291269e5e2b82dd22681489aa1"; + hash = "sha256-9DPvcFmhzw6MipQeCQnr35LktW0uxtEL8axMMPXIfWw="; }; nativeBuildInputs = [ @@ -74,6 +75,7 @@ in stdenv.mkDerivation (finalAttrs: { doxygen sphinx python3Packages.recommonmark + python3Packages.myst-parser ]; buildInputs = [ @@ -154,9 +156,11 @@ in stdenv.mkDerivation (finalAttrs: { rm test/tools/llvm-exegesis/AArch64/latency-by-opcode-name.s ''; - postInstall = lib.optionalString (!isNative) '' + postInstall = '' + cp ${lib.getExe lit} $out/bin/llvm-lit + '' + (lib.optionalString (!isNative) '' cp -a NATIVE/bin/llvm-config $out/bin/llvm-config-native - ''; + ''); doCheck = buildTests; diff --git a/pkgs/development/python-modules/triton/0000-dont-download-ptxas.patch b/pkgs/development/python-modules/triton/0000-dont-download-ptxas.patch index d31a4798af05..265595e93de9 100644 --- a/pkgs/development/python-modules/triton/0000-dont-download-ptxas.patch +++ b/pkgs/development/python-modules/triton/0000-dont-download-ptxas.patch @@ -1,15 +1,67 @@ +From 10f3d49aa6084d1b9b9624017cce7df106b9fb7e Fri Jul 19 00:00:00 2024 +From: derdennisop +Date: Fri, 19 jul 2024 00:00:00 +0100 +Subject: [PATCH] ptxas: disable version key for non-cuda targets + +--- + python/setup.py | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + diff --git a/python/setup.py b/python/setup.py -index 18764ec13..b3bb5b60a 100644 +index d55972b4b..bd875a701 100644 --- a/python/setup.py +++ b/python/setup.py -@@ -269,10 +269,6 @@ class CMakeBuild(build_ext): - subprocess.check_call(["cmake", self.base_dir] + cmake_args, cwd=cmake_dir, env=env) - subprocess.check_call(["cmake", "--build", "."] + build_args, cwd=cmake_dir) - +@@ -437,54 +117,5 @@ + with open(nvidia_version_path, "r") as nvidia_version_file: + NVIDIA_TOOLCHAIN_VERSION = nvidia_version_file.read().strip() + +-download_and_copy( +- name="ptxas", +- src_path="bin/ptxas", +- variable="TRITON_PTXAS_PATH", +- version=NVIDIA_TOOLCHAIN_VERSION, +- url_func=lambda arch, version: +- f"https://anaconda.org/nvidia/cuda-nvcc/{version}/download/linux-{arch}/cuda-nvcc-{version}-0.tar.bz2", +-) +-download_and_copy( +- name="cuobjdump", +- src_path="bin/cuobjdump", +- variable="TRITON_CUOBJDUMP_PATH", +- version=NVIDIA_TOOLCHAIN_VERSION, +- url_func=lambda arch, version: +- f"https://anaconda.org/nvidia/cuda-cuobjdump/{version}/download/linux-{arch}/cuda-cuobjdump-{version}-0.tar.bz2", +-) +-download_and_copy( +- name="nvdisasm", +- src_path="bin/nvdisasm", +- variable="TRITON_NVDISASM_PATH", +- version=NVIDIA_TOOLCHAIN_VERSION, +- url_func=lambda arch, version: +- f"https://anaconda.org/nvidia/cuda-nvdisasm/{version}/download/linux-{arch}/cuda-nvdisasm-{version}-0.tar.bz2", +-) +-download_and_copy( +- name="cudacrt", +- src_path="include", +- variable="TRITON_CUDACRT_PATH", +- version=NVIDIA_TOOLCHAIN_VERSION, +- url_func=lambda arch, version: +- f"https://anaconda.org/nvidia/cuda-nvcc/{version}/download/linux-{arch}/cuda-nvcc-{version}-0.tar.bz2", +-) +-download_and_copy( +- name="cudart", +- src_path="include", +- variable="TRITON_CUDART_PATH", +- version=NVIDIA_TOOLCHAIN_VERSION, +- url_func=lambda arch, version: +- f"https://anaconda.org/nvidia/cuda-cudart-dev/{version}/download/linux-{arch}/cuda-cudart-dev-{version}-0.tar.bz2", +-) +-download_and_copy( +- name="cupti", +- src_path="include", +- variable="TRITON_CUPTI_PATH", +- version=NVIDIA_TOOLCHAIN_VERSION, +- url_func=lambda arch, version: +- f"https://anaconda.org/nvidia/cuda-cupti/{version}/download/linux-{arch}/cuda-cupti-{version}-0.tar.bz2", +-) - --download_and_copy_ptxas() -- -- - setup( - name="triton", - version="2.1.0", + backends = [*BackendInstaller.copy(["nvidia", "amd"]), *BackendInstaller.copy_externals()] diff --git a/pkgs/development/python-modules/triton/0001-ptxas-disable-version-key-for-non-cuda-targets.patch b/pkgs/development/python-modules/triton/0001-ptxas-disable-version-key-for-non-cuda-targets.patch deleted file mode 100644 index 3941d54b8b37..000000000000 --- a/pkgs/development/python-modules/triton/0001-ptxas-disable-version-key-for-non-cuda-targets.patch +++ /dev/null @@ -1,27 +0,0 @@ -From 10f3d49aa6084d1b9b9624017cce7df106b9fb7e Mon Sep 17 00:00:00 2001 -From: Yaroslav Bolyukin -Date: Tue, 6 Feb 2024 13:51:28 +0100 -Subject: [PATCH] ptxas: disable version key for non-cuda targets - ---- - python/triton/runtime/jit.py | 4 ++-- - 1 file changed, 2 insertions(+), 2 deletions(-) - -diff --git a/python/triton/runtime/jit.py b/python/triton/runtime/jit.py -index d55972b4b..bd875a701 100644 ---- a/python/triton/runtime/jit.py -+++ b/python/triton/runtime/jit.py -@@ -117,8 +117,8 @@ def version_key(): - with open(lib.module_finder.find_spec(lib.name).origin, "rb") as f: - contents += [hashlib.md5(f.read()).hexdigest()] - # ptxas version -- ptxas = path_to_ptxas()[0] -- ptxas_version = hashlib.md5(subprocess.check_output([ptxas, "--version"])).hexdigest() -+ # ptxas = path_to_ptxas()[0] -+ ptxas_version = "noptxas" - return '-'.join(TRITON_VERSION) + '-' + ptxas_version + '-' + '-'.join(contents) - - --- -2.43.0 - diff --git a/pkgs/development/python-modules/triton/bin.nix b/pkgs/development/python-modules/triton/bin.nix index 0189278bc0e9..6bb67753a8bd 100644 --- a/pkgs/development/python-modules/triton/bin.nix +++ b/pkgs/development/python-modules/triton/bin.nix @@ -5,11 +5,8 @@ cudaPackages, buildPythonPackage, fetchurl, - isPy38, - isPy39, - isPy310, - isPy311, python, + pythonOlder, autoPatchelfHook, filelock, lit, @@ -29,7 +26,7 @@ buildPythonPackage rec { in fetchurl srcs; - disabled = !(isPy38 || isPy39 || isPy310 || isPy311); + disabled = pythonOlder "3.8"; pythonRemoveDeps = [ "cmake" diff --git a/pkgs/development/python-modules/triton/default.nix b/pkgs/development/python-modules/triton/default.nix index b8c2624981dc..9a6efae237b8 100644 --- a/pkgs/development/python-modules/triton/default.nix +++ b/pkgs/development/python-modules/triton/default.nix @@ -1,100 +1,56 @@ { lib, - config, - addDriverRunpath, buildPythonPackage, - fetchFromGitHub, - setuptools, cmake, - ninja, - pybind11, + config, + cudaPackages, + fetchFromGitHub, + filelock, gtest, - zlib, - ncurses, libxml2, lit, llvm, - filelock, - torchWithRocm, + ncurses, + ninja, + pybind11, python, - runCommand, - - cudaPackages, + setuptools, + torchWithRocm, + zlib, cudaSupport ? config.cudaSupport, }: -let - ptxas = lib.getExe' cudaPackages.cuda_nvcc "ptxas"; # Make sure cudaPackages is the right version each update (See python/setup.py) -in -buildPythonPackage rec { +buildPythonPackage { pname = "triton"; version = "3.0.0"; pyproject = true; src = fetchFromGitHub { owner = "triton-lang"; - repo = pname; + repo = "triton"; # latest branch commit from https://github.com/triton-lang/triton/commits/release/3.0.x/ rev = "91f24d87e50cb748b121a6c24e65a01187699c22"; hash = "sha256-L5KqiR+TgSyKjEBlkE0yOU1pemMHFk2PhEmxLdbbxUU="; }; - patches = - [ - # Upstream startded pinning CUDA version and falling back to downloading from Conda - # in https://github.com/triton-lang/triton/pull/1574/files#diff-eb8b42d9346d0a5d371facf21a8bfa2d16fb49e213ae7c21f03863accebe0fcfR120-R123 - ./0000-dont-download-ptxas.patch - ] - ++ lib.optionals (!cudaSupport) [ - # triton wants to get ptxas version even if ptxas is not - # used, resulting in ptxas not found error. - ./0001-ptxas-disable-version-key-for-non-cuda-targets.patch - ]; + # triton wants to download every dependency, even if we are not using cuda. + patches = lib.optionals (!cudaSupport) [ ./0000-dont-download-ptxas.patch ]; postPatch = - let - quote = x: ''"${x}"''; - subs.ldFlags = - 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/" - ]; - in - { - oldStr = lib.concatMapStringsSep ", " quote old; - newStr = lib.concatMapStringsSep ", " quote new; - }; - in '' # Use our `cmakeFlags` instead and avoid downloading dependencies + # remove any downloads substituteInPlace python/setup.py \ - --replace "= get_thirdparty_packages(triton_cache_path)" "= os.environ[\"cmakeFlags\"].split()" - - # Already defined in llvm, when built with -DLLVM_INSTALL_UTILS - substituteInPlace bin/CMakeLists.txt \ - --replace "add_subdirectory(FileCheck)" "" + --replace-fail "get_json_package_info(), get_pybind11_package_info()" ""\ + --replace-fail "get_pybind11_package_info(), get_llvm_package_info()" ""\ + --replace-fail 'packages += ["triton/profiler"]' ""\ + --replace-fail "curr_version != version" "False" # Don't fetch googletest substituteInPlace unittest/CMakeLists.txt \ - --replace "include (\''${CMAKE_CURRENT_SOURCE_DIR}/googletest.cmake)" ""\ - --replace "include(GoogleTest)" "find_package(GTest REQUIRED)" - - cat << \EOF >> python/triton/common/build.py - def libcuda_dirs(): - return [ "${addDriverRunpath.driverLink}/lib" ] - EOF - '' - + lib.optionalString cudaSupport '' - # Use our linker flags - substituteInPlace python/triton/common/build.py \ - --replace '${subs.ldFlags.oldStr}' '${subs.ldFlags.newStr}' + --replace-fail "include (\''${CMAKE_CURRENT_SOURCE_DIR}/googletest.cmake)" ""\ + --replace-fail "include(GoogleTest)" "find_package(GTest REQUIRED)" ''; nativeBuildInputs = [ @@ -133,40 +89,38 @@ buildPythonPackage rec { ]; # Avoid GLIBCXX mismatch with other cuda-enabled python packages - preConfigure = - '' - # Ensure that the build process uses the requested number of cores - export MAX_JOBS="$NIX_BUILD_CORES" + preConfigure = '' + # Ensure that the build process uses the requested number of cores + export MAX_JOBS="$NIX_BUILD_CORES" - # Upstream's setup.py tries to write cache somewhere in ~/ - export HOME=$(mktemp -d) + # Upstream's setup.py tries to write cache somewhere in ~/ + export HOME=$(mktemp -d) - # Upstream's github actions patch setup.cfg to write base-dir. May be redundant - echo " - [build_ext] - base-dir=$PWD" >> python/setup.cfg + # Upstream's github actions patch setup.cfg to write base-dir. May be redundant + echo " + [build_ext] + base-dir=$PWD" >> python/setup.cfg - # The rest (including buildPhase) is relative to ./python/ - cd python - '' - + lib.optionalString cudaSupport '' - export CC=${cudaPackages.backendStdenv.cc}/bin/cc; - export CXX=${cudaPackages.backendStdenv.cc}/bin/c++; + # The rest (including buildPhase) is relative to ./python/ + cd python + ''; - # Work around download_and_copy_ptxas() - mkdir -p $PWD/triton/third_party/cuda/bin - ln -s ${ptxas} $PWD/triton/third_party/cuda/bin - ''; + env = { + TRITON_BUILD_PROTON = "OFF"; + } // lib.optionalAttrs cudaSupport { + CC = "${cudaPackages.backendStdenv.cc}/bin/cc"; + CXX = "${cudaPackages.backendStdenv.cc}/bin/c++"; + + TRITON_PTXAS_PATH = lib.getExe' cudaPackages.cuda_nvcc "ptxas"; # Make sure cudaPackages is the right version each update (See python/setup.py) + TRITON_CUOBJDUMP_PATH = cudaPackages.cuda_cuobjdump; + TRITON_NVDISASM_PATH = cudaPackages.cuda_nvdisasm; + TRITON_CUDACRT_PATH = cudaPackages.cuda_nvcc; + TRITON_CUDART_PATH = cudaPackages.cuda_cudart; + TRITON_CUPTI_PATH = cudaPackages.cuda_cupti; + }; # CMake is run by setup.py instead dontUseCmakeConfigure = true; - - # Setuptools (?) strips runpath and +x flags. Let's just restore the symlink - postFixup = lib.optionalString cudaSupport '' - rm -f $out/${python.sitePackages}/triton/third_party/cuda/bin/ptxas - ln -s ${ptxas} $out/${python.sitePackages}/triton/third_party/cuda/bin/ptxas - ''; - checkInputs = [ cmake ]; # ctest dontUseSetuptoolsCheck = true; diff --git a/pkgs/development/python-modules/triton/prefetch.sh b/pkgs/development/python-modules/triton/prefetch.sh deleted file mode 100755 index f218718a5cf3..000000000000 --- a/pkgs/development/python-modules/triton/prefetch.sh +++ /dev/null @@ -1,40 +0,0 @@ -#!/usr/bin/env nix-shell -#!nix-shell -i bash -p nix-prefetch-scripts - -set -eou pipefail - -version=$1 - -linux_bucket="https://download.pytorch.org/whl" - -url_and_key_list=( - "x86_64-linux-38 $linux_bucket/triton-${version}-0-cp38-cp38-manylinux2014_x86_64.manylinux_2_17_x86_64.whl triton-${version}-cp38-cp38-linux_x86_64.whl" - "x86_64-linux-39 $linux_bucket/triton-${version}-0-cp39-cp39-manylinux2014_x86_64.manylinux_2_17_x86_64.whl triton-${version}-cp39-cp39-linux_x86_64.whl" - "x86_64-linux-310 $linux_bucket/triton-${version}-0-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.whl triton-${version}-cp310-cp310-linux_x86_64.whl" - "x86_64-linux-311 $linux_bucket/triton-${version}-0-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.whl triton-${version}-cp311-cp311-linux_x86_64.whl" -) - -hashfile=binary-hashes-"$version".nix -echo " \"$version\" = {" >> $hashfile - -for url_and_key in "${url_and_key_list[@]}"; do - key=$(echo "$url_and_key" | cut -d' ' -f1) - url=$(echo "$url_and_key" | cut -d' ' -f2) - name=$(echo "$url_and_key" | cut -d' ' -f3) - - echo "prefetching ${url}..." - hash=$(nix hash to-sri --type sha256 `nix-prefetch-url "$url" --name "$name"`) - - cat << EOF >> $hashfile - $key = { - name = "$name"; - url = "$url"; - hash = "$hash"; - }; -EOF - - echo -done - -echo " };" >> $hashfile -echo "done."