blob: a2d3ba6c09b21bf6c6f2091bd726a09778a4d36e [file] [log] [blame]
Usama Arif52c54f62019-05-14 10:22:36 +01001/*
Michele Di Giorgiod9eaf612020-07-08 11:12:57 +01002 * Copyright (c) 2019-2020 Arm Limited.
Usama Arif52c54f62019-05-14 10:22:36 +01003 *
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/CLElementwiseOperations.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"
35#include "tests/validation/fixtures/ElementwiseOperationsFixture.h"
36
37namespace arm_compute
38{
39namespace test
40{
41namespace validation
42{
43namespace
44{
45RelativeTolerance<float> tolerance_fp32(0.000001f);
46RelativeTolerance<float> tolerance_fp16(0.001f);
47
Usama Arif52c54f62019-05-14 10:22:36 +010048/** Input data sets **/
49const auto ElementwisePowerFP16Dataset = combine(combine(framework::dataset::make("DataType", DataType::F16), framework::dataset::make("DataType", DataType::F16)),
50 framework::dataset::make("DataType", DataType::F16));
51const auto ElementwisePowerFP32Dataset = combine(combine(framework::dataset::make("DataType", DataType::F32), framework::dataset::make("DataType", DataType::F32)),
52 framework::dataset::make("DataType", DataType::F32));
Giorgio Arena8b2a7d32020-02-11 17:21:31 +000053const auto EmptyActivationFunctionsDataset = framework::dataset::make("ActivationInfo",
54{ ActivationLayerInfo() });
55const auto ActivationFunctionsDataset = framework::dataset::make("ActivationInfo",
56{
57 ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::BOUNDED_RELU, 0.75f, 0.25f),
58 ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LOGISTIC, 0.75f, 0.25f)
59});
Usama Arif52c54f62019-05-14 10:22:36 +010060} // namespace
61
62TEST_SUITE(CL)
63TEST_SUITE(ElementwisePower)
64
65// *INDENT-OFF*
66// clang-format off
67DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(
68 framework::dataset::make("Input1Info", { TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32),
69 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F16),
Usama Arif52c54f62019-05-14 10:22:36 +010070 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), // Invalid data type combination
71 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), // Mismatching shapes
72 }),
73 framework::dataset::make("Input2Info",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32),
74 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F16),
Usama Arif52c54f62019-05-14 10:22:36 +010075 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S16),
76 TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::F32),
77 })),
78 framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32),
79 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F16),
Usama Arif52c54f62019-05-14 10:22:36 +010080 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
81 TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::F32),
82 })),
Manuel Bottinied2a8ed2020-10-07 17:17:16 +010083 framework::dataset::make("Expected", { true, true, false, false})),
Usama Arif52c54f62019-05-14 10:22:36 +010084 input1_info, input2_info, output_info, expected)
85{
86 ARM_COMPUTE_EXPECT(bool(CLElementwisePower::validate(&input1_info.clone()->set_is_resizable(false), &input2_info.clone()->set_is_resizable(false), &output_info.clone()->set_is_resizable(false))) == expected, framework::LogLevel::ERRORS);
87}
88// clang-format on
89// *INDENT-ON*
90
91template <typename T>
Giorgio Arena8b2a7d32020-02-11 17:21:31 +000092using CLElementwisePowerFloatFixture = ElementwisePowerValidationFloatFixture<CLTensor, CLAccessor, CLElementwisePower, T>;
Usama Arif52c54f62019-05-14 10:22:36 +010093
94template <typename T>
Giorgio Arena8b2a7d32020-02-11 17:21:31 +000095using CLElementwisePowerBroadcastFloatFixture = ElementwisePowerBroadcastValidationFloatFixture<CLTensor, CLAccessor, CLElementwisePower, T>;
Usama Arif52c54f62019-05-14 10:22:36 +010096
97TEST_SUITE(Float)
98TEST_SUITE(FP16)
Giorgio Arena8b2a7d32020-02-11 17:21:31 +000099FIXTURE_DATA_TEST_CASE(RunSmall, CLElementwisePowerFloatFixture<half>, framework::DatasetMode::ALL, combine(combine(datasets::SmallShapes(), ElementwisePowerFP16Dataset),
100 EmptyActivationFunctionsDataset))
101{
102 // Validate output
103 validate(CLAccessor(_target), _reference, tolerance_fp16, 0.01);
104}
105FIXTURE_DATA_TEST_CASE(RunWithActivation, CLElementwisePowerFloatFixture<half>, framework::DatasetMode::ALL, combine(combine(datasets::TinyShapes(), ElementwisePowerFP16Dataset),
106 ActivationFunctionsDataset))
Usama Arif52c54f62019-05-14 10:22:36 +0100107{
108 // Validate output
109 validate(CLAccessor(_target), _reference, tolerance_fp16, 0.01);
110}
111
Giorgio Arena8b2a7d32020-02-11 17:21:31 +0000112FIXTURE_DATA_TEST_CASE(RunSmallBroadcast, CLElementwisePowerBroadcastFloatFixture<half>, framework::DatasetMode::ALL, combine(combine(datasets::SmallShapesBroadcast(),
113 ElementwisePowerFP16Dataset),
114 EmptyActivationFunctionsDataset))
115{
116 // Validate output
117 validate(CLAccessor(_target), _reference, tolerance_fp16, 0.01);
118}
119FIXTURE_DATA_TEST_CASE(RunWithActivationBroadcast, CLElementwisePowerBroadcastFloatFixture<half>, framework::DatasetMode::ALL, combine(combine(datasets::TinyShapesBroadcast(),
120 ElementwisePowerFP16Dataset),
121 ActivationFunctionsDataset))
Usama Arif52c54f62019-05-14 10:22:36 +0100122{
123 // Validate output
124 validate(CLAccessor(_target), _reference, tolerance_fp16, 0.01);
125}
126TEST_SUITE_END() //FP16
127
128TEST_SUITE(FP32)
Giorgio Arena8b2a7d32020-02-11 17:21:31 +0000129FIXTURE_DATA_TEST_CASE(RunSmall, CLElementwisePowerFloatFixture<float>, framework::DatasetMode::ALL, combine(combine(datasets::SmallShapes(), ElementwisePowerFP32Dataset),
130 EmptyActivationFunctionsDataset))
131{
132 // Validate output
133 validate(CLAccessor(_target), _reference, tolerance_fp32);
134}
135FIXTURE_DATA_TEST_CASE(RunWithActivation, CLElementwisePowerFloatFixture<float>, framework::DatasetMode::ALL, combine(combine(datasets::TinyShapes(), ElementwisePowerFP32Dataset),
136 ActivationFunctionsDataset))
Usama Arif52c54f62019-05-14 10:22:36 +0100137{
138 // Validate output
139 validate(CLAccessor(_target), _reference, tolerance_fp32);
140}
141
Giorgio Arena8b2a7d32020-02-11 17:21:31 +0000142FIXTURE_DATA_TEST_CASE(RunSmallBroadcast, CLElementwisePowerBroadcastFloatFixture<float>, framework::DatasetMode::ALL, combine(combine(datasets::SmallShapesBroadcast(),
143 ElementwisePowerFP32Dataset),
144 EmptyActivationFunctionsDataset))
145{
146 // Validate output
147 validate(CLAccessor(_target), _reference, tolerance_fp32);
148}
149FIXTURE_DATA_TEST_CASE(RunWithActivationBroadcast, CLElementwisePowerBroadcastFloatFixture<float>, framework::DatasetMode::ALL, combine(combine(datasets::TinyShapesBroadcast(),
150 ElementwisePowerFP32Dataset),
151 ActivationFunctionsDataset))
Usama Arif52c54f62019-05-14 10:22:36 +0100152{
153 // Validate output
154 validate(CLAccessor(_target), _reference, tolerance_fp32);
155}
156TEST_SUITE_END() // FP32
157TEST_SUITE_END() // Float
158TEST_SUITE_END() // ElementwisePower
159TEST_SUITE_END() // CL
160} // namespace validation
161} // namespace test
162} // namespace arm_compute