Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1 | /* |
| 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/CLConvolutionLayer.h" |
| 38 | |
| 39 | #include "benchmark/benchmark_api.h" |
| 40 | |
| 41 | using namespace arm_compute; |
| 42 | using namespace arm_compute::test; |
| 43 | using namespace arm_compute::test::benchmark; |
| 44 | using namespace arm_compute::test::cl; |
| 45 | |
| 46 | #include "benchmark/common/ConvolutionLayer.h" |
| 47 | |
| 48 | namespace |
| 49 | { |
| 50 | using ConvolutionLayerAlexNet = ConvolutionLayer<AlexNetConvolutionLayerDataset, CLTensor, CLAccessor, CLConvolutionLayer>; |
| 51 | using ConvolutionLayerLeNet5 = ConvolutionLayer<LeNet5ConvolutionLayerDataset, CLTensor, CLAccessor, CLConvolutionLayer>; |
| 52 | using ConvolutionLayerGoogLeNet1 = ConvolutionLayer<GoogLeNetConvolutionLayerDataset1, CLTensor, CLAccessor, CLConvolutionLayer>; |
| 53 | using ConvolutionLayerGoogLeNet2 = ConvolutionLayer<GoogLeNetConvolutionLayerDataset2, CLTensor, CLAccessor, CLConvolutionLayer>; |
| 54 | } // namespace |
| 55 | |
| 56 | BENCHMARK_DEFINE_F(ConvolutionLayerAlexNet, cl_alexnet) |
| 57 | (::benchmark::State &state) |
| 58 | { |
| 59 | while(state.KeepRunning()) |
| 60 | { |
| 61 | // Run function |
| 62 | profiler.start(); |
| 63 | conv_layer->run(); |
| 64 | CLScheduler::get().sync(); |
| 65 | profiler.stop(); |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | BENCHMARK_REGISTER_F(ConvolutionLayerAlexNet, cl_alexnet) |
| 70 | ->Threads(1) |
| 71 | ->Apply(DataSetArgBatched<AlexNetConvolutionLayerDataset, 0, 1, 4, 8>); |
| 72 | BENCHMARK_REGISTER_F(ConvolutionLayerAlexNet, cl_alexnet) |
| 73 | ->Threads(1) |
| 74 | ->Apply(DataSetArgBatched<AlexNetConvolutionLayerDataset, 1, 1, 4, 8>); |
| 75 | BENCHMARK_REGISTER_F(ConvolutionLayerAlexNet, cl_alexnet) |
| 76 | ->Threads(1) |
| 77 | ->Apply(DataSetArgBatched<AlexNetConvolutionLayerDataset, 2, 1, 4, 8>); |
| 78 | BENCHMARK_REGISTER_F(ConvolutionLayerAlexNet, cl_alexnet) |
| 79 | ->Threads(1) |
| 80 | ->Apply(DataSetArgBatched<AlexNetConvolutionLayerDataset, 3, 1, 4, 8>); |
| 81 | BENCHMARK_REGISTER_F(ConvolutionLayerAlexNet, cl_alexnet) |
| 82 | ->Threads(1) |
| 83 | ->Apply(DataSetArgBatched<AlexNetConvolutionLayerDataset, 4, 1, 4, 8>); |
| 84 | |
| 85 | BENCHMARK_DEFINE_F(ConvolutionLayerLeNet5, cl_lenet5) |
| 86 | (::benchmark::State &state) |
| 87 | { |
| 88 | while(state.KeepRunning()) |
| 89 | { |
| 90 | // Run function |
| 91 | profiler.start(); |
| 92 | conv_layer->run(); |
| 93 | CLScheduler::get().sync(); |
| 94 | profiler.stop(); |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | BENCHMARK_REGISTER_F(ConvolutionLayerLeNet5, cl_lenet5) |
| 99 | ->Threads(1) |
| 100 | ->Apply(DataSetArgBatched<LeNet5ConvolutionLayerDataset, 0, 1, 4, 8>); |
| 101 | BENCHMARK_REGISTER_F(ConvolutionLayerLeNet5, cl_lenet5) |
| 102 | ->Threads(1) |
| 103 | ->Apply(DataSetArgBatched<LeNet5ConvolutionLayerDataset, 1, 1, 4, 8>); |
| 104 | |
| 105 | BENCHMARK_DEFINE_F(ConvolutionLayerGoogLeNet1, cl_googlenet) |
| 106 | (::benchmark::State &state) |
| 107 | { |
| 108 | while(state.KeepRunning()) |
| 109 | { |
| 110 | // Run function |
| 111 | profiler.start(); |
| 112 | conv_layer->run(); |
| 113 | CLScheduler::get().sync(); |
| 114 | profiler.stop(); |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | BENCHMARK_DEFINE_F(ConvolutionLayerGoogLeNet2, cl_googlenet) |
| 119 | (::benchmark::State &state) |
| 120 | { |
| 121 | while(state.KeepRunning()) |
| 122 | { |
| 123 | // Run function |
| 124 | profiler.start(); |
| 125 | conv_layer->run(); |
| 126 | CLScheduler::get().sync(); |
| 127 | profiler.stop(); |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | BENCHMARK_REGISTER_F(ConvolutionLayerGoogLeNet1, cl_googlenet) |
| 132 | ->Threads(1) |
| 133 | ->Apply(DataSetArgBatched<GoogLeNetConvolutionLayerDataset1, 0, 1, 4, 8>); |
| 134 | BENCHMARK_REGISTER_F(ConvolutionLayerGoogLeNet1, cl_googlenet) |
| 135 | ->Threads(1) |
| 136 | ->Apply(DataSetArgBatched<GoogLeNetConvolutionLayerDataset1, 1, 1, 4, 8>); |
| 137 | BENCHMARK_REGISTER_F(ConvolutionLayerGoogLeNet1, cl_googlenet) |
| 138 | ->Threads(1) |
| 139 | ->Apply(DataSetArgBatched<GoogLeNetConvolutionLayerDataset1, 2, 1, 4, 8>); |
| 140 | BENCHMARK_REGISTER_F(ConvolutionLayerGoogLeNet1, cl_googlenet) |
| 141 | ->Threads(1) |
| 142 | ->Apply(DataSetArgBatched<GoogLeNetConvolutionLayerDataset1, 3, 1, 4, 8>); |
| 143 | BENCHMARK_REGISTER_F(ConvolutionLayerGoogLeNet1, cl_googlenet) |
| 144 | ->Threads(1) |
| 145 | ->Apply(DataSetArgBatched<GoogLeNetConvolutionLayerDataset1, 4, 1, 4, 8>); |
| 146 | BENCHMARK_REGISTER_F(ConvolutionLayerGoogLeNet1, cl_googlenet) |
| 147 | ->Threads(1) |
| 148 | ->Apply(DataSetArgBatched<GoogLeNetConvolutionLayerDataset1, 5, 1, 4, 8>); |
| 149 | BENCHMARK_REGISTER_F(ConvolutionLayerGoogLeNet1, cl_googlenet) |
| 150 | ->Threads(1) |
| 151 | ->Apply(DataSetArgBatched<GoogLeNetConvolutionLayerDataset1, 6, 1, 4, 8>); |
| 152 | BENCHMARK_REGISTER_F(ConvolutionLayerGoogLeNet1, cl_googlenet) |
| 153 | ->Threads(1) |
| 154 | ->Apply(DataSetArgBatched<GoogLeNetConvolutionLayerDataset1, 7, 1, 4, 8>); |
| 155 | BENCHMARK_REGISTER_F(ConvolutionLayerGoogLeNet1, cl_googlenet) |
| 156 | ->Threads(1) |
| 157 | ->Apply(DataSetArgBatched<GoogLeNetConvolutionLayerDataset1, 8, 1, 4, 8>); |
| 158 | BENCHMARK_REGISTER_F(ConvolutionLayerGoogLeNet1, cl_googlenet) |
| 159 | ->Threads(1) |
| 160 | ->Apply(DataSetArgBatched<GoogLeNetConvolutionLayerDataset1, 9, 1, 4, 8>); |
| 161 | BENCHMARK_REGISTER_F(ConvolutionLayerGoogLeNet1, cl_googlenet) |
| 162 | ->Threads(1) |
| 163 | ->Apply(DataSetArgBatched<GoogLeNetConvolutionLayerDataset1, 10, 1, 4, 8>); |
| 164 | BENCHMARK_REGISTER_F(ConvolutionLayerGoogLeNet1, cl_googlenet) |
| 165 | ->Threads(1) |
| 166 | ->Apply(DataSetArgBatched<GoogLeNetConvolutionLayerDataset1, 11, 1, 4, 8>); |
| 167 | BENCHMARK_REGISTER_F(ConvolutionLayerGoogLeNet1, cl_googlenet) |
| 168 | ->Threads(1) |
| 169 | ->Apply(DataSetArgBatched<GoogLeNetConvolutionLayerDataset1, 12, 1, 4, 8>); |
| 170 | BENCHMARK_REGISTER_F(ConvolutionLayerGoogLeNet1, cl_googlenet) |
| 171 | ->Threads(1) |
| 172 | ->Apply(DataSetArgBatched<GoogLeNetConvolutionLayerDataset1, 13, 1, 4, 8>); |
| 173 | BENCHMARK_REGISTER_F(ConvolutionLayerGoogLeNet1, cl_googlenet) |
| 174 | ->Threads(1) |
| 175 | ->Apply(DataSetArgBatched<GoogLeNetConvolutionLayerDataset1, 14, 1, 4, 8>); |
| 176 | BENCHMARK_REGISTER_F(ConvolutionLayerGoogLeNet1, cl_googlenet) |
| 177 | ->Threads(1) |
| 178 | ->Apply(DataSetArgBatched<GoogLeNetConvolutionLayerDataset1, 15, 1, 4, 8>); |
| 179 | BENCHMARK_REGISTER_F(ConvolutionLayerGoogLeNet1, cl_googlenet) |
| 180 | ->Threads(1) |
| 181 | ->Apply(DataSetArgBatched<GoogLeNetConvolutionLayerDataset1, 16, 1, 4, 8>); |
| 182 | BENCHMARK_REGISTER_F(ConvolutionLayerGoogLeNet1, cl_googlenet) |
| 183 | ->Threads(1) |
| 184 | ->Apply(DataSetArgBatched<GoogLeNetConvolutionLayerDataset1, 17, 1, 4, 8>); |
| 185 | BENCHMARK_REGISTER_F(ConvolutionLayerGoogLeNet1, cl_googlenet) |
| 186 | ->Threads(1) |
| 187 | ->Apply(DataSetArgBatched<GoogLeNetConvolutionLayerDataset1, 18, 1, 4, 8>); |
| 188 | BENCHMARK_REGISTER_F(ConvolutionLayerGoogLeNet1, cl_googlenet) |
| 189 | ->Threads(1) |
| 190 | ->Apply(DataSetArgBatched<GoogLeNetConvolutionLayerDataset1, 19, 1, 4, 8>); |
| 191 | BENCHMARK_REGISTER_F(ConvolutionLayerGoogLeNet1, cl_googlenet) |
| 192 | ->Threads(1) |
| 193 | ->Apply(DataSetArgBatched<GoogLeNetConvolutionLayerDataset1, 20, 1, 4, 8>); |
| 194 | BENCHMARK_REGISTER_F(ConvolutionLayerGoogLeNet1, cl_googlenet) |
| 195 | ->Threads(1) |
| 196 | ->Apply(DataSetArgBatched<GoogLeNetConvolutionLayerDataset1, 21, 1, 4, 8>); |
| 197 | BENCHMARK_REGISTER_F(ConvolutionLayerGoogLeNet1, cl_googlenet) |
| 198 | ->Threads(1) |
| 199 | ->Apply(DataSetArgBatched<GoogLeNetConvolutionLayerDataset1, 22, 1, 4, 8>); |
| 200 | BENCHMARK_REGISTER_F(ConvolutionLayerGoogLeNet1, cl_googlenet) |
| 201 | ->Threads(1) |
| 202 | ->Apply(DataSetArgBatched<GoogLeNetConvolutionLayerDataset1, 23, 1, 4, 8>); |
| 203 | BENCHMARK_REGISTER_F(ConvolutionLayerGoogLeNet1, cl_googlenet) |
| 204 | ->Threads(1) |
| 205 | ->Apply(DataSetArgBatched<GoogLeNetConvolutionLayerDataset1, 24, 1, 4, 8>); |
| 206 | BENCHMARK_REGISTER_F(ConvolutionLayerGoogLeNet1, cl_googlenet) |
| 207 | ->Threads(1) |
| 208 | ->Apply(DataSetArgBatched<GoogLeNetConvolutionLayerDataset1, 25, 1, 4, 8>); |
| 209 | BENCHMARK_REGISTER_F(ConvolutionLayerGoogLeNet1, cl_googlenet) |
| 210 | ->Threads(1) |
| 211 | ->Apply(DataSetArgBatched<GoogLeNetConvolutionLayerDataset1, 26, 1, 4, 8>); |
| 212 | BENCHMARK_REGISTER_F(ConvolutionLayerGoogLeNet1, cl_googlenet) |
| 213 | ->Threads(1) |
| 214 | ->Apply(DataSetArgBatched<GoogLeNetConvolutionLayerDataset1, 27, 1, 4, 8>); |
| 215 | BENCHMARK_REGISTER_F(ConvolutionLayerGoogLeNet1, cl_googlenet) |
| 216 | ->Threads(1) |
| 217 | ->Apply(DataSetArgBatched<GoogLeNetConvolutionLayerDataset1, 28, 1, 4, 8>); |
| 218 | BENCHMARK_REGISTER_F(ConvolutionLayerGoogLeNet1, cl_googlenet) |
| 219 | ->Threads(1) |
| 220 | ->Apply(DataSetArgBatched<GoogLeNetConvolutionLayerDataset1, 29, 1, 4, 8>); |
| 221 | BENCHMARK_REGISTER_F(ConvolutionLayerGoogLeNet1, cl_googlenet) |
| 222 | ->Threads(1) |
| 223 | ->Apply(DataSetArgBatched<GoogLeNetConvolutionLayerDataset1, 30, 1, 4, 8>); |
| 224 | BENCHMARK_REGISTER_F(ConvolutionLayerGoogLeNet1, cl_googlenet) |
| 225 | ->Threads(1) |
| 226 | ->Apply(DataSetArgBatched<GoogLeNetConvolutionLayerDataset1, 31, 1, 4, 8>); |
| 227 | BENCHMARK_REGISTER_F(ConvolutionLayerGoogLeNet2, cl_googlenet) |
| 228 | ->Threads(1) |
| 229 | ->Apply(DataSetArgBatched<GoogLeNetConvolutionLayerDataset2, 0, 1, 4, 8>); |
| 230 | BENCHMARK_REGISTER_F(ConvolutionLayerGoogLeNet2, cl_googlenet) |
| 231 | ->Threads(1) |
| 232 | ->Apply(DataSetArgBatched<GoogLeNetConvolutionLayerDataset2, 1, 1, 4, 8>); |
| 233 | BENCHMARK_REGISTER_F(ConvolutionLayerGoogLeNet2, cl_googlenet) |
| 234 | ->Threads(1) |
| 235 | ->Apply(DataSetArgBatched<GoogLeNetConvolutionLayerDataset2, 2, 1, 4, 8>); |
| 236 | BENCHMARK_REGISTER_F(ConvolutionLayerGoogLeNet2, cl_googlenet) |
| 237 | ->Threads(1) |
| 238 | ->Apply(DataSetArgBatched<GoogLeNetConvolutionLayerDataset2, 3, 1, 4, 8>); |
| 239 | BENCHMARK_REGISTER_F(ConvolutionLayerGoogLeNet2, cl_googlenet) |
| 240 | ->Threads(1) |
| 241 | ->Apply(DataSetArgBatched<GoogLeNetConvolutionLayerDataset2, 4, 1, 4, 8>); |
| 242 | BENCHMARK_REGISTER_F(ConvolutionLayerGoogLeNet2, cl_googlenet) |
| 243 | ->Threads(1) |
| 244 | ->Apply(DataSetArgBatched<GoogLeNetConvolutionLayerDataset2, 5, 1, 4, 8>); |
| 245 | BENCHMARK_REGISTER_F(ConvolutionLayerGoogLeNet2, cl_googlenet) |
| 246 | ->Threads(1) |
| 247 | ->Apply(DataSetArgBatched<GoogLeNetConvolutionLayerDataset2, 6, 1, 4, 8>); |
| 248 | BENCHMARK_REGISTER_F(ConvolutionLayerGoogLeNet2, cl_googlenet) |
| 249 | ->Threads(1) |
| 250 | ->Apply(DataSetArgBatched<GoogLeNetConvolutionLayerDataset2, 7, 1, 4, 8>); |
| 251 | BENCHMARK_REGISTER_F(ConvolutionLayerGoogLeNet2, cl_googlenet) |
| 252 | ->Threads(1) |
| 253 | ->Apply(DataSetArgBatched<GoogLeNetConvolutionLayerDataset2, 8, 1, 4, 8>); |
| 254 | BENCHMARK_REGISTER_F(ConvolutionLayerGoogLeNet2, cl_googlenet) |
| 255 | ->Threads(1) |
| 256 | ->Apply(DataSetArgBatched<GoogLeNetConvolutionLayerDataset2, 9, 1, 4, 8>); |
| 257 | BENCHMARK_REGISTER_F(ConvolutionLayerGoogLeNet2, cl_googlenet) |
| 258 | ->Threads(1) |
| 259 | ->Apply(DataSetArgBatched<GoogLeNetConvolutionLayerDataset2, 10, 1, 4, 8>); |
| 260 | BENCHMARK_REGISTER_F(ConvolutionLayerGoogLeNet2, cl_googlenet) |
| 261 | ->Threads(1) |
| 262 | ->Apply(DataSetArgBatched<GoogLeNetConvolutionLayerDataset2, 11, 1, 4, 8>); |
| 263 | BENCHMARK_REGISTER_F(ConvolutionLayerGoogLeNet2, cl_googlenet) |
| 264 | ->Threads(1) |
| 265 | ->Apply(DataSetArgBatched<GoogLeNetConvolutionLayerDataset2, 12, 1, 4, 8>); |
| 266 | BENCHMARK_REGISTER_F(ConvolutionLayerGoogLeNet2, cl_googlenet) |
| 267 | ->Threads(1) |
| 268 | ->Apply(DataSetArgBatched<GoogLeNetConvolutionLayerDataset2, 13, 1, 4, 8>); |
| 269 | BENCHMARK_REGISTER_F(ConvolutionLayerGoogLeNet2, cl_googlenet) |
| 270 | ->Threads(1) |
| 271 | ->Apply(DataSetArgBatched<GoogLeNetConvolutionLayerDataset2, 14, 1, 4, 8>); |
| 272 | BENCHMARK_REGISTER_F(ConvolutionLayerGoogLeNet2, cl_googlenet) |
| 273 | ->Threads(1) |
| 274 | ->Apply(DataSetArgBatched<GoogLeNetConvolutionLayerDataset2, 15, 1, 4, 8>); |
| 275 | BENCHMARK_REGISTER_F(ConvolutionLayerGoogLeNet2, cl_googlenet) |
| 276 | ->Threads(1) |
| 277 | ->Apply(DataSetArgBatched<GoogLeNetConvolutionLayerDataset2, 16, 1, 4, 8>); |