From d6a30485be2015115b8abb60d8240af8f4e8a977 Mon Sep 17 00:00:00 2001 From: Yufeng Li Date: Fri, 26 Jul 2019 14:15:53 -0700 Subject: [PATCH] Rename Tensor.Size() to Tensor.SizeInBytes() (#1502) Rename Tensor.Size() to Tensor.SizeInBytes() --- include/onnxruntime/core/framework/tensor.h | 2 +- onnxruntime/core/framework/data_transfer.cc | 4 ++-- onnxruntime/core/framework/tensorprotoutils.cc | 2 +- onnxruntime/core/providers/cpu/controlflow/loop.cc | 12 ++++++------ .../core/providers/cpu/controlflow/scan_utils.h | 2 +- onnxruntime/core/providers/cpu/tensor/scatter.cc | 2 +- onnxruntime/core/providers/cpu/tensor/size.cc | 2 +- onnxruntime/core/providers/cpu/tensor/upsample.cc | 2 +- onnxruntime/core/providers/cuda/gpu_data_transfer.cc | 2 +- onnxruntime/test/framework/parallel_executor_test.cc | 2 +- onnxruntime/test/framework/sparse_kernels_test.cc | 2 +- 11 files changed, 17 insertions(+), 17 deletions(-) diff --git a/include/onnxruntime/core/framework/tensor.h b/include/onnxruntime/core/framework/tensor.h index 260d1731bc..35eb359c71 100644 --- a/include/onnxruntime/core/framework/tensor.h +++ b/include/onnxruntime/core/framework/tensor.h @@ -170,7 +170,7 @@ class Tensor final { /** The number of bytes of data. */ - size_t Size() const { + size_t SizeInBytes() const { size_t ret; int64_t l = shape_.Size(); if (l >= static_cast(std::numeric_limits::max())) { diff --git a/onnxruntime/core/framework/data_transfer.cc b/onnxruntime/core/framework/data_transfer.cc index c028a12202..465655f03d 100644 --- a/onnxruntime/core/framework/data_transfer.cc +++ b/onnxruntime/core/framework/data_transfer.cc @@ -21,8 +21,8 @@ common::Status CPUDataTransfer::CopyTensor(const Tensor& src, Tensor& dst, int / return Status::OK(); } // Copying only happens between two same size tensors. - ORT_ENFORCE(src.Size() == dst.Size()); - memcpy(dst_data, src_data, src.Size()); + ORT_ENFORCE(src.SizeInBytes() == dst.SizeInBytes()); + memcpy(dst_data, src_data, src.SizeInBytes()); return Status::OK(); } diff --git a/onnxruntime/core/framework/tensorprotoutils.cc b/onnxruntime/core/framework/tensorprotoutils.cc index 634a59232c..ce7fc4e91d 100644 --- a/onnxruntime/core/framework/tensorprotoutils.cc +++ b/onnxruntime/core/framework/tensorprotoutils.cc @@ -557,7 +557,7 @@ ONNX_NAMESPACE::TensorProto TensorToTensorProto(const Tensor& tensor, const std: tensor_proto.set_data_type(tensor_proto_type.tensor_type().elem_type()); - tensor_proto.set_raw_data(tensor.DataRaw(), tensor.Size()); + tensor_proto.set_raw_data(tensor.DataRaw(), tensor.SizeInBytes()); return tensor_proto; } diff --git a/onnxruntime/core/providers/cpu/controlflow/loop.cc b/onnxruntime/core/providers/cpu/controlflow/loop.cc index 02609cdfee..3937ab4ed5 100644 --- a/onnxruntime/core/providers/cpu/controlflow/loop.cc +++ b/onnxruntime/core/providers/cpu/controlflow/loop.cc @@ -302,7 +302,7 @@ void LoopImpl::SaveOutputsAndUpdateFeeds(const std::vector& last_outpu Status LoopImpl::ConcatenateLoopOutput(std::vector& per_iteration_output, int output_index) { const auto& first_output = per_iteration_output.front().Get(); - size_t bytes_per_iteration = first_output.Size(); + size_t bytes_per_iteration = first_output.SizeInBytes(); const auto& per_iteration_shape = first_output.Shape(); const auto& per_iteration_dims = per_iteration_shape.GetDims(); @@ -317,19 +317,19 @@ Status LoopImpl::ConcatenateLoopOutput(std::vector& per_iteration_outp // we can't easily use a C++ template for the tensor element type, // so use a span for some protection but work in bytes gsl::span output_span = gsl::make_span(static_cast(output->MutableDataRaw()), - output->Size()); + output->SizeInBytes()); for (int64_t i = 0; i < num_iterations; ++i) { auto& ort_value = per_iteration_output[i]; auto& iteration_data = ort_value.Get(); // sanity check - if (bytes_per_iteration != iteration_data.Size()) { + if (bytes_per_iteration != iteration_data.SizeInBytes()) { return ORT_MAKE_STATUS(ONNXRUNTIME, FAIL, "Inconsistent shape in loop output for output ", output_index, " Expected:", per_iteration_shape, " Got:", iteration_data.Shape()); } - auto num_bytes = iteration_data.Size(); + auto num_bytes = iteration_data.SizeInBytes(); auto src = gsl::make_span(static_cast(iteration_data.DataRaw()), num_bytes); auto dst = output_span.subspan(i * bytes_per_iteration, bytes_per_iteration); gsl::copy(src, dst); @@ -382,8 +382,8 @@ Status LoopImpl::Execute(FeedsFetchesManager* ffm, const FeedsFetchesManager* ca auto copy_tensor_from_mlvalue_to_output = [this](const OrtValue& input, int output_idx) { auto& data = input.Get(); Tensor* output = context_.Output(output_idx, data.Shape()); - auto src = gsl::make_span(static_cast(data.DataRaw()), data.Size()); - auto dst = gsl::make_span(static_cast(output->MutableDataRaw()), output->Size()); + auto src = gsl::make_span(static_cast(data.DataRaw()), data.SizeInBytes()); + auto dst = gsl::make_span(static_cast(output->MutableDataRaw()), output->SizeInBytes()); gsl::copy(src, dst); }; diff --git a/onnxruntime/core/providers/cpu/controlflow/scan_utils.h b/onnxruntime/core/providers/cpu/controlflow/scan_utils.h index c300602427..7840463c02 100644 --- a/onnxruntime/core/providers/cpu/controlflow/scan_utils.h +++ b/onnxruntime/core/providers/cpu/controlflow/scan_utils.h @@ -103,7 +103,7 @@ class OutputIterator { // set the output for the current iteration to zeros. used for short sequence lengths void ZeroOutCurrent() { auto* tensor = (**this).GetMutable(); - memset(tensor->MutableDataRaw(), 0, tensor->Size()); + memset(tensor->MutableDataRaw(), 0, tensor->SizeInBytes()); } const OrtValue& GetOutput() const { diff --git a/onnxruntime/core/providers/cpu/tensor/scatter.cc b/onnxruntime/core/providers/cpu/tensor/scatter.cc index 0cdacbef2e..403ef62ec3 100644 --- a/onnxruntime/core/providers/cpu/tensor/scatter.cc +++ b/onnxruntime/core/providers/cpu/tensor/scatter.cc @@ -45,7 +45,7 @@ Status CopyScatterData(const Tensor* data_input, const Tensor* indices_input, co } const auto input_elements = input_data_shape.Size(); - const auto total_input_bytes = data_input->Size(); + const auto total_input_bytes = data_input->SizeInBytes(); const auto* src_base = static_cast(data_input->DataRaw()); auto* dst_base = static_cast(data_output->MutableDataRaw()); diff --git a/onnxruntime/core/providers/cpu/tensor/size.cc b/onnxruntime/core/providers/cpu/tensor/size.cc index a649560c10..675c14b8cf 100644 --- a/onnxruntime/core/providers/cpu/tensor/size.cc +++ b/onnxruntime/core/providers/cpu/tensor/size.cc @@ -12,7 +12,7 @@ Status Size::Compute(OpKernelContext* ctx) const { TensorShape scalar_shape; Tensor* p_output_tensor = ctx->Output(0, scalar_shape); auto* p_output_scalar = p_output_tensor->template MutableData(); - assert(p_output_tensor->Size() == sizeof(int64_t)); + assert(p_output_tensor->SizeInBytes() == sizeof(int64_t)); *p_output_scalar = input_tensor->Shape().Size(); diff --git a/onnxruntime/core/providers/cpu/tensor/upsample.cc b/onnxruntime/core/providers/cpu/tensor/upsample.cc index bd98715423..95605dbef4 100644 --- a/onnxruntime/core/providers/cpu/tensor/upsample.cc +++ b/onnxruntime/core/providers/cpu/tensor/upsample.cc @@ -342,7 +342,7 @@ Status Upsample::BaseCompute(OpKernelContext* context, const std::vectorOutput(0, Y_dims); if (no_scale) { - memcpy(Y->MutableDataRaw(), X->DataRaw(), Y->Size()); + memcpy(Y->MutableDataRaw(), X->DataRaw(), Y->SizeInBytes()); return Status::OK(); } diff --git a/onnxruntime/core/providers/cuda/gpu_data_transfer.cc b/onnxruntime/core/providers/cuda/gpu_data_transfer.cc index b80a1f8cab..ec930946aa 100644 --- a/onnxruntime/core/providers/cuda/gpu_data_transfer.cc +++ b/onnxruntime/core/providers/cuda/gpu_data_transfer.cc @@ -18,7 +18,7 @@ bool GPUDataTransfer::CanCopy(const OrtDevice& src_device, const OrtDevice& dst_ } common::Status GPUDataTransfer::CopyTensor(const Tensor& src, Tensor& dst, int exec_queue_id) const { - size_t bytes = src.Size(); + size_t bytes = src.SizeInBytes(); const void* src_data = src.DataRaw(); void* dst_data = dst.MutableDataRaw(); diff --git a/onnxruntime/test/framework/parallel_executor_test.cc b/onnxruntime/test/framework/parallel_executor_test.cc index a4ccd7f72d..fc6d885d67 100644 --- a/onnxruntime/test/framework/parallel_executor_test.cc +++ b/onnxruntime/test/framework/parallel_executor_test.cc @@ -46,7 +46,7 @@ struct TestOp { // success Tensor* Y = ctx->Output(0, action_tensor.Shape()); void* target = Y->MutableData(); - memcpy(target, action, action_tensor.Size()); + memcpy(target, action, action_tensor.SizeInBytes()); break; } case 1: { diff --git a/onnxruntime/test/framework/sparse_kernels_test.cc b/onnxruntime/test/framework/sparse_kernels_test.cc index 80ede37bce..02923b569a 100644 --- a/onnxruntime/test/framework/sparse_kernels_test.cc +++ b/onnxruntime/test/framework/sparse_kernels_test.cc @@ -196,7 +196,7 @@ This operator applies the Abs op element-wise to the input sparse-tensor. // So, we copy indices/shape from input to output. // TODO: Extend allocation-planner to enable such sharing. const auto& input_indices = input->Indices(); - memcpy(output->MutableIndices().MutableData(), input_indices.Data(), input_indices.Size()); + memcpy(output->MutableIndices().MutableData(), input_indices.Data(), input_indices.SizeInBytes()); return Status::OK(); } };