blob: bf81f55e41a0abc74f43c84520bb764f89226cbf [file] [log] [blame]
Vidhya Sudhan Loganathan5e96be72018-12-18 14:17:00 +00001/*
Michele Di Giorgiod9eaf612020-07-08 11:12:57 +01002 * Copyright (c) 2018 Arm Limited.
Vidhya Sudhan Loganathan5e96be72018-12-18 14:17:00 +00003 *
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"
25#include "arm_compute/runtime/CL/CLTensor.h"
26#include "arm_compute/runtime/CL/CLTensorAllocator.h"
27#include "arm_compute/runtime/CL/functions/CLRange.h"
28#include "tests/CL/CLAccessor.h"
29#include "tests/PaddingCalculator.h"
30#include "tests/datasets/ConvertPolicyDataset.h"
31#include "tests/datasets/ShapeDatasets.h"
32#include "tests/framework/Asserts.h"
33#include "tests/framework/Macros.h"
34#include "tests/framework/datasets/Datasets.h"
35#include "tests/validation/Validation.h"
36#include "tests/validation/fixtures/RangeFixture.h"
37
38namespace arm_compute
39{
40namespace test
41{
42namespace validation
43{
44namespace
45{
46constexpr RelativeTolerance<float> tolerance(0.01f);
47constexpr AbsoluteTolerance<float> abs_tolerance(0.02f);
48const auto start_dataset = framework::dataset::make("Start", { float(3), float(-17), float(16) });
49const auto unsigned_start_dataset = framework::dataset::make("Start", { float(3), float(16) });
50const 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) });
51const auto step_dataset = framework::dataset::make("Step", { float(1), float(12), float(-12), float(-1), float(-3), float(3) });
52const auto unsigned_step_dataset = framework::dataset::make("Step", { float(1), float(12), float(3) });
53} // namespace
54
55TEST_SUITE(CL)
56TEST_SUITE(Range)
57
58// *INDENT-OFF*
59// clang-format off
60
61DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip(
62 framework::dataset::make("OutputInfo", { TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
63 TensorInfo(TensorShape(32U), 1, DataType::U8),
64 TensorInfo(TensorShape(27U), 1, DataType::U8),
65 TensorInfo(TensorShape(32U), 1, DataType::U8),
66 TensorInfo(TensorShape(32U), 1, DataType::F32),
67 TensorInfo(TensorShape(27U), 1, DataType::U8),
68 TensorInfo(TensorShape(27U), 1, DataType::U8),
69 TensorInfo(TensorShape(10U), 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{
85 ARM_COMPUTE_EXPECT(bool(CLRange::validate(&output_info, start, end, step)) == expected, framework::LogLevel::ERRORS);
86}
87// clang-format on
88// *INDENT-ON*
89
90template <typename T>
91using CLRangeFixture = RangeFixture<CLTensor, CLAccessor, CLRange, T>;
92
93TEST_SUITE(U8)
94FIXTURE_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}
103TEST_SUITE_END() //U8
104
105TEST_SUITE(Quantized)
106TEST_SUITE(QASYMM8)
107
108FIXTURE_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}
117TEST_SUITE_END() //QASYMM8
118TEST_SUITE_END() //Quantized
119
120TEST_SUITE(S16)
121FIXTURE_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}
130TEST_SUITE_END() //S16
131
132TEST_SUITE(Float)
133TEST_SUITE(FP16)
134FIXTURE_DATA_TEST_CASE(RunSmall, CLRangeFixture<half>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(
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}
143TEST_SUITE_END() //FP16
144
145TEST_SUITE(FP32)
146FIXTURE_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}
155TEST_SUITE_END() //FP32
156TEST_SUITE_END() //Float
157
158TEST_SUITE_END() //Range
159TEST_SUITE_END() //CL
160} // namespace validation
161} // namespace test
162} // namespace arm_compute