[XPU] Preserve non-contiguous strides when pinning CPU tensors for UVA view (#54874)

Signed-off-by: Chaojun Zhang <chaojun.zhang@intel.com>
This commit is contained in:
Chaojun Zhang
2026-09-29 09:43:07 +08:00
committed by GitHub
parent 70ae0b7435
commit 7230dfea50
3 changed files with 125 additions and 34 deletions
+9 -4
View File
@@ -912,10 +912,15 @@ def get_accelerator_view_from_cpu_tensor(cpu_tensor: torch.Tensor) -> torch.Tens
if cpu_tensor.numel() == 0:
return torch.empty(cpu_tensor.shape, dtype=cpu_tensor.dtype, device="xpu")
if not cpu_tensor.is_pinned():
contiguous_cpu = cpu_tensor.contiguous()
pinned = torch.empty_like(contiguous_cpu, pin_memory=True)
pinned.copy_(contiguous_cpu)
cpu_tensor = pinned
pinned = torch.empty_strided(
cpu_tensor.size(),
cpu_tensor.stride(),
dtype=cpu_tensor.dtype,
device="cpu",
pin_memory=True,
)
pinned.copy_(cpu_tensor)
return torch.ops._C.get_xpu_view_from_cpu_tensor(pinned)
return torch.ops._C.get_xpu_view_from_cpu_tensor(cpu_tensor)
elif current_platform.is_cuda_alike():
return torch.ops._C.get_cuda_view_from_cpu_tensor(cpu_tensor)