blob: 62e59e1b3087da7cbe6b7606e648a71b5b20efcd [file] [log] [blame]
XNNPACK Teamb455b122019-09-27 18:10:33 -07001// 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#pragma once
7
8#include <cstddef>
9#include <cstdint>
10
Marat Dukhanbad48fe2019-11-04 10:35:22 -080011#include <benchmark/benchmark.h>
12
XNNPACK Teamb455b122019-09-27 18:10:33 -070013namespace benchmark {
14namespace utils {
15
Marat Dukhan42323232019-10-23 02:09:02 -070016uint32_t WipeCache();
17uint32_t PrefetchToL1(const void* ptr, size_t size);
Marat Dukhand62f3cc2019-10-01 12:37:52 -070018
Marat Dukhan4a4a7fa2019-10-21 13:46:14 -070019// Disable support for denormalized numbers in floating-point units.
20void DisableDenormals();
21
Marat Dukhand62f3cc2019-10-01 12:37:52 -070022// Return clock rate, in Hz, for the currently used logical processor.
23uint64_t GetCurrentCpuFrequency();
24
25// Return maximum (across all cores/clusters/sockets) last level cache size.
26// Can overestimate, but not underestimate LLC size.
27size_t GetMaxCacheSize();
XNNPACK Teamb455b122019-09-27 18:10:33 -070028
Marat Dukhanbad48fe2019-11-04 10:35:22 -080029// Set multi-threading parameters appropriate for the processor.
30void MultiThreadingParameters(benchmark::internal::Benchmark* benchmark);
31
Marat Dukhanc8466f52019-11-25 18:01:10 -080032typedef bool (*IsaCheckFunction)(benchmark::State& state);
33
Marat Dukhan3b98f6b2020-05-17 10:09:22 -070034// Check if either ARM VFPv2 or VFPv3 extension is supported.
35// If VFP is unsupported, report error in benchmark state, and return false.
36bool CheckVFP(benchmark::State& state);
37
Frank Barchard40f50e12020-05-29 22:21:56 -070038// Check if ARM NEON-FP16-ARITH extension is supported.
39// If NEON-FP16-ARITH is unsupported, report error in benchmark state, and return false.
40bool CheckNEONFP16ARITH(benchmark::State& state);
41
Marat Dukhanc8466f52019-11-25 18:01:10 -080042// Check if ARM NEON extension is supported.
43// If NEON is unsupported, report error in benchmark state, and return false.
44bool CheckNEON(benchmark::State& state);
45
46// Check if ARM NEON-FMA extension is supported.
47// If NEON-FMA is unsupported, report error in benchmark state, and return false.
48bool CheckNEONFMA(benchmark::State& state);
49
Marat Dukhan1566fee2020-08-02 21:55:41 -070050// Check if x86 SSSE3 extension is supported.
51// If SSSE3 is unsupported, report error in benchmark state, and return false.
52bool CheckSSSE3(benchmark::State& state);
53
Marat Dukhanc8466f52019-11-25 18:01:10 -080054// Check if x86 SSE4.1 extension is supported.
55// If SSE4.1 is unsupported, report error in benchmark state, and return false.
56bool CheckSSE41(benchmark::State& state);
57
58// Check if x86 AVX extension is supported.
59// If AVX is unsupported, report error in benchmark state, and return false.
60bool CheckAVX(benchmark::State& state);
61
Marat Dukhan1566fee2020-08-02 21:55:41 -070062// Check if x86 XOP extension is supported.
63// If XOP is unsupported, report error in benchmark state, and return false.
64bool CheckXOP(benchmark::State& state);
65
Marat Dukhanc8466f52019-11-25 18:01:10 -080066// Check if x86 FMA3 extension is supported.
67// If FMA3 is unsupported, report error in benchmark state, and return false.
68bool CheckFMA3(benchmark::State& state);
69
70// Check if x86 AVX2 extension is supported.
71// If AVX2 is unsupported, report error in benchmark state, and return false.
72bool CheckAVX2(benchmark::State& state);
73
74// Check if x86 AVX512F extension is supported.
75// If AVX512F is unsupported, report error in benchmark state, and return false.
76bool CheckAVX512F(benchmark::State& state);
77
XNNPACK Teamb455b122019-09-27 18:10:33 -070078template <class T>
Marat Dukhan42323232019-10-23 02:09:02 -070079inline T DivideRoundUp(T x, T q) {
XNNPACK Teamb455b122019-09-27 18:10:33 -070080 return x / q + T(x % q != 0);
81}
82
83template <class T>
Marat Dukhan42323232019-10-23 02:09:02 -070084inline T RoundUp(T x, T q) {
85 return q * DivideRoundUp(x, q);
XNNPACK Teamb455b122019-09-27 18:10:33 -070086}
87
88template <class T>
Marat Dukhan42323232019-10-23 02:09:02 -070089inline T Doz(T a, T b) {
XNNPACK Teamb455b122019-09-27 18:10:33 -070090 return a >= b ? a - b : T(0);
91}
92
93} // namespace utils
94} // namespace benchmark