Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
6 changes: 5 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ if((NOT OGL_ALLOW_REFERENCE_ONLY) AND (NOT OGL_USE_EXTERNAL_GINKGO))
endif()

set(GINKGO_CHECKOUT_VERSION
"ogl_rebase_1.8.0"
"multilevel-schwarz"
CACHE STRING "Use specific version of ginkgo")

include(CheckIncludeFileCXX)
Expand Down Expand Up @@ -158,6 +158,8 @@ target_sources(
PRIVATE common/common.C
${CMAKE_CURRENT_BINARY_DIR}/version.C
lduLduBase/lduLduBase.C
HostMatrix/HostMatrix.C
HostMatrix/HostMatrixFreeFunctions.C
StoppingCriterion/StoppingCriterion.C
DevicePersistent/Base/Base.C
DevicePersistent/Partition/Partition.C
Expand All @@ -170,6 +172,8 @@ target_sources(
BaseWrapper/CoupledLduBase/GKOCoupledLduBase.C
Solver/CG/GKOCG.C
Solver/BiCGStab/GKOBiCGStab.C
# Solver / IR / GKOIR.C
Solver/Multigrid/GKOMultigrid.C
Solver/GMRES/GKOGMRES.C
PUBLIC common/common.H
StoppingCriterion/StoppingCriterion.H
Expand Down
51 changes: 22 additions & 29 deletions DevicePersistent/Array/Array.H
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,6 @@ class PersistentArray

mutable label size_;

const ExecutorHandler &exec_;

// indicating if the underlying array needs to
// updated even if was found in the object registry
const bool update_;
Expand Down Expand Up @@ -133,7 +131,6 @@ public:
ArrayInitFunctor<T>(exec, name, size, verbose, on_device), update,
verbose),
size_(size),
exec_(exec),
update_(update)
{}

Expand All @@ -160,7 +157,6 @@ public:
update, verbose),
memory_(memory),
size_(size),
exec_(exec),
update_(update)
{}

Expand All @@ -183,16 +179,16 @@ public:

/* Create a Dense<T> vector from underlying data
* */
std::shared_ptr<gko::matrix::Dense<T>> get_dense_vec() const
{
auto array = get_array();
auto result = gko::share(vec::create(
exec_.get_device_exec(), gko::dim<2>(array->get_num_elems(), 1),
gko::array<T>::view(exec_.get_device_exec(), array->get_num_elems(),
get_data()),
1));
return result;
}
// std::shared_ptr<gko::matrix::Dense<T>> get_dense_vec() const
// {
// auto array = get_array();
// auto result = gko::share(vec::create(
// exec_.get_device_exec(), gko::dim<2>(array->get_num_elems(), 1),
// gko::array<T>::view(exec_.get_device_exec(), array->get_num_elems(),
// get_data()),
// 1));
// return result;
// }

