Skip to content

Commit d00af3d

Browse files
committed
[bench] adapt benchmarks to new input
1 parent 0b2ce25 commit d00af3d

File tree

14 files changed

+408
-952
lines changed

14 files changed

+408
-952
lines changed

benchmark/blas/blas.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,17 +106,20 @@ Parameters for a benchmark case are:
106106
stride_B: stride for B matrix in gemm (optional, default m)
107107
stride_C: stride for C matrix in gemm (optional, default m)
108108
)";
109-
std::string format = Generator::get_example_config();
110-
initialize_argument_parsing(&argc, &argv, header, format);
109+
auto schema =
110+
json::parse(std::ifstream(GKO_ROOT "/benchmark/schema/blas.json"));
111+
112+
initialize_argument_parsing(&argc, &argv, header, schema["examples"]);
111113

112114
std::string extra_information = "The operations are " + FLAGS_operations;
113115
auto exec = executor_factory.at(FLAGS_executor)(FLAGS_gpu_timer);
114116
print_general_information(extra_information, exec);
115117

116118
auto test_cases = json::parse(get_input_stream());
117119

118-
run_test_cases(BlasBenchmark{operation_map}, exec,
119-
get_timer(exec, FLAGS_gpu_timer), test_cases);
120+
auto results =
121+
run_test_cases(BlasBenchmark{operation_map}, exec,
122+
get_timer(exec, FLAGS_gpu_timer), schema, test_cases);
120123

121-
std::cout << std::setw(4) << test_cases << std::endl;
124+
std::cout << std::setw(4) << results << std::endl;
122125
}

benchmark/blas/blas_common.hpp

Lines changed: 34 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
// Command-line arguments
2525
DEFINE_string(
2626
operations, "copy,axpy,scal",
27-
"A comma-separated list of operations to benchmark.\nCandidates are"
27+
"A comma-separated list of operations to benchmark.\nCandidates are\n"
2828
"BLAS algorithms:\n"
2929
" copy (y = x),\n"
3030
" axpy (y = y + a * x),\n"
@@ -437,56 +437,18 @@ struct BlasBenchmark : Benchmark<dimensions> {
437437

438438
const std::string& get_name() const override { return name; }
439439

440-
const std::vector<std::string>& get_operations() const override
441-
{
442-
return operations;
443-
}
444440

445441
bool should_print() const override { return do_print; }
446442

447-
std::string get_example_config() const override
448-
{
449-
return json::parse(R"([{"n": 100}, {"n": 200, "m": 200, "k": 200}])")
450-
.dump(4);
451-
}
452-
453-
bool validate_config(const json& value) const override
454-
{
455-
return value.contains("n") && value["n"].is_number_integer();
456-
}
457-
458-
std::string describe_config(const json& test_case) const override
459-
{
460-
std::stringstream ss;
461-
auto optional_output = [&](const char* name) {
462-
if (test_case.contains(name) &&
463-
test_case[name].is_number_integer()) {
464-
ss << name << " = " << test_case[name].get<gko::int64>() << " ";
465-
}
466-
};
467-
optional_output("n");
468-
optional_output("k");
469-
optional_output("m");
470-
optional_output("r");
471-
optional_output("stride");
472-
optional_output("stride_x");
473-
optional_output("stride_y");
474-
optional_output("stride_A");
475-
optional_output("stride_B");
476-
optional_output("stride_C");
477-
return ss.str();
478-
}
479-
480443
dimensions setup(std::shared_ptr<gko::Executor> exec,
481444
json& test_case) const override
482445
{
483446
auto get_optional = [](json& obj, const char* name,
484447
gko::size_type default_value) -> gko::size_type {
485-
if (obj.contains(name)) {
486-
return obj[name].get<gko::uint64>();
487-
} else {
488-
return default_value;
448+
if (!obj.contains(name)) {
449+
obj[name] = default_value;
489450
}
451+
return obj[name].get<gko::uint64>();
490452
};
491453

492454
dimensions result;
@@ -507,40 +469,43 @@ struct BlasBenchmark : Benchmark<dimensions> {
507469
return result;
508470
}
509471

510-
511472
void run(std::shared_ptr<gko::Executor> exec, std::shared_ptr<Timer> timer,
512473
annotate_functor annotate, dimensions& dims,
513-
const std::string& operation_name,
514-
json& operation_case) const override
474+
const json& operation_case, json& result_case) const override
515475
{
516-
auto op = operation_map.at(operation_name)(exec, dims);
476+
for (auto& operation_name : operations) {
477+
result_case[operation_name] = json::object();
478+
auto& op_result_case = result_case[operation_name];
517479

518-
IterationControl ic(timer);
480+
auto op = operation_map.at(operation_name)(exec, dims);
519481

520-
// warm run
521-
{
522-
auto range = annotate("warmup", FLAGS_warmup > 0);
523-
for (auto _ : ic.warmup_run()) {
524-
op->prepare();
525-
exec->synchronize();
526-
op->run();
527-
exec->synchronize();
482+
IterationControl ic(timer);
483+
484+
// warm run
485+
{
486+
auto range = annotate("warmup", FLAGS_warmup > 0);
487+
for (auto _ : ic.warmup_run()) {
488+
op->prepare();
489+
exec->synchronize();
490+
op->run();
491+
exec->synchronize();
492+
}
528493
}
529-
}
530494

531-
// timed run
532-
op->prepare();
533-
for (auto _ : ic.run()) {
534-
auto range = annotate("repetition");
535-
op->run();
495+
// timed run
496+
op->prepare();
497+
for (auto _ : ic.run()) {
498+
auto range = annotate("repetition");
499+
op->run();
500+
}
501+
const auto runtime = ic.compute_time(FLAGS_timer_method);
502+
const auto flops = static_cast<double>(op->get_flops());
503+
const auto mem = static_cast<double>(op->get_memory());
504+
const auto repetitions = ic.get_num_repetitions();
505+
op_result_case["time"] = runtime;
506+
op_result_case["flops"] = flops / runtime;
507+
op_result_case["bandwidth"] = mem / runtime;
508+
op_result_case["repetitions"] = repetitions;
536509
}
537-
const auto runtime = ic.compute_time(FLAGS_timer_method);
538-
const auto flops = static_cast<double>(op->get_flops());
539-
const auto mem = static_cast<double>(op->get_memory());
540-
const auto repetitions = ic.get_num_repetitions();
541-
operation_case["time"] = runtime;
542-
operation_case["flops"] = flops / runtime;
543-
operation_case["bandwidth"] = mem / runtime;
544-
operation_case["repetitions"] = repetitions;
545510
}
546511
};

benchmark/blas/distributed/multi_vector.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// SPDX-FileCopyrightText: 2017 - 2024 The Ginkgo authors
1+
// SPDX-FileCopyrightText: 2017 - 2025 The Ginkgo authors
22
//
33
// SPDX-License-Identifier: BSD-3-Clause
44

@@ -38,8 +38,11 @@ Parameters for a benchmark case are:
3838
stride_x: stride for input vector x (optional, default r)
3939
stride_y: stride for in/out vector y (optional, default r)
4040
)";
41-
std::string format = Generator::get_example_config();
42-
initialize_argument_parsing(&argc, &argv, header, format, do_print);
41+
auto schema = json::parse(
42+
std::ifstream(GKO_ROOT "/benchmark/schema/blas-distributed.json"));
43+
44+
initialize_argument_parsing(&argc, &argv, header, schema["examples"],
45+
do_print);
4346

4447
auto exec = executor_factory_mpi.at(FLAGS_executor)(comm.get());
4548

@@ -98,10 +101,11 @@ Parameters for a benchmark case are:
98101
exec, Generator{comm, {}}, dims.n, dims.r, dims.stride_y);
99102
}}};
100103

