-
Notifications
You must be signed in to change notification settings - Fork 99
Expand file tree
/
Copy pathsetup.py
More file actions
103 lines (84 loc) · 2.58 KB
/
Copy pathsetup.py
File metadata and controls
103 lines (84 loc) · 2.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import os
import subprocess
from pathlib import Path
from setuptools import Command, Extension, find_packages, setup
from setuptools.command.build import build as _build
from setuptools.command.build_ext import build_ext
def _get_torch_cmake_prefix_path() -> str:
import torch
return torch.utils.cmake_prefix_path
class CMakeBuild(build_ext):
def run(self) -> None:
try:
subprocess.check_output(["cmake", "--version"])
except OSError as exn:
raise RuntimeError(
f"CMake must be installed to build the following extensions: {', '.join(e.name for e in self.extensions)}"
) from exn
for ext in self.extensions:
self.build_extension(ext)
def build_extension(self, ext: Extension) -> None:
build_lib = Path(self.build_lib)
build_lib.mkdir(parents=True, exist_ok=True)
root_dir = Path(__file__).parent
build_dir = root_dir / "build-cmake"
build_dir.mkdir(parents=True, exist_ok=True)
source_dir = root_dir / "csrc"
subprocess.check_call(
[
"cmake",
"-B",
str(build_dir),
"-S",
str(source_dir),
"-G",
"Ninja",
"-DCMAKE_PREFIX_PATH=" + _get_torch_cmake_prefix_path(),
"-DTORCH_CUDA_ARCH_LIST=" + os.environ["TORCH_CUDA_ARCH_LIST"],
"-WITH_TESTS=OFF",
]
)
subprocess.check_call(["ninja"], cwd=str(build_dir))
class CustomBuild(_build):
def run(self) -> None:
self.run_command("build_ext")
super().run()
class CleanCommand(Command):
user_options = []
def initialize_options(self) -> None:
pass
def finalize_options(self) -> None:
pass
def run(self) -> None:
subprocess.run(
[
"rm",
"-rf",
"build",
"build-cmake",
"src/pplx_kernels.egg-info",
"src/pplx_kernels/libpplx_kernels.so",
]
)
extensions = [
Extension(
"pplx-kernels",
sources=[],
),
]
setup(
packages=find_packages(where="src"),
package_dir={"": "src"},
package_data={
"pplx_kernels": ["libpplx_kernels.so", "py.typed"],
},
cmdclass={
"build_ext": CMakeBuild,
"build": CustomBuild,
"clean": CleanCommand,
},
options={"bdist_wheel": {"py_limited_api": "cp39"}},
zip_safe=False,
ext_modules=extensions,
include_package_data=True,
)