diff --git a/src/ATen/native/xpu/sycl/ResizeKernel.cpp b/src/ATen/native/xpu/sycl/ResizeKernel.cpp index 237a1c213..f1ee7f944 100644 --- a/src/ATen/native/xpu/sycl/ResizeKernel.cpp +++ b/src/ATen/native/xpu/sycl/ResizeKernel.cpp @@ -25,8 +25,9 @@ void resize_bytes_xpu(StorageImpl* storage, size_t size_bytes) { c10::xpu::XPUGuard guard(device.index()); at::DataPtr data = allocator->allocate(size_bytes); if (storage->data_ptr()) { - auto q = at::xpu::getCurrentSYCLQueue(); + at::globalContext().lazyInitDevice(c10::DeviceType::XPU); + auto q = at::xpu::getCurrentSYCLQueue(); q.memcpy( data.get(), storage->data(), std::min(storage->nbytes(), size_bytes)); } diff --git a/src/ATen/xpu/EmptyTensor.cpp b/src/ATen/xpu/EmptyTensor.cpp index 3f5e998f8..6411bb221 100644 --- a/src/ATen/xpu/EmptyTensor.cpp +++ b/src/ATen/xpu/EmptyTensor.cpp @@ -54,6 +54,7 @@ TensorBase empty_strided_xpu( IntArrayRef stride, ScalarType dtype, c10::optional device_opt) { + at::globalContext().lazyInitDevice(c10::DeviceType::XPU); const auto device = device_or_default(device_opt); TORCH_INTERNAL_ASSERT(device.is_xpu()); const c10::DeviceGuard device_guard(device);