File size: 7,938 Bytes
8b7c501 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
// Copyright 2019 Google LLC
//
// This source code is licensed under the BSD-style license found in the
// LICENSE file in the root directory of this source tree.
#include <algorithm>
#include <cmath>
#include <functional>
#include <memory>
#include <random>
#include <vector>
#include <benchmark/benchmark.h>
#include "bench/utils.h"
#include <xnnpack.h>
#include <xnnpack/models.h>
static void End2EndBenchmark(
benchmark::State& state,
models::ExecutionPlanFactory model_factory)
{
if (xnn_initialize(nullptr /* allocator */) != xnn_status_success) {
state.SkipWithError("failed to initialize XNNPACK");
return;
}
const size_t num_threads = state.range(0);
std::unique_ptr<pthreadpool, decltype(&pthreadpool_destroy)> threadpool(
pthreadpool_create(num_threads), pthreadpool_destroy);
auto execution_plan = model_factory(threadpool.get());
if (execution_plan.empty()) {
state.SkipWithError("failed to create a model");
return;
}
for (auto _ : state) {
for (const std::unique_ptr<xnn_operator, decltype(&xnn_delete_operator)>& op : execution_plan) {
xnn_status status = xnn_run_operator(op.get(), threadpool.get());
if (status != xnn_status_success) {
state.SkipWithError("failed to run a model");
return;
}
}
}
const uint64_t cpu_frequency = benchmark::utils::GetCurrentCpuFrequency();
if (cpu_frequency != 0) {
state.counters["cpufreq"] = cpu_frequency;
}
}
static void FP32MobileNetV1(benchmark::State& state) {
End2EndBenchmark(state, models::FP32MobileNetV1);
}
static void FP32MobileNetV2(benchmark::State& state) {
End2EndBenchmark(state, models::FP32MobileNetV2);
}
static void FP32MobileNetV3Large(benchmark::State& state) {
End2EndBenchmark(state, models::FP32MobileNetV3Large);
}
static void FP32MobileNetV3Small(benchmark::State& state) {
End2EndBenchmark(state, models::FP32MobileNetV3Small);
}
#if XNN_PLATFORM_JIT && XNN_ENABLE_JIT
static void FP32MobileNetV3SmallFused(benchmark::State& state) {
End2EndBenchmark(state, models::FP32MobileNetV3SmallFused);
}
#endif // XNN_PLATFORM_JIT && XNN_ENABLE_JIT
static void FP32Sparse80MobileNetV1(benchmark::State& state) {
End2EndBenchmark(state, [](pthreadpool_t threadpool) {
return models::FP32SparseMobileNetV1(0.8f, threadpool);
});
}
static void FP32Sparse80MobileNetV2(benchmark::State& state) {
End2EndBenchmark(state, [](pthreadpool_t threadpool) {
return models::FP32SparseMobileNetV2(0.8f, threadpool);
});
}
static void FP32Sparse80MobileNetV3Large(benchmark::State& state) {
End2EndBenchmark(state, [](pthreadpool_t threadpool) {
return models::FP32SparseMobileNetV3Large(0.8f, threadpool);
});
}
static void FP32Sparse80MobileNetV3Small(benchmark::State& state) {
End2EndBenchmark(state, [](pthreadpool_t threadpool) {
return models::FP32SparseMobileNetV3Small(0.8f, threadpool);
});
}
static void FP16MobileNetV1(benchmark::State& state) {
End2EndBenchmark(state, models::FP16MobileNetV1);
}
static void FP16MobileNetV2(benchmark::State& state) {
End2EndBenchmark(state, models::FP16MobileNetV2);
}
static void FP16MobileNetV3Large(benchmark::State& state) {
End2EndBenchmark(state, models::FP16MobileNetV3Large);
}
static void FP16MobileNetV3Small(benchmark::State& state) {
End2EndBenchmark(state, models::FP16MobileNetV3Small);
}
static void FP16Sparse80MobileNetV1(benchmark::State& state) {
End2EndBenchmark(state, [](pthreadpool_t threadpool) {
return models::FP16SparseMobileNetV1(0.8f, threadpool);
});
}
static void FP16Sparse80MobileNetV2(benchmark::State& state) {
End2EndBenchmark(state, [](pthreadpool_t threadpool) {
return models::FP16SparseMobileNetV2(0.8f, threadpool);
});
}
static void FP16Sparse80MobileNetV3Large(benchmark::State& state) {
End2EndBenchmark(state, [](pthreadpool_t threadpool) {
return models::FP16SparseMobileNetV3Large(0.8f, threadpool);
});
}
static void FP16Sparse80MobileNetV3Small(benchmark::State& state) {
End2EndBenchmark(state, [](pthreadpool_t threadpool) {
return models::FP16SparseMobileNetV3Small(0.8f, threadpool);
});
}
static void QC8MobileNetV1(benchmark::State& state) {
End2EndBenchmark(state, models::QC8MobileNetV1);
}
static void QC8MobileNetV2(benchmark::State& state) {
End2EndBenchmark(state, models::QC8MobileNetV2);
}
static void QS8MobileNetV1(benchmark::State& state) {
End2EndBenchmark(state, models::QS8MobileNetV1);
}
static void QS8MobileNetV2(benchmark::State& state) {
End2EndBenchmark(state, models::QS8MobileNetV2);
}
static void QU8MobileNetV1(benchmark::State& state) {
End2EndBenchmark(state, models::QU8MobileNetV1);
}
static void QU8MobileNetV2(benchmark::State& state) {
End2EndBenchmark(state, models::QU8MobileNetV2);
}
BENCHMARK(FP32MobileNetV1)->Apply(benchmark::utils::MultiThreadingParameters)->Unit(benchmark::kMicrosecond)->UseRealTime();
BENCHMARK(FP32MobileNetV2)->Apply(benchmark::utils::MultiThreadingParameters)->Unit(benchmark::kMicrosecond)->UseRealTime();
BENCHMARK(FP32MobileNetV3Large)->Apply(benchmark::utils::MultiThreadingParameters)->Unit(benchmark::kMicrosecond)->UseRealTime();
BENCHMARK(FP32MobileNetV3Small)->Apply(benchmark::utils::MultiThreadingParameters)->Unit(benchmark::kMicrosecond)->UseRealTime();
BENCHMARK(FP32Sparse80MobileNetV1)->Apply(benchmark::utils::MultiThreadingParameters)->Unit(benchmark::kMicrosecond)->UseRealTime();
BENCHMARK(FP32Sparse80MobileNetV2)->Apply(benchmark::utils::MultiThreadingParameters)->Unit(benchmark::kMicrosecond)->UseRealTime();
BENCHMARK(FP32Sparse80MobileNetV3Large)->Apply(benchmark::utils::MultiThreadingParameters)->Unit(benchmark::kMicrosecond)->UseRealTime();
BENCHMARK(FP32Sparse80MobileNetV3Small)->Apply(benchmark::utils::MultiThreadingParameters)->Unit(benchmark::kMicrosecond)->UseRealTime();
BENCHMARK(FP16MobileNetV1)->Apply(benchmark::utils::MultiThreadingParameters)->Unit(benchmark::kMicrosecond)->UseRealTime();
BENCHMARK(FP16MobileNetV2)->Apply(benchmark::utils::MultiThreadingParameters)->Unit(benchmark::kMicrosecond)->UseRealTime();
BENCHMARK(FP16MobileNetV3Large)->Apply(benchmark::utils::MultiThreadingParameters)->Unit(benchmark::kMicrosecond)->UseRealTime();
BENCHMARK(FP16MobileNetV3Small)->Apply(benchmark::utils::MultiThreadingParameters)->Unit(benchmark::kMicrosecond)->UseRealTime();
BENCHMARK(FP16Sparse80MobileNetV1)->Apply(benchmark::utils::MultiThreadingParameters)->Unit(benchmark::kMicrosecond)->UseRealTime();
BENCHMARK(FP16Sparse80MobileNetV2)->Apply(benchmark::utils::MultiThreadingParameters)->Unit(benchmark::kMicrosecond)->UseRealTime();
BENCHMARK(FP16Sparse80MobileNetV3Large)->Apply(benchmark::utils::MultiThreadingParameters)->Unit(benchmark::kMicrosecond)->UseRealTime();
BENCHMARK(FP16Sparse80MobileNetV3Small)->Apply(benchmark::utils::MultiThreadingParameters)->Unit(benchmark::kMicrosecond)->UseRealTime();
BENCHMARK(QC8MobileNetV1)->Apply(benchmark::utils::MultiThreadingParameters)->Unit(benchmark::kMicrosecond)->UseRealTime();
BENCHMARK(QC8MobileNetV2)->Apply(benchmark::utils::MultiThreadingParameters)->Unit(benchmark::kMicrosecond)->UseRealTime();
BENCHMARK(QS8MobileNetV1)->Apply(benchmark::utils::MultiThreadingParameters)->Unit(benchmark::kMicrosecond)->UseRealTime();
BENCHMARK(QS8MobileNetV2)->Apply(benchmark::utils::MultiThreadingParameters)->Unit(benchmark::kMicrosecond)->UseRealTime();
BENCHMARK(QU8MobileNetV1)->Apply(benchmark::utils::MultiThreadingParameters)->Unit(benchmark::kMicrosecond)->UseRealTime();
BENCHMARK(QU8MobileNetV2)->Apply(benchmark::utils::MultiThreadingParameters)->Unit(benchmark::kMicrosecond)->UseRealTime();
#if XNN_PLATFORM_JIT && XNN_ENABLE_JIT
BENCHMARK(FP32MobileNetV3SmallFused)->Apply(benchmark::utils::MultiThreadingParameters)->Unit(benchmark::kMicrosecond)->UseRealTime();
#endif // XNN_PLATFORM_JIT && XNN_ENABLE_JIT
#ifndef XNNPACK_BENCHMARK_NO_MAIN
BENCHMARK_MAIN();
#endif
|