diff options
Diffstat (limited to 'arm_compute/core/TensorInfo.h')
-rw-r--r-- | arm_compute/core/TensorInfo.h | 138 |
1 files changed, 82 insertions, 56 deletions
diff --git a/arm_compute/core/TensorInfo.h b/arm_compute/core/TensorInfo.h index 31f27328dd..b18f750427 100644 --- a/arm_compute/core/TensorInfo.h +++ b/arm_compute/core/TensorInfo.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016-2019 Arm Limited. + * Copyright (c) 2016-2023 Arm Limited. * * SPDX-License-Identifier: MIT * @@ -24,23 +24,19 @@ #ifndef ARM_COMPUTE_TENSORINFO_H #define ARM_COMPUTE_TENSORINFO_H -#include "arm_compute/core/ITensorInfo.h" - -#include "ITensorInfo.h" #include "arm_compute/core/Coordinates.h" #include "arm_compute/core/Helpers.h" +#include "arm_compute/core/ITensorInfo.h" #include "arm_compute/core/Strides.h" #include "arm_compute/core/TensorShape.h" #include "arm_compute/core/Types.h" -#include "arm_compute/core/Utils.h" +#include "ITensorInfo.h" #include <cstddef> #include <memory> namespace arm_compute { -class HOGInfo; - /** Store the tensor's metadata */ class TensorInfo final : public ITensorInfo { @@ -52,7 +48,7 @@ public: /** Allow instances of this class to be copy constructed */ TensorInfo(const ITensorInfo &info); /** Allow instances of this class to be copy constructed */ - TensorInfo(const TensorInfo &) = default; + TensorInfo(const TensorInfo &); /** Allow instances of this class to be copied */ TensorInfo &operator=(const TensorInfo &) = default; /** Allow instances of this class to be move constructed */ @@ -115,15 +111,10 @@ public: * @param[in] data_type Data type to use for each tensor element * @param[in] quantization_info The quantization settings for the tensor data. */ - TensorInfo(const TensorShape &tensor_shape, size_t num_channels, DataType data_type, QuantizationInfo quantization_info); - - /** Constructor - * - * @param[in] hog_info HOG's metadata used to allocate normalized HOG space - * @param[in] width Width of the 2D tensor where the HOG descriptor will be computed on - * @param[in] height Height of the 2D tensor where the HOG descriptor will be computed on - */ - TensorInfo(const HOGInfo &hog_info, unsigned int width, unsigned int height); + TensorInfo(const TensorShape &tensor_shape, + size_t num_channels, + DataType data_type, + QuantizationInfo quantization_info); /** Initialize the tensor info with just a format. * @@ -147,7 +138,11 @@ public: * @param[in] offset_first_element_in_bytes Offset in bytes from the beginning of memory allocation to access the first element. * @param[in] total_size_in_bytes Size in bytes of the memory allocation (including the offset to the first element). */ - void 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 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); /** Initialize the tensor info with just a format. * @@ -175,15 +170,12 @@ public: * @param[in] offset_first_element_in_bytes Offset in bytes from the beginning of memory allocation to access the first element. * @param[in] total_size_in_bytes Size in bytes of the memory allocation (including the offset to the first element). */ - void 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); - /** Initialize the metadata structure for the given HOG's metadata - * - * @param[in] hog_info HOG's metadata used to allocate normalized HOG space - * @param[in] width Width of the 2D tensor where the HOG descriptor will be computed on - * @param[in] height Height of the 2D tensor where the HOG descriptor will be computed on - */ - void init(const HOGInfo &hog_info, unsigned int width, unsigned int height); + void 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); /** Initialize the metadata structure for the given tensor shape and single-plane format, (Padding is automatically calculated) * * @note The padding used by this method is really conservative so that the tensor can be used for most functions. @@ -206,30 +198,22 @@ public: * @return Total allocation size including padding in bytes. */ size_t init_auto_padding(const TensorShape &tensor_shape, size_t num_channels, DataType data_type); - /** Initialize the metadata structure for the given HOG's metadata - * - * @note init_auto_padding will be used for the tensor initialization. - * - * @param[in] hog_info HOG's metadata used to allocate normalized HOG space - * @param[in] width Width of the 2D tensor where the HOG descriptor will be computed on - * @param[in] height Height of the 2D tensor where the HOG descriptor will be computed on - * - * @return Total allocation size including padding in bytes. - */ - size_t init_auto_padding(const HOGInfo &hog_info, unsigned int width, unsigned int height); // Inherited methods overridden: std::unique_ptr<ITensorInfo> clone() const override; - ITensorInfo &set_data_type(DataType data_type) override; - ITensorInfo &set_num_channels(int num_channels) override; - ITensorInfo &set_format(Format format) override; - ITensorInfo &set_tensor_shape(const TensorShape &shape) override; - ITensorInfo &set_quantization_info(const QuantizationInfo &quantization_info) override; - ITensorInfo &set_data_layout(const DataLayout &data_layout) override; - ITensorInfo &reset_padding() override; - bool auto_padding() override; - bool extend_padding(const PaddingSize &padding) override; - size_t dimension(size_t index) const override + ITensorInfo &set_data_type(DataType data_type) override; + ITensorInfo &set_num_channels(int num_channels) override; + ITensorInfo &set_format(Format format) override; + ITensorInfo &set_tensor_shape(const TensorShape &shape) override; + ITensorInfo &set_tensor_dims_state(const TensorDimsState &state) override; + ITensorInfo &set_quantization_info(const QuantizationInfo &quantization_info) override; + ITensorInfo &set_data_layout(const DataLayout &data_layout) override; + ITensorInfo &reset_padding() override; + bool auto_padding() override; + ITensorInfo &set_lock_paddings(bool flag) override; + bool lock_paddings() const override; + bool extend_padding(const PaddingSize &padding) override; + size_t dimension(size_t index) const override { return _tensor_shape[index]; } @@ -246,7 +230,7 @@ public: return _offset_first_element_in_bytes; } int32_t offset_element_in_bytes(const Coordinates &pos) const override; - size_t element_size() const override + size_t element_size() const override { return data_size_from_type(_data_type) * _num_channels; } @@ -262,6 +246,10 @@ public: { return _tensor_shape; } + const TensorDimsState &tensor_dims_state() const override + { + return _dims_state; + } DataType data_type() const override { return _data_type; @@ -288,16 +276,16 @@ public: } bool is_dynamic() const override { - return _is_dynamic; + return std::find(std::cbegin(_dims_state), std::cend(_dims_state), get_dynamic_state_value()) != + std::cend(_dims_state); } - ITensorInfo &set_is_resizable(bool is_resizable) override + bool are_values_constant() const override { - _is_resizable = is_resizable; - return *this; + return _are_values_constant; } - ITensorInfo &set_is_dynamic(bool is_dynamic) override + ITensorInfo &set_is_resizable(bool is_resizable) override { - _is_dynamic = is_dynamic; + _is_resizable = is_resizable; return *this; } ValidRegion valid_region() const override @@ -316,6 +304,21 @@ public: { return _data_layout; } + ITensorInfo &set_are_values_constant(bool are_values_constant) override + { + _are_values_constant = are_values_constant; + return *this; + } + ITensorInfo::Id id() const override + { + return _id; + } + ITensorInfo &set_id(ITensorInfo::Id id) override + { + _id = id; + return *this; + } + inline friend bool operator==(const TensorInfo &lhs, const TensorInfo &rhs); private: /** Calculates strides, offset and total size resulting from the specified padding around the XY plane. @@ -329,14 +332,37 @@ private: Strides _strides_in_bytes; size_t _num_channels; TensorShape _tensor_shape; + TensorDimsState _dims_state; DataType _data_type; Format _format; bool _is_resizable; - bool _is_dynamic; ValidRegion _valid_region; PaddingSize _padding; QuantizationInfo _quantization_info; DataLayout _data_layout; + bool _are_values_constant; + ITensorInfo::Id _id; + bool _lock_paddings; }; + +/** Check whether two tensor info are equal. + * + * @param[in] lhs LHS tensor info. + * @param[in] rhs RHS tensor info. + * + * @return True if the given tensor infos are the same. + */ +inline bool operator==(const TensorInfo &lhs, const TensorInfo &rhs) +{ + return (lhs._total_size == rhs._total_size) && + (lhs._offset_first_element_in_bytes == rhs._offset_first_element_in_bytes) && + (lhs._strides_in_bytes == rhs._strides_in_bytes) && (lhs._num_channels == rhs._num_channels) && + (lhs._tensor_shape == rhs._tensor_shape) && (lhs._dims_state == rhs._dims_state) && + (lhs._data_type == rhs._data_type) && (lhs._format == rhs._format) && + (lhs._is_resizable == rhs._is_resizable) && (lhs._valid_region == rhs._valid_region) && + (lhs._padding == rhs._padding) && (lhs._quantization_info == rhs._quantization_info) && + (lhs._data_layout == rhs._data_layout) && (lhs._are_values_constant == rhs._are_values_constant) && + (lhs._id == rhs._id); +} } // namespace arm_compute #endif /*ARM_COMPUTE_TENSORINFO_H */ |