Skip to content

Commit

Permalink
reuse in macro
Browse files Browse the repository at this point in the history
  • Loading branch information
yhmtsai committed May 13, 2024
1 parent 227d73b commit eecf8ca
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 168 deletions.
109 changes: 10 additions & 99 deletions core/config/factorization_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,111 +17,22 @@

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


namespace gko {
namespace config {


template <>
deferred_factory_parameter<gko::LinOpFactory>
parse<LinOpFactoryType::Factorization_Ic>(const pnode& config,
const registry& context,
const type_descriptor& td)
{
auto updated = update_type(config, td);
return dispatch<gko::LinOpFactory, gko::factorization::Ic>(
config, context, updated,
make_type_selector(updated.get_value_typestr(), value_type_list()),
make_type_selector(updated.get_index_typestr(), index_type_list()));
}


template <>
deferred_factory_parameter<gko::LinOpFactory>
parse<LinOpFactoryType::Factorization_Ilu>(const pnode& config,
const registry& context,
const type_descriptor& td)
{
auto updated = update_type(config, td);
return dispatch<gko::LinOpFactory, gko::factorization::Ilu>(
config, context, updated,
make_type_selector(updated.get_value_typestr(), value_type_list()),
make_type_selector(updated.get_index_typestr(), index_type_list()));
}


template <>
deferred_factory_parameter<gko::LinOpFactory> parse<LinOpFactoryType::Cholesky>(
const pnode& config, const registry& context, const type_descriptor& td)
{
auto updated = update_type(config, td);
return dispatch<gko::LinOpFactory,
gko::experimental::factorization::Cholesky>(
config, context, updated,
make_type_selector(updated.get_value_typestr(), value_type_list()),
make_type_selector(updated.get_index_typestr(), index_type_list()));
}


template <>
deferred_factory_parameter<gko::LinOpFactory> parse<LinOpFactoryType::Lu>(
const pnode& config, const registry& context, const type_descriptor& td)
{
auto updated = update_type(config, td);
return dispatch<gko::LinOpFactory, gko::experimental::factorization::Lu>(
config, context, updated,
make_type_selector(updated.get_value_typestr(), value_type_list()),
make_type_selector(updated.get_index_typestr(), index_type_list()));
}


template <>
deferred_factory_parameter<gko::LinOpFactory> parse<LinOpFactoryType::ParIlu>(
const pnode& config, const registry& context, const type_descriptor& td)
{
auto updated = update_type(config, td);
return dispatch<gko::LinOpFactory, gko::factorization::ParIlu>(
config, context, updated,
make_type_selector(updated.get_value_typestr(), value_type_list()),
make_type_selector(updated.get_index_typestr(), index_type_list()));
}


template <>
deferred_factory_parameter<gko::LinOpFactory> parse<LinOpFactoryType::ParIlut>(
const pnode& config, const registry& context, const type_descriptor& td)
{
auto updated = update_type(config, td);
return dispatch<gko::LinOpFactory, gko::factorization::ParIlut>(
config, context, updated,
make_type_selector(updated.get_value_typestr(), value_type_list()),
make_type_selector(updated.get_index_typestr(), index_type_list()));
}


template <>
deferred_factory_parameter<gko::LinOpFactory> parse<LinOpFactoryType::ParIc>(
const pnode& config, const registry& context, const type_descriptor& td)
{
auto updated = update_type(config, td);
return dispatch<gko::LinOpFactory, gko::factorization::ParIc>(
config, context, updated,
make_type_selector(updated.get_value_typestr(), value_type_list()),
make_type_selector(updated.get_index_typestr(), index_type_list()));
}


template <>
deferred_factory_parameter<gko::LinOpFactory> parse<LinOpFactoryType::ParIct>(
const pnode& config, const registry& context, const type_descriptor& td)
{
auto updated = update_type(config, td);
return dispatch<gko::LinOpFactory, gko::factorization::ParIct>(
config, context, updated,
make_type_selector(updated.get_value_typestr(), value_type_list()),
make_type_selector(updated.get_index_typestr(), index_type_list()));
}
PARSE_VALUE_AND_INDEX_TYPE(Factorization_Ic, gko::factorization::Ic);
PARSE_VALUE_AND_INDEX_TYPE(Factorization_Ilu, gko::factorization::Ilu);
PARSE_VALUE_AND_INDEX_TYPE(Cholesky,
gko::experimental::factorization::Cholesky);
PARSE_VALUE_AND_INDEX_TYPE(Lu, gko::experimental::factorization::Lu);
PARSE_VALUE_AND_INDEX_TYPE(ParIlu, gko::factorization::ParIlu);
PARSE_VALUE_AND_INDEX_TYPE(ParIlut, gko::factorization::ParIlut);
PARSE_VALUE_AND_INDEX_TYPE(ParIc, gko::factorization::ParIc);
PARSE_VALUE_AND_INDEX_TYPE(ParIct, gko::factorization::ParIct);


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

#ifndef GKO_CORE_CONFIG_PARSE_MARCO_HPP_
#define GKO_CORE_CONFIG_PARSE_MARCO_HPP_


#include <ginkgo/core/config/config.hpp>
#include <ginkgo/core/config/registry.hpp>
#include <ginkgo/core/config/type_descriptor.hpp>


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


// for value_type only
#define PARSE_VALUE_TYPE(_type, _configurator) \
template <> \
deferred_factory_parameter<gko::LinOpFactory> \
parse<gko::config::LinOpFactoryType::_type>( \
const gko::config::pnode& config, \
const gko::config::registry& context, \
const gko::config::type_descriptor& td) \
{ \
auto updated = gko::config::update_type(config, td); \
return gko::config::dispatch<gko::LinOpFactory, _configurator>( \
config, context, updated, \
gko::config::make_type_selector(updated.get_value_typestr(), \
gko::config::value_type_list())); \
} \
static_assert(true, \
"This assert is used to counter the false positive extra " \
"semi-colon warnings")


// for value_type and index_type
#define PARSE_VALUE_AND_INDEX_TYPE(_type, _configurator) \
template <> \
deferred_factory_parameter<gko::LinOpFactory> \
parse<gko::config::LinOpFactoryType::_type>( \
const gko::config::pnode& config, \
const gko::config::registry& context, \
const gko::config::type_descriptor& td) \
{ \
auto updated = gko::config::update_type(config, td); \
return gko::config::dispatch<gko::LinOpFactory, _configurator>( \
config, context, updated, \
gko::config::make_type_selector(updated.get_value_typestr(), \
gko::config::value_type_list()), \
gko::config::make_type_selector(updated.get_index_typestr(), \
gko::config::index_type_list())); \
} \
static_assert(true, \
"This assert is used to counter the false positive extra " \
"semi-colon warnings")


#endif // GKO_CORE_CONFIG_PARSE_MARCO_HPP_
12 changes: 2 additions & 10 deletions core/config/preconditioner_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#include "core/config/config_helper.hpp"
#include "core/config/dispatch.hpp"
#include "core/config/parse_marco.hpp"
#include "core/config/type_descriptor_helper.hpp"


Expand Down Expand Up @@ -287,16 +288,7 @@ deferred_factory_parameter<gko::LinOpFactory> parse<LinOpFactoryType::Isai>(
}


template <>
deferred_factory_parameter<gko::LinOpFactory> parse<LinOpFactoryType::Jacobi>(
const pnode& config, const registry& context, const type_descriptor& td)
{
auto updated = update_type(config, td);
return dispatch<gko::LinOpFactory, preconditioner::Jacobi>(
config, context, updated,
make_type_selector(updated.get_value_typestr(), value_type_list()),
make_type_selector(updated.get_index_typestr(), index_type_list()));
}
PARSE_VALUE_AND_INDEX_TYPE(Jacobi, gko::preconditioner::Jacobi);


} // namespace config
Expand Down
73 changes: 14 additions & 59 deletions core/config/solver_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,72 +21,27 @@

#include "core/config/config_helper.hpp"
#include "core/config/dispatch.hpp"
#include "core/config/parse_marco.hpp"
#include "core/config/solver_config.hpp"


namespace gko {
namespace config {

// for valuetype only
#define PARSE(_type) \
template <> \
deferred_factory_parameter<gko::LinOpFactory> \
parse<LinOpFactoryType::_type>(const pnode& config, \
const registry& context, \
const type_descriptor& td) \
{ \
auto updated = update_type(config, td); \
return dispatch<gko::LinOpFactory, gko::solver::_type>( \
config, context, updated, \
make_type_selector(updated.get_value_typestr(), \
value_type_list())); \
}

PARSE(Cg)
PARSE(Bicg)
PARSE(Bicgstab)
PARSE(Cgs)
PARSE(Fcg)
PARSE(Ir)
PARSE(Idr)
PARSE(Gcr)
PARSE(Gmres)
PARSE(CbGmres)


template <>
deferred_factory_parameter<gko::LinOpFactory> parse<LinOpFactoryType::Direct>(
const pnode& config, const registry& context, const type_descriptor& td)
{
auto updated = update_type(config, td);
return dispatch<gko::LinOpFactory, gko::experimental::solver::Direct>(
config, context, updated,
make_type_selector(updated.get_value_typestr(), value_type_list()),
make_type_selector(updated.get_index_typestr(), index_type_list()));
}


template <>
deferred_factory_parameter<gko::LinOpFactory> parse<LinOpFactoryType::LowerTrs>(
const pnode& config, const registry& context, const type_descriptor& td)
{
auto updated = update_type(config, td);
return dispatch<gko::LinOpFactory, gko::solver::LowerTrs>(
config, context, updated,
make_type_selector(updated.get_value_typestr(), value_type_list()),
make_type_selector(updated.get_index_typestr(), index_type_list()));
}

template <>
deferred_factory_parameter<gko::LinOpFactory> parse<LinOpFactoryType::UpperTrs>(
const pnode& config, const registry& context, const type_descriptor& td)
{
auto updated = update_type(config, td);
return dispatch<gko::LinOpFactory, gko::solver::UpperTrs>(
config, context, updated,
make_type_selector(updated.get_value_typestr(), value_type_list()),
make_type_selector(updated.get_index_typestr(), index_type_list()));
}
PARSE_VALUE_TYPE(Cg, gko::solver::Cg);
PARSE_VALUE_TYPE(Bicg, gko::solver::Bicg);
PARSE_VALUE_TYPE(Bicgstab, gko::solver::Bicgstab);
PARSE_VALUE_TYPE(Cgs, gko::solver::Cgs);
PARSE_VALUE_TYPE(Fcg, gko::solver::Fcg);
PARSE_VALUE_TYPE(Ir, gko::solver::Ir);
PARSE_VALUE_TYPE(Idr, gko::solver::Idr);
PARSE_VALUE_TYPE(Gcr, gko::solver::Gcr);
PARSE_VALUE_TYPE(Gmres, gko::solver::Gmres);
PARSE_VALUE_TYPE(CbGmres, gko::solver::CbGmres);
PARSE_VALUE_AND_INDEX_TYPE(Direct, gko::experimental::solver::Direct);
PARSE_VALUE_AND_INDEX_TYPE(LowerTrs, gko::solver::LowerTrs);
PARSE_VALUE_AND_INDEX_TYPE(UpperTrs, gko::solver::UpperTrs);


} // namespace config
Expand Down

0 comments on commit eecf8ca

Please sign in to comment.