blob: 2353bda8d3eedb28581f674f4785bdc19a15085f [file] [log] [blame]
Michalis Spyroue9362622018-11-23 17:41:37 +00001/*
Ramy Elgammal14d7b532023-01-30 04:56:47 +00002 * Copyright (c) 2018-2019, 2023 Arm Limited.
Michalis Spyroue9362622018-11-23 17:41:37 +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"
Jakub Sujakee301b32021-06-04 09:46:08 +010025#include "arm_compute/runtime/CL/functions/CLElementwiseUnaryLayer.h"
Michalis Spyroue9362622018-11-23 17:41:37 +000026#include "arm_compute/runtime/Tensor.h"
27#include "arm_compute/runtime/TensorAllocator.h"
28#include "tests/CL/CLAccessor.h"
29#include "tests/PaddingCalculator.h"
30#include "tests/datasets/ShapeDatasets.h"
31#include "tests/framework/Asserts.h"
32#include "tests/framework/Macros.h"
33#include "tests/framework/datasets/Datasets.h"
34#include "tests/validation/Validation.h"
Jakub Sujakee301b32021-06-04 09:46:08 +010035#include "tests/validation/fixtures/ElementwiseUnaryFixture.h"
Michalis Spyroue9362622018-11-23 17:41:37 +000036
37namespace arm_compute
38{
39namespace test
40{
41namespace validation
42{
43namespace
44{
Ramy Elgammal14d7b532023-01-30 04:56:47 +000045RelativeTolerance<float> tolerance_fp32(0.000001f);
46RelativeTolerance<float> tolerance_fp16(0.001f);
47constexpr AbsoluteTolerance<uint8_t> tolerance_qasymm8(1); /**< Tolerance value for comparing reference's output against implementation's output for unsigned 8-bit asymmetric type */
48constexpr AbsoluteTolerance<int8_t> tolerance_qasymm8_s(1); /**< Tolerance value for comparing reference's output against implementation's output for signed 8-bit asymmetric type */
49
Michalis Spyroue9362622018-11-23 17:41:37 +000050} // namespace
51TEST_SUITE(CL)
52TEST_SUITE(RsqrtLayer)
53
Michalis Spyrou80943252019-01-10 17:19:50 +000054// *INDENT-OFF*
55// clang-format off
56DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(
57 framework::dataset::make("InputInfo", { TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32), // Mismatching data types
58 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), // Valid
59 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32), // Mismatching shapes
60 }),
61 framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F16),
62 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32),
63 TensorInfo(TensorShape(30U, 11U, 2U), 1, DataType::F32),
64 })),
65 framework::dataset::make("Expected", { false, true, false })),
66 input_info, output_info, expected)
Michalis Spyroue9362622018-11-23 17:41:37 +000067{
Michalis Spyrou80943252019-01-10 17:19:50 +000068 ARM_COMPUTE_EXPECT(bool(CLRsqrtLayer::validate(&input_info.clone()->set_is_resizable(false), &output_info.clone()->set_is_resizable(false))) == expected, framework::LogLevel::ERRORS);
Michalis Spyroue9362622018-11-23 17:41:37 +000069}
Michalis Spyrou80943252019-01-10 17:19:50 +000070// clang-format on
71// *INDENT-ON*
Michalis Spyroue9362622018-11-23 17:41:37 +000072template <typename T>
73using CLRsqrtLayerFixture = RsqrtValidationFixture<CLTensor, CLAccessor, CLRsqrtLayer, T>;
Ramy Elgammal14d7b532023-01-30 04:56:47 +000074template <typename T>
75using CLRsqrtLayerQuantizedFixture = RsqrtQuantizedValidationFixture<CLTensor, CLAccessor, CLRsqrtLayer, T>;
Michalis Spyroue9362622018-11-23 17:41:37 +000076
77TEST_SUITE(Float)
78TEST_SUITE(FP16)
79FIXTURE_DATA_TEST_CASE(RunSmall, CLRsqrtLayerFixture<half>, framework::DatasetMode::PRECOMMIT, combine(datasets::SmallShapes(), framework::dataset::make("DataType",
80 DataType::F16)))
81{
82 // Validate output
83 validate(CLAccessor(_target), _reference, tolerance_fp16);
84}
85FIXTURE_DATA_TEST_CASE(RunLarge, CLRsqrtLayerFixture<half>, framework::DatasetMode::NIGHTLY, combine(datasets::LargeShapes(), framework::dataset::make("DataType",
86 DataType::F16)))
87{
88 // Validate output
89 validate(CLAccessor(_target), _reference, tolerance_fp16);
90}
91
92TEST_SUITE_END() // FP16
93TEST_SUITE(FP32)
94FIXTURE_DATA_TEST_CASE(RunSmall, CLRsqrtLayerFixture<float>, framework::DatasetMode::PRECOMMIT, combine(datasets::SmallShapes(), framework::dataset::make("DataType",
95 DataType::F32)))
96{
97 // Validate output
98 validate(CLAccessor(_target), _reference, tolerance_fp32);
99}
100FIXTURE_DATA_TEST_CASE(RunLarge, CLRsqrtLayerFixture<float>, framework::DatasetMode::NIGHTLY, combine(datasets::LargeShapes(), framework::dataset::make("DataType",
101 DataType::F32)))
102{
103 // Validate output
104 validate(CLAccessor(_target), _reference, tolerance_fp32);
105}
106
107TEST_SUITE_END() // FP32
108TEST_SUITE_END() // Float
109
Ramy Elgammal14d7b532023-01-30 04:56:47 +0000110TEST_SUITE(Quantized)
111TEST_SUITE(QASYMM8_SIGNED)
112FIXTURE_DATA_TEST_CASE(RunSmall, CLRsqrtLayerQuantizedFixture<int8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::SmallShapes(), framework::dataset::make("DataType",
113 DataType::QASYMM8_SIGNED)),
114 framework::dataset::make("SrcQInfo", { QuantizationInfo(0.4044, -128) })),
115 framework::dataset::make("OutQInfo", { QuantizationInfo(0.0027, -128) })))
116{
117 // Validate output
118 validate(CLAccessor(_target), _reference, tolerance_qasymm8_s);
119}
120TEST_SUITE_END() // QASYMM8_SIGNED
121TEST_SUITE(QASYMM8)
122
123FIXTURE_DATA_TEST_CASE(RunSmall, CLRsqrtLayerQuantizedFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::SmallShapes(), framework::dataset::make("DataType",
124 DataType::QASYMM8)),
125 framework::dataset::make("SrcQInfo", { QuantizationInfo(0.4044, 0) })),
126 framework::dataset::make("OutQInfo", { QuantizationInfo(0.0027, 0) })))
127{
128 // Validate output
129 validate(CLAccessor(_target), _reference, tolerance_qasymm8);
130}
131TEST_SUITE_END() // QASYMM8
132TEST_SUITE_END() // Quantized
133
Michalis Spyroue9362622018-11-23 17:41:37 +0000134TEST_SUITE_END() // RsqrtLayer
135TEST_SUITE_END() // CL
136} // namespace validation
137} // namespace test
138} // namespace arm_compute