MCPcopy Create free account
hub / github.com/LMCache/LMCache / _get_copy_lib

Function _get_copy_lib

lmcache/python_ops_fallback.py:36–58  ·  view source on GitHub ↗

Lazily load and cache the CUDA/ROCm runtime library, or None for CPU fallback.

()

Source from the content-addressed store, hash-verified

34
35
36def _get_copy_lib() -> Optional[ctypes.CDLL]:
37 """Lazily load and cache the CUDA/ROCm runtime library, or None for CPU fallback."""
38 global _copy_lib
39 if _copy_lib is _copy_lib_NOT_LOADED:
40 # Try to load GPU runtime libraries in priority order: CUDA first, then ROCm
41 # TODO: ROCm path to be validated on real device
42 for name, fallback in [
43 ("cudart", "libcudart.so"), # NVIDIA CUDA Runtime
44 ("amdhip64", "libamdhip64.so"), # AMD ROCm HIP Runtime
45 ]:
46 try:
47 path = ctypes.util.find_library(name)
48 if path:
49 _copy_lib = ctypes.CDLL(path)
50 else:
51 _copy_lib = ctypes.CDLL(fallback)
52 break # Successfully loaded, stop trying
53 except OSError:
54 continue # Current library not available, try next
55 else:
56 # All GPU libraries failed to load, fall back to CPU
57 _copy_lib = None
58 return _copy_lib
59
60
61def _tensor_from_ptr(

Callers 2

_tensor_from_cuda_ptrFunction · 0.85
lmcache_memcpy_asyncFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected