blob: be68fd39e4cb740c570cf13201ce8714705d3017 [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"
Anthony Barbier6ff3b192017-09-04 18:44:23 +010025#include "NEON/NEAccessor.h"
26#include "TensorLibrary.h"
27#include "benchmark/Datasets.h"
28#include "benchmark/Profiler.h"
29#include "benchmark/WallClockTimer.h"
30
31#include "arm_compute/core/Helpers.h"
32#include "arm_compute/core/Types.h"
33#include "arm_compute/runtime/NEON/functions/NEBitwiseAnd.h"
34#include "arm_compute/runtime/Tensor.h"
35#include "arm_compute/runtime/TensorAllocator.h"
36
37#include "benchmark/benchmark_api.h"
38
39#include <memory>
40#include <string>
41
42using namespace arm_compute;
43using namespace arm_compute::test;
44using namespace arm_compute::test::benchmark;
45using namespace arm_compute::test::neon;
46
47namespace
48{
49template <typename DataSet>
50class BitwiseAnd : public ::benchmark::Fixture
51{
52public:
53 void SetUp(::benchmark::State &state) override
54 {
55 profiler.add(std::make_shared<WallClockTimer>());
56
57 const std::string image_name = *(DataSet().begin() + state.range(0));
Moritz Pflanzer94450f12017-06-30 12:48:43 +010058 const RawTensor &raw = library->get(image_name);
Anthony Barbier6ff3b192017-09-04 18:44:23 +010059
60 // Create tensors
Moritz Pflanzer94450f12017-06-30 12:48:43 +010061 src1 = create_tensor<Tensor>(raw.shape(), DataType::U8);
62 src2 = create_tensor<Tensor>(raw.shape(), DataType::U8);
63 dst = create_tensor<Tensor>(raw.shape(), DataType::U8);
Anthony Barbier6ff3b192017-09-04 18:44:23 +010064
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>);