blob: 46509a28704b6e297ab5174f46de1fb628d36849 [file] [log] [blame]
Usama Arif52c54f62019-05-14 10:22:36 +01001/*
2 * Copyright (c) 2019 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"
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));
53} // namespace
54
55TEST_SUITE(CL)
56TEST_SUITE(ElementwisePower)
57
58// *INDENT-OFF*
59// clang-format off
60DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(
61 framework::dataset::make("Input1Info", { TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32),
62 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F16),
63 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32), // Window shrink
64 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), // Invalid data type combination
65 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), // Mismatching shapes
66 }),
67 framework::dataset::make("Input2Info",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32),
68 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F16),
69 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32),
70 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S16),
71 TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::F32),
72 })),
73 framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32),
74 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F16),
75 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32),
76 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
77 TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::F32),
78 })),
79 framework::dataset::make("Expected", { true, true, false, false, false})),
80 input1_info, input2_info, output_info, expected)
81{
82 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);
83}
84// clang-format on
85// *INDENT-ON*
86
87template <typename T>
88using CLElementwisePowerFixture = ElementwisePowerValidationFixture<CLTensor, CLAccessor, CLElementwisePower, T>;
89
90template <typename T>
91using CLElementwisePowerBroadcastFixture = ElementwisePowerBroadcastValidationFixture<CLTensor, CLAccessor, CLElementwisePower, T>;
92
93TEST_SUITE(Float)
94TEST_SUITE(FP16)
95FIXTURE_DATA_TEST_CASE(RunSmall, CLElementwisePowerFixture<half>, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), ElementwisePowerFP16Dataset))
96{
97 // Validate output
98 validate(CLAccessor(_target), _reference, tolerance_fp16, 0.01);
99}
100
101FIXTURE_DATA_TEST_CASE(RunSmallBroadcast, CLElementwisePowerBroadcastFixture<half>, framework::DatasetMode::ALL, combine(datasets::SmallShapesBroadcast(),
102 ElementwisePowerFP16Dataset))
103{
104 // Validate output
105 validate(CLAccessor(_target), _reference, tolerance_fp16, 0.01);
106}
107TEST_SUITE_END() //FP16
108
109TEST_SUITE(FP32)
110FIXTURE_DATA_TEST_CASE(RunSmall, CLElementwisePowerFixture<float>, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), ElementwisePowerFP32Dataset))
111{
112 // Validate output
113 validate(CLAccessor(_target), _reference, tolerance_fp32);
114}
115
116FIXTURE_DATA_TEST_CASE(RunSmallBroadcast, CLElementwisePowerBroadcastFixture<float>, framework::DatasetMode::ALL, combine(datasets::SmallShapesBroadcast(),
117 ElementwisePowerFP32Dataset))
118{
119 // Validate output
120 validate(CLAccessor(_target), _reference, tolerance_fp32);
121}
122TEST_SUITE_END() // FP32
123TEST_SUITE_END() // Float
124TEST_SUITE_END() // ElementwisePower
125TEST_SUITE_END() // CL
126} // namespace validation
127} // namespace test
128} // namespace arm_compute