Compute Library
 22.11
Range.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018-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  */
24 #include "arm_compute/core/Types.h"
28 #include "tests/NEON/Accessor.h"
30 #include "tests/datasets/ShapeDatasets.h"
32 #include "tests/framework/Macros.h"
35 #include "tests/validation/fixtures/RangeFixture.h"
36 
37 namespace arm_compute
38 {
39 namespace test
40 {
41 namespace validation
42 {
43 namespace
44 {
45 constexpr RelativeTolerance<float> tolerance(0.01f);
46 constexpr AbsoluteTolerance<float> abs_tolerance(0.02f);
47 
48 const auto start_dataset = framework::dataset::make("Start", { float(3), float(-17), float(16) });
49 const auto unsigned_start_dataset = framework::dataset::make("Start", { float(3), float(16) });
50 const auto float_step_dataset = framework::dataset::make("Step", { float(1), float(-0.2f), float(0.2), float(12.2), float(-12.2), float(-1.2), float(-3), float(3) });
51 const auto step_dataset = framework::dataset::make("Step", { float(1), float(12), float(-12), float(-1), float(-3), float(3) });
52 const auto unsigned_step_dataset = framework::dataset::make("Step", { float(1), float(12), float(3) });
53 } // namespace
54 
55 TEST_SUITE(NEON)
56 TEST_SUITE(Range)
57 
58 // *INDENT-OFF*
59 // clang-format off
60 
61 DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip(
62  framework::dataset::make("OutputInfo", { TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
71  }),
72  framework::dataset::make("Start",{ 0.0f,
73  15.0f,
74  1500.0f,
75  100.0f,
76  -15.0f,
77  0.2f,
78  2.0f,
79  10.0f,
80  10.0f
81  })),
82  framework::dataset::make("End",{ 100.0f,
83  15.0f,
84  2500.0f,
85  -1000.0f,
86  15.0f,
87  10.0f,
88  10.0f,
89  100.0f,
90  100.0f
91  })),
92  framework::dataset::make("Step",{ 100.0f,
93  15.0f,
94  10.0f,
95  100.0f,
96  -15.0f,
97  1.0f,
98  0.0f,
99  10.0f,
100  10.0f
101  })),
102  framework::dataset::make("Expected", { false, // 1-D tensor expected
103  false, // start == end
104  false, // output vector size insufficient
105  false, // sign of step incorrect
106  false, // sign of step incorrect
107  false, // data type incompatible
108  false, // step = 0
109  false, // invalid QASYMM8 datatype
110  true,
111  })),
112  output_info, start, end, step, expected)
113 {
115 }
116 // clang-format on
117 // *INDENT-ON*
118 
119 template <typename T>
120 using NERangeFixture = RangeFixture<Tensor, Accessor, NERange, T>;
121 
122 TEST_SUITE(U8)
123 FIXTURE_DATA_TEST_CASE(RunSmall, NERangeFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(
124  framework::dataset::make("DataType", DataType::U8),
125  unsigned_start_dataset),
126  unsigned_step_dataset),
127  framework::dataset::make("QuantizationInfo", { QuantizationInfo() })))
128 {
129  // Validate output
130  validate(Accessor(_target), _reference, tolerance, 0.f, abs_tolerance);
131 }
132 TEST_SUITE_END() // U8
133 
135 FIXTURE_DATA_TEST_CASE(RunSmall, NERangeFixture<int16_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(
136  framework::dataset::make("DataType", DataType::S16),
137  start_dataset),
138  step_dataset),
139  framework::dataset::make("QuantizationInfo", { QuantizationInfo() })))
140 {
141  // Validate output
142  validate(Accessor(_target), _reference, tolerance, 0.f, abs_tolerance);
143 }
144 TEST_SUITE_END() // S16
145 
146 TEST_SUITE(Float)
147 #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
148 TEST_SUITE(FP16)
151  start_dataset),
152  float_step_dataset),
153  framework::dataset::make("QuantizationInfo", { QuantizationInfo() })))
154 {
155  // Validate output
156  validate(Accessor(_target), _reference, tolerance, 0.f, abs_tolerance);
157 }
158 TEST_SUITE_END() // FP16
159 #endif // __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
160 
161 TEST_SUITE(FP32)
162 FIXTURE_DATA_TEST_CASE(RunSmall, NERangeFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(
163  framework::dataset::make("DataType", DataType::F32),
164  start_dataset),
165  float_step_dataset),
166  framework::dataset::make("QuantizationInfo", { QuantizationInfo() })))
167 {
168  // Validate output
169  validate(Accessor(_target), _reference, tolerance, 0.f, abs_tolerance);
170 }
171 TEST_SUITE_END() // FP32
172 TEST_SUITE_END() // Float
173 
174 TEST_SUITE_END() // Range
175 TEST_SUITE_END() // Neon
176 } // namespace validation
177 } // namespace test
178 } // namespace arm_compute
Shape of a tensor.
Definition: TensorShape.h:39
1 channel, 1 U8 per channel
1 channel, 1 F32 per channel
ARM_COMPUTE_EXPECT(has_error==expected, framework::LogLevel::ERRORS)
std::enable_if< is_container< T >::value, ContainerDataset< T > >::type make(std::string name, T &&values)
Helper function to create a ContainerDataset.
Copyright (c) 2017-2022 Arm Limited.
1 channel, 1 F16 per channel
Quantization information.
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)
Accessor implementation for Tensor objects.
Definition: Accessor.h:35
DatasetMode
Possible dataset modes.
Definition: DatasetModes.h:40
TEST_SUITE_END() FIXTURE_DATA_TEST_CASE(RunSmall
[CLActivationLayer Test snippet]
quantized, asymmetric fixed-point 8-bit number unsigned
static Status validate(const ITensorInfo *output, float start, float end, float step=1.f)
Static function to check if given info will lead to a valid configuration of NERange.
Definition: NERange.cpp:46
RangeFixture< Tensor, Accessor, NERange, T > NERangeFixture
Definition: Range.cpp:120
void end(TokenStream &in, bool &valid)
Definition: MLGOParser.cpp:290
validate(CLAccessor(output_state), expected_output)
1 channel, 1 S16 per channel
FIXTURE_DATA_TEST_CASE(RunSmall, CLAbsLayerFixture< half >, framework::DatasetMode::PRECOMMIT, combine(datasets::SmallShapes(), framework::dataset::make("DataType", DataType::F16)))
Definition: AbsLayer.cpp:50
constexpr int step
Definition: fp32.cpp:35
Store the tensor&#39;s metadata.
Definition: TensorInfo.h:43
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}))
TEST_SUITE(QASYMM8_to_F32) FIXTURE_DATA_TEST_CASE(RunSmall
DataType
Available data types.
Definition: Types.h:79
combine(datasets::SmallShapes(), framework::dataset::make("DataType", DataType::F32)))
Definition: AbsLayer.cpp:65