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