#include "bench_util.h" #include "core/mlas/lib/mlasi.h" #if defined(MLAS_F16VEC_INTRINSICS_SUPPORTED) && defined(MLAS_TARGET_ARM64) void BM_ConvertF16ToF32(benchmark::State& state) { bool aligned = static_cast(state.range(0)); const size_t count = 1 << 18; auto src = RandomVectorUniform(count, 0, 60000); auto dst = std::vector(count + 16); auto aligned_dst = (reinterpret_cast(dst.data()) + 15) & (~15); float* dst_start = aligned ? reinterpret_cast(aligned_dst) : reinterpret_cast(aligned_dst + 1); // Warm up MlasCastF16ToF32KernelNeon(src.data(), dst_start, count); for (auto _ : state) { MlasCastF16ToF32KernelNeon(src.data(), dst_start, count); } } void BM_ConvertF32ToF16(benchmark::State& state) { bool aligned = static_cast(state.range(0)); const size_t count = 1 << 18; auto src = RandomVectorUniform(count, -30000.0f, 30000.0f); auto dst = std::vector(count + 16); auto aligned_dst = (reinterpret_cast(dst.data()) + 15) & (~15); unsigned short* dst_start = aligned ? reinterpret_cast(aligned_dst) : reinterpret_cast(aligned_dst + 1); // Warm up MlasCastF32ToF16KernelNeon(src.data(), dst_start, count); for (auto _ : state) { MlasCastF32ToF16KernelNeon(src.data(), dst_start, count); } } BENCHMARK(BM_ConvertF16ToF32) ->UseRealTime() ->Apply([](benchmark::Benchmark* b) { b->ArgNames({"aligned"}); b->ArgsProduct({{0, 1}}); }); BENCHMARK(BM_ConvertF32ToF16) ->UseRealTime() ->Apply([](benchmark::Benchmark* b) { b->ArgNames({"aligned"}); b->ArgsProduct({{0, 1}}); }); #endif // defined(MLAS_F16VEC_INTRINSICS_SUPPORTED) && defined(MLAS_TARGET_ARM64)