blob: 8e22281025a7da5383942f69c036b49cdf998e7b [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
2 * Copyright (c) 2017 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_BENCHMARK_ACTIVATION_LAYER_H__
25#define __ARM_COMPUTE_TEST_BENCHMARK_ACTIVATION_LAYER_H__
26
27#include "TensorLibrary.h"
28#include "Utils.h"
29#include "dataset/ActivationLayerDataset.h"
30
31#include <memory>
32
33using namespace arm_compute;
34using namespace arm_compute::test;
35using namespace arm_compute::test::benchmark;
36
37namespace arm_compute
38{
39namespace test
40{
41namespace benchmark
42{
43template <typename DataSet, typename TensorType, typename Accessor, typename Function, DataType dt = DataType::F32>
44class ActivationLayer : public ::benchmark::Fixture
45{
46public:
47 void SetUp(::benchmark::State &state) override
48 {
49 profiler.add(std::make_shared<WallClockTimer>());
50
51 const ActivationLayerDataObject act_obj = *(DataSet().begin() + state.range(0));
52
53 // Set batched in source and destination shapes
54 const unsigned int batches = state.range(1);
55 const unsigned int fixed_point_position = 4;
56 TensorShape shape = act_obj.shape;
57 shape.set(shape.num_dimensions(), batches);
58
59 // Create tensors
Moritz Pflanzer94450f12017-06-30 12:48:43 +010060 src = create_tensor<TensorType>(shape, dt, 1, fixed_point_position);
61 dst = create_tensor<TensorType>(shape, dt, 1, fixed_point_position);
Anthony Barbier6ff3b192017-09-04 18:44:23 +010062
63 // Create and configure function
64 act_layer.configure(&src, &dst, act_obj.info);
65
66 // Allocate tensors
67 src.allocator()->allocate();
68 dst.allocator()->allocate();
69
70 // Fill tensors
71 library->fill_tensor_uniform(Accessor(src), 0);
72 }
73
74 void TearDown(::benchmark::State &state) override
75 {
76 src.allocator()->free();
77 dst.allocator()->free();
78
79 profiler.submit(state);
80 }
81
82 Function act_layer{};
83 Profiler profiler{};
84
85private:
86 TensorType src{};
87 TensorType dst{};
88};
89} // namespace benchmark
90} // namespace test
91} // namespace arm_compute
92#endif //__ARM_COMPUTE_TEST_BENCHMARK_ACTIVATION_LAYER_H__