Skip to content

Commit

Permalink
benchmark updates
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcelKoch committed Feb 6, 2025
1 parent efbf245 commit e647449
Show file tree
Hide file tree
Showing 8 changed files with 227 additions and 152 deletions.
24 changes: 21 additions & 3 deletions benchmark/solver/distributed/solver.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2017 - 2024 The Ginkgo authors
// SPDX-FileCopyrightText: 2017 - 2025 The Ginkgo authors
//
// SPDX-License-Identifier: BSD-3-Clause

Expand Down Expand Up @@ -48,6 +48,24 @@ struct Generator : public DistributedDefaultSystemGenerator<SolverGenerator> {
};


std::string solver_distributed_example_config = R"(
[
{
"stencil": {
"name": "7pt",
"local_size": 100,
"process_grid": [2, 3, 4],
}
"optimal": {"spmv": "csr-coo"}
},
{"filename": "my_file.mtx", "optimal": {"spmv": "ell-csr"},
"rhs": "my_file_rhs.mtx"},
{"filename": "my_file2.mtx", "optimal": {"spmv": "coo-coo"},
"rhs": "my_file_rhs.mtx"}
]
)";


int main(int argc, char* argv[])
{
gko::experimental::mpi::environment mpi_env{argc, argv};
Expand All @@ -62,7 +80,7 @@ int main(int argc, char* argv[])

std::string header =
"A benchmark for measuring Ginkgo's distributed solvers\n";
std::string format = solver_example_config + R"(
std::string format = solver_distributed_example_config + R"(
The matrix will either be read from an input file if the filename parameter
is given, or generated as a stencil matrix.
If the filename parameter is given, all processes will read the file and
Expand Down Expand Up @@ -113,7 +131,7 @@ int main(int argc, char* argv[])
: broadcast_json_input(get_input_stream(), comm);
auto test_cases = json::parse(json_input);

run_test_cases(SolverBenchmark<Generator>{Generator{comm}}, exec,
run_test_cases(SolverBenchmark<Generator>{Generator{comm}, do_print}, exec,
get_mpi_timer(exec, comm, FLAGS_gpu_timer), test_cases);

if (do_print) {
Expand Down
23 changes: 13 additions & 10 deletions benchmark/solver/solver_common.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2017 - 2024 The Ginkgo authors
// SPDX-FileCopyrightText: 2017 - 2025 The Ginkgo authors
//
// SPDX-License-Identifier: BSD-3-Clause

Expand Down Expand Up @@ -84,12 +84,11 @@ DEFINE_bool(overhead, false,

std::string solver_example_config = R"(
[
{"filename": "my_file.mtx", "optimal": {"spmv": "ell-csr"},
{"filename": "my_file.mtx", "optimal": {"spmv": "ell"},
"rhs": "my_file_rhs.mtx"},
{"filename": "my_file2.mtx", "optimal": {"spmv": "coo-coo"},
{"filename": "my_file2.mtx", "optimal": {"spmv": "coo"},
"rhs": "my_file_rhs.mtx"},
{"size": 100, "stencil": "7pt", "comm_pattern": "stencil",
"optimal": {"spmv": "csr-coo"}}
{"size": 100, "stencil": "7pt", "optimal": {"spmv": "csr"}}
]
)";

Expand Down Expand Up @@ -363,8 +362,10 @@ struct SolverBenchmark : Benchmark<solver_benchmark_state<Generator>> {
std::vector<std::string> precond_solvers;
std::map<std::string, std::pair<std::string, std::string>> decoder;
Generator generator;
bool do_print;

SolverBenchmark(Generator generator) : name{"solver"}, generator{generator}
SolverBenchmark(Generator generator, bool do_print = true)
: name{"solver"}, generator{generator}, do_print(do_print)
{
auto solvers = split(FLAGS_solvers, ',');
auto preconds = split(FLAGS_preconditioners, ',');
Expand All @@ -383,7 +384,7 @@ struct SolverBenchmark : Benchmark<solver_benchmark_state<Generator>> {
return precond_solvers;
}

bool should_print() const override { return true; }
bool should_print() const override { return do_print; }

std::string get_example_config() const override
{
Expand Down Expand Up @@ -428,9 +429,11 @@ struct SolverBenchmark : Benchmark<solver_benchmark_state<Generator>> {
exec, state.system_matrix.get(), state.b.get());
}

std::clog << "Matrix is of size (" << state.system_matrix->get_size()[0]
<< ", " << state.system_matrix->get_size()[1] << ")"
<< std::endl;
if (do_print) {
std::clog << "Matrix is of size ("
<< state.system_matrix->get_size()[0] << ", "
<< state.system_matrix->get_size()[1] << ")" << std::endl;
}
test_case["rows"] = state.system_matrix->get_size()[0];
test_case["cols"] = state.system_matrix->get_size()[1];
return state;
Expand Down
9 changes: 6 additions & 3 deletions benchmark/utils/general.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2017 - 2024 The Ginkgo authors
// SPDX-FileCopyrightText: 2017 - 2025 The Ginkgo authors
//
// SPDX-License-Identifier: BSD-3-Clause

Expand Down Expand Up @@ -123,7 +123,7 @@ void initialize_argument_parsing(int* argc, char** argv[], std::string& header,
if (do_print) {
std::ostringstream doc;
doc << header << "Usage: " << (*argv)[0] << " [options]\n"
<< format
<< format << "\n"
<< " The results are written on standard output, in the same "
"format,\n"
<< " but with test cases extended to include an additional member "
Expand All @@ -144,7 +144,10 @@ void initialize_argument_parsing(int* argc, char** argv[], std::string& header,
gflags::SetUsageMessage("");
gflags::SetVersionString("");
}
gflags::ParseCommandLineFlags(argc, argv, true);
gflags::ParseCommandLineNonHelpFlags(argc, argv, true);
if (do_print) {
gflags::HandleCommandLineHelpFlags();
}
if (FLAGS_profile) {
FLAGS_repetitions = "1";
FLAGS_warmup = 0;
Expand Down
64 changes: 37 additions & 27 deletions benchmark/utils/generator.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2017 - 2024 The Ginkgo authors
// SPDX-FileCopyrightText: 2017 - 2025 The Ginkgo authors
//
// SPDX-License-Identifier: BSD-3-Clause

Expand Down Expand Up @@ -32,8 +32,8 @@ struct DefaultSystemGenerator {
data = gko::read_generic_raw<ValueType, IndexType>(in);
} else if (config.contains("stencil")) {
data = generate_stencil<ValueType, IndexType>(
config["stencil"].get<std::string>(),
config["size"].get<gko::int64>());
config["stencil"]["name"].get<std::string>(),
config["stencil"]["local_size"].get<gko::int64>());
} else {
throw std::runtime_error(
"No known way to generate matrix data found.");
Expand All @@ -45,17 +45,19 @@ struct DefaultSystemGenerator {
static std::string get_example_config()
{
return json::
parse(R"([{"filename": "my_file.mtx"},{"filename": "my_file2.mtx"},{"size": 100, "stencil": "7pt"}])")
parse(R"([{"filename": "my_file.mtx"},{"filename": "my_file2.mtx"},{"stencil": {"name": "7pt", "local_size": 100}}])")
.dump(4);
}

static bool validate_config(const json& test_case)
{
return ((test_case.contains("size") && test_case.contains("stencil") &&
test_case["size"].is_number_integer() &&
test_case["stencil"].is_string()) ||
(test_case.contains("filename") &&
test_case["filename"].is_string()));
return (test_case.contains("stencil") &&
test_case["stencil"].is_object() &&
test_case["stencil"].contains("name") &&
test_case["stencil"]["name"].is_string() &&
test_case["stencil"].contains("local_size")) ||
(test_case.contains("filename") &&
test_case["filename"].is_string());
}

static std::string describe_config(const json& config)
Expand All @@ -64,8 +66,9 @@ struct DefaultSystemGenerator {
return config["filename"].get<std::string>();
} else if (config.contains("stencil")) {
std::stringstream ss;
ss << "stencil(" << config["size"].get<gko::int64>() << ", "
<< config["stencil"].get<std::string>() << ")";
ss << "stencil("
<< config["stencil"]["local_size"].get<gko::int64>() << ", "
<< config["stencil"]["name"].get<std::string>() << ")";
return ss.str();
} else {
throw std::runtime_error("No known way to describe config.");
Expand Down Expand Up @@ -170,12 +173,11 @@ struct DistributedDefaultSystemGenerator {
std::ifstream in(config["filename"].get<std::string>());
data = gko::read_generic_raw<value_type, index_type>(in);
} else if (config.contains("stencil")) {
auto local_size = static_cast<global_itype>(
config["size"].get<gko::int64>() / comm.size());
auto& stencil = config["stencil"];
data = generate_stencil<value_type, index_type>(
config["stencil"].get<std::string>(), comm, local_size,
config["comm_pattern"].get<std::string>() ==
std::string("optimal"));
stencil["name"].get<std::string>(), comm,
stencil["local_size"].get<gko::int64>(),
stencil.value("process_grid", std::vector<gko::int64>()));
} else {
throw std::runtime_error(
"No known way to generate matrix data found.");
Expand All @@ -187,19 +189,22 @@ struct DistributedDefaultSystemGenerator {
static std::string get_example_config()
{
return json::
parse(R"([{"size": 100, "stencil": "7pt", "comm_pattern": "stencil"}, {"filename": "my_file.mtx"}])")
parse(R"([{"stencil": {"name": "5pt", "local_size": 100, "process_grid": [2, 3]}}, {"filename": "my_file.mtx"}])")
.dump(4);
}

static bool validate_config(const json& test_case)
{
return ((test_case.contains("size") && test_case.contains("stencil") &&
test_case.contains("comm_pattern") &&
test_case["size"].is_number_integer() &&
test_case["stencil"].is_string() &&
test_case["comm_pattern"].is_string()) ||
(test_case.contains("filename") &&
test_case["filename"].is_string()));
return (test_case.contains("stencil") &&
test_case["stencil"].is_object() &&
test_case["stencil"].contains("name") &&
test_case["stencil"]["name"].is_string() &&
test_case["stencil"].contains("local_size") &&
test_case["stencil"]["local_size"].is_number_integer() &&
(!test_case["stencil"].contains("process_grid") ||
test_case["stencil"]["process_grid"].is_array())) ||
(test_case.contains("filename") &&
test_case["filename"].is_string());
}

static std::string describe_config(const json& config)
Expand All @@ -208,9 +213,14 @@ struct DistributedDefaultSystemGenerator {
return config["filename"].get<std::string>();
} else if (config.contains("stencil")) {
std::stringstream ss;
ss << "stencil(" << config["size"].get<gko::int64>() << ", "
<< config["stencil"].get<std::string>() << ", "
<< config["comm_pattern"].get<std::string>() << ")";
ss << "stencil(" << config["stencil"]["local_size"] << ", "
<< config["stencil"]["name"] << ", ";
if (config["stencil"].contains("process_grid")) {
ss << config["stencil"]["process_grid"];
} else {
ss << "[tbd]";
}
ss << ")";
return ss.str();
} else {
throw std::runtime_error("No known way to describe config.");
Expand Down
15 changes: 14 additions & 1 deletion benchmark/utils/loggers.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2017 - 2024 The Ginkgo authors
// SPDX-FileCopyrightText: 2017 - 2025 The Ginkgo authors
//
// SPDX-License-Identifier: BSD-3-Clause

Expand Down Expand Up @@ -92,12 +92,15 @@ struct StorageLogger : gko::log::Logger {
{
const std::lock_guard<std::mutex> lock(mutex);
storage[location] = num_bytes;
cur_storage += num_bytes;
max_storage = std::max(max_storage, cur_storage);
}

void on_free_completed(const gko::Executor*,
const gko::uintptr& location) const override
{
const std::lock_guard<std::mutex> lock(mutex);
cur_storage -= storage[location];
storage[location] = 0;
}

Expand All @@ -109,6 +112,7 @@ struct StorageLogger : gko::log::Logger {
total += e.second;
}
output["storage"] = total;
output["max_storage"] = max_storage;
}

#if GINKGO_BUILD_MPI
Expand All @@ -125,12 +129,21 @@ struct StorageLogger : gko::log::Logger {
: &total,
&total, 1, MPI_SUM, 0);
output["storage"] = total;
gko::size_type global_max_storage = max_storage;
comm.reduce(gko::ReferenceExecutor::create(),
comm.rank() == 0
? static_cast<gko::size_type*>(MPI_IN_PLACE)
: &global_max_storage,
&global_max_storage, 1, MPI_MAX, 0);
output["max_storage"] = global_max_storage;
}
#endif

private:
mutable std::mutex mutex;
mutable std::unordered_map<gko::uintptr, gko::size_type> storage;
mutable gko::size_type cur_storage = 0;
mutable gko::size_type max_storage = 0;
};


Expand Down
Loading

0 comments on commit e647449

Please sign in to comment.