Skip to content

Commit

Permalink
Add lazy init to empty/resize (#1183)
Browse files Browse the repository at this point in the history
# Motivation
As titled.

# Additional Context
Align to CUDA.

(cherry picked from commit cd0873c)
  • Loading branch information
guangyey committed Dec 26, 2024
1 parent 7ecb0b1 commit 8251ec9
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/ATen/native/xpu/sycl/ResizeKernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
1 change: 1 addition & 0 deletions src/ATen/xpu/EmptyTensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ TensorBase empty_strided_xpu(
IntArrayRef stride,
ScalarType dtype,
c10::optional<Device> 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);
Expand Down

0 comments on commit 8251ec9

Please sign in to comment.