@@ -173,6 +173,135 @@ def load_with_system_search(libname: str) -> Optional[LoadedDL]:
173
173
return None
174
174
175
175
176
+ def load_with_conda_search (libname : str ) -> Optional [LoadedDL ]:
177
+ """Try to load a library using conda search paths.
178
+
179
+ Args:
180
+ libname: The name of the library to load
181
+
182
+ Returns:
183
+ A LoadedDL object if successful, None if the library cannot be loaded
184
+ """
185
+ in_conda_build = False
186
+ in_conda_env = False
187
+ if os .getenv ("CONDA_BUILD" ) == "1" :
188
+ in_conda_build = True
189
+ elif os .getenv ("CONDA_PREFIX" ):
190
+ in_conda_env = True
191
+ else :
192
+ return None
193
+
194
+ normal_conda_lib_path = os .path .join ("lib" )
195
+ # TODO KEITH: All the libs in the targets directory are symlinked into the lib directory, do we need to search it?
196
+ # TODO KEITH: Should we do platform detection here to avoid extra searches? Any considerations we need to do in a
197
+ # cross compilation build environment?
198
+ nvidia_conda_target_lib_paths = [
199
+ os .path .join ("targets" , "x86_64-linux" , "lib" ),
200
+ os .path .join ("targets" , "sbsa-linux" , "lib" ),
201
+ ]
202
+ if libname == "nvvm" :
203
+ normal_conda_lib_path = os .path .join ("nvvm" )
204
+ nvidia_conda_target_lib_paths = [
205
+ os .path .join ("targets" , "x86_64-linux" , "nvvm" , "lib64" ),
206
+ os .path .join ("targets" , "sbsa-linux" , "nvvm" , "lib64" ),
207
+ ]
208
+
209
+ for soname in get_candidate_sonames (libname ):
210
+ if in_conda_build :
211
+ if prefix := os .getenv ("PREFIX" ):
212
+ for nvidia_conda_target_lib_path in nvidia_conda_target_lib_paths :
213
+ prefix_target_lib_path = os .path .join (prefix , nvidia_conda_target_lib_path )
214
+ if os .path .isdir (prefix_target_lib_path ):
215
+ soname = os .path .join (prefix_target_lib_path , soname )
216
+ try :
217
+ handle = _load_lib (libname , soname )
218
+ except OSError :
219
+ pass
220
+ else :
221
+ # TODO KEITH: Do we need this abs_path_for_dynamic_library call?
222
+ # We're already resolving the absolute path based on the conda environment variables
223
+ abs_path = abs_path_for_dynamic_library (libname , handle )
224
+ if abs_path is None :
225
+ raise RuntimeError (f"No expected symbol for { libname = !r} " )
226
+ return LoadedDL (abs_path , False , handle ._handle )
227
+ # Only run if not found in the target lib paths
228
+ prefix_normal_lib_path = os .path .join (prefix , normal_conda_lib_path )
229
+ if os .path .isdir (prefix_normal_lib_path ):
230
+ soname = os .path .join (prefix_normal_lib_path , soname )
231
+ try :
232
+ handle = _load_lib (libname , soname )
233
+ except OSError :
234
+ pass
235
+ else :
236
+ # TODO KEITH: Do we need this abs_path_for_dynamic_library call?
237
+ # We're already resolving the absolute path based on the conda environment variables
238
+ abs_path = abs_path_for_dynamic_library (libname , handle )
239
+ if abs_path is None :
240
+ raise RuntimeError (f"No expected symbol for { libname = !r} " )
241
+ return LoadedDL (abs_path , False , handle ._handle )
242
+ if build_prefix := os .getenv ("BUILD_PREFIX" ):
243
+ for nvidia_conda_target_lib_path in nvidia_conda_target_lib_paths :
244
+ build_prefix_target_lib_path = os .path .join (build_prefix , nvidia_conda_target_lib_path )
245
+ if os .path .isdir (build_prefix_target_lib_path ):
246
+ soname = os .path .join (build_prefix_target_lib_path , soname )
247
+ try :
248
+ handle = _load_lib (libname , soname )
249
+ except OSError :
250
+ pass
251
+ else :
252
+ # TODO KEITH: Do we need this abs_path_for_dynamic_library call?
253
+ # We're already resolving the absolute path based on the conda environment variables
254
+ abs_path = abs_path_for_dynamic_library (libname , handle )
255
+ if abs_path is None :
256
+ raise RuntimeError (f"No expected symbol for { libname = !r} " )
257
+ return LoadedDL (abs_path , False , handle ._handle )
258
+ # Only run if not found in the target lib paths
259
+ build_prefix_normal_lib_path = os .path .join (build_prefix , normal_conda_lib_path )
260
+ if os .path .isdir (build_prefix_normal_lib_path ):
261
+ soname = os .path .join (build_prefix_normal_lib_path , soname )
262
+ try :
263
+ handle = _load_lib (libname , soname )
264
+ except OSError :
265
+ pass
266
+ else :
267
+ # TODO KEITH: Do we need this abs_path_for_dynamic_library call?
268
+ # We're already resolving the absolute path based on the conda environment variables
269
+ abs_path = abs_path_for_dynamic_library (libname , handle )
270
+ if abs_path is None :
271
+ raise RuntimeError (f"No expected symbol for { libname = !r} " )
272
+ return LoadedDL (abs_path , False , handle ._handle )
273
+ elif in_conda_env :
274
+ if conda_prefix := os .getenv ("CONDA_PREFIX" ):
275
+ for nvidia_conda_target_lib_path in nvidia_conda_target_lib_paths :
276
+ conda_prefix_target_lib_path = os .path .join (conda_prefix , nvidia_conda_target_lib_path )
277
+ if os .path .isdir (conda_prefix_target_lib_path ):
278
+ soname = os .path .join (conda_prefix_target_lib_path , soname )
279
+ try :
280
+ handle = _load_lib (libname , soname )
281
+ except OSError :
282
+ pass
283
+ else :
284
+ # TODO KEITH: Do we need this abs_path_for_dynamic_library call?
285
+ # We're already resolving the absolute path based on the conda environment variables
286
+ abs_path = abs_path_for_dynamic_library (libname , handle )
287
+ if abs_path is None :
288
+ raise RuntimeError (f"No expected symbol for { libname = !r} " )
289
+ return LoadedDL (abs_path , False , handle ._handle )
290
+ # Only run if not found in the target lib paths
291
+ conda_prefix_normal_lib_path = os .path .join (conda_prefix , normal_conda_lib_path )
292
+ if os .path .isdir (conda_prefix_normal_lib_path ):
293
+ soname = os .path .join (conda_prefix_normal_lib_path , soname )
294
+ try :
295
+ handle = _load_lib (libname , soname )
296
+ except OSError :
297
+ pass
298
+ else :
299
+ # TODO KEITH: Do we need this abs_path_for_dynamic_library call?
300
+ # We're already resolving the absolute path based on the conda environment variables
301
+ abs_path = abs_path_for_dynamic_library (libname , handle )
302
+ return None
303
+
304
+
176
305
def _work_around_known_bugs (libname : str , found_path : str ) -> None :
177
306
if libname == "nvrtc" :
178
307
# Work around bug/oversight in
0 commit comments