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)
| 229 | |
| 230 | |
| 231 | def _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 | |
| 247 | class TransferDirection(IntEnum): |
no outgoing calls
no test coverage detected