Skip to content

Commit

Permalink
allow passing matrix filename as benchmark input
Browse files Browse the repository at this point in the history
  • Loading branch information
upsj committed Aug 14, 2023
1 parent ee648e2 commit 92d9f57
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 1 deletion.
2 changes: 2 additions & 0 deletions benchmark/blas/blas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ Parameters for a benchmark case are:
stride_C: stride for C matrix in gemm (optional, default m)
)";
std::string format = example_config;
// this benchmark doesn't use input matrices
matrix_input = false;
initialize_argument_parsing(&argc, &argv, header, format);

std::string extra_information =
Expand Down
2 changes: 2 additions & 0 deletions benchmark/blas/distributed/multi_vector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ Parameters for a benchmark case are:
stride_y: stride for in/out vector y (optional, default r)
)";
std::string format = example_config;
// this benchmark doesn't use input matrices
matrix_input = false;
initialize_argument_parsing(&argc, &argv, header, format);

const auto comm = gko::experimental::mpi::communicator(MPI_COMM_WORLD);
Expand Down
2 changes: 2 additions & 0 deletions benchmark/matrix_generator/matrix_generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ int main(int argc, char* argv[])
std::string header =
"A utility that generates various types of "
"matrices.\n";
// this benchmark doesn't use input matrices
matrix_input = false;
initialize_argument_parsing(&argc, &argv, header, input_format);

std::clog << gko::version_info::get() << std::endl;
Expand Down
2 changes: 2 additions & 0 deletions benchmark/solver/distributed/solver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ int main(int argc, char* argv[])
"<local_format>-<non_local_format>", where both "local_format" and
"non_local_format" can be any of the recognized spmv formats.
)";
// this benchmark needs an additional "optimal" object in the input
matrix_input_additional_json = ",\"optimal\":{\"spmv\":\"csr-csr\"}";
initialize_argument_parsing(&argc, &argv, header, format);

const auto comm = gko::experimental::mpi::communicator(MPI_COMM_WORLD);
Expand Down
2 changes: 2 additions & 0 deletions benchmark/solver/solver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ int main(int argc, char* argv[])
std::string format = example_config + R"(
"optimal":"spmv" can be one of the recognized spmv formats
)";
// this benchmark needs an additional "optimal" object in the input
matrix_input_additional_json = ",\"optimal\":{\"spmv\":\"csr\"}";
initialize_argument_parsing(&argc, &argv, header, format);

std::stringstream ss_rel_res_goal;
Expand Down
19 changes: 18 additions & 1 deletion benchmark/utils/general.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@ DEFINE_string(double_buffer, "",
DEFINE_string(
input, "",
"If set, the value is used as the input for the benchmark (if set to a "
"json string ending with ]) or as input file path (otherwise).");
"json string ending with ]), as the \"filename\" of a generated JSON input "
"(if the variable points to a MatrixMarket or Ginkgo binary matrix file) "
"or as JSON input file path (otherwise).");

DEFINE_bool(detailed, true,
"If set, performs several runs to obtain more detailed results");
Expand Down Expand Up @@ -297,6 +299,12 @@ std::vector<std::string> split(const std::string& s, char delimiter = ',')
}


// allow matrix files as -input value
bool matrix_input = true;
// additional JSON to append to the input_str if the input file is a matrix file
std::string matrix_input_additional_json = "";


// returns the stream to be used as input of the application
std::istream& get_input_stream()
{
Expand All @@ -308,6 +316,15 @@ std::istream& get_input_stream()
if (input_str.back() == ']') {
return std::make_unique<std::stringstream>(input_str);
}
if (matrix_input) {
auto first_char = std::ifstream{input_str}.peek();
// if the input looks like a MatrixMarket or Ginkgo binary file
if (first_char == '%' || first_char == 'G') {
input_str = "[{\"filename\":\"" + input_str + "\"" +
matrix_input_additional_json + "}]";
return std::make_unique<std::stringstream>(input_str);
}
}
return std::make_unique<std::ifstream>(input_str);
}();
if (stream) {
Expand Down

0 comments on commit 92d9f57

Please sign in to comment.