blob: a26f7c84c02a3b1ad045d9a903bf533e440b5cdc [file] [log] [blame]
Manuel Bottinied753262019-05-15 15:30:47 +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#ifndef ARM_COMPUTE_TEST_ELEMENTWISE_UNARY_FIXTURE
25#define ARM_COMPUTE_TEST_ELEMENTWISE_UNARY_FIXTURE
26
27#include "arm_compute/core/TensorShape.h"
28#include "arm_compute/core/Types.h"
29#include "tests/AssetsLibrary.h"
30#include "tests/Globals.h"
31#include "tests/IAccessor.h"
32#include "tests/framework/Asserts.h"
33#include "tests/framework/Fixture.h"
34#include "tests/validation/reference/ElementWiseUnary.h"
35
36namespace arm_compute
37{
38namespace test
39{
40namespace benchmark
41{
42template <typename TensorType, typename AccessorType, typename FunctionType, typename T>
43class ElementWiseUnaryBenchmarkFixture : public framework::Fixture
44{
45public:
46 template <typename...>
Michalis Spyrou6bff1952019-10-02 17:22:11 +010047 void setup(TensorShape input_shape, DataType input_data_type)
Manuel Bottinied753262019-05-15 15:30:47 +010048 {
49 src = create_tensor<TensorType>(input_shape, input_data_type);
50 dst = create_tensor<TensorType>(input_shape, input_data_type);
51
52 elwiseunary_layer.configure(&src, &dst);
53
54 // Allocate tensors
55 src.allocator()->allocate();
56 dst.allocator()->allocate();
57 }
58
59 void run()
60 {
61 elwiseunary_layer.run();
62 }
63
64 void sync()
65 {
66 sync_if_necessary<TensorType>();
67 sync_tensor_if_necessary<TensorType>(dst);
68 }
69
70private:
71 TensorType src{};
72 TensorType dst{};
73 FunctionType elwiseunary_layer{};
74};
75
76template <typename TensorType, typename AccessorType, typename FunctionType, typename T>
77class RsqrtBenchmarkFixture : public ElementWiseUnaryBenchmarkFixture<TensorType, AccessorType, FunctionType, T>
78{
79public:
80 template <typename...>
81 void setup(const TensorShape &shape, DataType data_type)
82 {
Michalis Spyrou6bff1952019-10-02 17:22:11 +010083 ElementWiseUnaryBenchmarkFixture<TensorType, AccessorType, FunctionType, T>::setup(shape, data_type);
Manuel Bottinied753262019-05-15 15:30:47 +010084 }
85};
86
87template <typename TensorType, typename AccessorType, typename FunctionType, typename T>
88class ExpBenchmarkFixture : public ElementWiseUnaryBenchmarkFixture<TensorType, AccessorType, FunctionType, T>
89{
90public:
91 template <typename...>
92 void setup(const TensorShape &shape, DataType data_type)
93 {
Michalis Spyrou6bff1952019-10-02 17:22:11 +010094 ElementWiseUnaryBenchmarkFixture<TensorType, AccessorType, FunctionType, T>::setup(shape, data_type);
Manuel Bottinied753262019-05-15 15:30:47 +010095 }
96};
97
98template <typename TensorType, typename AccessorType, typename FunctionType, typename T>
99class NegBenchmarkFixture : public ElementWiseUnaryBenchmarkFixture<TensorType, AccessorType, FunctionType, T>
100{
101public:
102 template <typename...>
103 void setup(const TensorShape &shape, DataType data_type)
104 {
Michalis Spyrou6bff1952019-10-02 17:22:11 +0100105 ElementWiseUnaryBenchmarkFixture<TensorType, AccessorType, FunctionType, T>::setup(shape, data_type);
Manuel Bottinied753262019-05-15 15:30:47 +0100106 }
107};
108
109template <typename TensorType, typename AccessorType, typename FunctionType, typename T>
110class LogBenchmarkFixture : public ElementWiseUnaryBenchmarkFixture<TensorType, AccessorType, FunctionType, T>
111{
112public:
113 template <typename...>
114 void setup(const TensorShape &shape, DataType data_type)
115 {
Michalis Spyrou6bff1952019-10-02 17:22:11 +0100116 ElementWiseUnaryBenchmarkFixture<TensorType, AccessorType, FunctionType, T>::setup(shape, data_type);
Manuel Bottinied753262019-05-15 15:30:47 +0100117 }
118};
119
120template <typename TensorType, typename AccessorType, typename FunctionType, typename T>
121class AbsBenchmarkFixture : public ElementWiseUnaryBenchmarkFixture<TensorType, AccessorType, FunctionType, T>
122{
123public:
124 template <typename...>
125 void setup(const TensorShape &shape, DataType data_type)
126 {
Michalis Spyrou6bff1952019-10-02 17:22:11 +0100127 ElementWiseUnaryBenchmarkFixture<TensorType, AccessorType, FunctionType, T>::setup(shape, data_type);
Manuel Bottinied753262019-05-15 15:30:47 +0100128 }
129};
130
131template <typename TensorType, typename AccessorType, typename FunctionType, typename T>
132class SinBenchmarkFixture : public ElementWiseUnaryBenchmarkFixture<TensorType, AccessorType, FunctionType, T>
133{
134public:
135 template <typename...>
136 void setup(const TensorShape &shape, DataType data_type)
137 {
Michalis Spyrou6bff1952019-10-02 17:22:11 +0100138 ElementWiseUnaryBenchmarkFixture<TensorType, AccessorType, FunctionType, T>::setup(shape, data_type);
Manuel Bottinied753262019-05-15 15:30:47 +0100139 }
140};
141} // namespace validation
142} // namespace test
143} // namespace arm_compute
144#endif /* ARM_COMPUTE_TEST_ELEMENTWISE_UNARY_FIXTURE */