Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add HDF5 input and output to reduction_to_band miniapp #975

Merged
merged 5 commits into from
Sep 29, 2023
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 48 additions & 6 deletions miniapp/miniapp_reduction_to_band.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <dlaf/eigensolver/reduction_to_band.h>
#include <dlaf/init.h>
#include <dlaf/matrix/copy.h>
#include <dlaf/matrix/hdf5.h>
#include <dlaf/matrix/index.h>
#include <dlaf/matrix/matrix.h>
#include <dlaf/matrix/matrix_mirror.h>
Expand All @@ -36,11 +37,19 @@ namespace {
using dlaf::Device;
using dlaf::SizeType;

#ifdef DLAF_WITH_HDF5
using dlaf::matrix::internal::FileHDF5;
#endif

struct Options
: dlaf::miniapp::MiniappOptions<dlaf::miniapp::SupportReal::Yes, dlaf::miniapp::SupportComplex::Yes> {
SizeType m;
SizeType mb;
SizeType b;
#ifdef DLAF_WITH_HDF5
std::optional<dlaf::matrix::internal::FileHDF5> input_file;
std::optional<dlaf::matrix::internal::FileHDF5> output_file;
#endif

Options(const pika::program_options::variables_map& vm)
: MiniappOptions(vm), m(vm["matrix-size"].as<SizeType>()), mb(vm["block-size"].as<SizeType>()),
Expand All @@ -53,6 +62,21 @@ struct Options

DLAF_ASSERT(b > 0 && (mb % b == 0), b, mb);

#ifdef DLAF_WITH_HDF5
if (vm.count("input-file") == 1) {
input_file = FileHDF5(vm["input-file"].as<std::string>(), FileHDF5::FileMode::readonly);

if (!vm["matrix-size"].defaulted()) {
std::cerr << "Warning! "
"Specified matrix size will be ignored because an input file has been specified."
<< std::endl;
}
}
if (vm.count("output-file") == 1) {
output_file = FileHDF5(vm["output-file"].as<std::string>(), FileHDF5::FileMode::readwrite);
}
#endif

if (do_check != dlaf::miniapp::CheckIterFreq::None) {
std::cerr << "Warning! At the moment result checking it is not implemented." << std::endl;
do_check = dlaf::miniapp::CheckIterFreq::None;
Expand Down Expand Up @@ -81,19 +105,25 @@ struct reductionToBandMiniapp {
Communicator world(MPI_COMM_WORLD);
CommunicatorGrid comm_grid(world, opts.grid_rows, opts.grid_cols, common::Ordering::ColumnMajor);

// Allocate memory for the matrix
const GlobalElementSize matrix_size(opts.m, opts.m);
const TileElementSize block_size(opts.mb, opts.mb);

ConstMatrixType matrix_ref = [matrix_size, block_size, comm_grid]() {
ConstMatrixType matrix_ref = [comm_grid, &opts]() {
#ifdef DLAF_WITH_HDF5
if (opts.input_file) {
Matrix<T, Device::CPU> input = opts.input_file->read<T>("/a", {opts.mb, opts.mb});
RMeli marked this conversation as resolved.
Show resolved Hide resolved
return input;
}
#endif
using dlaf::matrix::util::set_random_hermitian;

HostMatrixType hermitian(matrix_size, block_size, comm_grid);
HostMatrixType hermitian(GlobalElementSize(opts.m, opts.m), TileElementSize(opts.mb, opts.mb),
comm_grid);
set_random_hermitian(hermitian);

return hermitian;
}();

auto matrix_size = matrix_ref.size();
auto block_size = matrix_ref.blockSize();

for (int64_t run_index = -opts.nwarmups; run_index < opts.nruns; ++run_index) {
if (0 == world.rank() && run_index >= 0)
std::cout << "[" << run_index << "]" << std::endl;
Expand Down Expand Up @@ -136,6 +166,14 @@ struct reductionToBandMiniapp {
gigaflops = dlaf::total_ops<T>(add_mul, add_mul) / elapsed_time / 1e9;
}

#ifdef DLAF_WITH_HDF5
if (run_index == opts.nruns - 1) {
if (opts.output_file) {
opts.output_file->write<T>(matrix_host, "/band");
RMeli marked this conversation as resolved.
Show resolved Hide resolved
}
}
#endif

// print benchmark results
if (0 == world.rank() && run_index >= 0) {
std::cout << "[" << run_index << "]"
Expand Down Expand Up @@ -196,6 +234,10 @@ int main(int argc, char** argv) {
("matrix-size", value<SizeType>() ->default_value(4096), "Matrix rows")
("block-size", value<SizeType>() ->default_value( 256), "Block cyclic distribution size")
("band-size", value<SizeType>() ->default_value( -1), "Band size (a negative value implies band-size=block-size")
#ifdef DLAF_WITH_HDF5
("input-file", value<std::string>() , "Load matrix from given HDF5 file")
("output-file", value<std::string>() , "Save band matrix to given HDF5 file")
#endif
;
// clang-format on

Expand Down
Loading