mirror of
https://github.com/saymrwulf/onnxruntime.git
synced 2026-07-07 17:15:29 +00:00
Delete Tensor::ShallowCopy
This commit is contained in:
parent
fc90a9b2fc
commit
d05b74b1b7
4 changed files with 10 additions and 33 deletions
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -50,18 +50,8 @@ class CPUExecutionProvider : public IExecutionProvider {
|
|||
const std::vector<const KernelRegistry*>& 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 {
|
||||
|
|
|
|||
Loading…
Reference in a new issue