blob: dba3d1ebeaba96fd6b9e5a2a5c2d384cac7c722b [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#include "Globals.h"
25#include "NEON/Helper.h"
26#include "NEON/NEAccessor.h"
27#include "TensorLibrary.h"
28#include "benchmark/Datasets.h"
29#include "benchmark/Profiler.h"
30#include "benchmark/WallClockTimer.h"
31
32#include "arm_compute/core/Helpers.h"
33#include "arm_compute/core/Types.h"
34#include "arm_compute/runtime/NEON/functions/NEBitwiseAnd.h"
35#include "arm_compute/runtime/Tensor.h"
36#include "arm_compute/runtime/TensorAllocator.h"
37
38#include "benchmark/benchmark_api.h"
39
40#include <memory>
41#include <string>
42
43using namespace arm_compute;
44using namespace arm_compute::test;
45using namespace arm_compute::test::benchmark;
46using namespace arm_compute::test::neon;
47
48namespace
49{
50template <typename DataSet>
51class BitwiseAnd : public ::benchmark::Fixture
52{
53public:
54 void SetUp(::benchmark::State &state) override
55 {
56 profiler.add(std::make_shared<WallClockTimer>());
57
58 const std::string image_name = *(DataSet().begin() + state.range(0));
59
60 // Create tensors
61 src1 = create_tensor(image_name, DataType::U8);
62 src2 = create_tensor(image_name, DataType::U8);
63 dst = create_tensor(image_name, DataType::U8);
64
65 // Create and configure function
66 band.configure(&src1, &src2, &dst);
67
68 // Allocate tensors
69 src1.allocator()->allocate();
70 src2.allocator()->allocate();
71 dst.allocator()->allocate();
72
73 // Fill source tensors
74 library->fill(NEAccessor(src1), image_name, Channel::R);
75 library->fill(NEAccessor(src2), image_name, Channel::G);
76 }
77
78 void TearDown(::benchmark::State &state) override
79 {
80 profiler.submit(state);
81 }
82
83 NEBitwiseAnd band{};
84 Profiler profiler{};
85
86private:
87 Tensor src1{};
88 Tensor src2{};
89 Tensor dst{};
90};
91
92using BitwiseAndSmall = BitwiseAnd<SmallImages>;
93using BitwiseAndLarge = BitwiseAnd<LargeImages>;
94} // namespace
95
96BENCHMARK_DEFINE_F(BitwiseAndSmall, neon_bitwise_and)
97(::benchmark::State &state)
98{
99 while(state.KeepRunning())
100 {
101 // Run function
102 profiler.start();
103 band.run();
104 profiler.stop();
105 }
106}
107
108BENCHMARK_REGISTER_F(BitwiseAndSmall, neon_bitwise_and)
109->Threads(1)
110->Apply(DataSetArgs<SmallImages>);
111
112BENCHMARK_DEFINE_F(BitwiseAndLarge, neon_bitwise_and)
113(::benchmark::State &state)
114{
115 while(state.KeepRunning())
116 {
117 // Run function
118 profiler.start();
119 band.run();
120 profiler.stop();
121 }
122}
123
124BENCHMARK_REGISTER_F(BitwiseAndLarge, neon_bitwise_and)
125->Threads(1)
126->Apply(DataSetArgs<LargeImages>);