// Copyright 2022 Google LLC // // This source code is licensed under the BSD-style license found in the // LICENSE file in the root directory of this source tree. #include #include #include #include #include #include #include "bench/utils.h" #include #include #include #include #include #include static void u64_u32_vsqrtshift( benchmark::State& state, xnn_u64_u32_vsqrtshift_ukernel_function vsqrtshift, benchmark::utils::IsaCheckFunction isa_check = nullptr) { if (isa_check && !isa_check(state)) { return; } const size_t num_elements = state.range(0); std::random_device random_device; auto rng = std::mt19937(random_device()); auto u64rng = std::bind(std::uniform_int_distribution(), std::ref(rng)); std::vector> x(num_elements + XNN_EXTRA_BYTES / sizeof(uint64_t)); std::vector> y(num_elements); std::generate(x.begin(), x.end(), std::ref(u64rng)); std::fill(y.begin(), y.end(), UINT32_C(0xDEADBEEF)); for (auto _ : state) { vsqrtshift(num_elements * sizeof(uint64_t), x.data(), y.data(), 1 /* shift */); } const uint64_t cpu_frequency = benchmark::utils::GetCurrentCpuFrequency(); if (cpu_frequency != 0) { state.counters["cpufreq"] = cpu_frequency; } const size_t elements_per_iteration = num_elements; state.counters["elements"] = benchmark::Counter(uint64_t(state.iterations()) * elements_per_iteration, benchmark::Counter::kIsRate); const size_t bytes_per_iteration = num_elements * (sizeof(uint64_t) + sizeof(uint32_t)); state.counters["bytes"] = benchmark::Counter(uint64_t(state.iterations()) * bytes_per_iteration, benchmark::Counter::kIsRate); } BENCHMARK_CAPTURE(u64_u32_vsqrtshift, scalar_cvtu32_sqrt_cvtu32f64_x1, xnn_u64_u32_vsqrtshift_ukernel__scalar_cvtu32_sqrt_cvtu32f64_x1) ->Apply(benchmark::utils::UnaryElementwiseParameters) ->UseRealTime(); #ifndef XNNPACK_BENCHMARK_NO_MAIN BENCHMARK_MAIN(); #endif