Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions torch_xla/csrc/aten_xla_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,16 @@ int64_t AtenXlaType::numel(const at::Tensor& self) const {
return xla::ShapeUtil::ElementsIn(self_tensor.shape());
}

at::Tensor AtenXlaType::copy(const at::Tensor& src, bool /* non_blocking */,
at::optional<c10::Device> to_device) const {
std::vector<at::Tensor> tensors = {src};
std::vector<bool> writeables = {false};
auto xla_tensors = bridge::XlaCreateTensorList(tensors, &writeables);
Device device = to_device ? bridge::AtenDeviceToXlaDevice(*to_device)
: *GetDefaultDevice();
return bridge::CreateXlaTensor(xla_tensors.front(), device);
}

at::Tensor AtenXlaType::_s_copy_from(const at::Tensor& self,
const at::Tensor& dst,
bool /* non_blocking */) const {
Expand Down
3 changes: 3 additions & 0 deletions torch_xla/csrc/aten_xla_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ class AtenXlaType : public AtenXlaTypeBase {

int64_t numel(const at::Tensor& self) const override;

at::Tensor copy(const at::Tensor& src, bool non_blocking,
at::optional<c10::Device> to_device) const override;

at::Tensor _s_copy_from(const at::Tensor& self, const at::Tensor& dst,
bool non_blocking) const override;

Expand Down