88
99import 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
1812class 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