101-
run_test_cases(BlasBenchmark{operation_map, do_print}, exec,
102-
get_mpi_timer(exec, comm, FLAGS_gpu_timer), test_cases);
104+
auto results = run_test_cases(BlasBenchmark{operation_map, do_print}, exec,
105+
get_mpi_timer(exec, comm, FLAGS_gpu_timer),
106+
schema, test_cases);
103107

104108
if (do_print) {
105-
std::cout << std::setw(4) << test_cases << std::endl;
109+
std::cout << std::setw(4) << results << std::endl;
106110
}
107111
}

benchmark/conversion/conversion.cpp

Lines changed: 52 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -61,28 +61,8 @@ struct ConversionBenchmark : Benchmark<gko::device_matrix_data<etype, itype>> {
6161

6262
const std::string& get_name() const override { return name; }
6363

64-
const std::vector<std::string>& get_operations() const override
65-
{
66-
return operations;
67-
}
68-
6964
bool should_print() const override { return true; }
7065

71-
std::string get_example_config() const override
72-
{
73-
return Generator::get_example_config();
74-
}
75-
76-
bool validate_config(const json& test_case) const override
77-
{
78-
return Generator::validate_config(test_case);
79-
}
80-
81-
std::string describe_config(const json& test_case) const override
82-
{
83-
return Generator::describe_config(test_case);
84-
}
85-
8666
gko::device_matrix_data<etype, itype> setup(
8767
std::shared_ptr<gko::Executor> exec, json& test_case) const override
8868
{
@@ -98,57 +78,60 @@ struct ConversionBenchmark : Benchmark<gko::device_matrix_data<etype, itype>> {
9878
data);
9979
}
10080

101-
10281
void run(std::shared_ptr<gko::Executor> exec, std::shared_ptr<Timer> timer,
10382
annotate_functor annotate,
10483
gko::device_matrix_data<etype, itype>& data,
105-
const std::string& operation_name,
106-
json& operation_case) const override
84+
const json& operation_case, json& result_case) const override
10785
{
108-
auto split_it =
109-
std::find(operation_name.begin(), operation_name.end(), '-');
110-
std::string from_name{operation_name.begin(), split_it};
111-
std::string to_name{split_it + 1, operation_name.end()};
112-
auto mtx_from = formats::matrix_type_factory.at(from_name)(exec);
113-
auto readable =
114-
gko::as<gko::ReadableFromMatrixData<etype, itype>>(mtx_from.get());
115-
IterationControl ic{timer};
116-
if (to_name == "read") {
117-
// warm run
118-
{
119-
auto range = annotate("warmup", FLAGS_warmup > 0);
120-
for (auto _ : ic.warmup_run()) {
121-
exec->synchronize();
86+
for (const auto& operation_name : operations) {
87+
result_case[operation_name] = json::object();
88+
auto& op_result_case = result_case[operation_name];
89+
90+
auto split_it =
91+
std::find(operation_name.begin(), operation_name.end(), '-');
92+
std::string from_name{operation_name.begin(), split_it};
93+
std::string to_name{split_it + 1, operation_name.end()};
94+
auto mtx_from = formats::matrix_type_factory.at(from_name)(exec);
95+
auto readable = gko::as<gko::ReadableFromMatrixData<etype, itype>>(
96+
mtx_from.get());
97+
IterationControl ic{timer};
98+
if (to_name == "read") {
99+
// warm run
100+
{
101+
auto range = annotate("warmup", FLAGS_warmup > 0);
102+
for (auto _ : ic.warmup_run()) {
103+
exec->synchronize();
104+
readable->read(data);
105+
exec->synchronize();
106+
}
107+
}
108+
// timed run
109+
for (auto _ : ic.run()) {
110+
auto range = annotate("repetition");
122111
readable->read(data);
123-
exec->synchronize();
124112
}
125-
}
126-
// timed run
127-
for (auto _ : ic.run()) {
128-
auto range = annotate("repetition");
113+
} else {
129114
readable->read(data);
130-
}
131-
} else {
132-
readable->read(data);
133-
auto mtx_to = formats::matrix_type_factory.at(to_name)(exec);
134-
135-
// warm run
136-
{
137-
auto range = annotate("warmup", FLAGS_warmup > 0);
138-
for (auto _ : ic.warmup_run()) {
139-
exec->synchronize();
115+
auto mtx_to = formats::matrix_type_factory.at(to_name)(exec);
116+
117+
// warm run
118+
{
119+
auto range = annotate("warmup", FLAGS_warmup > 0);
120+
for (auto _ : ic.warmup_run()) {
121+
exec->synchronize();
122+
mtx_to->copy_from(mtx_from);
123+
exec->synchronize();
124+
}
125+
}
126+
// timed run
127+
for (auto _ : ic.run()) {
128+
auto range = annotate("repetition");
140129
mtx_to->copy_from(mtx_from);
141-
exec->synchronize();
142130
}
143131
}
144-
// timed run
145-
for (auto _ : ic.run()) {
146-
auto range = annotate("repetition");
147-
mtx_to->copy_from(mtx_from);
148-
}
132+
op_result_case["time"] = ic.compute_time(FLAGS_timer_method);
133+
op_result_case["repetitions"] = ic.get_num_repetitions();
149134
}
150-
operation_case["time"] = ic.compute_time(FLAGS_timer_method);
151-
operation_case["repetitions"] = ic.get_num_repetitions();
152135
}
153136
};
154137

@@ -157,8 +140,11 @@ int main(int argc, char* argv[])
157140
{
158141
std::string header =
159142
"A benchmark for measuring performance of Ginkgo's conversions.\n";
160-
std::string format_str = Generator::get_example_config();
161-
initialize_argument_parsing_matrix(&argc, &argv, header, format_str);
143+
144+
auto schema = json::parse(
145+
std::ifstream(GKO_ROOT "/benchmark/schema/conversion.json"));
146+
147+
initialize_argument_parsing(&argc, &argv, header, schema["examples"]);
162148

163149
std::string extra_information =
164150
std::string() + "The formats are " + FLAGS_formats;
@@ -169,8 +155,9 @@ int main(int argc, char* argv[])
169155

170156
auto test_cases = json::parse(get_input_stream());
171157

172-
run_test_cases(ConversionBenchmark{}, exec,
173-
get_timer(exec, FLAGS_gpu_timer), test_cases);
158+
auto results =
159+
run_test_cases(ConversionBenchmark{}, exec,
160+
get_timer(exec, FLAGS_gpu_timer), schema, test_cases);
174161

175-
std::cout << std::setw(4) << test_cases << std::endl;
162+
std::cout << std::setw(4) << results << std::endl;
176163
}

0 commit comments

Comments
 (0)