python312Packages.triton: use more generic patch to unvendor ptxas/cuda

This commit is contained in:
Someone Serge 2024-07-29 15:01:48 +00:00 committed by SomeoneSerge
parent 5ed0e25be8
commit e262792bf1
3 changed files with 68 additions and 69 deletions

View File

@ -1,67 +0,0 @@
From 10f3d49aa6084d1b9b9624017cce7df106b9fb7e Fri Jul 19 00:00:00 2024
From: derdennisop <just@patch.local>
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 d55972b4b..bd875a701 100644
--- a/python/setup.py
+++ b/python/setup.py
@@ -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",
-)
-
backends = [*BackendInstaller.copy(["nvidia", "amd"]), *BackendInstaller.copy_externals()]

View File

@ -0,0 +1,64 @@
From 587d1f3428eca63544238802f19e0be670d03244 Mon Sep 17 00:00:00 2001
From: SomeoneSerge <else@someonex.net>
Date: Mon, 29 Jul 2024 14:31:11 +0000
Subject: [PATCH] setup.py: introduce TRITON_OFFLINE_BUILD
To prevent any vendoring whatsoever
---
python/setup.py | 26 ++++++++++++++++++++++++--
1 file changed, 24 insertions(+), 2 deletions(-)
diff --git a/python/setup.py b/python/setup.py
index 73800ec40..4e5b04de4 100644
--- a/python/setup.py
+++ b/python/setup.py
@@ -112,6 +112,20 @@ def get_env_with_keys(key: list):
return os.environ[k]
return ""
+def is_offline_build() -> bool:
+ """
+ Downstream projects and distributions which bootstrap their own dependencies from scratch
+ and run builds in offline sandboxes
+ may set `TRITON_OFFLINE_BUILD` in the build environment to prevent any attempts at downloading
+ pinned dependencies from the internet or at using dependencies vendored in-tree.
+
+ Dependencies must be defined using respective search paths (cf. `syspath_var_name` in `Package`).
+ Missing dependencies lead to an early abortion.
+ Dependencies' compatibility is not verified.
+
+ Note that this flag isn't tested by the CI and does not provide any guarantees.
+ """
+ return os.environ.get("TRITON_OFFLINE_BUILD", "") != ""
# --- third party packages -----
@@ -220,8 +234,14 @@ def get_thirdparty_packages(packages: list):
if os.environ.get(p.syspath_var_name):
package_dir = os.environ[p.syspath_var_name]
version_file_path = os.path.join(package_dir, "version.txt")
- if p.syspath_var_name not in os.environ and\
- (not os.path.exists(version_file_path) or Path(version_file_path).read_text() != p.url):
+
+ input_defined = p.syspath_var_name not in os.environ
+ input_exists = input_defined and os.path.exists(version_file_path)
+ input_compatible = input_exists and Path(version_file_path).read_text() == p.url
+
+ if is_offline_build() and not input_defined:
+ raise RuntimeError(f"Requested an offline build but {p.syspath_var_name} is not set")
+ if not is_offline_build() and not input_compatible:
with contextlib.suppress(Exception):
shutil.rmtree(package_root_dir)
os.makedirs(package_root_dir, exist_ok=True)
@@ -245,6 +265,8 @@ def get_thirdparty_packages(packages: list):
def download_and_copy(name, src_path, variable, version, url_func):
+ if is_offline_build():
+ return
triton_cache_path = get_triton_cache_path()
if variable in os.environ:
return
--
2.45.1

View File

@ -34,8 +34,9 @@ buildPythonPackage {
hash = "sha256-L5KqiR+TgSyKjEBlkE0yOU1pemMHFk2PhEmxLdbbxUU=";
};
# triton wants to download every dependency, even if we are not using cuda.
patches = lib.optionals (!cudaSupport) [ ./0000-dont-download-ptxas.patch ];
patches = [
./0001-setup.py-introduce-TRITON_OFFLINE_BUILD.patch
];
postPatch =
''
@ -107,6 +108,7 @@ buildPythonPackage {
env = {
TRITON_BUILD_PROTON = "OFF";
TRITON_OFFLINE_BUILD = true;
} // lib.optionalAttrs cudaSupport {
CC = "${cudaPackages.backendStdenv.cc}/bin/cc";
CXX = "${cudaPackages.backendStdenv.cc}/bin/c++";