blob: fb8e1bc09fb32fbdb8495cca77906221362a3c1a [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 "CL/CLAccessor.h"
Anthony Barbier6ff3b192017-09-04 18:44:23 +010025#include "Globals.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/CL/CLScheduler.h"
34#include "arm_compute/runtime/CL/CLTensor.h"
35#include "arm_compute/runtime/CL/CLTensorAllocator.h"
36#include "arm_compute/runtime/CL/functions/CLFullyConnectedLayer.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::cl;
47
48#include "benchmark/common/FullyConnectedLayer.h"
49
50namespace
51{
52using FullyConnectedLayerAlexNet = FullyConnectedLayer<AlexNetFullyConnectedLayerDataset, CLTensor, CLAccessor, CLFullyConnectedLayer>;
53using FullyConnectedLayerLeNet5 = FullyConnectedLayer<LeNet5FullyConnectedLayerDataset, CLTensor, CLAccessor, CLFullyConnectedLayer>;
54using FullyConnectedLayerGoogLeNet = FullyConnectedLayer<GoogLeNetFullyConnectedLayerDataset, CLTensor, CLAccessor, CLFullyConnectedLayer>;
55} // namespace
56
57BENCHMARK_DEFINE_F(FullyConnectedLayerAlexNet, cl_alexnet)
58(::benchmark::State &state)
59{
60 while(state.KeepRunning())
61 {
62 // Run function
63 profiler.start();
64 fc_layer->run();
65 CLScheduler::get().sync();
66 profiler.stop();
67 }
68}
69
70BENCHMARK_REGISTER_F(FullyConnectedLayerAlexNet, cl_alexnet)
71->Threads(1)
72->Apply(DataSetArgBatched<AlexNetFullyConnectedLayerDataset, 0, 1, 4, 8>);
73BENCHMARK_REGISTER_F(FullyConnectedLayerAlexNet, cl_alexnet)
74->Threads(1)
75->Apply(DataSetArgBatched<AlexNetFullyConnectedLayerDataset, 1, 1, 4, 8>);
76BENCHMARK_REGISTER_F(FullyConnectedLayerAlexNet, cl_alexnet)
77->Threads(1)
78->Apply(DataSetArgBatched<AlexNetFullyConnectedLayerDataset, 2, 1, 4, 8>);
79
80BENCHMARK_DEFINE_F(FullyConnectedLayerLeNet5, cl_lenet5)
81(::benchmark::State &state)
82{
83 while(state.KeepRunning())
84 {
85 // Run function
86 profiler.start();
87 fc_layer->run();
88 CLScheduler::get().sync();
89 profiler.stop();
90 }
91}
92
93BENCHMARK_REGISTER_F(FullyConnectedLayerLeNet5, cl_lenet5)
94->Threads(1)
95->Apply(DataSetArgBatched<LeNet5FullyConnectedLayerDataset, 0, 1, 4, 8>);
96BENCHMARK_REGISTER_F(FullyConnectedLayerLeNet5, cl_lenet5)
97->Threads(1)
98->Apply(DataSetArgBatched<LeNet5FullyConnectedLayerDataset, 1, 1, 4, 8>);
99
100BENCHMARK_DEFINE_F(FullyConnectedLayerGoogLeNet, cl_googlenet)
101(::benchmark::State &state)
102{
103 while(state.KeepRunning())
104 {
105 // Run function
106 profiler.start();
107 fc_layer->run();
108 CLScheduler::get().sync();
109 profiler.stop();
110 }
111}
112
113BENCHMARK_REGISTER_F(FullyConnectedLayerGoogLeNet, cl_googlenet)
114->Threads(1)
115->Apply(DataSetArgBatched<GoogLeNetFullyConnectedLayerDataset, 0, 1, 4, 8>);