[BUILD] Use a persistent directory for cmake (#1548)

Fixes #1545

`build_temp` is a temporary directory which `distutils` used to keep in
the `./build` directory, but when `pyproject.toml` is present `pip` now
puts it in `/tmp` and removes it at the end of the build.

Instead, this creates a new permanent directory like
`python/build/cmake.linux_x86_64-cpython-3.8` (the old name but with
cmake instead of temp).

While I was looking at the verbose pip output, I also noticed a bunch of
warnings like
```
Python recognizes 'triton/runtime.backends' as an importable package,
but it is not listed in the `packages` configuration of setuptools.

'triton/runtime.backends' has been automatically added to the distribution only
because it may contain data files, but this behavior is likely to change
in future versions of setuptools (and therefore is considered deprecated).
```

So I've also added these to the packages list.

---------

Co-authored-by: Keren Zhou <kerenzhou@openai.com>
This commit is contained in:
peterbell10
2023-04-20 23:38:44 +00:00
committed by GitHub
parent 3e213dccb1
commit c71bf73f24
2 changed files with 17 additions and 4 deletions

View File

@@ -161,6 +161,14 @@ class CMakeBuild(build_ext):
for ext in self.extensions:
self.build_extension(ext)
def get_cmake_dir(self):
plat_name = sysconfig.get_platform()
python_version = sysconfig.get_python_version()
dir_name = f"cmake.{plat_name}-{sys.implementation.name}-{python_version}"
cmake_dir = Path(self.base_dir) / "python" / "build" / dir_name
cmake_dir.mkdir(parents=True, exist_ok=True)
return cmake_dir
def build_extension(self, ext):
lit_dir = shutil.which('lit')
user_home = os.getenv("HOME") or os.getenv("USERPROFILE") or \
@@ -212,8 +220,9 @@ class CMakeBuild(build_ext):
"-DCMAKE_SHARED_LINKER_FLAGS=-fuse-ld=lld"]
env = os.environ.copy()
subprocess.check_call(["cmake", self.base_dir] + cmake_args, cwd=self.build_temp, env=env)
subprocess.check_call(["cmake", "--build", "."] + build_args, cwd=self.build_temp)
cmake_dir = self.get_cmake_dir()
subprocess.check_call(["cmake", self.base_dir] + cmake_args, cwd=cmake_dir, env=env)
subprocess.check_call(["cmake", "--build", "."] + build_args, cwd=cmake_dir)
download_and_copy_ptxas()
@@ -236,6 +245,10 @@ setup(
"triton/ops",
"triton/ops/blocksparse",
"triton/runtime",
"triton/runtime/backends",
"triton/third_party/cuda/bin",
"triton/third_party/cuda/include",
"triton/third_party/cuda/lib",
"triton/tools",
],
install_requires=[