XNNPACK Team | b455b12 | 2019-09-27 18:10:33 -0700 | [diff] [blame] | 1 | // Copyright 2019 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 <random> |
| 10 | #include <vector> |
| 11 | |
XNNPACK Team | b455b12 | 2019-09-27 18:10:33 -0700 | [diff] [blame] | 12 | #include <benchmark/benchmark.h> |
Frank Barchard | bb4c18b | 2019-09-30 11:05:52 -0700 | [diff] [blame] | 13 | #include "bench/utils.h" |
XNNPACK Team | b455b12 | 2019-09-27 18:10:33 -0700 | [diff] [blame] | 14 | #include <xnnpack/AlignedAllocator.h> |
Marat Dukhan | 1dadbf7 | 2019-10-01 10:46:20 -0700 | [diff] [blame] | 15 | #include <xnnpack/common.h> |
XNNPACK Team | b455b12 | 2019-09-27 18:10:33 -0700 | [diff] [blame] | 16 | #include <xnnpack/params.h> |
| 17 | #include <xnnpack/rmax.h> |
| 18 | |
| 19 | |
| 20 | static void f32_rmax( |
| 21 | benchmark::State& state, |
| 22 | xnn_f32_rmax_ukernel_function f32_rmax) |
| 23 | { |
| 24 | const size_t n = state.range(0); |
| 25 | |
| 26 | std::random_device random_device; |
| 27 | auto rng = std::mt19937(random_device()); |
Marat Dukhan | 44f0ca7 | 2020-08-02 21:46:58 -0700 | [diff] [blame] | 28 | auto f32rng = std::bind(std::uniform_real_distribution<float>(-10.0f, 10.0f), std::ref(rng)); |
XNNPACK Team | b455b12 | 2019-09-27 18:10:33 -0700 | [diff] [blame] | 29 | |
| 30 | std::vector<float, AlignedAllocator<float, 64>> x(n); |
| 31 | std::generate(x.begin(), x.end(), std::ref(f32rng)); |
| 32 | |
| 33 | float y; |
| 34 | for (auto _ : state) { |
| 35 | f32_rmax(n * sizeof(float), x.data(), &y); |
| 36 | } |
| 37 | |
Frank Barchard | bb4c18b | 2019-09-30 11:05:52 -0700 | [diff] [blame] | 38 | state.counters["Freq"] = benchmark::utils::GetCurrentCpuFrequency(); |
| 39 | |
| 40 | state.counters["elements"] = |
XNNPACK Team | b455b12 | 2019-09-27 18:10:33 -0700 | [diff] [blame] | 41 | benchmark::Counter(uint64_t(state.iterations()) * n, benchmark::Counter::kIsRate); |
| 42 | |
| 43 | state.counters["bytes"] = |
| 44 | benchmark::Counter(uint64_t(state.iterations()) * n * sizeof(float), benchmark::Counter::kIsRate); |
| 45 | } |
| 46 | |
Marat Dukhan | 1dadbf7 | 2019-10-01 10:46:20 -0700 | [diff] [blame] | 47 | #if XNN_ARCH_X86 || XNN_ARCH_X86_64 |
XNNPACK Team | b455b12 | 2019-09-27 18:10:33 -0700 | [diff] [blame] | 48 | BENCHMARK_CAPTURE(f32_rmax, sse, xnn_f32_rmax_ukernel__sse) |
| 49 | ->RangeMultiplier(10) |
| 50 | ->Range(1000, 100000000) |
| 51 | ->UseRealTime(); |
| 52 | |
| 53 | BENCHMARK_CAPTURE(f32_rmax, avx, xnn_f32_rmax_ukernel__avx) |
| 54 | ->RangeMultiplier(10) |
| 55 | ->Range(1000, 100000000) |
| 56 | ->UseRealTime(); |
| 57 | |
| 58 | BENCHMARK_CAPTURE(f32_rmax, avx512f, xnn_f32_rmax_ukernel__avx512f) |
| 59 | ->RangeMultiplier(10) |
| 60 | ->Range(1000, 100000000) |
| 61 | ->UseRealTime(); |
Marat Dukhan | 1dadbf7 | 2019-10-01 10:46:20 -0700 | [diff] [blame] | 62 | #endif // XNN_ARCH_X86 || XNN_ARCH_X86_64 |
XNNPACK Team | b455b12 | 2019-09-27 18:10:33 -0700 | [diff] [blame] | 63 | |
Marat Dukhan | 1dadbf7 | 2019-10-01 10:46:20 -0700 | [diff] [blame] | 64 | #if XNN_ARCH_ARM || XNN_ARCH_ARM64 |
XNNPACK Team | b455b12 | 2019-09-27 18:10:33 -0700 | [diff] [blame] | 65 | BENCHMARK_CAPTURE(f32_rmax, neon, xnn_f32_rmax_ukernel__neon) |
| 66 | ->RangeMultiplier(10) |
| 67 | ->Range(1000, 100000000) |
| 68 | ->UseRealTime(); |
Marat Dukhan | 1dadbf7 | 2019-10-01 10:46:20 -0700 | [diff] [blame] | 69 | #endif // XNN_ARCH_ARM || XNN_ARCH_ARM64 |
Marat Dukhan | 8c41796 | 2020-07-08 12:27:50 -0700 | [diff] [blame] | 70 | |
| 71 | #if XNN_ARCH_WASMSIMD |
| 72 | BENCHMARK_CAPTURE(f32_rmax, wasmsimd_arm, xnn_f32_rmax_ukernel__wasmsimd_arm) |
| 73 | ->RangeMultiplier(10) |
| 74 | ->Range(1000, 100000000) |
| 75 | ->UseRealTime(); |
| 76 | |
| 77 | BENCHMARK_CAPTURE(f32_rmax, wasmsimd_x86, xnn_f32_rmax_ukernel__wasmsimd_x86) |
| 78 | ->RangeMultiplier(10) |
| 79 | ->Range(1000, 100000000) |
| 80 | ->UseRealTime(); |
| 81 | #endif // XNN_ARCH_WASMSIMD |
| 82 | |
XNNPACK Team | b455b12 | 2019-09-27 18:10:33 -0700 | [diff] [blame] | 83 | BENCHMARK_CAPTURE(f32_rmax, scalar, xnn_f32_rmax_ukernel__scalar) |
| 84 | ->RangeMultiplier(10) |
| 85 | ->Range(1000, 100000000) |
| 86 | ->UseRealTime(); |
| 87 | |
| 88 | #ifndef XNNPACK_BENCHMARK_NO_MAIN |
| 89 | BENCHMARK_MAIN(); |
| 90 | #endif |