@@ -113,57 +113,55 @@ def build_cmake(self, extension: CMakeExtension):
113113 'BUILD_FT' : 'OFF'
114114 }
115115
116+ compute_backend = os .getenv ('COMPUTE_BACKEND' , 'n/a' )
116117 runtime = 'gcc'
117- if 'COMPUTE_BACKEND' in os .environ :
118- if os .environ ['COMPUTE_BACKEND' ] == 'dpcpp' :
119- runtime = 'dpcpp'
120- build_options ['COMPUTE_BACKEND' ] = os .environ ['COMPUTE_BACKEND' ]
121- import intel_extension_for_pytorch
122- build_options ['CMAKE_PREFIX_PATH' ] += ";" + intel_extension_for_pytorch .cmake_prefix_path
123- if "DPCPP_GCC_INSTALL_DIR" in my_env :
124- exist_cflags = "CFLAGS" in my_env
125- cflags = ""
126- if exist_cflags :
127- cflags = my_env ["CFLAGS" ]
128- my_env ["CFLAGS" ] = f"--gcc-install-dir={ my_env ['DPCPP_GCC_INSTALL_DIR' ]} { cflags } "
129- exist_cxxflags = "CXXFLAGS" in my_env
130- cxxflags = ""
131- if exist_cxxflags :
132- cxxflags = my_env ["CXXFLAGS" ]
133- my_env ["CXXFLAGS" ] = f"--gcc-install-dir={ my_env ['DPCPP_GCC_INSTALL_DIR' ]} { cxxflags } "
134- exist_ldflags = "LDFLAGS" in my_env
135- ldflags = ""
136- if exist_ldflags :
137- ldflags = my_env ["LDFLAGS" ]
138- my_env ["LDFLAGS" ] = f"--gcc-install-dir={ my_env ['DPCPP_GCC_INSTALL_DIR' ]} -fuse-ld=lld -lrt -lpthread { ldflags } "
118+ if compute_backend == 'dpcpp' :
119+ runtime = 'dpcpp'
120+ build_options ['COMPUTE_BACKEND' ] = compute_backend
121+ import intel_extension_for_pytorch
122+ build_options ['CMAKE_PREFIX_PATH' ] += ";" + intel_extension_for_pytorch .cmake_prefix_path
123+ if "DPCPP_GCC_INSTALL_DIR" in my_env :
124+ exist_cflags = "CFLAGS" in my_env
125+ cflags = ""
126+ if exist_cflags :
127+ cflags = my_env ["CFLAGS" ]
128+ my_env ["CFLAGS" ] = f"--gcc-install-dir={ my_env ['DPCPP_GCC_INSTALL_DIR' ]} { cflags } "
129+ exist_cxxflags = "CXXFLAGS" in my_env
130+ cxxflags = ""
131+ if exist_cxxflags :
132+ cxxflags = my_env ["CXXFLAGS" ]
133+ my_env ["CXXFLAGS" ] = f"--gcc-install-dir={ my_env ['DPCPP_GCC_INSTALL_DIR' ]} { cxxflags } "
134+ exist_ldflags = "LDFLAGS" in my_env
135+ ldflags = ""
136+ if exist_ldflags :
137+ ldflags = my_env ["LDFLAGS" ]
138+ my_env ["LDFLAGS" ] = f"--gcc-install-dir={ my_env ['DPCPP_GCC_INSTALL_DIR' ]} -fuse-ld=lld -lrt -lpthread { ldflags } "
139139
140140 cc , cxx = get_compiler (runtime )
141141 build_options ['CMAKE_C_COMPILER' ] = cc
142142 build_options ['CMAKE_CXX_COMPILER' ] = cxx
143143
144144 extension .generate (build_options , my_env , build_dir , install_dir )
145145
146- if 'COMPUTE_BACKEND' in os .environ :
147- if os .environ ['COMPUTE_BACKEND' ] == 'dpcpp' :
148- if "DPCPP_GCC_INSTALL_DIR" in my_env :
149- if exist_cflags :
150- my_env ["CFLAGS" ] = cflags
151- else :
152- del my_env ["CFLAGS" ]
153- if exist_cxxflags :
154- my_env ["CXXFLAGS" ] = cxxflags
155- else :
156- del my_env ["CXXFLAGS" ]
157- if exist_ldflags :
158- my_env ["LDFLAGS" ] = ldflags
159- else :
160- del my_env ["LDFLAGS" ]
146+ if compute_backend == 'dpcpp' :
147+ if "DPCPP_GCC_INSTALL_DIR" in my_env :
148+ if exist_cflags :
149+ my_env ["CFLAGS" ] = cflags
150+ else :
151+ del my_env ["CFLAGS" ]
152+ if exist_cxxflags :
153+ my_env ["CXXFLAGS" ] = cxxflags
154+ else :
155+ del my_env ["CXXFLAGS" ]
156+ if exist_ldflags :
157+ my_env ["LDFLAGS" ] = ldflags
158+ else :
159+ del my_env ["LDFLAGS" ]
161160
162161 build_args = ['-j' , str (os .cpu_count ())]
163162 check_call (['make' , 'oneccl_bindings_for_pytorch' ] + build_args , cwd = str (build_dir ))
164- if 'COMPUTE_BACKEND' in os .environ :
165- if os .environ ['COMPUTE_BACKEND' ] == 'dpcpp' :
166- check_call (['make' , 'oneccl_bindings_for_pytorch_xpu' ] + build_args , cwd = str (build_dir ))
163+ if compute_backend == 'dpcpp' :
164+ check_call (['make' , 'oneccl_bindings_for_pytorch_xpu' ] + build_args , cwd = str (build_dir ))
167165 check_call (['make' , 'install' ], cwd = str (build_dir ))
168166
169167
@@ -223,7 +221,12 @@ def get_python_c_module():
223221 ]
224222
225223 def make_relative_rpath (path ):
226- return '-Wl,-rpath,$ORIGIN/' + path
224+ ret = []
225+ ret .append ('-Wl,-rpath,$ORIGIN/' + path )
226+ if os .getenv ('COMPUTE_BACKEND' , 'n/a' ) == 'dpcpp' :
227+ ret .append ('-Wl,-rpath,$ORIGIN/../../../' )
228+ ret .append ('-Wl,--disable-new-dtags' )
229+ return ret
227230
228231 _c_module = CppExtension ("oneccl_bindings_for_pytorch._C" ,
229232 libraries = main_libraries ,
@@ -232,7 +235,7 @@ def make_relative_rpath(path):
232235 extra_compile_args = main_compile_args + extra_compile_args ,
233236 include_dirs = include_dirs ,
234237 library_dirs = library_dirs ,
235- extra_link_args = extra_link_args + main_link_args + [ make_relative_rpath ('lib' )] )
238+ extra_link_args = extra_link_args + main_link_args + make_relative_rpath ('lib' ))
236239
237240 return _c_module
238241
0 commit comments