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
10 changes: 5 additions & 5 deletions core/base/block_operator.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2017 - 2025 The Ginkgo authors
// SPDX-FileCopyrightText: 2017 - 2026 The Ginkgo authors
//
// SPDX-License-Identifier: BSD-3-Clause

Expand Down Expand Up @@ -153,14 +153,14 @@ std::unique_ptr<BlockOperator> BlockOperator::create(


BlockOperator::BlockOperator(std::shared_ptr<const Executor> exec)
: EnableLinOp<BlockOperator>(std::move(exec))
: EnableClonableLinOp<BlockOperator>(std::move(exec))
{}


BlockOperator::BlockOperator(
std::shared_ptr<const Executor> exec,
std::vector<std::vector<std::shared_ptr<const LinOp>>> blocks)
: EnableLinOp<BlockOperator>(exec, compute_global_size(blocks)),
: EnableClonableLinOp<BlockOperator>(exec, compute_global_size(blocks)),
block_size_(blocks.empty()
? dim<2>{}
: dim<2>(blocks.size(), blocks.front().size())),
Expand Down Expand Up @@ -246,14 +246,14 @@ void BlockOperator::apply_impl(const LinOp* alpha, const LinOp* b,


BlockOperator::BlockOperator(const BlockOperator& other)
: EnableLinOp<BlockOperator>(other.get_executor())
: EnableClonableLinOp<BlockOperator>(other.get_executor())
{
*this = other;
}


BlockOperator::BlockOperator(BlockOperator&& other) noexcept
: EnableLinOp<BlockOperator>(other.get_executor())
: EnableClonableLinOp<BlockOperator>(other.get_executor())
{
*this = std::move(other);
}
Expand Down
7 changes: 4 additions & 3 deletions core/base/combination.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Combination<ValueType>& Combination<ValueType>::operator=(
const Combination& other)
{
if (&other != this) {
EnableLinOp<Combination>::operator=(other);
EnableClonableLinOp<Combination>::operator=(other);
auto exec = this->get_executor();
coefficients_ = other.coefficients_;
operators_ = other.operators_;
Expand All @@ -58,7 +58,7 @@ template <typename ValueType>
Combination<ValueType>& Combination<ValueType>::operator=(Combination&& other)
{
if (&other != this) {
EnableLinOp<Combination>::operator=(std::move(other));
EnableClonableLinOp<Combination>::operator=(std::move(other));
auto exec = this->get_executor();
coefficients_ = std::move(other.coefficients_);
operators_ = std::move(other.operators_);
Expand Down Expand Up @@ -99,7 +99,8 @@ std::unique_ptr<LinOp> Combination<ValueType>::transpose() const
transposed->set_size(gko::transpose(this->get_size()));
// copy coefficients
for (auto& coef : get_coefficients()) {
transposed->coefficients_.push_back(share(coef->clone()));
transposed->coefficients_.push_back(
share(as<LinOp>(as<ClonableObject>(coef)->clone())));
}
// transpose operators
for (auto& op : get_operators()) {
Expand Down
4 changes: 2 additions & 2 deletions core/base/composition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ Composition<ValueType>& Composition<ValueType>::operator=(
const Composition& other)
{
if (&other != this) {
EnableLinOp<Composition>::operator=(other);
EnableClonableLinOp<Composition>::operator=(other);
auto exec = this->get_executor();
operators_ = other.operators_;
// if the operators are on the wrong executor, copy them over
Expand All @@ -123,7 +123,7 @@ template <typename ValueType>
Composition<ValueType>& Composition<ValueType>::operator=(Composition&& other)
{
if (&other != this) {
EnableLinOp<Composition>::operator=(std::move(other));
EnableClonableLinOp<Composition>::operator=(std::move(other));
auto exec = this->get_executor();
operators_ = std::move(other.operators_);
// if the operators are on the wrong executor, copy them over
Expand Down
10 changes: 5 additions & 5 deletions core/base/perturbation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Perturbation<ValueType>& Perturbation<ValueType>::operator=(
const Perturbation& other)
{
if (&other != this) {
EnableLinOp<Perturbation>::operator=(other);
EnableClonableLinOp<Perturbation>::operator=(other);
auto exec = this->get_executor();
scalar_ = other.scalar_;
basis_ = other.basis_;
Expand All @@ -35,7 +35,7 @@ Perturbation<ValueType>& Perturbation<ValueType>::operator=(
Perturbation&& other)
{
if (&other != this) {
EnableLinOp<Perturbation>::operator=(std::move(other));
EnableClonableLinOp<Perturbation>::operator=(std::move(other));
auto exec = this->get_executor();
scalar_ = std::move(other.scalar_);
basis_ = std::move(other.basis_);
Expand Down Expand Up @@ -68,7 +68,7 @@ Perturbation<ValueType>::Perturbation(Perturbation&& other)

template <typename ValueType>
Perturbation<ValueType>::Perturbation(std::shared_ptr<const Executor> exec)
: EnableLinOp<Perturbation>(std::move(exec))
: EnableClonableLinOp<Perturbation>(std::move(exec))
{}


Expand All @@ -87,8 +87,8 @@ template <typename ValueType>
Perturbation<ValueType>::Perturbation(std::shared_ptr<const LinOp> scalar,
std::shared_ptr<const LinOp> basis,
std::shared_ptr<const LinOp> projector)
: EnableLinOp<Perturbation>(basis->get_executor(),
gko::dim<2>{basis->get_size()[0]}),
: EnableClonableLinOp<Perturbation>(basis->get_executor(),
gko::dim<2>{basis->get_size()[0]}),
basis_{std::move(basis)},
projector_{std::move(projector)},
scalar_{std::move(scalar)}
Expand Down
67 changes: 41 additions & 26 deletions core/distributed/matrix.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2017 - 2025 The Ginkgo authors
// SPDX-FileCopyrightText: 2017 - 2026 The Ginkgo authors
//
// SPDX-License-Identifier: BSD-3-Clause

Expand Down Expand Up @@ -49,13 +49,13 @@ Matrix<ValueType, LocalIndexType, GlobalIndexType>::Matrix(
std::shared_ptr<const RowGatherer<LocalIndexType>> row_gather_template,
ptr_param<const LinOp> local_matrix_template,
ptr_param<const LinOp> non_local_matrix_template)
: EnableLinOp<Matrix>{exec},
: EnableClonableLinOp<Matrix>{exec},
DistributedBase{row_gather_template->get_communicator()},
row_gatherer_{row_gather_template->clone(exec)},
row_gatherer_{clone(exec, row_gather_template)},
imap_{exec},
one_scalar_{exec, 1.0},
local_mtx_{local_matrix_template->clone(exec)},
non_local_mtx_{non_local_matrix_template->clone(exec)}
local_mtx_{clone(exec, local_matrix_template.get())},
non_local_mtx_{clone(exec, non_local_matrix_template.get())}
{
GKO_ASSERT(
(dynamic_cast<ReadableFromMatrixData<ValueType, LocalIndexType>*>(
Expand All @@ -69,7 +69,7 @@ template <typename ValueType, typename LocalIndexType, typename GlobalIndexType>
Matrix<ValueType, LocalIndexType, GlobalIndexType>::Matrix(
std::shared_ptr<const Executor> exec, mpi::communicator comm, dim<2> size,
std::shared_ptr<LinOp> local_linop)
: EnableLinOp<Matrix>{exec},
: EnableClonableLinOp<Matrix>{exec},
DistributedBase{comm},
row_gatherer_{RowGatherer<LocalIndexType>::create(
exec, mpi::detail::create_default_collective_communicator(comm))},
Expand All @@ -87,7 +87,7 @@ Matrix<ValueType, LocalIndexType, GlobalIndexType>::Matrix(
std::shared_ptr<const Executor> exec, mpi::communicator comm,
index_map<LocalIndexType, GlobalIndexType> imap,
std::shared_ptr<LinOp> local_linop, std::shared_ptr<LinOp> non_local_linop)
: EnableLinOp<Matrix>{exec},
: EnableClonableLinOp<Matrix>{exec},
DistributedBase{comm},
row_gatherer_(RowGatherer<LocalIndexType>::create(
exec,
Expand Down Expand Up @@ -206,9 +206,12 @@ void Matrix<ValueType, LocalIndexType, GlobalIndexType>::convert_to(
{
GKO_ASSERT(this->get_communicator().size() ==
result->get_communicator().size());
result->local_mtx_->copy_from(this->local_mtx_);
result->non_local_mtx_->copy_from(this->non_local_mtx_);
result->row_gatherer_->copy_from(this->row_gatherer_);
as<ClonableObject>(result->local_mtx_)
->copy_from(as<ClonableObject>(this->local_mtx_));
as<ClonableObject>(result->non_local_mtx_)
->copy_from(as<ClonableObject>(this->non_local_mtx_));
as<ClonableObject>(result->row_gatherer_)
->copy_from(as<ClonableObject>(this->row_gatherer_));
result->imap_ = this->imap_;
result->set_size(this->get_size());
}
Expand All @@ -221,9 +224,12 @@ void Matrix<ValueType, LocalIndexType, GlobalIndexType>::move_to(
{
GKO_ASSERT(this->get_communicator().size() ==
result->get_communicator().size());
result->local_mtx_->move_from(this->local_mtx_);
result->non_local_mtx_->move_from(this->non_local_mtx_);
result->row_gatherer_->move_from(this->row_gatherer_);
as<ClonableObject>(result->local_mtx_)
->move_from(as<ClonableObject>(this->local_mtx_));
as<ClonableObject>(result->non_local_mtx_)
->move_from(as<ClonableObject>(this->non_local_mtx_));
as<ClonableObject>(result->row_gatherer_)
->move_from(as<ClonableObject>(this->row_gatherer_));
result->imap_ = std::move(this->imap_);
result->set_size(this->get_size());
this->set_size({});
Expand All @@ -238,9 +244,12 @@ void Matrix<ValueType, LocalIndexType, GlobalIndexType>::convert_to(
{
GKO_ASSERT(this->get_communicator().size() ==
result->get_communicator().size());
result->local_mtx_->copy_from(this->local_mtx_.get());
result->non_local_mtx_->copy_from(this->non_local_mtx_.get());
result->row_gatherer_->copy_from(this->row_gatherer_);
as<ClonableObject>(result->local_mtx_)
->copy_from(as<ClonableObject>(this->local_mtx_.get()));
as<ClonableObject>(result->non_local_mtx_)
->copy_from(as<ClonableObject>(this->non_local_mtx_.get()));
as<ClonableObject>(result->row_gatherer_)
->copy_from(as<ClonableObject>(this->row_gatherer_));
result->imap_ = this->imap_;
result->set_size(this->get_size());
}
Expand Down Expand Up @@ -671,8 +680,8 @@ void Matrix<ValueType, LocalIndexType, GlobalIndexType>::row_scale(

template <typename ValueType, typename LocalIndexType, typename GlobalIndexType>
Matrix<ValueType, LocalIndexType, GlobalIndexType>::Matrix(const Matrix& other)
: EnableLinOp<Matrix<value_type, local_index_type,
global_index_type>>{other.get_executor()},
: EnableClonableLinOp<Matrix<value_type, local_index_type,
global_index_type>>{other.get_executor()},
DistributedBase{other.get_communicator()},
row_gatherer_{RowGatherer<LocalIndexType>::create(
other.get_executor(), other.get_communicator())},
Expand All @@ -686,8 +695,8 @@ Matrix<ValueType, LocalIndexType, GlobalIndexType>::Matrix(const Matrix& other)
template <typename ValueType, typename LocalIndexType, typename GlobalIndexType>
Matrix<ValueType, LocalIndexType, GlobalIndexType>::Matrix(
Matrix&& other) noexcept
: EnableLinOp<Matrix<value_type, local_index_type,
global_index_type>>{other.get_executor()},
: EnableClonableLinOp<Matrix<value_type, local_index_type,
global_index_type>>{other.get_executor()},
DistributedBase{other.get_communicator()},
row_gatherer_{RowGatherer<LocalIndexType>::create(
other.get_executor(), other.get_communicator())},
Expand All @@ -707,9 +716,12 @@ Matrix<ValueType, LocalIndexType, GlobalIndexType>::operator=(
GKO_ASSERT_EQ(other.get_communicator().size(),
this->get_communicator().size());
this->set_size(other.get_size());
local_mtx_->copy_from(other.local_mtx_);
non_local_mtx_->copy_from(other.non_local_mtx_);
row_gatherer_->copy_from(other.row_gatherer_);
as<ClonableObject>(local_mtx_)
->copy_from(as<ClonableObject>(other.local_mtx_));
as<ClonableObject>(non_local_mtx_)
->copy_from(as<ClonableObject>(other.non_local_mtx_));
as<ClonableObject>(row_gatherer_)
->copy_from(as<ClonableObject>(other.row_gatherer_));
imap_ = other.imap_;
}
return *this;
Expand All @@ -725,9 +737,12 @@ Matrix<ValueType, LocalIndexType, GlobalIndexType>::operator=(Matrix&& other)
this->get_communicator().size());
this->set_size(other.get_size());
other.set_size({});
local_mtx_->move_from(other.local_mtx_);
non_local_mtx_->move_from(other.non_local_mtx_);
row_gatherer_->move_from(other.row_gatherer_);
as<ClonableObject>(local_mtx_)
->move_from(as<ClonableObject>(other.local_mtx_));
as<ClonableObject>(non_local_mtx_)
->move_from(as<ClonableObject>(other.non_local_mtx_));
as<ClonableObject>(row_gatherer_)
->move_from(as<ClonableObject>(other.row_gatherer_));
imap_ = std::move(other.imap_);
}
return *this;
Expand Down
6 changes: 3 additions & 3 deletions core/distributed/vector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ template <typename ValueType>
Vector<ValueType>::Vector(std::shared_ptr<const Executor> exec,
mpi::communicator comm, dim<2> global_size,
dim<2> local_size, size_type stride)
: EnableLinOp<Vector>{exec, global_size},
: EnableClonableLinOp<Vector>{exec, global_size},
DistributedBase{comm},
local_{exec, local_size, stride}
{
Expand All @@ -74,7 +74,7 @@ template <typename ValueType>
Vector<ValueType>::Vector(std::shared_ptr<const Executor> exec,
mpi::communicator comm, dim<2> global_size,
std::unique_ptr<local_vector_type> local_vector)
: EnableLinOp<Vector>{exec, global_size},
: EnableClonableLinOp<Vector>{exec, global_size},
DistributedBase{comm},
local_{exec}
{
Expand All @@ -86,7 +86,7 @@ template <typename ValueType>
Vector<ValueType>::Vector(std::shared_ptr<const Executor> exec,
mpi::communicator comm,
std::unique_ptr<local_vector_type> local_vector)
: EnableLinOp<Vector>{exec, {}}, DistributedBase{comm}, local_{exec}
: EnableClonableLinOp<Vector>{exec, {}}, DistributedBase{comm}, local_{exec}
{
this->set_size(compute_global_size(exec, comm, local_vector->get_size()));
local_vector->move_to(&local_);
Expand Down
17 changes: 14 additions & 3 deletions core/factorization/factorization.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 - 2026 The Ginkgo authors
//
// SPDX-License-Identifier: BSD-3-Clause

Expand Down Expand Up @@ -39,8 +39,19 @@ Factorization<ValueType, IndexType>::unpack() const
case storage_type::empty:
GKO_NOT_SUPPORTED(nullptr);
case storage_type::composition:
case storage_type::symm_composition:
return this->clone();
case storage_type::symm_composition: {
// bring the original clone function here
auto clone = std::unique_ptr<Factorization>{
new Factorization{this->get_executor()}};
clone->EnableLinOp<Factorization<ValueType, IndexType>>::operator=(
*this);
clone->storage_type_ = storage_type_;
// composition clone only copy the pointer when they are on the same
// executor
clone->factors_ = Composition<ValueType>::create(
factors_->get_operators().begin(), factors_->get_operators().end());
return clone;
}
case storage_type::combined_lu: {
// count nonzeros
array<index_type> l_row_ptrs{exec, size[0] + 1};
Expand Down
10 changes: 7 additions & 3 deletions core/log/convergence.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,18 @@ void Convergence<ValueType>::on_iteration_complete(
}
this->num_iterations_ = num_iterations;
if (residual != nullptr) {
this->residual_.reset(residual->clone().release());
this->residual_.reset(
as<LinOp>(as<ClonableObject>(residual)->clone()).release());
}
if (implicit_resnorm_sq != nullptr) {
this->implicit_sq_resnorm_.reset(
implicit_resnorm_sq->clone().release());
as<LinOp>(as<ClonableObject>(implicit_resnorm_sq)->clone())
.release());
}
if (residual_norm != nullptr) {
this->residual_norm_.reset(residual_norm->clone().release());
this->residual_norm_.reset(
as<LinOp>(as<ClonableObject>(residual_norm)->clone())
.release());
} else if (residual != nullptr) {
using NormVector = matrix::Dense<remove_complex<ValueType>>;
detail::vector_dispatch<ValueType>(
Expand Down
4 changes: 2 additions & 2 deletions core/matrix/coo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ Coo<ValueType, IndexType>::create_const(
template <typename ValueType, typename IndexType>
Coo<ValueType, IndexType>::Coo(std::shared_ptr<const Executor> exec,
const dim<2>& size, size_type num_nonzeros)
: EnableLinOp<Coo>(exec, size),
: EnableClonableLinOp<Coo>(exec, size),
values_(exec, num_nonzeros),
col_idxs_(exec, num_nonzeros),
row_idxs_(exec, num_nonzeros)
Expand All @@ -102,7 +102,7 @@ Coo<ValueType, IndexType>::Coo(std::shared_ptr<const Executor> exec,
const dim<2>& size, array<value_type> values,
array<index_type> col_idxs,
array<index_type> row_idxs)
: EnableLinOp<Coo>(exec, size),
: EnableClonableLinOp<Coo>(exec, size),
values_{exec, std::move(values)},
col_idxs_{exec, std::move(col_idxs)},
row_idxs_{exec, std::move(row_idxs)}
Expand Down
8 changes: 4 additions & 4 deletions core/matrix/csr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ template <typename ValueType, typename IndexType>
Csr<ValueType, IndexType>::Csr(std::shared_ptr<const Executor> exec,
const dim<2>& size, size_type num_nonzeros,
std::shared_ptr<strategy_type> strategy)
: EnableLinOp<Csr>(exec, size),
: EnableClonableLinOp<Csr>(exec, size),
strategy_(strategy ? strategy->copy() : Csr::make_default_strategy(exec)),
values_(exec, num_nonzeros),
col_idxs_(exec, num_nonzeros),
Expand All @@ -179,7 +179,7 @@ Csr<ValueType, IndexType>::Csr(std::shared_ptr<const Executor> exec,
array<index_type> col_idxs,
array<index_type> row_ptrs,
std::shared_ptr<strategy_type> strategy)
: EnableLinOp<Csr>(exec, size),
: EnableClonableLinOp<Csr>(exec, size),
strategy_(strategy ? strategy->copy() : Csr::make_default_strategy(exec)),
values_{exec, std::move(values)},
col_idxs_{exec, std::move(col_idxs)},
Expand All @@ -197,7 +197,7 @@ Csr<ValueType, IndexType>& Csr<ValueType, IndexType>::operator=(
const Csr<ValueType, IndexType>& other)
{
if (&other != this) {
EnableLinOp<Csr>::operator=(other);
EnableClonableLinOp<Csr>::operator=(other);
// NOTE: as soon as strategies are improved, this can be reverted
values_ = other.values_;
col_idxs_ = other.col_idxs_;
Expand All @@ -219,7 +219,7 @@ Csr<ValueType, IndexType>& Csr<ValueType, IndexType>::operator=(
Csr<ValueType, IndexType>&& other)
{
if (&other != this) {
EnableLinOp<Csr>::operator=(std::move(other));
EnableClonableLinOp<Csr>::operator=(std::move(other));
values_ = std::move(other.values_);
col_idxs_ = std::move(other.col_idxs_);
row_ptrs_ = std::move(other.row_ptrs_);
Expand Down
Loading
Loading