Unverified Commit 41b19900 authored by Stephen Huan's avatar Stephen Huan
Browse files

python3Packages.triton: fix patches

parent f722b576
Loading
Loading
Loading
Loading
+7 −8
Original line number Diff line number Diff line
diff --git a/python/triton/runtime/build.py b/python/triton/runtime/build.py
index 1b76548d4..1edbfd3da 100644
index 1b76548d4..2756dccdb 100644
--- a/python/triton/runtime/build.py
+++ b/python/triton/runtime/build.py
@@ -30,6 +30,14 @@ def _build(name, src, srcdir, library_dirs, include_dirs, libraries):
     include_dirs = include_dirs + [srcdir, py_include_dir, *custom_backend_dirs]
     # for -Wno-psabi, see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111047
     cc_cmd = [cc, src, "-O3", "-shared", "-fPIC", "-Wno-psabi", "-o", so]
@@ -33,5 +33,13 @@ def _build(name, src, srcdir, library_dirs, include_dirs, libraries):
     cc_cmd += [f'-l{lib}' for lib in libraries]
     cc_cmd += [f"-L{dir}" for dir in library_dirs]
     cc_cmd += [f"-I{dir}" for dir in include_dirs if dir is not None]
+
+    # Nixpkgs support branch
+    # Allows passing e.g. extra -Wl,-rpath
@@ -14,6 +14,5 @@ index 1b76548d4..1edbfd3da 100644
+        import shlex
+        cc_cmd.extend(shlex.split(cc_cmd_extra_flags))
+
     cc_cmd += [f'-l{lib}' for lib in libraries]
     cc_cmd += [f"-L{dir}" for dir in library_dirs]
     cc_cmd += [f"-I{dir}" for dir in include_dirs if dir is not None]
     subprocess.check_call(cc_cmd, stdout=subprocess.DEVNULL)
     return so
+0 −64
Original line number Diff line number Diff line
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
+3 −30
Original line number Diff line number Diff line
diff --git a/python/triton/runtime/build.py b/python/triton/runtime/build.py
index 1edbfd3da..2756dccdb 100644
--- a/python/triton/runtime/build.py
+++ b/python/triton/runtime/build.py
@@ -30,6 +30,9 @@ def _build(name, src, srcdir, library_dirs, include_dirs, libraries):
     include_dirs = include_dirs + [srcdir, py_include_dir, *custom_backend_dirs]
     # for -Wno-psabi, see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111047
     cc_cmd = [cc, src, "-O3", "-shared", "-fPIC", "-Wno-psabi", "-o", so]
+    cc_cmd += [f'-l{lib}' for lib in libraries]
+    cc_cmd += [f"-L{dir}" for dir in library_dirs]
+    cc_cmd += [f"-I{dir}" for dir in include_dirs if dir is not None]
 
     # Nixpkgs support branch
     # Allows passing e.g. extra -Wl,-rpath
@@ -38,8 +41,5 @@ def _build(name, src, srcdir, library_dirs, include_dirs, libraries):
         import shlex
         cc_cmd.extend(shlex.split(cc_cmd_extra_flags))
 
-    cc_cmd += [f'-l{lib}' for lib in libraries]
-    cc_cmd += [f"-L{dir}" for dir in library_dirs]
-    cc_cmd += [f"-I{dir}" for dir in include_dirs if dir is not None]
     subprocess.check_call(cc_cmd, stdout=subprocess.DEVNULL)
     return so
diff --git a/third_party/amd/backend/driver.py b/third_party/amd/backend/driver.py
index b99ff86c8..ea8bc103d 100644
index ca712f904..0961d2dda 100644
--- a/third_party/amd/backend/driver.py
+++ b/third_party/amd/backend/driver.py
@@ -79,6 +79,13 @@ def _get_path_to_hip_runtime_dylib():
@@ -79,6 +79,9 @@ def _get_path_to_hip_runtime_dylib():
             return mmapped_path
         raise RuntimeError(f"memory mapped '{mmapped_path}' in process does not point to a valid {lib_name}")
 
+    # ...on release/3.1.x:
+    #         return mmapped_path
+    #     raise RuntimeError(f"memory mapped '{mmapped_path}' in process does not point to a valid {lib_name}")
+
+    if os.path.isdir("@libhipDir@"):
+        return ["@libhipDir@"]
+
@@ -40,7 +13,7 @@ index b99ff86c8..ea8bc103d 100644
 
     import site
diff --git a/third_party/nvidia/backend/driver.py b/third_party/nvidia/backend/driver.py
index 5f2621ae5..e7762a3ec 100644
index d088ec092..625de2db8 100644
--- a/third_party/nvidia/backend/driver.py
+++ b/third_party/nvidia/backend/driver.py
@@ -23,6 +23,9 @@ def libcuda_dirs():
+5 −17
Original line number Diff line number Diff line
From e503e572b6d444cd27f1cdf124aaf553aa3a8665 Mon Sep 17 00:00:00 2001
From: SomeoneSerge <else+aalto@someonex.net>
Date: Mon, 14 Oct 2024 00:12:05 +0000
Subject: [PATCH 4/4] nvidia: allow static ptxas path

---
 third_party/nvidia/backend/compiler.py | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/third_party/nvidia/backend/compiler.py b/third_party/nvidia/backend/compiler.py
index 6d7994923..6720e8f97 100644
index 960334744..269e22e6e 100644
--- a/third_party/nvidia/backend/compiler.py
+++ b/third_party/nvidia/backend/compiler.py
@@ -20,6 +20,9 @@ def _path_to_binary(binary: str):
@@ -38,6 +38,9 @@ def _path_to_binary(binary: str):
         os.path.join(os.path.dirname(__file__), "bin", binary),
     ]
 
+    import shlex
+    paths.extend(shlex.split("@nixpkgsExtraBinaryPaths@"))
+
     for bin in paths:
         if os.path.exists(bin) and os.path.isfile(bin):
             result = subprocess.check_output([bin, "--version"], stderr=subprocess.STDOUT)
-- 
2.46.0
     for path in paths:
         if os.path.exists(path) and os.path.isfile(path):
             result = subprocess.check_output([path, "--version"], stderr=subprocess.STDOUT)
+1 −1
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ buildPythonPackage rec {
  version = "3.3.1";
  pyproject = true;

  # Remember to bump triton-llvm as well!
  src = fetchFromGitHub {
    owner = "triton-lang";
    repo = "triton";
@@ -42,7 +43,6 @@ buildPythonPackage rec {

  patches =
    [
      # ./0001-setup.py-introduce-TRITON_OFFLINE_BUILD.patch
      (replaceVars ./0001-_build-allow-extra-cc-flags.patch {
        ccCmdExtraFlags = "-Wl,-rpath,${addDriverRunpath.driverLink}/lib";
      })