aboutsummaryrefslogtreecommitdiff
path: root/src/core/TensorInfo.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/TensorInfo.cpp')
-rw-r--r--src/core/TensorInfo.cpp131
1 files changed, 93 insertions, 38 deletions
diff --git a/src/core/TensorInfo.cpp b/src/core/TensorInfo.cpp
index c471615ee8..31bddbde40 100644
--- a/src/core/TensorInfo.cpp
+++ b/src/core/TensorInfo.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2016-2021 Arm Limited.
+ * Copyright (c) 2016-2023 Arm Limited.
*
* SPDX-License-Identifier: MIT
*
@@ -27,20 +27,34 @@
#include "arm_compute/core/Helpers.h"
#include "arm_compute/core/TensorInfo.h"
#include "arm_compute/core/Validate.h"
+
#include "src/core/helpers/Utils.h"
#include <memory>
-using namespace arm_compute;
-
+namespace arm_compute
+{
TensorInfo::TensorInfo()
- : _total_size(0), _offset_first_element_in_bytes(0), _strides_in_bytes(), _num_channels(0), _tensor_shape(), _dims_state(), _data_type(DataType::UNKNOWN), _format(Format::UNKNOWN), _is_resizable{ true },
- _valid_region{ Coordinates(), _tensor_shape }, _padding{ 0 }, _quantization_info(), _data_layout(DataLayout::NCHW)
+ : _total_size(0),
+ _offset_first_element_in_bytes(0),
+ _strides_in_bytes(),
+ _num_channels(0),
+ _tensor_shape(),
+ _dims_state(),
+ _data_type(DataType::UNKNOWN),
+ _format(Format::UNKNOWN),
+ _is_resizable{true},
+ _valid_region{Coordinates(), _tensor_shape},
+ _padding{0},
+ _quantization_info(),
+ _data_layout(DataLayout::NCHW),
+ _are_values_constant(true),
+ _id(invalid_tensor_id),
+ _lock_paddings(false)
{
}
-TensorInfo::TensorInfo(const ITensorInfo &info)
- : TensorInfo()
+TensorInfo::TensorInfo(const ITensorInfo &info) : TensorInfo()
{
_total_size = info.total_size();
_offset_first_element_in_bytes = info.offset_first_element_in_bytes();
@@ -55,10 +69,31 @@ TensorInfo::TensorInfo(const ITensorInfo &info)
_padding = info.padding();
_quantization_info = info.quantization_info();
_data_layout = info.data_layout();
+ _are_values_constant = info.are_values_constant();
+ _id = info.id();
+ _lock_paddings = info.lock_paddings();
}
-TensorInfo::TensorInfo(Format format)
- : TensorInfo(TensorShape(), format)
+TensorInfo::TensorInfo(const TensorInfo &info) : TensorInfo()
+{
+ _total_size = info.total_size();
+ _offset_first_element_in_bytes = info.offset_first_element_in_bytes();
+ _strides_in_bytes = info.strides_in_bytes();
+ _num_channels = info.num_channels();
+ _tensor_shape = info.tensor_shape();
+ _dims_state = info.tensor_dims_state();
+ _data_type = info.data_type();
+ _format = info.format();
+ _is_resizable = info.is_resizable();
+ _valid_region = info.valid_region();
+ _padding = info.padding();
+ _quantization_info = info.quantization_info();
+ _data_layout = info.data_layout();
+ _are_values_constant = info.are_values_constant();
+ _id = info.id();
+ _lock_paddings = false;
+}
+TensorInfo::TensorInfo(Format format) : TensorInfo(TensorShape(), format)
{
}
@@ -67,25 +102,25 @@ TensorInfo::TensorInfo(unsigned int width, unsigned int height, Format format)
{
}
-TensorInfo::TensorInfo(const TensorShape &tensor_shape, Format format)
- : TensorInfo()
+TensorInfo::TensorInfo(const TensorShape &tensor_shape, Format format) : TensorInfo()
{
init(tensor_shape, format);
}
-TensorInfo::TensorInfo(size_t num_channels, DataType data_type)
- : TensorInfo()
+TensorInfo::TensorInfo(size_t num_channels, DataType data_type) : TensorInfo()
{
init(TensorShape(), num_channels, data_type);
}
-TensorInfo::TensorInfo(const TensorShape &tensor_shape, size_t num_channels, DataType data_type)
- : TensorInfo()
+TensorInfo::TensorInfo(const TensorShape &tensor_shape, size_t num_channels, DataType data_type) : TensorInfo()
{
init(tensor_shape, num_channels, data_type);
}
-TensorInfo::TensorInfo(const TensorShape &tensor_shape, size_t num_channels, DataType data_type, QuantizationInfo quantization_info)
+TensorInfo::TensorInfo(const TensorShape &tensor_shape,
+ size_t num_channels,
+ DataType data_type,
+ QuantizationInfo quantization_info)
: TensorInfo()
{
init(tensor_shape, num_channels, data_type);
@@ -114,9 +149,11 @@ void TensorInfo::init(const TensorShape &tensor_shape, Format format)
_format = format;
}
-void TensorInfo::init(const TensorShape &tensor_shape, Format format,
- const Strides &strides_in_bytes, size_t offset_first_element_in_bytes,
- size_t total_size_in_bytes)
+void TensorInfo::init(const TensorShape &tensor_shape,
+ Format format,
+ const Strides &strides_in_bytes,
+ size_t offset_first_element_in_bytes,
+ size_t total_size_in_bytes)
{
size_t num_channels = num_channels_from_format(format);
const DataType type = data_type_from_format(format);
@@ -142,9 +179,12 @@ void TensorInfo::init(const TensorShape &tensor_shape, size_t num_channels, Data
set_tensor_shape(tensor_shape);
}
-void TensorInfo::init(const TensorShape &tensor_shape, size_t num_channels, DataType data_type,
- const Strides &strides_in_bytes, size_t offset_first_element_in_bytes,
- size_t total_size_in_bytes)
+void TensorInfo::init(const TensorShape &tensor_shape,
+ size_t num_channels,
+ DataType data_type,
+ const Strides &strides_in_bytes,
+ size_t offset_first_element_in_bytes,
+ size_t total_size_in_bytes)
{
ARM_COMPUTE_ERROR_ON(num_channels == 0);
@@ -156,7 +196,7 @@ void TensorInfo::init(const TensorShape &tensor_shape, size_t num_channels, Data
_strides_in_bytes = strides_in_bytes;
_total_size = total_size_in_bytes;
- _valid_region = ValidRegion{ Coordinates(), _tensor_shape };
+ _valid_region = ValidRegion{Coordinates(), _tensor_shape};
}
size_t TensorInfo::init_auto_padding(const TensorShape &tensor_shape, Format format)
@@ -179,7 +219,7 @@ size_t TensorInfo::init_auto_padding(const TensorShape &tensor_shape, size_t num
_format = Format::UNKNOWN;
_tensor_shape = tensor_shape;
- _valid_region = ValidRegion{ Coordinates(), _tensor_shape };
+ _valid_region = ValidRegion{Coordinates(), _tensor_shape};
auto_padding();
@@ -210,11 +250,11 @@ std::tuple<Strides, size_t, size_t> TensorInfo::calculate_padding_requirements(c
size_t required_total_size = 0;
const size_t required_offset_first_element = padding.left * stride_x + padding.top * stride_y;
- switch(_tensor_shape.num_dimensions())
+ switch (_tensor_shape.num_dimensions())
{
case 0:
{
- if(_tensor_shape.total_size() > 0)
+ if (_tensor_shape.total_size() > 0)
{
required_strides = Strides(stride_x, stride_x);
required_total_size = stride_z;
@@ -235,7 +275,8 @@ std::tuple<Strides, size_t, size_t> TensorInfo::calculate_padding_requirements(c
const unsigned int idx_last_dimension = _tensor_shape.num_dimensions() - 1;
- required_total_size = static_cast<size_t>(_tensor_shape[idx_last_dimension]) * required_strides[idx_last_dimension];
+ required_total_size =
+ static_cast<size_t>(_tensor_shape[idx_last_dimension]) * required_strides[idx_last_dimension];
break;
}
}
@@ -243,31 +284,43 @@ std::tuple<Strides, size_t, size_t> TensorInfo::calculate_padding_requirements(c
return std::make_tuple(required_strides, required_offset_first_element, required_total_size);
}
+ITensorInfo &TensorInfo::set_lock_paddings(bool flag)
+{
+ _lock_paddings = flag;
+ return *this;
+}
+
+bool TensorInfo::lock_paddings() const
+{
+ return _lock_paddings;
+}
+
bool TensorInfo::extend_padding(const PaddingSize &padding)
{
+ ARM_COMPUTE_ERROR_ON(_lock_paddings);
ARM_COMPUTE_ERROR_ON(!_is_resizable);
bool updated = false;
- if(padding.top > _padding.top)
+ if (padding.top > _padding.top)
{
_padding.top = padding.top;
updated = true;
}
- if(padding.right > _padding.right)
+ if (padding.right > _padding.right)
{
_padding.right = padding.right;
updated = true;
}
- if(padding.bottom > _padding.bottom)
+ if (padding.bottom > _padding.bottom)
{
_padding.bottom = padding.bottom;
updated = true;
}
- if(padding.left > _padding.left)
+ if (padding.left > _padding.left)
{
_padding.left = padding.left;
updated = true;
@@ -301,7 +354,7 @@ ITensorInfo &TensorInfo::set_format(Format format)
{
_format = format;
- if(_data_type == DataType::UNKNOWN)
+ if (_data_type == DataType::UNKNOWN)
{
_num_channels = num_channels_from_format(format);
_data_type = data_type_from_format(format);
@@ -320,19 +373,19 @@ ITensorInfo &TensorInfo::set_tensor_shape(const TensorShape &shape)
_offset_first_element_in_bytes = 0;
_strides_in_bytes = compute_strides(*this);
- if(_tensor_shape.num_dimensions() == 0)
+ if (_tensor_shape.num_dimensions() == 0)
{
_total_size = _strides_in_bytes[0];
}
else
{
const unsigned int idx_last_dimension = _tensor_shape.num_dimensions() - 1;
- _total_size = static_cast<size_t>(_tensor_shape[idx_last_dimension]) * _strides_in_bytes[idx_last_dimension];
+ _total_size = static_cast<size_t>(_tensor_shape[idx_last_dimension]) * _strides_in_bytes[idx_last_dimension];
}
std::tie(_strides_in_bytes, _offset_first_element_in_bytes, _total_size) = calculate_padding_requirements(_padding);
- _valid_region = ValidRegion{ Coordinates(), _tensor_shape };
+ _valid_region = ValidRegion{Coordinates(), _tensor_shape};
return *this;
}
@@ -357,9 +410,10 @@ ITensorInfo &TensorInfo::set_data_layout(const DataLayout &data_layout)
ITensorInfo &TensorInfo::reset_padding()
{
_padding = PaddingSize();
- if(((_format != Format::UNKNOWN) || (_data_type != DataType::UNKNOWN)) && _total_size != 0)
+ if (((_format != Format::UNKNOWN) || (_data_type != DataType::UNKNOWN)) && _total_size != 0)
{
- std::tie(_strides_in_bytes, _offset_first_element_in_bytes, _total_size) = calculate_padding_requirements(_padding);
+ std::tie(_strides_in_bytes, _offset_first_element_in_bytes, _total_size) =
+ calculate_padding_requirements(_padding);
}
return *this;
}
@@ -370,10 +424,11 @@ int32_t TensorInfo::offset_element_in_bytes(const Coordinates &pos) const
int32_t offset = _offset_first_element_in_bytes;
- for(size_t i = 0; i < _tensor_shape.num_dimensions(); ++i)
+ for (size_t i = 0; i < _tensor_shape.num_dimensions(); ++i)
{
offset += pos[i] * _strides_in_bytes[i];
}
return offset;
}
+} // namespace arm_compute