diff --git a/include/onnxruntime/core/framework/tensor.h b/include/onnxruntime/core/framework/tensor.h index ac98756964..46b6d830b3 100644 --- a/include/onnxruntime/core/framework/tensor.h +++ b/include/onnxruntime/core/framework/tensor.h @@ -72,9 +72,6 @@ class Tensor final { //Move is allowed ORT_DISALLOW_COPY_AND_ASSIGNMENT(Tensor); - ///requires other.buffer_deleter_ == nullptr - Tensor& ShallowCopy(const Tensor& other); - Tensor(Tensor&& other); Tensor& operator=(Tensor&& other); diff --git a/onnxruntime/core/framework/tensor.cc b/onnxruntime/core/framework/tensor.cc index c78c7da9da..1dc3bf73fe 100644 --- a/onnxruntime/core/framework/tensor.cc +++ b/onnxruntime/core/framework/tensor.cc @@ -83,22 +83,6 @@ Tensor::~Tensor() { ReleaseBuffer(); } -Tensor& Tensor::ShallowCopy(const Tensor& other) { - // similar as above - ORT_ENFORCE(other.buffer_deleter_ == nullptr, - "Can't copy tensor with its owned buffer. Please transfer ownership by move."); - - if (this != &other) { - dtype_ = other.dtype_; - alloc_info_ = other.alloc_info_; - shape_ = other.shape_; - byte_offset_ = other.byte_offset_; - p_data_ = other.p_data_; - buffer_deleter_ = nullptr; - } - return *this; -} - void Tensor::ReleaseBuffer() { if (buffer_deleter_) { // if current tensor is responsible for delete the buffer diff --git a/onnxruntime/core/framework/utils.cc b/onnxruntime/core/framework/utils.cc index fe996fdc1a..08b869c444 100644 --- a/onnxruntime/core/framework/utils.cc +++ b/onnxruntime/core/framework/utils.cc @@ -155,8 +155,11 @@ common::Status CopyOneInputAcrossDevices(const SessionState& session_state, // our CPU exec provider doesn't support copy from GPU->CPU if (required_provider_type != onnxruntime::kCpuExecutionProvider) { ORT_RETURN_IF_ERROR(required_provider->CopyTensor(input_tensor, *new_tensor)); - } else { + } else if (input_provider_type != onnxruntime::kCpuExecutionProvider) { ORT_RETURN_IF_ERROR(p_input_provider->CopyTensor(input_tensor, *new_tensor)); + } else { + //both tensors are on CPU. + return Status(common::ONNXRUNTIME, common::FAIL, "can't copy a tensor from CPU to CPU"); } // } loop of node_info_vec @@ -309,8 +312,11 @@ common::Status CopyOutputsAcrossDevices(const SessionState& session_state, // our CPU exec provider doesn't support copy from GPU->CPU if (fetched_provider_type != onnxruntime::kCpuExecutionProvider) { ORT_RETURN_IF_ERROR(p_fetched_provider->CopyTensor(fetched_tensor, *p_output_tensor)); - } else { + } else if (output_provider_type != onnxruntime::kCpuExecutionProvider) { ORT_RETURN_IF_ERROR(p_output_provider->CopyTensor(fetched_tensor, *p_output_tensor)); + } else { + //both tensors are on CPU. + return Status(common::ONNXRUNTIME, common::FAIL, "can't copy a tensor from CPU to CPU"); } } diff --git a/onnxruntime/core/providers/cpu/cpu_execution_provider.h b/onnxruntime/core/providers/cpu/cpu_execution_provider.h index b8580a3d89..fa3e78c87c 100644 --- a/onnxruntime/core/providers/cpu/cpu_execution_provider.h +++ b/onnxruntime/core/providers/cpu/cpu_execution_provider.h @@ -50,18 +50,8 @@ class CPUExecutionProvider : public IExecutionProvider { const std::vector& kernel_registries) const override; ///requires src.buffer_deleter_ == nullptr - Status CopyTensor(const Tensor& src, Tensor& dst) const override { - ORT_ENFORCE(strcmp(dst.Location().name, CPU) == 0); - - // Todo: support copy with different devices. - if (strcmp(src.Location().name, CPU) != 0) { - ORT_NOT_IMPLEMENTED("copy from ", src.Location().name, " is not implemented"); - } - - // no really copy needed if is copy to cpu. - dst.ShallowCopy(src); - - return Status::OK(); + Status CopyTensor(const Tensor&, Tensor&) const override { + return Status(common::ONNXRUNTIME, common::FAIL, "Shouldn't reach here. CPUExecutionProvider doesn't support CopyTensor"); } const void* GetExecutionHandle() const noexcept override {