From f2352e77c39b3f1346852545304e88819e61df3e Mon Sep 17 00:00:00 2001 From: Jez Ng Date: Mon, 29 Jul 2024 15:35:10 -0400 Subject: [PATCH] Fix importlib issues (#80) The previous implementation worked on Python 3.11 but had a host of issues with other versions. It boiled down to `triton._C` not being a regular package -- it doesn't have an `__init__.py` file. However, it can still be imported as a [namespace package][1]. Namespace packages can map to multiple locations on the filesystem, so we cannot get a path to the package contents without materializing the package. The solution is to look up the files of the top-level `triton` package instead, which is a regular package, and use that to find the location of the `_C` directory. I've tested that this approach works on 3.9 and 3.12 in macOS. Fixes #76. [1]: https://packaging.python.org/en/latest/guides/packaging-namespace-packages/#native-namespace-packages --- third_party/cpu/backend/driver.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/third_party/cpu/backend/driver.py b/third_party/cpu/backend/driver.py index 2cedbcae99ba..a9eb00a874f3 100644 --- a/third_party/cpu/backend/driver.py +++ b/third_party/cpu/backend/driver.py @@ -12,7 +12,7 @@ _dirname = os.getenv("TRITON_SYS_PATH", default="/usr/local") # for locating libTritonCPURuntime -_triton_C_dir = importlib.resources.files(triton._C).joinpath("") +_triton_C_dir = importlib.resources.files(triton).joinpath("_C") include_dirs = [os.path.join(_dirname, "include")] library_dirs = [os.path.join(_dirname, "lib"), _triton_C_dir]