blob: 5bb332fd6b88894d5d0f038b31a0a4b2e2a8d5f0 [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_POOLING_LAYER_H__
25#define __ARM_COMPUTE_TEST_BENCHMARK_POOLING_LAYER_H__
26
27#include "TensorLibrary.h"
28#include "Utils.h"
29#include "dataset/PoolingLayerDataset.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 PoolingLayer : public ::benchmark::Fixture
45{
46public:
47 void SetUp(::benchmark::State &state) override
48 {
49 profiler.add(std::make_shared<WallClockTimer>());
50
51 const PoolingLayerDataObject pool_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 src_shape = pool_obj.src_shape;
57 TensorShape dst_shape = pool_obj.dst_shape;
58 src_shape.set(src_shape.num_dimensions(), batches);
59 dst_shape.set(dst_shape.num_dimensions(), batches);
60
61 // Create tensors
62 src = create_tensor(src_shape, dt, 1, fixed_point_position);
63 dst = create_tensor(dst_shape, dt, 1, fixed_point_position);
64
65 // Create and configure function
66 pool_layer.configure(&src, &dst, pool_obj.info);
67
68 // Allocate tensors
69 src.allocator()->allocate();
70 dst.allocator()->allocate();
71
72 // Fill tensors
73 library->fill_tensor_uniform(Accessor(src), 0);
74 }
75
76 void TearDown(::benchmark::State &state) override
77 {
78 // Free allocators
79 src.allocator()->free();
80 dst.allocator()->free();
81
82 profiler.submit(state);
83 }
84
85 Function pool_layer{};
86 Profiler profiler{};
87
88private:
89 TensorType src{};
90 TensorType dst{};
91};
92} // namespace benchmark
93} // namespace test
94} // namespace arm_compute
95#endif //__ARM_COMPUTE_TEST_BENCHMARK_POOLING_LAYER_H__