Compute Library
 23.11
TensorInfo.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017-2021 Arm Limited.
3  *
4  * SPDX-License-Identifier: MIT
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to
8  * deal in the Software without restriction, including without limitation the
9  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10  * sell copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in all
14  * copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  */
25 #include "arm_compute/core/Types.h"
27 #include "tests/framework/Macros.h"
30 #include "utils/TypePrinter.h"
31 
32 namespace arm_compute
33 {
34 namespace test
35 {
36 namespace validation
37 {
38 TEST_SUITE(UNIT)
39 TEST_SUITE(TensorInfo)
40 
41 // *INDENT-OFF*
42 // clang-format off
43 /** Validates TensorInfo Autopadding */
44 DATA_TEST_CASE(AutoPadding, framework::DatasetMode::ALL, zip(zip(zip(
45  framework::dataset::make("TensorShape", {
46  TensorShape{},
47  TensorShape{ 10U },
48  TensorShape{ 10U, 10U },
49  TensorShape{ 10U, 10U, 10U },
50  TensorShape{ 10U, 10U, 10U, 10U },
51  TensorShape{ 10U, 10U, 10U, 10U, 10U },
52  TensorShape{ 10U, 10U, 10U, 10U, 10U, 10U }}),
53  framework::dataset::make("PaddingSize", {
54  PaddingSize{ 0, 0, 0, 0 },
55  PaddingSize{ 0, 36, 0, 4 },
56  PaddingSize{ 4, 36, 4, 4 },
57  PaddingSize{ 4, 36, 4, 4 },
58  PaddingSize{ 4, 36, 4, 4 },
59  PaddingSize{ 4, 36, 4, 4 },
60  PaddingSize{ 4, 36, 4, 4 }})),
61  framework::dataset::make("Strides", {
62  Strides{},
63  Strides{ 1U, 50U },
64  Strides{ 1U, 50U },
65  Strides{ 1U, 50U, 900U },
66  Strides{ 1U, 50U, 900U, 9000U },
67  Strides{ 1U, 50U, 900U, 9000U, 90000U },
68  Strides{ 1U, 50U, 900U, 9000U, 90000U, 900000U }})),
69  framework::dataset::make("Offset", { 0U, 4U, 204U, 204U, 204U, 204U, 204U })),
70  shape, auto_padding, strides, offset)
71 {
72  TensorInfo info{ shape, Format::U8 };
73 
75 
76  info.auto_padding();
77 
78  validate(info.padding(), auto_padding);
79 
81  ARM_COMPUTE_EXPECT(info.offset_first_element_in_bytes() == offset, framework::LogLevel::ERRORS);
82 }
83 // clang-format on
84 // *INDENT-ON*
85 
86 /** Validates that TensorInfo is clonable */
88 {
89  // Create tensor info
90  TensorInfo info(TensorShape(23U, 17U, 3U), // tensor shape
91  1, // number of channels
92  DataType::F32); // data type
93 
94  // Get clone of current tensor info
95  std::unique_ptr<ITensorInfo> info_clone = info.clone();
96  ARM_COMPUTE_ASSERT(info_clone != nullptr);
97  ARM_COMPUTE_EXPECT(info_clone->total_size() == info.total_size(), framework::LogLevel::ERRORS);
98  ARM_COMPUTE_EXPECT(info_clone->num_channels() == info.num_channels(), framework::LogLevel::ERRORS);
99  ARM_COMPUTE_EXPECT(info_clone->data_type() == info.data_type(), framework::LogLevel::ERRORS);
100 }
101 
102 /** Validates that TensorInfo can chain multiple set commands */
104 {
105  // Create tensor info
106  TensorInfo info(TensorShape(23U, 17U, 3U), // tensor shape
107  1, // number of channels
108  DataType::F32); // data type
109 
110  // Update data type and number of channels
111  info.set_data_type(DataType::S32).set_num_channels(3);
114 
115  // Update data type and set quantization info
116  info.set_data_type(DataType::QASYMM8).set_quantization_info(QuantizationInfo(0.5f, 15));
118  ARM_COMPUTE_EXPECT(info.quantization_info() == QuantizationInfo(0.5f, 15), framework::LogLevel::ERRORS);
119 
120  // Update tensor shape
121  info.set_tensor_shape(TensorShape(13U, 15U));
123 }
124 
125 /** Validates empty quantization info */
127 {
128  // Create tensor info
129  const TensorInfo info(TensorShape(32U, 16U), 1, DataType::F32);
130 
131  // Check quantization information
132  ARM_COMPUTE_EXPECT(info.quantization_info().empty(), framework::LogLevel::ERRORS);
133 }
134 
135 /** Validates symmetric quantization info */
137 {
138  // Create tensor info
139  const float scale = 0.25f;
141 
142  // Check quantization information
143  ARM_COMPUTE_EXPECT(!info.quantization_info().empty(), framework::LogLevel::ERRORS);
144  ARM_COMPUTE_EXPECT(!info.quantization_info().scale().empty(), framework::LogLevel::ERRORS);
145  ARM_COMPUTE_EXPECT(info.quantization_info().scale().size() == 1, framework::LogLevel::ERRORS);
146  ARM_COMPUTE_EXPECT(info.quantization_info().offset().empty(), framework::LogLevel::ERRORS);
147 
148  UniformQuantizationInfo qinfo = info.quantization_info().uniform();
151 }
152 
153 /** Validates asymmetric quantization info */
154 TEST_CASE(AsymmQuantizationInfo, framework::DatasetMode::ALL)
155 {
156  // Create tensor info
157  const float scale = 0.25f;
158  const int32_t offset = 126;
160 
161  // Check quantization information
162  ARM_COMPUTE_EXPECT(!info.quantization_info().empty(), framework::LogLevel::ERRORS);
163  ARM_COMPUTE_EXPECT(!info.quantization_info().scale().empty(), framework::LogLevel::ERRORS);
164  ARM_COMPUTE_EXPECT(info.quantization_info().scale().size() == 1, framework::LogLevel::ERRORS);
165  ARM_COMPUTE_EXPECT(!info.quantization_info().offset().empty(), framework::LogLevel::ERRORS);
166  ARM_COMPUTE_EXPECT(info.quantization_info().offset().size() == 1, framework::LogLevel::ERRORS);
167 
168  UniformQuantizationInfo qinfo = info.quantization_info().uniform();
171 }
172 
173 /** Validates symmetric per channel quantization info */
174 TEST_CASE(SymmPerChannelQuantizationInfo, framework::DatasetMode::ALL)
175 {
176  // Create tensor info
177  const std::vector<float> scale = { 0.25f, 1.4f, 3.2f, 2.3f, 4.7f };
179 
180  // Check quantization information
181  ARM_COMPUTE_EXPECT(!info.quantization_info().empty(), framework::LogLevel::ERRORS);
182  ARM_COMPUTE_EXPECT(!info.quantization_info().scale().empty(), framework::LogLevel::ERRORS);
183  ARM_COMPUTE_EXPECT(info.quantization_info().scale().size() == scale.size(), framework::LogLevel::ERRORS);
184  ARM_COMPUTE_EXPECT(info.quantization_info().offset().empty(), framework::LogLevel::ERRORS);
185 }
186 
187 /** Validates lock paddings flag*/
188 TEST_CASE(SubTensorPaddingExpansion, framework::DatasetMode::ALL)
189 {
190  TensorInfo tensor_info(TensorShape(23U, 17U, 3U), 1, DataType::F32);
191  tensor_info.set_lock_paddings(true);
192 
193  // Now lock padding is set to true, therefore the extend padding would fail
195 }
196 TEST_SUITE_END() // TensorInfo
197 TEST_SUITE_END() // UNIT
198 } // namespace validation
199 } // namespace test
200 } // namespace arm_compute
Datasets.h
arm_compute::test::validation::TEST_SUITE_END
TEST_SUITE_END() FIXTURE_DATA_TEST_CASE(RunSmall
[CLActivationLayer Test snippet]
Definition: DequantizationLayer.cpp:111
arm_compute::DataType::QSYMM8_PER_CHANNEL
@ QSYMM8_PER_CHANNEL
quantized, symmetric per channel fixed-point 8-bit number
arm_compute::test::validation::TEST_CASE
TEST_CASE(FusedActivation, framework::DatasetMode::ALL)
Validate fused activation expecting the following behaviours:
Definition: ArithmeticAddition.cpp:93
arm_compute::test::validation::DATA_TEST_CASE
DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(framework::dataset::make("InputInfo", { TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32), TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32), TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::QASYMM8), TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::QASYMM8), TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32), TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::QSYMM16), TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::QSYMM16), TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::QSYMM16), }), framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F16), TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32), TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::QASYMM8), TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::QASYMM8), TensorInfo(TensorShape(30U, 11U, 2U), 1, DataType::F32), TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::QSYMM16, QuantizationInfo(1.f/32768.f, 0)), TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::QSYMM16, QuantizationInfo(1.f/32768.f, 0)), TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::QSYMM16, QuantizationInfo(1.f/32768.f, 0)), })), framework::dataset::make("ActivationInfo", { ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU), ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU), ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU), ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LU_BOUNDED_RELU), ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::TANH), ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU), ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::TANH), ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LOGISTIC), ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::SQRT), })), framework::dataset::make("Expected", { false, true, true, true, false, false, true, true, false })), input_info, output_info, act_info, expected)
Definition: ActivationLayer.cpp:100
arm_compute::QuantizationInfo
Quantization information.
Definition: QuantizationInfo.h:67
arm_compute::BorderSize
Container for 2D border size.
Definition: Types.h:239
arm_compute::DataType::QASYMM8
@ QASYMM8
quantized, asymmetric fixed-point 8-bit number unsigned
arm_compute::TensorShape
Shape of a tensor.
Definition: TensorShape.h:39
arm_compute::DataType::QSYMM8
@ QSYMM8
quantized, symmetric fixed-point 8-bit number
Types.h
TensorInfo.h
arm_compute::UniformQuantizationInfo
Quantization info when assuming per layer quantization.
Definition: QuantizationInfo.h:42
arm_compute::test::validation::validate
validate(CLAccessor(output_state), expected_output)
arm_compute::utils::cast::U
U
Definition: SaturateCast.h:65
arm_compute::test::validation::shape
shape
Definition: DFT.cpp:115
arm_compute::test::framework::DatasetMode::ALL
@ ALL
TypePrinter.h
arm_compute::test::validation::ARM_COMPUTE_EXPECT
ARM_COMPUTE_EXPECT(has_error==expected, framework::LogLevel::ERRORS)
Asserts.h
arm_compute::QuantizationInfo::scale
const std::vector< float > & scale() const
Scale vector accessor.
Definition: QuantizationInfo.h:116
ARM_COMPUTE_ASSERT
#define ARM_COMPUTE_ASSERT(cond)
Definition: Validate.h:37
offset
__global uchar * offset(const Image *img, int x, int y)
Get the pointer position of a Image.
Definition: helpers.h:1128
Macros.h
ARM_COMPUTE_EXPECT_THROW
#define ARM_COMPUTE_EXPECT_THROW(X, LEVEL)
Definition: Asserts.h:187
arm_compute::Format::U8
@ U8
1 channel, 1 U8 per channel
arm_compute::test::framework::dataset::make
std::enable_if< is_container< T >::value, ContainerDataset< T > >::type make(std::string name, T &&values)
Helper function to create a ContainerDataset.
Definition: ContainerDataset.h:160
Validation.h
arm_compute::TensorInfo
Store the tensor's metadata.
Definition: TensorInfo.h:41
arm_compute::test::validation::zip
zip(zip(framework::dataset::make("Weights", { TensorInfo(TensorShape(32U, 13U, 2U, 2U), 1, DataType::F32), TensorInfo(TensorShape(32U, 13U, 2U, 2U), 1, DataType::F32), TensorInfo(TensorShape(32U, 13U, 2U, 1U), 1, DataType::F32), }), framework::dataset::make("MVBGInfo",{ TensorInfo(TensorShape(2U), 1, DataType::F32), TensorInfo(TensorShape(2U), 1, DataType::F16), TensorInfo(TensorShape(5U), 1, DataType::F32), })), framework::dataset::make("Expected", { true, false, false}))
arm_compute::PaddingSize
BorderSize PaddingSize
Container for 2D padding size.
Definition: Types.h:346
arm_compute::test::validation::scale
NEScale scale
Definition: Scale.cpp:272
arm_compute
Copyright (c) 2017-2023 Arm Limited.
Definition: introduction.dox:24
arm_compute::test::validation::TEST_SUITE
TEST_SUITE(QASYMM8_to_F32) FIXTURE_DATA_TEST_CASE(RunSmall
arm_compute::DataType::S32
@ S32
signed 32-bit number
arm_compute::DataType::F32
@ F32
32-bit floating-point number
arm_compute::test::validation::info
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)
arm_compute::test::validation::compare_dimensions
bool compare_dimensions(const Dimensions< T > &dimensions1, const Dimensions< T > &dimensions2, const DataLayout &data_layout=DataLayout::NCHW)
Definition: Validation.h:150
arm_compute::test::framework::DatasetMode
DatasetMode
Possible dataset modes.
Definition: DatasetModes.h:40
tensor_info
TensorInfo tensor_info
Associated tensor info.
Definition: ClWorkloadRuntime.cpp:68
arm_compute::test::validation::qinfo
const QuantizationInfo qinfo
Definition: Im2Col.cpp:155
arm_compute::QuantizationInfo::offset
const std::vector< int32_t > & offset() const
Offset vector accessor.
Definition: QuantizationInfo.h:124
arm_compute::test::framework::LogLevel::ERRORS
@ ERRORS