@@ -74,21 +74,20 @@ struct BenchmarkResult {
7474 clock_t total_time = 0 ;
7575};
7676
77- enum BenchmarkFlags { SINGLE_THREADED = 0x1 , SINGLE_WAVE = 0x2 };
78-
7977BenchmarkResult benchmark (const BenchmarkOptions &options,
8078 cpp::function<uint64_t (void )> wrapper_func);
8179
8280class Benchmark {
8381 const cpp::function<uint64_t (void )> func;
8482 const cpp::string_view suite_name;
8583 const cpp::string_view test_name;
86- const uint8_t flags ;
84+ const uint32_t num_threads ;
8785
8886public:
8987 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) {
9291 add_benchmark (this );
9392 }
9493
@@ -108,18 +107,21 @@ class Benchmark {
108107} // namespace benchmarks
109108} // namespace LIBC_NAMESPACE_DECL
110109
110+ // Passing -1 indicates the benchmark should be run with as many threads as
111+ // allocated by the user in the benchmark's CMake.
111112#define BENCHMARK (SuiteName, TestName, Func ) \
112113 LIBC_NAMESPACE::benchmarks::Benchmark SuiteName##_##TestName##_Instance( \
113- Func, #SuiteName, #TestName, 0 )
114+ Func, #SuiteName, #TestName, - 1 )
114115
115- #define SINGLE_THREADED_BENCHMARK (SuiteName, TestName, Func ) \
116+ #define BENCHMARK_N_THREADS (SuiteName, TestName, Func, NumThreads ) \
116117 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 )
119122
120123#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 ())
124126
125127#endif
0 commit comments