From e6309acdba3a26e803d1ea7f66804f4ad30c2b9a Mon Sep 17 00:00:00 2001 From: "Jane (Yuan) Xu" <31798555+janeyx99@users.noreply.github.com> Date: Sat, 22 Nov 2025 05:35:32 -0500 Subject: [PATCH] Simplify `from_blob` usage in `get_cuda_view_from_cpu_tensor` (#29027) Signed-off-by: Jane Xu --- csrc/cuda_view.cu | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/csrc/cuda_view.cu b/csrc/cuda_view.cu index 938bd4ab7fc62..9853fc942bab7 100644 --- a/csrc/cuda_view.cu +++ b/csrc/cuda_view.cu @@ -22,15 +22,10 @@ torch::Tensor get_cuda_view_from_cpu_tensor(torch::Tensor& cpu_tensor) { auto strides = cpu_tensor.strides(); auto options = cpu_tensor.options().device(torch::kCUDA); - // from_blob signature: from_blob(void *data, IntArrayRef sizes, ..., Deleter, - // const TensorOptions &) Provide a no-op deleter. The CPU tensor holds the - // memory, so we don't free it here. - auto deleter = [](void*) { - // no-op, since the memory is owned by the original CPU tensor - }; - + // use default no-op deleter, since the memory is owned by the original CPU + // tensor torch::Tensor cuda_tensor = - torch::from_blob(device_ptr, sizes, strides, deleter, options); + torch::from_blob(device_ptr, sizes, strides, options); TORCH_CHECK(cuda_tensor.device().is_cuda(), "Resulting tensor is not on CUDA device");