Skip to content

Commit ab10b02

Browse files
committed
Incapsulate IPEX check in benchamrks
1 parent 008f27a commit ab10b02

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

benchmarks/setup.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,6 @@
88

99
import torch
1010

11-
ipex_cmake_prefix_path = ""
12-
USE_IPEX_OPTION = os.getenv("USE_IPEX", "1")
13-
if USE_IPEX_OPTION == "1":
14-
import intel_extension_for_pytorch
15-
ipex_cmake_prefix_path = f";{intel_extension_for_pytorch.cmake_prefix_path}"
16-
1711

1812
class CMakeBuild():
1913

@@ -22,10 +16,20 @@ def __init__(self, build_type="Debug"):
2216
self.build_temp = self.current_dir + "/build/temp"
2317
self.extdir = self.current_dir + "/triton_kernels_benchmark"
2418
self.build_type = build_type
19+
self.cmake_prefix_paths = [torch.utils.cmake_prefix_path]
20+
self.use_ipex = False
2521

2622
def run(self):
23+
self.check_ipex()
2724
self.build_extension()
2825

26+
def check_ipex(self):
27+
self.use_ipex = os.getenv("USE_IPEX", "1") == "1"
28+
if not self.use_ipex:
29+
return
30+
import intel_extension_for_pytorch
31+
self.cmake_prefix_paths.append(intel_extension_for_pytorch.cmake_prefix_path)
32+
2933
def build_extension(self):
3034
ninja_dir = shutil.which("ninja")
3135
# create build directories
@@ -36,8 +40,8 @@ def build_extension(self):
3640
"Ninja", # Ninja is much faster than make
3741
"-DCMAKE_MAKE_PROGRAM=" +
3842
ninja_dir, # Pass explicit path to ninja otherwise cmake may cache a temporary path
39-
f"-DCMAKE_PREFIX_PATH={torch.utils.cmake_prefix_path}{ipex_cmake_prefix_path}",
40-
f"-DUSE_IPEX={USE_IPEX_OPTION}",
43+
"-DCMAKE_PREFIX_PATH=" + ";".join(self.cmake_prefix_paths),
44+
"-DUSE_IPEX=" + ("1" if self.use_ipex else "0"),
4145
"-DCMAKE_INSTALL_PREFIX=" + self.extdir,
4246
"-DPython3_ROOT_DIR:FILEPATH=" + sys.exec_prefix,
4347
"-DCMAKE_VERBOSE_MAKEFILE=TRUE",

0 commit comments

Comments
 (0)