MCPcopy Create free account
hub / github.com/bitsandbytes-foundation/bitsandbytes / get_native_library

Function get_native_library

bitsandbytes/cextension.py:348–377  ·  view source on GitHub ↗

Load CUDA library XOR CPU, as the latter contains a subset of symbols of the former.

()

Source from the content-addressed store, hash-verified

346
347
348def get_native_library() -> BNBNativeLibrary:
349 """
350 Load CUDA library XOR CPU, as the latter contains a subset of symbols of the former.
351 """
352 cuda_specs = get_cuda_specs()
353 binary_path = PACKAGE_DIR / f"libbitsandbytes_cpu{DYNAMIC_LIBRARY_SUFFIX}"
354
355 if cuda_specs:
356 cuda_binary_path = get_cuda_bnb_library_path(cuda_specs)
357
358 if not cuda_binary_path.exists():
359 raise RuntimeError(f"No compatible {BNB_BACKEND} binary found at {cuda_binary_path}")
360
361 binary_path = cuda_binary_path
362
363 if torch._C._has_xpu:
364 binary_path = get_xpu_bnb_library_path()
365
366 logger.debug(f"Loading bitsandbytes native library from: {binary_path}")
367
368 # Try to load the library - any errors will propagate up
369 dll = ct.cdll.LoadLibrary(str(binary_path))
370
371 if hasattr(dll, "get_context"): # only a CUDA-built library exposes this
372 return CudaBNBNativeLibrary(dll)
373
374 if torch._C._has_xpu:
375 return XpuBNBNativeLibrary(dll)
376
377 return BNBNativeLibrary(dll)
378
379
380ROCM_GPU_ARCH = get_rocm_gpu_arch()

Callers 1

cextension.pyFile · 0.85

Calls 6

get_cuda_specsFunction · 0.90
get_xpu_bnb_library_pathFunction · 0.85
XpuBNBNativeLibraryClass · 0.85
BNBNativeLibraryClass · 0.85

Tested by

no test coverage detected