Marat Dukhan | 4c4eb00 | 2019-12-08 21:27:49 -0800 | [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 | |
| 12 | #include <benchmark/benchmark.h> |
| 13 | #include "bench/utils.h" |
| 14 | #include <xnnpack/AlignedAllocator.h> |
| 15 | #include <xnnpack/common.h> |
| 16 | #include <xnnpack/params.h> |
| 17 | #include <xnnpack/raddextexp.h> |
| 18 | |
| 19 | |
| 20 | static void f32_raddextexp( |
| 21 | benchmark::State& state, |
| 22 | xnn_f32_raddextexp_ukernel_function raddextexp, |
| 23 | benchmark::utils::IsaCheckFunction isa_check = nullptr) |
| 24 | { |
| 25 | if (isa_check && !isa_check(state)) { |
| 26 | return; |
| 27 | } |
| 28 | |
| 29 | const size_t n = state.range(0); |
| 30 | const size_t cache_line_size_max = 128; |
| 31 | const size_t packed_n = benchmark::utils::RoundUp(n, cache_line_size_max / sizeof(float)); |
| 32 | |
| 33 | std::random_device random_device; |
| 34 | auto rng = std::mt19937(random_device()); |
Marat Dukhan | 44f0ca7 | 2020-08-02 21:46:58 -0700 | [diff] [blame] | 35 | auto f32rng = std::bind(std::uniform_real_distribution<float>(-1000.0f, 1000.0f), std::ref(rng)); |
Marat Dukhan | 4c4eb00 | 2019-12-08 21:27:49 -0800 | [diff] [blame] | 36 | |
| 37 | const size_t num_buffers = 1 + |
| 38 | benchmark::utils::DivideRoundUp<size_t>(benchmark::utils::GetMaxCacheSize(), packed_n * sizeof(float)); |
| 39 | std::vector<float, AlignedAllocator<float, 64>> x(n); |
| 40 | |
| 41 | std::generate(x.begin(), x.end(), std::ref(f32rng)); |
| 42 | |
| 43 | benchmark::utils::DisableDenormals(); |
| 44 | |
| 45 | size_t buffer_index = 0; |
| 46 | for (auto _ : state) { |
| 47 | if (++buffer_index == num_buffers) { |
| 48 | buffer_index = 0; |
| 49 | } |
| 50 | |
| 51 | float y_sum[2] = { nanf(""), nanf("") }; |
| 52 | raddextexp(n * sizeof(float), x.data(), y_sum); |
| 53 | } |
| 54 | |
| 55 | state.counters["Freq"] = benchmark::utils::GetCurrentCpuFrequency(); |
| 56 | state.counters["elements"] = |
| 57 | benchmark::Counter(uint64_t(state.iterations()) * n, benchmark::Counter::kIsRate); |
| 58 | state.counters["bytes"] = |
| 59 | benchmark::Counter(uint64_t(state.iterations()) * sizeof(float) * n, benchmark::Counter::kIsRate); |
| 60 | } |
| 61 | |
| 62 | static void CharacteristicArguments(benchmark::internal::Benchmark* b) { |
| 63 | b->ArgName("N"); |
| 64 | for (int32_t n = 10000; n <= 100000000; n *= 10) { |
| 65 | b->Arg(n); |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | #if XNN_ARCH_X86 || XNN_ARCH_X86_64 |
| 70 | BENCHMARK_CAPTURE(f32_raddextexp, avx512f_p5_scalef_x128, |
| 71 | xnn_f32_raddextexp_ukernel__avx512f_p5_scalef_x128, |
| 72 | benchmark::utils::CheckAVX512F)->Apply(CharacteristicArguments)->UseRealTime(); |
| 73 | BENCHMARK_CAPTURE(f32_raddextexp, avx512f_p5_scalef_x128_acc2, |
| 74 | xnn_f32_raddextexp_ukernel__avx512f_p5_scalef_x128_acc2, |
| 75 | benchmark::utils::CheckAVX512F)->Apply(CharacteristicArguments)->UseRealTime(); |
| 76 | BENCHMARK_CAPTURE(f32_raddextexp, avx512f_p5_scalef_x128_acc4, |
| 77 | xnn_f32_raddextexp_ukernel__avx512f_p5_scalef_x128_acc4, |
| 78 | benchmark::utils::CheckAVX512F)->Apply(CharacteristicArguments)->UseRealTime(); |
| 79 | |
| 80 | BENCHMARK_CAPTURE(f32_raddextexp, avx512f_p5_scalef_x144, |
| 81 | xnn_f32_raddextexp_ukernel__avx512f_p5_scalef_x144, |
| 82 | benchmark::utils::CheckAVX512F)->Apply(CharacteristicArguments)->UseRealTime(); |
| 83 | BENCHMARK_CAPTURE(f32_raddextexp, avx512f_p5_scalef_x144_acc3, |
| 84 | xnn_f32_raddextexp_ukernel__avx512f_p5_scalef_x144_acc3, |
| 85 | benchmark::utils::CheckAVX512F)->Apply(CharacteristicArguments)->UseRealTime(); |
| 86 | |
| 87 | BENCHMARK_CAPTURE(f32_raddextexp, avx512f_p5_scalef_x160, |
| 88 | xnn_f32_raddextexp_ukernel__avx512f_p5_scalef_x160, |
| 89 | benchmark::utils::CheckAVX512F)->Apply(CharacteristicArguments)->UseRealTime(); |
| 90 | BENCHMARK_CAPTURE(f32_raddextexp, avx512f_p5_scalef_x160_acc2, |
| 91 | xnn_f32_raddextexp_ukernel__avx512f_p5_scalef_x160_acc2, |
| 92 | benchmark::utils::CheckAVX512F)->Apply(CharacteristicArguments)->UseRealTime(); |
| 93 | BENCHMARK_CAPTURE(f32_raddextexp, avx512f_p5_scalef_x160_acc5, |
| 94 | xnn_f32_raddextexp_ukernel__avx512f_p5_scalef_x160_acc5, |
| 95 | benchmark::utils::CheckAVX512F)->Apply(CharacteristicArguments)->UseRealTime(); |
| 96 | |
| 97 | BENCHMARK_CAPTURE(f32_raddextexp, avx512f_p5_scalef_x192, |
| 98 | xnn_f32_raddextexp_ukernel__avx512f_p5_scalef_x192, |
| 99 | benchmark::utils::CheckAVX512F)->Apply(CharacteristicArguments)->UseRealTime(); |
| 100 | BENCHMARK_CAPTURE(f32_raddextexp, avx512f_p5_scalef_x192_acc2, |
| 101 | xnn_f32_raddextexp_ukernel__avx512f_p5_scalef_x192_acc2, |
| 102 | benchmark::utils::CheckAVX512F)->Apply(CharacteristicArguments)->UseRealTime(); |
| 103 | BENCHMARK_CAPTURE(f32_raddextexp, avx512f_p5_scalef_x192_acc3, |
| 104 | xnn_f32_raddextexp_ukernel__avx512f_p5_scalef_x192_acc3, |
| 105 | benchmark::utils::CheckAVX512F)->Apply(CharacteristicArguments)->UseRealTime(); |
| 106 | BENCHMARK_CAPTURE(f32_raddextexp, avx512f_p5_scalef_x192_acc6, |
| 107 | xnn_f32_raddextexp_ukernel__avx512f_p5_scalef_x192_acc6, |
| 108 | benchmark::utils::CheckAVX512F)->Apply(CharacteristicArguments)->UseRealTime(); |
| 109 | |
| 110 | BENCHMARK_CAPTURE(f32_raddextexp, avx2_p5_x64, |
| 111 | xnn_f32_raddextexp_ukernel__avx2_p5_x64, |
| 112 | benchmark::utils::CheckAVX2)->Apply(CharacteristicArguments)->UseRealTime(); |
| 113 | BENCHMARK_CAPTURE(f32_raddextexp, avx2_p5_x64_acc2, |
| 114 | xnn_f32_raddextexp_ukernel__avx2_p5_x64_acc2, |
| 115 | benchmark::utils::CheckAVX2)->Apply(CharacteristicArguments)->UseRealTime(); |
| 116 | BENCHMARK_CAPTURE(f32_raddextexp, avx2_p5_x64_acc4, |
| 117 | xnn_f32_raddextexp_ukernel__avx2_p5_x64_acc4, |
| 118 | benchmark::utils::CheckAVX2)->Apply(CharacteristicArguments)->UseRealTime(); |
| 119 | |
| 120 | BENCHMARK_CAPTURE(f32_raddextexp, avx2_p5_x72, |
| 121 | xnn_f32_raddextexp_ukernel__avx2_p5_x72, |
| 122 | benchmark::utils::CheckAVX2)->Apply(CharacteristicArguments)->UseRealTime(); |
| 123 | BENCHMARK_CAPTURE(f32_raddextexp, avx2_p5_x72_acc3, |
| 124 | xnn_f32_raddextexp_ukernel__avx2_p5_x72_acc3, |
| 125 | benchmark::utils::CheckAVX2)->Apply(CharacteristicArguments)->UseRealTime(); |
| 126 | |
| 127 | BENCHMARK_CAPTURE(f32_raddextexp, avx2_p5_x80, |
| 128 | xnn_f32_raddextexp_ukernel__avx2_p5_x80, |
| 129 | benchmark::utils::CheckAVX2)->Apply(CharacteristicArguments)->UseRealTime(); |
| 130 | BENCHMARK_CAPTURE(f32_raddextexp, avx2_p5_x80_acc2, |
| 131 | xnn_f32_raddextexp_ukernel__avx2_p5_x80_acc2, |
| 132 | benchmark::utils::CheckAVX2)->Apply(CharacteristicArguments)->UseRealTime(); |
| 133 | BENCHMARK_CAPTURE(f32_raddextexp, avx2_p5_x80_acc5, |
| 134 | xnn_f32_raddextexp_ukernel__avx2_p5_x80_acc5, |
| 135 | benchmark::utils::CheckAVX2)->Apply(CharacteristicArguments)->UseRealTime(); |
| 136 | |
| 137 | BENCHMARK_CAPTURE(f32_raddextexp, avx2_p5_x96, |
| 138 | xnn_f32_raddextexp_ukernel__avx2_p5_x96, |
| 139 | benchmark::utils::CheckAVX2)->Apply(CharacteristicArguments)->UseRealTime(); |
| 140 | BENCHMARK_CAPTURE(f32_raddextexp, avx2_p5_x96_acc2, |
| 141 | xnn_f32_raddextexp_ukernel__avx2_p5_x96_acc2, |
| 142 | benchmark::utils::CheckAVX2)->Apply(CharacteristicArguments)->UseRealTime(); |
| 143 | BENCHMARK_CAPTURE(f32_raddextexp, avx2_p5_x96_acc3, |
| 144 | xnn_f32_raddextexp_ukernel__avx2_p5_x96_acc3, |
| 145 | benchmark::utils::CheckAVX2)->Apply(CharacteristicArguments)->UseRealTime(); |
| 146 | BENCHMARK_CAPTURE(f32_raddextexp, avx2_p5_x96_acc6, |
| 147 | xnn_f32_raddextexp_ukernel__avx2_p5_x96_acc6, |
| 148 | benchmark::utils::CheckAVX2)->Apply(CharacteristicArguments)->UseRealTime(); |
| 149 | #endif // XNN_ARCH_X86 || XNN_ARCH_X86_64 |
| 150 | |
| 151 | #ifndef XNNPACK_BENCHMARK_NO_MAIN |
| 152 | BENCHMARK_MAIN(); |
| 153 | #endif |