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 chebyshev Iteration #1289

Open
wants to merge 18 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 17 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
2 changes: 2 additions & 0 deletions common/unified/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ set(UNIFIED_SOURCES
solver/bicgstab_kernels.cpp
solver/cg_kernels.cpp
solver/cgs_kernels.cpp
solver/cgs_kernels.cpp
solver/chebyshev_kernels.cpp
solver/common_gmres_kernels.cpp
solver/fcg_kernels.cpp
solver/gcr_kernels.cpp
Expand Down
65 changes: 65 additions & 0 deletions common/unified/solver/chebyshev_kernels.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// SPDX-FileCopyrightText: 2017 - 2025 The Ginkgo authors
//
// SPDX-License-Identifier: BSD-3-Clause

#include "core/solver/chebyshev_kernels.hpp"

#include <ginkgo/core/matrix/dense.hpp>

#include "common/unified/base/kernel_launch.hpp"


namespace gko {
namespace kernels {
namespace GKO_DEVICE_NAMESPACE {
namespace chebyshev {


template <typename ValueType, typename ScalarType>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this actually need a second precision, or can we always use the highest precision available? This is memory-bound after all.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have the same thought and thinking maybe we just use double or complex directly?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there is a numerical benefit to using a higher-precision multiplication every time, I would go for it

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

after rethink about it, I do not have a good way to use double or complex double without any information from the vector or matrix. Maybe still keep the same way as how we handle IR/richardson now. also I need the ScalarType, which is the ValueType from Chebyshev class

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

currently keep the value type of class but change fosi, alpha, beta type to double/complex
when dpcpp only support float not double, it will cast to float/complex internally to keep the same interface among all backends

void init_update(std::shared_ptr<const DefaultExecutor> exec,
const ScalarType alpha,
const matrix::Dense<ValueType>* inner_sol,
matrix::Dense<ValueType>* update_sol,
matrix::Dense<ValueType>* output)
{
run_kernel(
exec,
[] GKO_KERNEL(auto row, auto col, auto alpha, auto inner_sol,
auto update_sol, auto output) {
const auto inner_val = inner_sol(row, col);
update_sol(row, col) = inner_val;
output(row, col) += alpha * inner_val;
},
output->get_size(), alpha, inner_sol, update_sol, output);
}

GKO_INSTANTIATE_FOR_EACH_VALUE_AND_SCALAR_TYPE(
GKO_DECLARE_CHEBYSHEV_INIT_UPDATE_KERNEL);


template <typename ValueType, typename ScalarType>
void update(std::shared_ptr<const DefaultExecutor> exec, const ScalarType alpha,
const ScalarType beta, matrix::Dense<ValueType>* inner_sol,
matrix::Dense<ValueType>* update_sol,
matrix::Dense<ValueType>* output)
{
run_kernel(
exec,
[] GKO_KERNEL(auto row, auto col, auto alpha, auto beta, auto inner_sol,
auto update_sol, auto output) {
const auto val = inner_sol(row, col) + beta * update_sol(row, col);
inner_sol(row, col) = val;
update_sol(row, col) = val;
output(row, col) += alpha * val;
},
output->get_size(), alpha, beta, inner_sol, update_sol, output);
}

GKO_INSTANTIATE_FOR_EACH_VALUE_AND_SCALAR_TYPE(
GKO_DECLARE_CHEBYSHEV_UPDATE_KERNEL);


} // namespace chebyshev
} // namespace GKO_DEVICE_NAMESPACE
} // namespace kernels
} // namespace gko
3 changes: 2 additions & 1 deletion core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ target_sources(${ginkgo_core}
matrix/scaled_permutation.cpp
matrix/sellp.cpp
matrix/sparsity_csr.cpp
multigrid/pgm.cpp
multigrid/fixed_coarsening.cpp
multigrid/pgm.cpp
preconditioner/batch_jacobi.cpp
preconditioner/gauss_seidel.cpp
preconditioner/sor.cpp
Expand All @@ -112,6 +112,7 @@ target_sources(${ginkgo_core}
solver/cb_gmres.cpp
solver/cg.cpp
solver/cgs.cpp
solver/chebyshev.cpp
solver/direct.cpp
solver/fcg.cpp
solver/gcr.cpp
Expand Down
10 changes: 5 additions & 5 deletions core/config/config_helper.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 All @@ -24,10 +24,9 @@ namespace gko {
namespace config {


#define GKO_INVALID_CONFIG_VALUE(_entry, _value) \
GKO_INVALID_STATE(std::string("The value >" + _value + \
"< is invalid for the entry >" + _entry + \
"<"))
#define GKO_INVALID_CONFIG_VALUE(_entry, _value) \
GKO_INVALID_STATE(std::string("The value >") + _value + \
"< is invalid for the entry >" + _entry + "<")


#define GKO_MISSING_CONFIG_ENTRY(_entry) \
Expand All @@ -52,6 +51,7 @@ enum class LinOpFactoryType : int {
Direct,
LowerTrs,
UpperTrs,
Chebyshev,
Factorization_Ic,
Factorization_Ilu,
Cholesky,
Expand Down
3 changes: 2 additions & 1 deletion core/config/registry.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 @@ -32,6 +32,7 @@ configuration_map generate_config_map()
{"solver::Direct", parse<LinOpFactoryType::Direct>},
{"solver::LowerTrs", parse<LinOpFactoryType::LowerTrs>},
{"solver::UpperTrs", parse<LinOpFactoryType::UpperTrs>},
{"solver::Chebyshev", parse<LinOpFactoryType::Chebyshev>},
{"factorization::Ic", parse<LinOpFactoryType::Factorization_Ic>},
{"factorization::Ilu", parse<LinOpFactoryType::Factorization_Ilu>},
{"factorization::Cholesky", parse<LinOpFactoryType::Cholesky>},
Expand Down
4 changes: 3 additions & 1 deletion core/config/solver_config.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 All @@ -12,6 +12,7 @@
#include <ginkgo/core/solver/cb_gmres.hpp>
#include <ginkgo/core/solver/cg.hpp>
#include <ginkgo/core/solver/cgs.hpp>
#include <ginkgo/core/solver/chebyshev.hpp>
#include <ginkgo/core/solver/direct.hpp>
#include <ginkgo/core/solver/fcg.hpp>
#include <ginkgo/core/solver/gcr.hpp>
Expand Down Expand Up @@ -43,6 +44,7 @@ GKO_PARSE_VALUE_TYPE_BASE(CbGmres, gko::solver::CbGmres);
GKO_PARSE_VALUE_AND_INDEX_TYPE(Direct, gko::experimental::solver::Direct);
GKO_PARSE_VALUE_AND_INDEX_TYPE(LowerTrs, gko::solver::LowerTrs);
GKO_PARSE_VALUE_AND_INDEX_TYPE(UpperTrs, gko::solver::UpperTrs);
GKO_PARSE_VALUE_TYPE(Chebyshev, gko::solver::Chebyshev);


template <>
Expand Down
11 changes: 11 additions & 0 deletions core/device_hooks/common_kernels.inc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
#include "core/solver/cb_gmres_kernels.hpp"
#include "core/solver/cg_kernels.hpp"
#include "core/solver/cgs_kernels.hpp"
#include "core/solver/chebyshev_kernels.hpp"
#include "core/solver/common_gmres_kernels.hpp"
#include "core/solver/fcg_kernels.hpp"
#include "core/solver/gcr_kernels.hpp"
Expand Down Expand Up @@ -674,6 +675,16 @@ GKO_STUB_CB_GMRES_CONST(GKO_DECLARE_CB_GMRES_SOLVE_KRYLOV_KERNEL);
} // namespace cb_gmres


namespace chebyshev {


GKO_STUB_VALUE_AND_SCALAR_TYPE(GKO_DECLARE_CHEBYSHEV_INIT_UPDATE_KERNEL);
GKO_STUB_VALUE_AND_SCALAR_TYPE(GKO_DECLARE_CHEBYSHEV_UPDATE_KERNEL);


} // namespace chebyshev


namespace ir {


Expand Down
Loading
Loading