• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
7 #include <algorithm>
8 #include <cmath>
9 #include <functional>
10 #include <numeric>
11 #include <vector>
12 
13 #include "bench/utils.h"
14 #include <benchmark/benchmark.h>
15 
16 #include <xnnpack.h>
17 #include <xnnpack/aligned-allocator.h>
18 #include <xnnpack/common.h>
19 #include <xnnpack/fft.h>
20 #include <xnnpack/microfnptr.h>
21 #include <xnnpack/microparams-init.h>
22 
23 
cs16_bfly4(benchmark::State & state,xnn_cs16_bfly4_ukernel_function bfly4,benchmark::utils::IsaCheckFunction isa_check=nullptr)24 void cs16_bfly4(
25     benchmark::State& state,
26     xnn_cs16_bfly4_ukernel_function bfly4,
27     benchmark::utils::IsaCheckFunction isa_check = nullptr)
28 {
29   if (isa_check && !isa_check(state)) {
30     return;
31   }
32   const size_t fft_size = state.range(0);
33   const size_t samples = state.range(1);
34   const size_t stride = state.range(2);
35 
36   assert(fft_size == samples * stride * 4);  // 4 for bfly4.
37 
38   std::vector<int16_t, AlignedAllocator<int16_t, 64>> output(
39       fft_size * 2 + XNN_EXTRA_BYTES / sizeof(int16_t));
40   std::vector<int16_t, AlignedAllocator<int16_t, 64>> twiddle(
41       fft_size * 2 + XNN_EXTRA_BYTES / sizeof(int16_t));
42 
43   std::iota(output.begin(), output.end(), 0);
44   std::iota(twiddle.begin(), twiddle.end(), 0);
45 
46   for (auto _ : state) {
47     bfly4(samples, output.data(), stride, twiddle.data());
48   }
49 
50   const uint64_t cpu_frequency = benchmark::utils::GetCurrentCpuFrequency();
51   if (cpu_frequency != 0) {
52     state.counters["cpufreq"] = cpu_frequency;
53   }
54 }
55 
BenchmarkKernelSize(benchmark::internal::Benchmark * b)56 static void BenchmarkKernelSize(benchmark::internal::Benchmark* b)
57 {
58   b->ArgNames({"fft_size", "samples", "stride"});
59   b->Args({256, 64, 1});
60   b->Args({256, 16, 4});
61   b->Args({256, 4, 16});
62   b->Args({256, 1, 64});
63   b->Args({1024, 256, 1});
64   b->Args({1024, 64,  4});
65   b->Args({1024, 16, 16});
66   b->Args({1024, 4,  64});
67   b->Args({1024, 1, 256});
68 }
69 
BenchmarkSamples1KernelSize(benchmark::internal::Benchmark * b)70 static void BenchmarkSamples1KernelSize(benchmark::internal::Benchmark* b)
71 {
72   b->ArgNames({"fft_size", "samples", "stride"});
73   b->Args({256, 1, 64});
74   b->Args({1024, 1, 256});
75 }
76 
77 #if XNN_ARCH_ARM || XNN_ARCH_ARM64
78 BENCHMARK_CAPTURE(cs16_bfly4, cs16_neon_m1, xnn_cs16_bfly4_samples1_ukernel__neon)->Apply(BenchmarkSamples1KernelSize)->UseRealTime();
79 #endif  // XNN_ARCH_ARM || XNN_ARCH_ARM64
80 
81 BENCHMARK_CAPTURE(cs16_bfly4, cs16_scalar_m1, xnn_cs16_bfly4_samples1_ukernel__scalar)->Apply(BenchmarkSamples1KernelSize)->UseRealTime();
82 BENCHMARK_CAPTURE(cs16_bfly4, cs16_scalar_x1, xnn_cs16_bfly4_ukernel__scalar_x1)->Apply(BenchmarkKernelSize)->UseRealTime();
83 BENCHMARK_CAPTURE(cs16_bfly4, cs16_scalar_x2, xnn_cs16_bfly4_ukernel__scalar_x2)->Apply(BenchmarkKernelSize)->UseRealTime();
84 BENCHMARK_CAPTURE(cs16_bfly4, cs16_scalar_x3, xnn_cs16_bfly4_ukernel__scalar_x3)->Apply(BenchmarkKernelSize)->UseRealTime();
85 BENCHMARK_CAPTURE(cs16_bfly4, cs16_scalar_x4, xnn_cs16_bfly4_ukernel__scalar_x4)->Apply(BenchmarkKernelSize)->UseRealTime();
86 
87 #ifndef XNNPACK_BENCHMARK_NO_MAIN
88 BENCHMARK_MAIN();
89 #endif
90