mirror of
https://github.com/saymrwulf/onnxruntime.git
synced 2026-05-23 22:13:38 +00:00
Rename Tensor.Size() to Tensor.SizeInBytes() (#1502)
Rename Tensor.Size() to Tensor.SizeInBytes()
This commit is contained in:
parent
6f538dc861
commit
d6a30485be
11 changed files with 17 additions and 17 deletions
|
|
@ -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<int64_t>(std::numeric_limits<ptrdiff_t>::max())) {
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -302,7 +302,7 @@ void LoopImpl::SaveOutputsAndUpdateFeeds(const std::vector<OrtValue>& last_outpu
|
|||
|
||||
Status LoopImpl::ConcatenateLoopOutput(std::vector<OrtValue>& per_iteration_output, int output_index) {
|
||||
const auto& first_output = per_iteration_output.front().Get<Tensor>();
|
||||
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<OrtValue>& 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<gsl::byte> output_span = gsl::make_span<gsl::byte>(static_cast<gsl::byte*>(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<Tensor>();
|
||||
|
||||
// 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<const gsl::byte>(static_cast<const gsl::byte*>(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>();
|
||||
Tensor* output = context_.Output(output_idx, data.Shape());
|
||||
auto src = gsl::make_span<const gsl::byte>(static_cast<const gsl::byte*>(data.DataRaw()), data.Size());
|
||||
auto dst = gsl::make_span<gsl::byte>(static_cast<gsl::byte*>(output->MutableDataRaw()), output->Size());
|
||||
auto src = gsl::make_span<const gsl::byte>(static_cast<const gsl::byte*>(data.DataRaw()), data.SizeInBytes());
|
||||
auto dst = gsl::make_span<gsl::byte>(static_cast<gsl::byte*>(output->MutableDataRaw()), output->SizeInBytes());
|
||||
gsl::copy(src, dst);
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -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<Tensor>();
|
||||
memset(tensor->MutableDataRaw(), 0, tensor->Size());
|
||||
memset(tensor->MutableDataRaw(), 0, tensor->SizeInBytes());
|
||||
}
|
||||
|
||||
const OrtValue& GetOutput() const {
|
||||
|
|
|
|||
|
|
@ -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<const Tdata*>(data_input->DataRaw());
|
||||
auto* dst_base = static_cast<Tdata*>(data_output->MutableDataRaw());
|
||||
|
|
|
|||
|
|
@ -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<int64_t>();
|
||||
assert(p_output_tensor->Size() == sizeof(int64_t));
|
||||
assert(p_output_tensor->SizeInBytes() == sizeof(int64_t));
|
||||
|
||||
*p_output_scalar = input_tensor->Shape().Size();
|
||||
|
||||
|
|
|
|||
|
|
@ -342,7 +342,7 @@ Status Upsample<T>::BaseCompute(OpKernelContext* context, const std::vector<floa
|
|||
Tensor* Y = context->Output(0, Y_dims);
|
||||
|
||||
if (no_scale) {
|
||||
memcpy(Y->MutableDataRaw(), X->DataRaw(), Y->Size());
|
||||
memcpy(Y->MutableDataRaw(), X->DataRaw(), Y->SizeInBytes());
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ struct TestOp {
|
|||
// success
|
||||
Tensor* Y = ctx->Output(0, action_tensor.Shape());
|
||||
void* target = Y->MutableData<int64_t>();
|
||||
memcpy(target, action, action_tensor.Size());
|
||||
memcpy(target, action, action_tensor.SizeInBytes());
|
||||
break;
|
||||
}
|
||||
case 1: {
|
||||
|
|
|
|||
|
|
@ -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<int64_t>(), input_indices.Data<int64_t>(), input_indices.Size());
|
||||
memcpy(output->MutableIndices().MutableData<int64_t>(), input_indices.Data<int64_t>(), input_indices.SizeInBytes());
|
||||
return Status::OK();
|
||||
}
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in a new issue