Skip to content

Commit 81b7817

Browse files
committed
Integrate cmake into cmdclass for benchmarks
1 parent e941eec commit 81b7817

File tree

1 file changed

+43
-11
lines changed

1 file changed

+43
-11
lines changed

benchmarks/setup.py

Lines changed: 43 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@
33
import subprocess
44
import sys
55

6+
from distutils import log
7+
from distutils.dir_util import remove_tree
8+
from distutils.command.clean import clean as _clean
9+
from distutils.command.build import build as _build
10+
611
from setuptools import setup
7-
from setuptools.command.build_ext import build_ext as build_ext_orig
812

913
import torch
1014

@@ -27,9 +31,18 @@ def check_ipex(self):
2731
self.use_ipex = os.getenv("USE_IPEX", "1") == "1"
2832
if not self.use_ipex:
2933
return
30-
import intel_extension_for_pytorch
34+
try:
35+
import intel_extension_for_pytorch
36+
except ImportError:
37+
log.warn("ipex is not installed trying to build without ipex")
38+
self.use_ipex = False
39+
return
3140
self.cmake_prefix_paths.append(intel_extension_for_pytorch.cmake_prefix_path)
3241

42+
def check_call(self, *popenargs, **kwargs):
43+
print(" ".join(popenargs[0]))
44+
subprocess.check_call(*popenargs, **kwargs)
45+
3346
def build_extension(self):
3447
ninja_dir = shutil.which("ninja")
3548
# create build directories
@@ -69,31 +82,50 @@ def build_extension(self):
6982
]
7083

7184
env = os.environ.copy()
72-
print(" ".join(["cmake"] + cmake_args))
73-
subprocess.check_call(["cmake"] + cmake_args, env=env)
74-
print(" ".join(["cmake"] + build_args))
75-
subprocess.check_call(["cmake"] + build_args)
76-
print(" ".join(["cmake"] + install_args))
77-
subprocess.check_call(["cmake"] + install_args)
85+
self.check_call(["cmake"] + cmake_args, env=env)
86+
self.check_call(["cmake"] + build_args)
87+
self.check_call(["cmake"] + install_args)
7888

89+
def clean(self):
90+
if os.path.exists(self.build_temp):
91+
remove_tree(self.build_temp, dry_run=self.dry_run)
92+
else:
93+
log.warn("'%s' does not exist -- can't clean it", os.path.relpath(self.build_temp,
94+
os.path.dirname(__file__)))
7995

80-
class build_ext(build_ext_orig):
96+
97+
class build(_build):
8198

8299
def run(self):
83100
self.build_cmake()
84101
super().run()
85102

86103
def build_cmake(self):
87104
DEBUG_OPTION = os.getenv("DEBUG", "0")
88-
build_type = "Debug" if self.debug or DEBUG_OPTION == "1" else "Release"
105+
debug = DEBUG_OPTION == "1"
106+
if hasattr(self, "debug"):
107+
debug = debug or self.debug
108+
build_type = "Debug" if debug else "Release"
89109
cmake = CMakeBuild(build_type)
90110
cmake.run()
91111

92112

113+
class clean(_clean):
114+
115+
def run(self):
116+
self.clean_cmake()
117+
super().run()
118+
119+
def clean_cmake(self):
120+
cmake = CMakeBuild()
121+
cmake.clean()
122+
123+
93124
setup(name="triton-kernels-benchmark", packages=[
94125
"triton_kernels_benchmark",
95126
], package_dir={
96127
"triton_kernels_benchmark": "triton_kernels_benchmark",
97128
}, package_data={"triton_kernels_benchmark": ["xetla_kernel.cpython-*.so"]}, cmdclass={
98-
"build_ext": build_ext,
129+
"build": build,
130+
"clean": clean,
99131
})

0 commit comments

Comments
 (0)