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

Preconditioner and Factorization config #1479

Merged
merged 11 commits into from
May 28, 2024
4 changes: 4 additions & 0 deletions core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ target_sources(ginkgo
base/version.cpp
config/config.cpp
config/config_helper.cpp
config/factorization_config.cpp
config/preconditioner_config.cpp
config/property_tree.cpp
config/registry.cpp
config/solver_config.cpp
Expand Down Expand Up @@ -71,6 +73,8 @@ target_sources(ginkgo
multigrid/pgm.cpp
multigrid/fixed_coarsening.cpp
preconditioner/batch_jacobi.cpp
preconditioner/ic.cpp
preconditioner/ilu.cpp
preconditioner/isai.cpp
preconditioner/jacobi.cpp
reorder/amd.cpp
Expand Down
2 changes: 1 addition & 1 deletion core/config/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ deferred_factory_parameter<gko::LinOpFactory> parse(const pnode& config,
obj.get_string());
return func(config, context, td);
}
GKO_INVALID_STATE("Should contain type property");
GKO_MISSING_CONFIG_ENTRY("type");
}


Expand Down
82 changes: 77 additions & 5 deletions core/config/config_helper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@ 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_MISSING_CONFIG_ENTRY(_entry) \
GKO_INVALID_STATE(std::string("The entry >") + _entry + "< is missing")


/**
* LinOpFactoryType enum is to avoid forward declaration, linopfactory header,
* two template versions of parse
Expand All @@ -43,7 +53,19 @@ enum class LinOpFactoryType : int {
CbGmres,
Direct,
LowerTrs,
UpperTrs
UpperTrs,
Factorization_Ic,
Factorization_Ilu,
Cholesky,
Lu,
ParIc,
ParIct,
ParIlu,
ParIlut,
Ic,
Ilu,
Isai,
Jacobi
};


Expand Down Expand Up @@ -82,15 +104,31 @@ deferred_factory_parameter<T> parse_or_get_factory(const pnode& config,
const registry& context,
const type_descriptor& td);

/**
* specialize for const LinOpFactory
*/
template <typename T>
inline deferred_factory_parameter<typename T::Factory>
parse_or_get_specific_factory(const pnode& config, const registry& context,
const type_descriptor& td)
{
using T_non_const = std::remove_const_t<T>;

if (config.get_tag() == pnode::tag_t::string) {
return detail::registry_accessor::get_data<
typename T_non_const::Factory>(context, config.get_string());
} else if (config.get_tag() == pnode::tag_t::map) {
return T_non_const::parse(config, context, td);
} else {
GKO_INVALID_STATE("The data of config is not valid.");
}
}


template <>
deferred_factory_parameter<const LinOpFactory>
parse_or_get_factory<const LinOpFactory>(const pnode& config,
const registry& context,
const type_descriptor& td);


/**
* specialize for const stop::CriterionFactory
*/
Expand Down Expand Up @@ -222,7 +260,41 @@ get_value(const pnode& config)
} else if (val == "provided") {
return solver::initial_guess_mode::provided;
}
GKO_INVALID_STATE("Wrong value for initial_guess_mode");
GKO_INVALID_CONFIG_VALUE("default_initial_guess", val);
}


template <typename Type>
inline typename std::enable_if<std::is_same<Type, precision_reduction>::value,
Type>::type
get_value(const pnode& config)
{
using T = typename Type::storage_type;
if (config.get_tag() == pnode::tag_t::array &&
config.get_array().size() == 2) {
return Type(get_value<T>(config.get(0)), get_value<T>(config.get(1)));
}
GKO_INVALID_STATE("should use size 2 array");
}


template <typename Csr>
inline std::shared_ptr<typename Csr::strategy_type> get_strategy(
const pnode& config)
{
auto str = config.get_string();
std::shared_ptr<typename Csr::strategy_type> strategy_ptr;
// automatical and load_balance requires the executor
if (str == "sparselib" || str == "cusparse") {
strategy_ptr = std::make_shared<typename Csr::sparselib>();
} else if (str == "merge_path") {
strategy_ptr = std::make_shared<typename Csr::merge_path>();
} else if (str == "classical") {
strategy_ptr = std::make_shared<typename Csr::classical>();
} else {
GKO_INVALID_CONFIG_VALUE("strategy", str);
}
yhmtsai marked this conversation as resolved.
Show resolved Hide resolved
return strategy_ptr;
}


Expand Down
39 changes: 39 additions & 0 deletions core/config/factorization_config.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// SPDX-FileCopyrightText: 2017 - 2024 The Ginkgo authors
//
// SPDX-License-Identifier: BSD-3-Clause

#include <ginkgo/core/base/exception_helpers.hpp>
#include <ginkgo/core/config/config.hpp>
#include <ginkgo/core/config/registry.hpp>
#include <ginkgo/core/factorization/cholesky.hpp>
#include <ginkgo/core/factorization/ic.hpp>
#include <ginkgo/core/factorization/ilu.hpp>
#include <ginkgo/core/factorization/lu.hpp>
#include <ginkgo/core/factorization/par_ic.hpp>
#include <ginkgo/core/factorization/par_ict.hpp>
#include <ginkgo/core/factorization/par_ilu.hpp>
#include <ginkgo/core/factorization/par_ilut.hpp>


#include "core/config/config_helper.hpp"
#include "core/config/dispatch.hpp"
#include "core/config/parse_macro.hpp"


namespace gko {
namespace config {


GKO_PARSE_VALUE_AND_INDEX_TYPE(Factorization_Ic, gko::factorization::Ic);
GKO_PARSE_VALUE_AND_INDEX_TYPE(Factorization_Ilu, gko::factorization::Ilu);
GKO_PARSE_VALUE_AND_INDEX_TYPE(Cholesky,
gko::experimental::factorization::Cholesky);
GKO_PARSE_VALUE_AND_INDEX_TYPE(Lu, gko::experimental::factorization::Lu);
GKO_PARSE_VALUE_AND_INDEX_TYPE(ParIlu, gko::factorization::ParIlu);
GKO_PARSE_VALUE_AND_INDEX_TYPE(ParIlut, gko::factorization::ParIlut);
GKO_PARSE_VALUE_AND_INDEX_TYPE(ParIc, gko::factorization::ParIc);
GKO_PARSE_VALUE_AND_INDEX_TYPE(ParIct, gko::factorization::ParIct);


} // namespace config
} // namespace gko
Loading
Loading