Alan Kelly | a1cad4a | 2022-01-25 13:02:20 -0800 | [diff] [blame] | 1 | // Copyright 2021 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 <xnnpack/AlignedAllocator.h> |
| 7 | #include <xnnpack/common.h> |
| 8 | #include <xnnpack/params.h> |
| 9 | #include <xnnpack/transpose.h> |
| 10 | |
| 11 | #include <algorithm> |
| 12 | #include <cmath> |
| 13 | #include <functional> |
| 14 | #include <numeric> |
| 15 | #include <vector> |
| 16 | |
| 17 | #include "bench/utils.h" |
| 18 | #include <benchmark/benchmark.h> |
| 19 | |
| 20 | void transpose( |
| 21 | benchmark::State& state, |
| 22 | xnn_x8_transpose_ukernel_function transpose, |
| 23 | benchmark::utils::IsaCheckFunction isa_check = nullptr) |
| 24 | { |
| 25 | if (isa_check && !isa_check(state)) { |
| 26 | return; |
| 27 | } |
| 28 | const size_t height = state.range(0); |
| 29 | const size_t width = state.range(1); |
| 30 | const size_t tile_hbytes = height * sizeof(uint8_t); |
| 31 | const size_t tile_wbytes = width * sizeof(uint8_t); |
| 32 | |
| 33 | std::vector<uint8_t, AlignedAllocator<uint8_t, 64>> x( |
| 34 | height * width + XNN_EXTRA_BYTES / sizeof(uint8_t)); |
| 35 | std::vector<uint8_t, AlignedAllocator<uint8_t, 64>> y( |
| 36 | height * width + XNN_EXTRA_BYTES / sizeof(uint8_t)); |
| 37 | std::iota(x.begin(), x.end(), 0); |
| 38 | std::fill(y.begin(), y.end(), 0); |
| 39 | |
| 40 | for (auto _ : state) { |
| 41 | transpose(x.data(), y.data(), tile_wbytes, tile_hbytes, width, |
| 42 | height); |
| 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 | |
| 51 | static void BenchmarkKernelSize(benchmark::internal::Benchmark* b) |
| 52 | { |
| 53 | b->ArgNames({"height", "width"}); |
| 54 | b->Args({32, 32}); |
| 55 | b->Args({64, 64}); |
| 56 | b->Args({117, 117}); |
| 57 | b->Args({1024, 1024}); |
| 58 | } |
| 59 | |
| 60 | BENCHMARK_CAPTURE(transpose, 1x2_scalar_int, xnn_x8_transpose_ukernel__1x2_scalar_int) |
| 61 | ->Apply(BenchmarkKernelSize)->UseRealTime(); |
| 62 | BENCHMARK_CAPTURE(transpose, 1x4_scalar_int, xnn_x8_transpose_ukernel__1x4_scalar_int) |
| 63 | ->Apply(BenchmarkKernelSize)->UseRealTime(); |
| 64 | BENCHMARK_CAPTURE(transpose, 2x1_scalar_int, xnn_x8_transpose_ukernel__2x1_scalar_int) |
| 65 | ->Apply(BenchmarkKernelSize)->UseRealTime(); |
| 66 | BENCHMARK_CAPTURE(transpose, 2x2_scalar_int, xnn_x8_transpose_ukernel__2x2_scalar_int) |
| 67 | ->Apply(BenchmarkKernelSize)->UseRealTime(); |
| 68 | BENCHMARK_CAPTURE(transpose, 2x4_scalar_int, xnn_x8_transpose_ukernel__2x4_scalar_int) |
| 69 | ->Apply(BenchmarkKernelSize)->UseRealTime(); |
| 70 | BENCHMARK_CAPTURE(transpose, 4x1_scalar_int, xnn_x8_transpose_ukernel__4x1_scalar_int) |
| 71 | ->Apply(BenchmarkKernelSize)->UseRealTime(); |
| 72 | BENCHMARK_CAPTURE(transpose, 4x2_scalar_int, xnn_x8_transpose_ukernel__4x2_scalar_int) |
| 73 | ->Apply(BenchmarkKernelSize)->UseRealTime(); |
| 74 | BENCHMARK_CAPTURE(transpose, 4x4_scalar_int, xnn_x8_transpose_ukernel__4x4_scalar_int) |
| 75 | ->Apply(BenchmarkKernelSize)->UseRealTime(); |
| 76 | |
Alan Kelly | cfd947d | 2022-02-02 00:18:46 -0800 | [diff] [blame] | 77 | #if XNN_ARCH_ARM || XNN_ARCH_ARM64 |
| 78 | BENCHMARK_CAPTURE(transpose, 16x16_reuse_mov_zip_neon, xnn_x8_transpose_ukernel__16x16_reuse_mov_zip_neon) |
| 79 | ->Apply(BenchmarkKernelSize)->UseRealTime(); |
| 80 | BENCHMARK_CAPTURE(transpose, 16x16_reuse_switch_neon, xnn_x8_transpose_ukernel__16x16_reuse_switch_zip_neon) |
| 81 | ->Apply(BenchmarkKernelSize)->UseRealTime(); |
| 82 | |
| 83 | #endif // XNN_ARCH_ARM || XNN_ARCH_ARM64 |
| 84 | |
Alan Kelly | a1cad4a | 2022-01-25 13:02:20 -0800 | [diff] [blame] | 85 | #if XNN_ARCH_X86 || XNN_ARCH_X86_64 |
Alan Kelly | f2b233b | 2022-01-31 02:53:57 -0800 | [diff] [blame] | 86 | BENCHMARK_CAPTURE(transpose, 16x16_reuse_mov_sse2, xnn_x8_transpose_ukernel__16x16_reuse_mov_sse2) |
Alan Kelly | a1cad4a | 2022-01-25 13:02:20 -0800 | [diff] [blame] | 87 | ->Apply(BenchmarkKernelSize)->UseRealTime(); |
| 88 | BENCHMARK_CAPTURE(transpose, 16x16_reuse_switch_sse2, xnn_x8_transpose_ukernel__16x16_reuse_switch_sse2) |
| 89 | ->Apply(BenchmarkKernelSize)->UseRealTime(); |
| 90 | #endif // XNN_ARCH_X86 || XNN_ARCH_X86_64 |
| 91 | |
| 92 | |
| 93 | #ifndef XNNPACK_BENCHMARK_NO_MAIN |
| 94 | BENCHMARK_MAIN(); |
| 95 | #endif |