/* Copies from a distributed::Vector<T> back into raw host memory
*
Expand All @@ -201,31 +197,28 @@ public:
void copy_back(
const std::shared_ptr<gko::experimental::distributed::Vector<T>> dist_x)
{
auto host_view = gko::array<T>::view(exec_.get_ref_exec(), size_,
auto dist_device_exec = dist_x->get_executor();
auto host_view = gko::array<T>::view(dist_device_exec->get_master(), size_,
const_cast<T *>(memory_));

auto dist_device_exec = dist_x->get_executor();
auto x_view = gko::array<T>::view(dist_device_exec, size_,
dist_x->get_local()->get_values());

host_view = x_view;
}

void copy_back(const std::shared_ptr<gko::matrix::Dense<T>> device_x)
{
auto host_view = gko::array<T>::view(exec_.get_ref_exec(), size_,
const_cast<T *>(memory_));

auto x_view = gko::array<T>::view(exec_.get_device_exec(), size_,
device_x->get_values());

host_view = x_view;
}
// void copy_back(const std::shared_ptr<gko::matrix::Dense<T>> device_x)
// {
// auto host_view = gko::array<T>::view(exec_.get_ref_exec(), size_,
// const_cast<T *>(memory_));
//
// auto x_view = gko::array<T>::view(exec_.get_device_exec(), size_,
// device_x->get_values());
//
// host_view = x_view;
// }

void set_size(const label size) const { size_ = size; }


const ExecutorHandler &get_exec_handler() const { return exec_; }
};

} // namespace Foam
6 changes: 6 additions & 0 deletions DevicePersistent/Base/Base.C
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,10 @@ defineTemplateTypeNameWithName(DevicePersistentBase<gko::LinOp>,
typedef gko::experimental::distributed::Matrix<scalar, label, label> GkoMatrix;
defineTemplateTypeNameWithName(DevicePersistentBase<GkoMatrix>,
"PersistentMatrix");

// typedef needed to avoid confusion with the comma separated template
// arguments as macro arguments
typedef gko::experimental::distributed::Partition<label,label> Partition;
defineTemplateTypeNameWithName(DevicePersistentBase<Partition>,
"PersistentPartition");
} // namespace Foam
91 changes: 60 additions & 31 deletions DevicePersistent/CsrMatrixWrapper/CsrMatrixWrapper.H
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ struct MatrixInitFunctor {

const PersistentArray<scalar> &non_local_coeffs_;

const CommunicationPattern &communication_pattern_;

const word matrix_format_;

const bool regenerate_;
Expand All @@ -54,6 +56,7 @@ struct MatrixInitFunctor {
const PersistentArray<label> &non_local_col_idxs,
const PersistentArray<label> &non_local_row_idxs,
const PersistentArray<scalar> &non_local_coeffs,
const CommunicationPattern &communication_pattern,
const word matrix_format, const bool regenerate,
const label verbose, const word field_name)
: db_(db),
Expand All @@ -65,6 +68,7 @@ struct MatrixInitFunctor {
non_local_col_idxs_(non_local_col_idxs),
non_local_row_idxs_(non_local_row_idxs),
non_local_coeffs_(non_local_coeffs),
communication_pattern_(communication_pattern),
matrix_format_(matrix_format),
regenerate_(regenerate),
verbose_(verbose),
Expand Down Expand Up @@ -101,15 +105,6 @@ struct MatrixInitFunctor {
(gko::matrix::Csr<scalar, label> *)non_local_matrix.get();
non_local_value_ptr = non_local_coo_ptr->get_values();
}
if (matrix_format_ == "Ell") {
gko::matrix::Ell<scalar, label> *coo_ptr =
(gko::matrix::Ell<scalar, label> *)local_matrix.get();
value_ptr = coo_ptr->get_values();

gko::matrix::Ell<scalar, label> *non_local_coo_ptr =
(gko::matrix::Ell<scalar, label> *)non_local_matrix.get();
non_local_value_ptr = non_local_coo_ptr->get_values();
}
if (matrix_format_ == "Coo") {
gko::matrix::Coo<scalar, label> *coo_ptr =
(gko::matrix::Coo<scalar, label> *)local_matrix.get();
Expand All @@ -119,6 +114,10 @@ struct MatrixInitFunctor {
(gko::matrix::Coo<scalar, label> *)non_local_matrix.get();
non_local_value_ptr = non_local_coo_ptr->get_values();
}
if (matrix_format_ == "Ell") {
FatalErrorInFunction << "Updating Ell matrices not supported"
<< "set: 'regenerate true;'" << abort(FatalError);
}

gko::array<scalar> device_values{device_exec, *coeffs.get()};
gko::array<scalar> device_non_local_values{device_exec,
Expand All @@ -137,23 +136,55 @@ struct MatrixInitFunctor {

std::shared_ptr<dist_mtx> generate_dist_mtx_with_inner_type(
std::shared_ptr<gko::Executor> exec,
std::shared_ptr<gko::experimental::mpi::communicator> comm) const
std::shared_ptr<gko::experimental::mpi::communicator> comm,
gko::dim<2> global_dim,
gko::device_matrix_data<scalar, label> &local_A_data,
gko::device_matrix_data<scalar, label> &non_local_A_data) const
{
auto [recv_sizes, recv_offsets] =
communication_pattern_.recv_sizes_offsets(comm);
auto recv_gather_idxs =
communication_pattern_.total_rank_send_idx(exec->get_master());

if (matrix_format_ == "Csr") {
return dist_mtx::create(exec, *comm.get(),
gko::with_matrix_type<gko::matrix::Csr>());
}
if (matrix_format_ == "Ell") {
return dist_mtx::create(exec, *comm.get(),
gko::with_matrix_type<gko::matrix::Ell>());
auto local_linop =
gko::share(gko::matrix::Csr<scalar, label>::create(exec));
local_linop->read(local_A_data);
auto non_local_linop =
gko::share(gko::matrix::Csr<scalar, label>::create(exec));
non_local_linop->read(non_local_A_data);
return dist_mtx::create(exec, *comm.get(), global_dim, local_linop,
non_local_linop,
recv_sizes, recv_offsets,
recv_gather_idxs
);
}
// if (matrix_format_ == "Hybrid") {
// return dist_mtx::create(
// *comm.get(), gko::with_matrix_type<gko::matrix::Hybrid>());
// }
if (matrix_format_ == "Coo") {
return dist_mtx::create(exec, *comm.get(),
gko::with_matrix_type<gko::matrix::Coo>());
auto local_linop =
gko::share(gko::matrix::Coo<scalar, label>::create(exec));
local_linop->read(local_A_data);
auto non_local_linop =
gko::share(gko::matrix::Coo<scalar, label>::create(exec));
non_local_linop->read(non_local_A_data);

auto dist = dist_mtx::create(
exec, *comm.get(), global_dim, local_linop, non_local_linop,
recv_sizes, recv_offsets, recv_gather_idxs);
return dist;
}

if (matrix_format_ == "Ell") {
auto local_linop =
gko::share(gko::matrix::Ell<scalar, label>::create(exec));
local_linop->read(local_A_data);
auto non_local_linop =
gko::share(gko::matrix::Coo<scalar, label>::create(exec));
non_local_linop->read(non_local_A_data);

auto dist = dist_mtx::create(
exec, *comm.get(), global_dim, local_linop, non_local_linop,
recv_sizes, recv_offsets, recv_gather_idxs);
return dist;
}

FatalErrorInFunction << "Matrix format " << matrix_format_
Expand All @@ -178,6 +209,7 @@ struct MatrixInitFunctor {
auto exec = exec_.get_ref_exec();

auto num_rows = partition_.get_local_size();
auto global_num_rows = partition_.get_total_size();
gko::device_matrix_data<scalar, label> A_data(
exec, gko::dim<2>(num_rows, num_rows), *rows.get(), *cols.get(),
*coeffs.get());
Expand All @@ -187,15 +219,12 @@ struct MatrixInitFunctor {
*non_local_rows.get(), *non_local_cols.get(),
*non_local_coeffs.get());


auto comm = exec_.get_gko_mpi_host_comm();
auto dist_A = generate_dist_mtx_with_inner_type(
exec_.get_ref_exec(), exec_.get_gko_mpi_host_comm());

auto device_mat = generate_dist_mtx_with_inner_type(
exec_.get_device_exec(), exec_.get_gko_mpi_device_comm());
dist_A->move_to(device_mat.get());
return device_mat;
return generate_dist_mtx_with_inner_type(
exec_.get_device_exec(), exec_.get_gko_mpi_host_comm(),
gko::dim<2>{global_num_rows, global_num_rows}, A_data,
non_local_A_data);
}
};

Expand All @@ -219,7 +248,6 @@ private:

mutable label prev_solve_iters_ = 0;


public:
MatrixWrapper(const objectRegistry &db, const PersistentExecutor &exec,
const PersistentArray<label> &col_idxs,
Expand All @@ -228,6 +256,7 @@ public:
const PersistentArray<label> &non_local_col_idxs,
const PersistentArray<label> &non_local_row_idxs,
const PersistentArray<scalar> &non_local_coeffs,
const CommunicationPattern &communication_pattern,
const PersistentPartition &partition,
const dictionary &controlDict, const word sys_matrix_name,
const label verbose)
Expand All @@ -242,7 +271,7 @@ public:
MatrixInitFunctor(
db, exec, partition, col_idxs, row_idxs, coeffs,
non_local_col_idxs, non_local_row_idxs, non_local_coeffs,
matrix_format_,
communication_pattern, matrix_format_,
controlDict.lookupOrDefault<Switch>("regenerate", false),
verbose_, sys_matrix_name),
controlDict.lookupOrDefault<Switch>("updateSysMatrix", true),
Expand Down
2 changes: 1 addition & 1 deletion DevicePersistent/ExecutorHandler/ExecutorHandler.H
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ struct ExecutorInitFunctor {
return gko::share(gko::CudaExecutor::create(
device_id_ % gko::CudaExecutor::get_num_devices(), host_exec));
}
if (executor_name_ == "sycl" || "dpcpp") {
if (executor_name_ == "sycl" || executor_name_ == "dpcpp") {
if (version.dpcpp_version.tag == not_compiled_tag) {
FatalErrorInFunction
<< "SYCL Backend was not compiled. Recompile OGL/Ginkgo "
Expand Down
11 changes: 6 additions & 5 deletions DevicePersistent/Partition/Partition.H
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,11 @@ struct PartitionInitFunctor {
std::to_string(local_size_)};
LOG_1(verbose_, msg)

if (ranks_per_gpu_ == 1) return {};

auto host_partition = gko::share(gko::experimental::distributed::build_partition_from_local_size<label,label>(
exec, *comm.get(), local_size_));

return host_partition;
}
};

Expand All @@ -84,8 +88,6 @@ class PersistentPartition

mutable label global_elements_;

const ExecutorHandler &exec_;

public:
using part_type = gko::experimental::distributed::Partition<label, label>;
/* PersistentPartition constructor using existing memory
Expand All @@ -107,8 +109,7 @@ public:
communication_pattern),
false, verbose),
ranks_per_gpu_(ranks_per_gpu),
local_elements_(elements),
exec_(exec)
local_elements_(elements)
{
auto comm = exec.get_gko_mpi_host_comm();
label local_elements = local_elements_;
Expand Down
Loading