@@ -111,23 +111,59 @@ def select_compiler():
111111 return cxx
112112
113113
114+ def _cxx_compile_cmd (cxx : str , src : list , include_dirs : list , only_compile : bool = True ) -> list :
115+ if "cl.EXE" in cxx or "clang-cl" in cxx :
116+ command = [cxx ] + src + ["/I" + include_dir for include_dir in include_dirs
117+ ] + ["/Zc:__cplusplus" , "/std:c++17" , "/MD" , "/nologo" , "/O2" , "/EHsc" , "/wd4996" ]
118+ if only_compile :
119+ command += ["/c" ]
120+ else :
121+ command = [cxx ] + src + ["-I" + include_dir for include_dir in include_dirs
122+ ] + ["-fPIC" if os .name != "nt" else "-Wno-deprecated-declarations" ]
123+ if only_compile :
124+ command += ["-c" ]
125+ return command
126+
127+
128+ def _cxx_link_cmd (cxx : str , o_files : list , out : str , extra_library_dirs : list = [], extra_libraries : list = [],
129+ shared_lib : bool = True ) -> list :
130+ extra_link_args = []
131+ if os .name == "nt" :
132+ libname_without_ext = out .split ("." )[0 ]
133+ extra_link_args = [f"/IMPLIB:{ libname_without_ext } .lib" ]
134+
135+ library_dirs = COMPILATION_HELPER .library_dir + COMPILATION_HELPER .libsycl_dir + extra_library_dirs
136+ if "cl.EXE" in cxx or "clang-cl" in cxx :
137+ command = [cxx ] + [* o_files , * (["/LD" ] if shared_lib else []), "/link" , f"/OUT:{ out } " ] + [
138+ "/LIBPATH:" + library_dir for library_dir in library_dirs
139+ ] + ["sycl8.lib" , "ze_loader.lib" ] + [f"{ lib } .lib" for lib in extra_libraries ] + extra_link_args
140+ else :
141+ command = [cxx ] + [* o_files , * (["-shared" ] if shared_lib else []), "-o" , out ] + [
142+ "-L" + library_dir for library_dir in library_dirs
143+ ] + ["-lsycl8" if os .name == "nt" else "-lsycl" , "-lze_loader" ] + [f"-l{ lib } "
144+ for lib in extra_libraries ] + extra_link_args
145+
146+ return command
147+
148+
149+ def _cxx_cmd (cxx : str , src : list , out : str , include_dirs : list , extra_library_dirs : list ,
150+ extra_libraries : list ) -> list :
151+ compile_command = _cxx_compile_cmd (cxx , src , include_dirs , only_compile = False )
152+ link_command = _cxx_link_cmd (cxx , [], out , extra_library_dirs , extra_libraries , shared_lib = False )
153+ return compile_command + link_command [1 :]
154+
155+
114156def gen_kernel_library_xpu (dir , libname ):
115157 cpp_files = glob .glob (os .path .join (dir , "*.cpp" ))
116158 cxx = select_compiler ()
117- command = [cxx ] + cpp_files + ["-I" + include_dir for include_dir in COMPILATION_HELPER .include_dir
118- ] + ["-c" , "-fPIC" if os .name != "nt" else "-Wno-deprecated-declarations" ]
159+ command = _cxx_compile_cmd (cxx , cpp_files , COMPILATION_HELPER .include_dir )
119160 subprocess .run (command , check = True , cwd = dir )
120- o_files = glob .glob (os .path .join (dir , "*.o" ))
121-
122- extra_link_args = []
123- if "icpx" in cxx and os .name == "nt" :
124- libname_without_ext = libname .split ("." )[0 ]
125- extra_link_args = [f"/IMPLIB:{ libname_without_ext } .lib" ]
126161
127- command = [cxx ] + [* o_files , "-shared" , "-o" , libname ] + [
128- "-L" + library_dir for library_dir in COMPILATION_HELPER .library_dir
129- ] + ["-L" + dir for dir in COMPILATION_HELPER .libsycl_dir
130- ] + ["-lsycl8" if os .name == "nt" else "-lsycl" , "-lze_loader" ] + extra_link_args
162+ if "cl.EXE" in cxx or "clang-cl" in cxx :
163+ o_files = glob .glob (os .path .join (dir , "*.obj" ))
164+ else :
165+ o_files = glob .glob (os .path .join (dir , "*.o" ))
166+ command = _cxx_link_cmd (cxx , o_files , libname )
131167 subprocess .run (command , check = True , cwd = dir )
132168
133169
@@ -250,7 +286,7 @@ def gen_test_bin(dir, M, N, K, exe="test", algo_id=0):
250286 fclose(file);
251287}}
252288int main(int argc, char ** argv) {{
253- int M = { M } , N = { N } , K = { K } ;
289+ constexpr int M = { M } , N = { N } , K = { K } ;
254290
255291 // initialize sycl handles
256292 sycl::queue q{{sycl::gpu_selector_v}};
@@ -314,17 +350,7 @@ def gen_test_bin(dir, M, N, K, exe="test", algo_id=0):
314350
315351 if is_xpu ():
316352 cxx = select_compiler ()
317- command = [cxx , "test.cpp" ]
318- for inc_dir in COMPILATION_HELPER .include_dir :
319- command .extend (["-I" , inc_dir ])
320- for lib_dir in COMPILATION_HELPER .library_dir :
321- command .extend (["-L" , lib_dir ])
322- if COMPILATION_HELPER .libsycl_dir :
323- for lib_dir in COMPILATION_HELPER .libsycl_dir :
324- command .extend (["-L" , lib_dir ])
325- if os .name == "nt" :
326- command .extend (["-Wno-deprecated-declarations" ])
327- command .extend (["-lsycl8" if os .name == "nt" else "-lsycl" , "-lze_loader" , "-L" , dir , "-lkernel" , "-o" , exe ])
353+ command = _cxx_cmd (cxx , ["test.cpp" ], exe , COMPILATION_HELPER .include_dir , [dir ], ["kernel" ])
328354 subprocess .run (command , check = True , cwd = dir )
329355
330356
0 commit comments