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

Function _copy_bytes_with_tensor

lmcache/python_ops_fallback.py:231–244  ·  view source on GitHub ↗

Copy raw bytes between pointers using torch tensor semantics. Note: This function only works for CPU-accessible memory. For device memory (CUDA/XPU), use lmcache_memcpy_async with the appropriate runtime library or PyTorch's tensor copy operations.

(dst: int, src: int, num_bytes: int)

Source from the content-addressed store, hash-verified

229
230
231def _copy_bytes_with_tensor(dst: int, src: int, num_bytes: int) -> None:
232 """Copy raw bytes between pointers using torch tensor semantics.
233
234 Note: This function only works for CPU-accessible memory. For device
235 memory (CUDA/XPU), use lmcache_memcpy_async with the appropriate runtime
236 library or PyTorch's tensor copy operations.
237 """
238 if num_bytes <= 0:
239 return
240
241 buffer_type = ctypes.c_uint8 * num_bytes
242 dst_tensor = torch.frombuffer(buffer_type.from_address(dst), dtype=torch.uint8)
243 src_tensor = torch.frombuffer(buffer_type.from_address(src), dtype=torch.uint8)
244 dst_tensor.copy_(src_tensor)
245
246
247class TransferDirection(IntEnum):

Callers 1

lmcache_memcpy_asyncFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected