1 // Copyright 2022 Google LLC
2 //
3 // This source code is licensed under the BSD-style license found in the
4 // LICENSE file in the root directory of this source tree.
5
6 #include <algorithm>
7 #include <cmath>
8 #include <functional>
9 #include <numeric>
10 #include <vector>
11
12 #include "bench/utils.h"
13 #include <benchmark/benchmark.h>
14
15 #include <xnnpack.h>
16 #include <xnnpack/aligned-allocator.h>
17 #include <xnnpack/common.h>
18 #include <xnnpack/microfnptr.h>
19 #include <xnnpack/vlshift.h>
20
21
vlshift(benchmark::State & state,xnn_s16_vlshift_ukernel_function vlshift,benchmark::utils::IsaCheckFunction isa_check=nullptr)22 void vlshift(
23 benchmark::State& state,
24 xnn_s16_vlshift_ukernel_function vlshift,
25 benchmark::utils::IsaCheckFunction isa_check = nullptr)
26 {
27 if (isa_check && !isa_check(state)) {
28 return;
29 }
30 const size_t batch = state.range(0);
31
32 std::vector<int16_t, AlignedAllocator<int16_t, 64>> input(
33 batch + XNN_EXTRA_BYTES / sizeof(int16_t));
34 std::vector<int16_t, AlignedAllocator<int16_t, 64>> output(batch);
35 std::iota(input.begin(), input.end(), 0);
36 std::iota(output.begin(), output.end(), 1);
37
38 for (auto _ : state) {
39 vlshift(batch, input.data(), output.data(), 4 /* shift */);
40 }
41
42 const uint64_t cpu_frequency = benchmark::utils::GetCurrentCpuFrequency();
43 if (cpu_frequency != 0) {
44 state.counters["cpufreq"] = cpu_frequency;
45 }
46 }
47
BenchmarkKernelSize(benchmark::internal::Benchmark * b)48 static void BenchmarkKernelSize(benchmark::internal::Benchmark* b)
49 {
50 b->ArgNames({"batch"});
51 b->Args({32});
52 b->Args({64});
53 b->Args({117});
54 b->Args({400});
55 b->Args({1000});
56 b->Args({10000});
57 }
58
59 #if XNN_ARCH_ARM || XNN_ARCH_ARM64
60 BENCHMARK_CAPTURE(vlshift, s16_neon_x8, xnn_s16_vlshift_ukernel__neon_x8)
61 ->Apply(BenchmarkKernelSize)->UseRealTime();
62 BENCHMARK_CAPTURE(vlshift, s16_neon_x16, xnn_s16_vlshift_ukernel__neon_x16)
63 ->Apply(BenchmarkKernelSize)->UseRealTime();
64 BENCHMARK_CAPTURE(vlshift, s16_neon_x24, xnn_s16_vlshift_ukernel__neon_x24)
65 ->Apply(BenchmarkKernelSize)->UseRealTime();
66 BENCHMARK_CAPTURE(vlshift, s16_neon_x32, xnn_s16_vlshift_ukernel__neon_x32)
67 ->Apply(BenchmarkKernelSize)->UseRealTime();
68 #endif // XNN_ARCH_ARM || XNN_ARCH_ARM64
69
70 BENCHMARK_CAPTURE(vlshift, s16_scalar_x1, xnn_s16_vlshift_ukernel__scalar_x1)
71 ->Apply(BenchmarkKernelSize)->UseRealTime();
72 BENCHMARK_CAPTURE(vlshift, s16_scalar_x2, xnn_s16_vlshift_ukernel__scalar_x2)
73 ->Apply(BenchmarkKernelSize)->UseRealTime();
74 BENCHMARK_CAPTURE(vlshift, s16_scalar_x3, xnn_s16_vlshift_ukernel__scalar_x3)
75 ->Apply(BenchmarkKernelSize)->UseRealTime();
76 BENCHMARK_CAPTURE(vlshift, s16_scalar_x4, xnn_s16_vlshift_ukernel__scalar_x4)
77 ->Apply(BenchmarkKernelSize)->UseRealTime();
78
79 #ifndef XNNPACK_BENCHMARK_NO_MAIN
80 BENCHMARK_MAIN();
81 #endif
82