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/filterbank.h>
19 #include <xnnpack/microfnptr.h>
20
21
filterbank_subtract(benchmark::State & state,xnn_u32_filterbank_subtract_ukernel_function filterbank_subtract,benchmark::utils::IsaCheckFunction isa_check=nullptr)22 void filterbank_subtract(
23 benchmark::State& state,
24 xnn_u32_filterbank_subtract_ukernel_function filterbank_subtract,
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<uint32_t, AlignedAllocator<uint32_t, 64>> input(batch + XNN_EXTRA_BYTES / sizeof(uint32_t));
33 std::vector<uint32_t, AlignedAllocator<uint32_t, 64>> noise_estimate(batch + XNN_EXTRA_BYTES / sizeof(uint32_t));
34 std::vector<uint32_t, AlignedAllocator<uint32_t, 64>> output(batch);
35 std::iota(input.begin(), input.end(), 0);
36 std::iota(noise_estimate.begin(), noise_estimate.end(), 1);
37 std::iota(output.begin(), output.end(), 0);
38
39 for (auto _ : state) {
40 filterbank_subtract(batch, input.data(),
41 655, 655, 15729, 15729, 819, 0, 14,
42 noise_estimate.data(), output.data());
43 }
44
45 const uint64_t cpu_frequency = benchmark::utils::GetCurrentCpuFrequency();
46 if (cpu_frequency != 0) {
47 state.counters["cpufreq"] = cpu_frequency;
48 }
49 }
50
BenchmarkKernelSize(benchmark::internal::Benchmark * b)51 static void BenchmarkKernelSize(benchmark::internal::Benchmark* b)
52 {
53 b->ArgNames({"batch"});
54 b->Args({48});
55 b->Args({480});
56 b->Args({1000});
57 b->Args({10000});
58 b->Args({48000});
59 }
60
61 BENCHMARK_CAPTURE(filterbank_subtract, u32_scalar_x1, xnn_u32_filterbank_subtract_ukernel__scalar_x2)->Apply(BenchmarkKernelSize)->UseRealTime();
62
63 #ifndef XNNPACK_BENCHMARK_NO_MAIN
64 BENCHMARK_MAIN();
65 #endif
66