@@ -74,21 +74,20 @@ struct BenchmarkResult {
74
74
clock_t total_time = 0 ;
75
75
};
76
76
77
- enum BenchmarkFlags { SINGLE_THREADED = 0x1 , SINGLE_WAVE = 0x2 };
78
-
79
77
BenchmarkResult benchmark (const BenchmarkOptions &options,
80
78
cpp::function<uint64_t (void )> wrapper_func);
81
79
82
80
class Benchmark {
83
81
const cpp::function<uint64_t (void )> func;
84
82
const cpp::string_view suite_name;
85
83
const cpp::string_view test_name;
86
- const uint8_t flags ;
84
+ const uint32_t num_threads ;
87
85
88
86
public:
89
87
Benchmark (cpp::function<uint64_t (void )> func, char const *suite_name,
90
- char const *test_name, uint8_t flags)
91
- : func(func), suite_name(suite_name), test_name(test_name), flags(flags) {
88
+ char const *test_name, uint32_t num_threads)
89
+ : func(func), suite_name(suite_name), test_name(test_name),
90
+ num_threads (num_threads) {
92
91
add_benchmark (this );
93
92
}
94
93
@@ -108,18 +107,21 @@ class Benchmark {
108
107
} // namespace benchmarks
109
108
} // namespace LIBC_NAMESPACE_DECL
110
109
110
+ // Passing -1 indicates the benchmark should be run with as many threads as
111
+ // allocated by the user in the benchmark's CMake.
111
112
#define BENCHMARK (SuiteName, TestName, Func ) \
112
113
LIBC_NAMESPACE::benchmarks::Benchmark SuiteName##_##TestName##_Instance( \
113
- Func, #SuiteName, #TestName, 0 )
114
+ Func, #SuiteName, #TestName, - 1 )
114
115
115
- #define SINGLE_THREADED_BENCHMARK (SuiteName, TestName, Func ) \
116
+ #define BENCHMARK_N_THREADS (SuiteName, TestName, Func, NumThreads ) \
116
117
LIBC_NAMESPACE::benchmarks::Benchmark SuiteName##_##TestName##_Instance( \
117
- Func, #SuiteName, #TestName, \
118
- LIBC_NAMESPACE::benchmarks::BenchmarkFlags::SINGLE_THREADED)
118
+ Func, #SuiteName, #TestName, NumThreads)
119
+
120
+ #define SINGLE_THREADED_BENCHMARK (SuiteName, TestName, Func ) \
121
+ BENCHMARK_N_THREADS (SuiteName, TestName, Func, 1 )
119
122
120
123
#define SINGLE_WAVE_BENCHMARK (SuiteName, TestName, Func ) \
121
- LIBC_NAMESPACE::benchmarks::Benchmark SuiteName##_##TestName##_Instance( \
122
- Func, #SuiteName, #TestName, \
123
- LIBC_NAMESPACE::benchmarks::BenchmarkFlags::SINGLE_WAVE)
124
+ BENCHMARK_N_THREADS (SuiteName, TestName, Func, \
125
+ LIBC_NAMESPACE::gpu::get_lane_size ())
124
126
125
127
#endif
0 commit comments