-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
216 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// 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> | ||
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) = val; | ||
output(row, col) += alpha_val * 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[0] * update_sol(row, col); | ||
inner_sol(row, col) = val; | ||
update_sol(row, col) = val; | ||
output(row, col) += alpha[0] * 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// SPDX-FileCopyrightText: 2017 - 2025 The Ginkgo authors | ||
// | ||
// SPDX-License-Identifier: BSD-3-Clause | ||
|
||
#ifndef GKO_CORE_SOLVER_CHEBYSHEV_KERNELS_HPP_ | ||
#define GKO_CORE_SOLVER_CHEBYSHEV_KERNELS_HPP_ | ||
|
||
|
||
#include <memory> | ||
|
||
#include <ginkgo/core/base/executor.hpp> | ||
#include <ginkgo/core/base/types.hpp> | ||
#include <ginkgo/core/matrix/dense.hpp> | ||
|
||
#include "core/base/kernel_declaration.hpp" | ||
|
||
|
||
namespace gko { | ||
namespace kernels { | ||
namespace chebyshev { | ||
|
||
|
||
#define GKO_DECLARE_CHEBYSHEV_INIT_UPDATE_KERNEL(ValueType, ScalarType) \ | ||
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) | ||
|
||
#define GKO_DECLARE_CHEBYSHEV_UPDATE_KERNEL(ValueType, 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) | ||
|
||
#define GKO_DECLARE_ALL_AS_TEMPLATES \ | ||
template <typename ValueType, typename ScalarType> \ | ||
GKO_DECLARE_CHEBYSHEV_INIT_UPDATE_KERNEL(ValueType, ScalarType); \ | ||
template <typename ValueType, typename ScalarType> \ | ||
GKO_DECLARE_CHEBYSHEV_UPDATE_KERNEL(ValueType, ScalarType) | ||
|
||
|
||
} // namespace chebyshev | ||
|
||
|
||
GKO_DECLARE_FOR_ALL_EXECUTOR_NAMESPACES(chebyshev, | ||
GKO_DECLARE_ALL_AS_TEMPLATES); | ||
|
||
|
||
#undef GKO_DECLARE_ALL_AS_TEMPLATES | ||
|
||
|
||
} // namespace kernels | ||
} // namespace gko | ||
|
||
|
||
#endif // GKO_CORE_SOLVER_CHEBYSHEV_KERNELS_HPP_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// 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> | ||
|
||
namespace gko { | ||
namespace kernels { | ||
namespace reference { | ||
namespace chebyshev { | ||
|
||
|
||
template <typename ValueType, typename ScalarType> | ||
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) | ||
{ | ||
const auto alpha_val = alpha[0]; | ||
for (size_t row = 0; row < output->get_size()[0]; row++) { | ||
for (size_t col = 0; col < output->get_size()[1]; col++) { | ||
const auto inner_val = inner_sol->at(row, col); | ||
update_sol->at(row, col) = inner_val; | ||
output->at(row, col) += alpha_val * inner_val; | ||
} | ||
} | ||
} | ||
|
||
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, | ||
const matrix::Dense<ValueType>* inner_sol, | ||
matrix::Dense<ValueType>* update_sol, | ||
matrix::Dense<ValueType>* output) | ||
{ | ||
const auto alpha_val = alpha[0]; | ||
const auto beta_val = beta[0]; | ||
for (size_t row = 0; row < output->get_size()[0]; row++) { | ||
for (size_t col = 0; col < output->get_size()[1]; col++) { | ||
const auto val = | ||
inner_sol->at(row, col) + beta[0] * update_sol->at(row, col); | ||
inner_sol->at(row, col) = inner_val; | ||
update_sol->at(row, col) = inner_val; | ||
output->at(row, col) += alpha_val * inner_val; | ||
} | ||
} | ||
} | ||
|
||
GKO_INSTANTIATE_FOR_EACH_VALUE_AND_SCALAR_TYPE( | ||
GKO_DECLARE_CHEBYSHEV_UPDATE_KERNEL); | ||
|
||
|
||
} // namespace chebyshev | ||
} // namespace reference | ||
} // namespace kernels | ||
} // namespace gko |