Compute Library
 22.05
Range.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018-2020 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/CL/CLAccessor.h"
30 #include "tests/datasets/ConvertPolicyDataset.h"
31 #include "tests/datasets/ShapeDatasets.h"
33 #include "tests/framework/Macros.h"
36 #include "tests/validation/fixtures/RangeFixture.h"
37 
38 namespace arm_compute
39 {
40 namespace test
41 {
42 namespace validation
43 {
44 namespace
45 {
46 constexpr RelativeTolerance<float> tolerance(0.01f);
47 constexpr AbsoluteTolerance<float> abs_tolerance(0.02f);
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(CL)
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),
70  }),
71  framework::dataset::make("Start",{ 0.0f, 15.0f, 1500.0f, 100.0f, -15.0f, 0.2f , 2.0f , 10.0f})),
72  framework::dataset::make("End",{ 100.0f, 15.0f, 2500.0f, -1000.0f, 15.0f, 10.0f, 10.0f,100.0f })),
73  framework::dataset::make("Step",{ 100.0f, 15.0f, 10.0f, 100.0f, -15.0f, 1.0f, 0.0f, 10.0f })),
74  framework::dataset::make("Expected", { false, //1-D tensor expected
75  false, //start == end
76  false, //output vector size insufficient
77  false, //sign of step incorrect
78  false, //sign of step incorrect
79  false, //data type incompatible
80  false, //step = 0
81  true,
82  })),
83  output_info, start, end, step, expected)
84 {
86 }
87 // clang-format on
88 // *INDENT-ON*
89 
90 template <typename T>
91 using CLRangeFixture = RangeFixture<CLTensor, CLAccessor, CLRange, T>;
92 
93 TEST_SUITE(U8)
94 FIXTURE_DATA_TEST_CASE(RunSmall, CLRangeFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(
95  framework::dataset::make("DataType", DataType::U8),
96  unsigned_start_dataset),
97  unsigned_step_dataset),
98  framework::dataset::make("QuantizationInfo", { QuantizationInfo() })))
99 {
100  // Validate output
101  validate(CLAccessor(_target), _reference, tolerance, 0.f, abs_tolerance);
102 }
103 TEST_SUITE_END() //U8
104 
105 TEST_SUITE(Quantized)
107 
108 FIXTURE_DATA_TEST_CASE(RunSmall, CLRangeFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(
109  framework::dataset::make("DataType", DataType::QASYMM8),
110  start_dataset),
111  step_dataset),
112  framework::dataset::make("QuantizationInfo", { QuantizationInfo(0.3457f, 120.0f) })))
113 {
114  // Validate output
115  validate(CLAccessor(_target), _reference, tolerance, 0.f, abs_tolerance);
116 }
117 TEST_SUITE_END() //QASYMM8
118 TEST_SUITE_END() //Quantized
119 
121 FIXTURE_DATA_TEST_CASE(RunSmall, CLRangeFixture<int16_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(
122  framework::dataset::make("DataType", DataType::S16),
123  start_dataset),
124  step_dataset),
125  framework::dataset::make("QuantizationInfo", { QuantizationInfo() })))
126 {
127  // Validate output
128  validate(CLAccessor(_target), _reference, tolerance, 0.f, abs_tolerance);
129 }
130 TEST_SUITE_END() //S16
131 
132 TEST_SUITE(Float)
133 TEST_SUITE(FP16)
135  framework::dataset::make("DataType", DataType::F16),
136  start_dataset),
137  float_step_dataset),
138  framework::dataset::make("QuantizationInfo", { QuantizationInfo() })))
139 {
140  // Validate output
141  validate(CLAccessor(_target), _reference, tolerance, 0.f, abs_tolerance);
142 }
143 TEST_SUITE_END() //FP16
144 
145 TEST_SUITE(FP32)
146 FIXTURE_DATA_TEST_CASE(RunSmall, CLRangeFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(
147  framework::dataset::make("DataType", DataType::F32),
148  start_dataset),
149  float_step_dataset),
150  framework::dataset::make("QuantizationInfo", { QuantizationInfo() })))
151 {
152  // Validate output
153  validate(CLAccessor(_target), _reference, tolerance, 0.f, abs_tolerance);
154 }
155 TEST_SUITE_END() //FP32
156 TEST_SUITE_END() //Float
157 
158 TEST_SUITE_END() //Range
159 TEST_SUITE_END() //CL
160 } // namespace validation
161 } // namespace test
162 } // namespace arm_compute
Shape of a tensor.
Definition: TensorShape.h:39
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 CLRange.
Definition: CLRange.cpp:53
RangeFixture< CLTensor, CLAccessor, CLRange, T > CLRangeFixture
Definition: Range.cpp:91
1 channel, 1 U8 per channel
half_float::half half
16-bit floating point type
Definition: Types.h:48
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.
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)
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
Accessor implementation for CLTensor objects.
Definition: CLAccessor.h:36
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