From 9e1a55ebf16daff9b7de92328b28ee026a94ed00 Mon Sep 17 00:00:00 2001 From: ylwang0701 <88826857+ylwang0701@users.noreply.github.com> Date: Sun, 29 Nov 2026 13:08:48 +0800 Subject: [PATCH] Find pip-installed tileiras across namespace directories Signed-off-by: ylwang0701 <88826857+ylwang0701@users.noreply.github.com> --- .../find-pip-tileiras-in-split-namespace.md | 3 ++ src/cuda/tile/_compile.py | 27 ++++++++------ test/test_compiler_discovery.py | 37 +++++++++++++++++++ 3 files changed, 56 insertions(+), 11 deletions(-) create mode 100644 changelog.d/find-pip-tileiras-in-split-namespace.md create mode 100644 test/test_compiler_discovery.py diff --git a/changelog.d/find-pip-tileiras-in-split-namespace.md b/changelog.d/find-pip-tileiras-in-split-namespace.md new file mode 100644 index 00000000..75d162a7 --- /dev/null +++ b/changelog.d/find-pip-tileiras-in-split-namespace.md @@ -0,0 +1,3 @@ +- Fixed compiler discovery when NVIDIA Python packages are installed across multiple + directories. cuTile now finds the pip-installed ``tileiras`` in later directories + and warns if the compiler packages are installed but no executable is found. diff --git a/src/cuda/tile/_compile.py b/src/cuda/tile/_compile.py index 27d49377..6d91b8d5 100644 --- a/src/cuda/tile/_compile.py +++ b/src/cuda/tile/_compile.py @@ -832,19 +832,24 @@ def _find_pip_tileiras() -> Optional[str]: try: import nvidia.cu13 as cu13_pkg - cu13_root = cu13_pkg.__path__[0] - except (ImportError, AttributeError, IndexError): + cu13_roots = cu13_pkg.__path__ + except (ImportError, AttributeError): logger.debug("Fail to get nvidia.cu13 package path.", exc_info=True) - return None - - pip_bin_dir = os.path.join(cu13_root, "bin") - res = shutil.which("tileiras", path=pip_bin_dir) - if res is None: - logger.debug("Fail to find tileiras under nvidia.cu13 path.") - return None + cu13_roots = () - logger.debug(f"Found tileiras from pip package: {res}") - return res + binary_name = "tileiras.exe" if is_windows() else "tileiras" + res = _find_file(cu13_roots, ["bin"], [binary_name], require_executable=True) + if res is not None: + tileiras_path, _ = res + logger.debug(f"Found tileiras from pip package: {tileiras_path}") + return tileiras_path + + warnings.warn( + "The NVIDIA compiler packages are installed, but tileiras was not found in nvidia.cu13. " + "Falling back to system tileiras.", + stacklevel=3, + ) + return None @cache diff --git a/test/test_compiler_discovery.py b/test/test_compiler_discovery.py new file mode 100644 index 00000000..0ef0a2e1 --- /dev/null +++ b/test/test_compiler_discovery.py @@ -0,0 +1,37 @@ +# SPDX-FileCopyrightText: Copyright (c) <2026> NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# +# SPDX-License-Identifier: Apache-2.0 + +import os +from pathlib import Path +import sys +from types import SimpleNamespace + +import pytest + +from cuda.tile import _compile + + +@pytest.mark.parametrize("installed", [(1,), (0, 1), ()], ids=["second", "both", "neither"]) +def test_find_pip_tileiras_in_namespace(tmp_path, monkeypatch, installed): + roots = [tmp_path / "first" / "nvidia" / "cu13", tmp_path / "second" / "nvidia" / "cu13"] + cu13 = SimpleNamespace(__path__=roots) + monkeypatch.setitem(sys.modules, "nvidia", SimpleNamespace(cu13=cu13)) + monkeypatch.setitem(sys.modules, "nvidia.cu13", cu13) + monkeypatch.setattr(_compile.importlib.metadata, "version", lambda name: "13.5.37") + + binary = "tileiras.exe" if os.name == "nt" else "tileiras" + candidates = [root / "bin" / binary for root in roots] + for index in installed: + path = candidates[index] + path.parent.mkdir(parents=True) + path.touch() + path.chmod(0o755) + + if installed: + found = _compile._find_pip_tileiras() + assert found is not None + assert Path(found) == candidates[installed[0]] + else: + with pytest.warns(UserWarning, match="Falling back to system tileiras"): + assert _compile._find_pip_tileiras() is None