blob: a54bd3e20df3d32463ae4c183d4e25e0be6dea54 [file] [log] [blame]
Alan Kellyfda06cb2021-12-15 03:30:32 -08001// 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>
Alan Kellye8bbda02022-01-25 04:51:12 -080014#include <numeric>
Alan Kellyfda06cb2021-12-15 03:30:32 -080015#include <vector>
16
17#include "bench/utils.h"
18#include <benchmark/benchmark.h>
19
Alan Kellye8bbda02022-01-25 04:51:12 -080020void transpose(
Alan Kellyfda06cb2021-12-15 03:30:32 -080021 benchmark::State& state,
22 xnn_x32_transpose_ukernel_function transpose,
Alan Kellye8bbda02022-01-25 04:51:12 -080023 benchmark::utils::IsaCheckFunction isa_check = nullptr)
24{
Alan Kellyfda06cb2021-12-15 03:30:32 -080025 if (isa_check && !isa_check(state)) {
26 return;
27 }
Alan Kellye8bbda02022-01-25 04:51:12 -080028 const size_t height = state.range(0);
29 const size_t width = state.range(1);
30 const size_t tile_hbytes = height * sizeof(uint32_t);
31 const size_t tile_wbytes = width * sizeof(uint32_t);
Alan Kellyfda06cb2021-12-15 03:30:32 -080032
33 std::vector<uint32_t, AlignedAllocator<uint32_t, 64>> x(
Alan Kellye8bbda02022-01-25 04:51:12 -080034 height * width + XNN_EXTRA_BYTES / sizeof(uint32_t));
Alan Kellyfda06cb2021-12-15 03:30:32 -080035 std::vector<uint32_t, AlignedAllocator<uint32_t, 64>> y(
Alan Kellye8bbda02022-01-25 04:51:12 -080036 height * width + XNN_EXTRA_BYTES / sizeof(uint32_t));
37 std::iota(x.begin(), x.end(), 0);
Alan Kellyfda06cb2021-12-15 03:30:32 -080038 std::fill(y.begin(), y.end(), 0);
39
40 for (auto _ : state) {
Alan Kellye8bbda02022-01-25 04:51:12 -080041 transpose(x.data(), y.data(), tile_wbytes, tile_hbytes, width,
42 height);
Alan Kellyfda06cb2021-12-15 03:30:32 -080043 }
Frank Barchardef0f09c2021-12-28 14:17:02 -080044
45 const uint64_t cpu_frequency = benchmark::utils::GetCurrentCpuFrequency();
46 if (cpu_frequency != 0) {
47 state.counters["cpufreq"] = cpu_frequency;
48 }
Alan Kellyfda06cb2021-12-15 03:30:32 -080049}
50
Alan Kellye8bbda02022-01-25 04:51:12 -080051static 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
60BENCHMARK_CAPTURE(transpose, 1x2_scalar_int, xnn_x32_transpose_ukernel__1x2_scalar_int)
61 ->Apply(BenchmarkKernelSize)->UseRealTime();
62BENCHMARK_CAPTURE(transpose, 1x4_scalar_int, xnn_x32_transpose_ukernel__1x4_scalar_int)
63 ->Apply(BenchmarkKernelSize)->UseRealTime();
64BENCHMARK_CAPTURE(transpose, 2x1_scalar_int, xnn_x32_transpose_ukernel__2x1_scalar_int)
65 ->Apply(BenchmarkKernelSize)->UseRealTime();
66BENCHMARK_CAPTURE(transpose, 2x2_scalar_int, xnn_x32_transpose_ukernel__2x2_scalar_int)
67 ->Apply(BenchmarkKernelSize)->UseRealTime();
68BENCHMARK_CAPTURE(transpose, 2x4_scalar_int, xnn_x32_transpose_ukernel__2x4_scalar_int)
69 ->Apply(BenchmarkKernelSize)->UseRealTime();
70BENCHMARK_CAPTURE(transpose, 4x1_scalar_int, xnn_x32_transpose_ukernel__4x1_scalar_int)
71 ->Apply(BenchmarkKernelSize)->UseRealTime();
72BENCHMARK_CAPTURE(transpose, 4x2_scalar_int, xnn_x32_transpose_ukernel__4x2_scalar_int)
73 ->Apply(BenchmarkKernelSize)->UseRealTime();
74BENCHMARK_CAPTURE(transpose, 4x4_scalar_int, xnn_x32_transpose_ukernel__4x4_scalar_int)
75 ->Apply(BenchmarkKernelSize)->UseRealTime();
76BENCHMARK_CAPTURE(transpose, 1x2_scalar_float, xnn_x32_transpose_ukernel__1x2_scalar_float)
77 ->Apply(BenchmarkKernelSize)->UseRealTime();
78BENCHMARK_CAPTURE(transpose, 1x4_scalar_float, xnn_x32_transpose_ukernel__1x4_scalar_float)
79 ->Apply(BenchmarkKernelSize)->UseRealTime();
80BENCHMARK_CAPTURE(transpose, 2x1_scalar_float, xnn_x32_transpose_ukernel__2x1_scalar_float)
81 ->Apply(BenchmarkKernelSize)->UseRealTime();
82BENCHMARK_CAPTURE(transpose, 2x2_scalar_float, xnn_x32_transpose_ukernel__2x2_scalar_float)
83 ->Apply(BenchmarkKernelSize)->UseRealTime();
84BENCHMARK_CAPTURE(transpose, 2x4_scalar_float, xnn_x32_transpose_ukernel__2x4_scalar_float)
85 ->Apply(BenchmarkKernelSize)->UseRealTime();
86BENCHMARK_CAPTURE(transpose, 4x1_scalar_float, xnn_x32_transpose_ukernel__4x1_scalar_float)
87 ->Apply(BenchmarkKernelSize)->UseRealTime();
88BENCHMARK_CAPTURE(transpose, 4x2_scalar_float, xnn_x32_transpose_ukernel__4x2_scalar_float)
89 ->Apply(BenchmarkKernelSize)->UseRealTime();
90BENCHMARK_CAPTURE(transpose, 4x4_scalar_float, xnn_x32_transpose_ukernel__4x4_scalar_float)
91 ->Apply(BenchmarkKernelSize)->UseRealTime();
Alan Kelly27808632022-01-10 11:16:33 -080092
Alan Kellyed902162022-01-05 01:51:30 -080093#if XNN_ARCH_ARM64
Alan Kellye8bbda02022-01-25 04:51:12 -080094 BENCHMARK_CAPTURE(transpose, 4x4_aarch64_neon_tbl, xnn_x32_transpose_ukernel__4x4_aarch64_neon_tbl)
95 ->Apply(BenchmarkKernelSize)->UseRealTime();
Alan Kellyed902162022-01-05 01:51:30 -080096#endif // XNN_ARCH_ARM64
97
Alan Kellye8bbda02022-01-25 04:51:12 -080098#if XNN_ARCH_WASMSIMD || XNN_ARCH_WASMRELAXEDSIMD
99 BENCHMARK_CAPTURE(transpose, 4x4_wasmsimd, xnn_x32_transpose_ukernel__4x4_wasmsimd)
100 ->Apply(BenchmarkKernelSize)->UseRealTime();
101#endif // XNN_ARCH_WASMSIMD || XNN_ARCH_WASMRELAXEDSIMD
102
Alan Kellyfda06cb2021-12-15 03:30:32 -0800103#if XNN_ARCH_X86 || XNN_ARCH_X86_64
Alan Kellye8bbda02022-01-25 04:51:12 -0800104 BENCHMARK_CAPTURE(transpose, 4x4_sse, xnn_x32_transpose_ukernel__4x4_sse)
105 ->Apply(BenchmarkKernelSize)->UseRealTime();
Alan Kellyf2b233b2022-01-31 02:53:57 -0800106 BENCHMARK_CAPTURE(transpose, 4x4_multi_mov_sse2, xnn_x32_transpose_ukernel__4x4_multi_mov_sse2)
Alan Kellye8bbda02022-01-25 04:51:12 -0800107 ->Apply(BenchmarkKernelSize)->UseRealTime();
108 BENCHMARK_CAPTURE(transpose, 4x4_multi_multi_sse2, xnn_x32_transpose_ukernel__4x4_multi_multi_sse2)
109 ->Apply(BenchmarkKernelSize)->UseRealTime();
110 BENCHMARK_CAPTURE(transpose, 4x4_multi_switch_sse2, xnn_x32_transpose_ukernel__4x4_multi_switch_sse2)
111 ->Apply(BenchmarkKernelSize)->UseRealTime();
Alan Kellyf2b233b2022-01-31 02:53:57 -0800112 BENCHMARK_CAPTURE(transpose, 4x4_reuse_mov_sse2, xnn_x32_transpose_ukernel__4x4_reuse_mov_sse2)
Alan Kellye8bbda02022-01-25 04:51:12 -0800113 ->Apply(BenchmarkKernelSize)->UseRealTime();
114 BENCHMARK_CAPTURE(transpose, 4x4_reuse_multi_sse2, xnn_x32_transpose_ukernel__4x4_reuse_multi_sse2)
115 ->Apply(BenchmarkKernelSize)->UseRealTime();
116 BENCHMARK_CAPTURE(transpose, 4x4_reuse_switch_sse2, xnn_x32_transpose_ukernel__4x4_reuse_switch_sse2)
117 ->Apply(BenchmarkKernelSize)->UseRealTime();
Alan Kellyfda06cb2021-12-15 03:30:32 -0800118#endif // XNN_ARCH_X86 || XNN_ARCH_X86_64
119
Alan Kellye8bbda02022-01-25 04:51:12 -0800120
Alan Kellyfda06cb2021-12-15 03:30:32 -0800121#ifndef XNNPACK_BENCHMARK_NO_MAIN
122BENCHMARK_MAIN();
123#endif