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

Factory improvements #1336

Merged
merged 12 commits into from
Oct 9, 2023
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -511,3 +511,8 @@ else()
FILE(READ ${PROJECT_BINARY_DIR}/minimal.log GINKGO_LOG_SUMMARY)
endif()
MESSAGE(STATUS "${GINKGO_LOG_SUMMARY}")

# make sure no build files get committed accidentally
if(NOT EXISTS ${CMAKE_CURRENT_BINARY_DIR}/.gitignore)
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/.gitignore "*")
MarcelKoch marked this conversation as resolved.
Show resolved Hide resolved
endif()
9 changes: 3 additions & 6 deletions benchmark/solver/solver_common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,21 +239,18 @@ std::unique_ptr<gko::LinOpFactory> generate_solver(
return gko::experimental::solver::Direct<etype, itype>::build()
.with_factorization(
gko::experimental::factorization::Cholesky<etype,
itype>::build()
.on(exec))
itype>::build())
.on(exec);
} else if (description == "symm_direct") {
return gko::experimental::solver::Direct<etype, itype>::build()
.with_factorization(
gko::experimental::factorization::Lu<etype, itype>::build()
.with_symmetric_sparsity(true)
.on(exec))
.with_symmetric_sparsity(true))
.on(exec);
} else if (description == "direct") {
return gko::experimental::solver::Direct<etype, itype>::build()
.with_factorization(
gko::experimental::factorization::Lu<etype, itype>::build().on(
exec))
gko::experimental::factorization::Lu<etype, itype>::build())
.on(exec);
} else if (description == "overhead") {
return add_criteria_precond_finalize<gko::Overhead<etype>>(
Expand Down
27 changes: 6 additions & 21 deletions benchmark/utils/overhead_linop.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,27 +104,12 @@ class Overhead : public EnableLinOp<Overhead<ValueType>>,
friend class EnablePolymorphicObject<Overhead, LinOp>;

public:
GKO_CREATE_FACTORY_PARAMETERS(parameters, Factory)
{
/**
* Criterion factories.
*/
std::vector<std::shared_ptr<const stop::CriterionFactory>>
GKO_FACTORY_PARAMETER_VECTOR(criteria, nullptr);

/**
* Preconditioner factory.
*/
std::shared_ptr<const LinOpFactory> GKO_FACTORY_PARAMETER_SCALAR(
preconditioner, nullptr);

/**
* Already generated preconditioner. If one is provided, the factory
* `preconditioner` will be ignored.
*/
std::shared_ptr<const LinOp> GKO_FACTORY_PARAMETER_SCALAR(
generated_preconditioner, nullptr);
};
class Factory;

struct parameters_type
: public gko::solver::
enable_preconditioned_iterative_solver_factory_parameters<
parameters_type, Factory> {};

GKO_ENABLE_LIN_OP_FACTORY(Overhead, parameters, Factory);
GKO_ENABLE_BUILD_METHOD(Factory);
Expand Down
45 changes: 22 additions & 23 deletions benchmark/utils/preconditioners.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ const std::map<std::string, std::function<std::unique_ptr<gko::LinOpFactory>(
.on(exec));
return gko::preconditioner::Ic<gko::solver::LowerTrs<etype, itype>,
itype>::build()
.with_factorization_factory(fact)
.with_factorization(fact)
.on(exec);
}},
{"parict",
Expand All @@ -137,7 +137,7 @@ const std::map<std::string, std::function<std::unique_ptr<gko::LinOpFactory>(
return gko::preconditioner::
Ilu<gko::solver::LowerTrs<etype, itype>,
gko::solver::UpperTrs<etype, itype>, false, itype>::build()
.with_factorization_factory(fact)
.with_factorization(fact)
.on(exec);
}},
{"parilu",
Expand All @@ -150,7 +150,7 @@ const std::map<std::string, std::function<std::unique_ptr<gko::LinOpFactory>(
return gko::preconditioner::
Ilu<gko::solver::LowerTrs<etype, itype>,
gko::solver::UpperTrs<etype, itype>, false, itype>::build()
.with_factorization_factory(fact)
.with_factorization(fact)
.on(exec);
}},
{"parilut",
Expand All @@ -165,7 +165,7 @@ const std::map<std::string, std::function<std::unique_ptr<gko::LinOpFactory>(
return gko::preconditioner::
Ilu<gko::solver::LowerTrs<etype, itype>,
gko::solver::UpperTrs<etype, itype>, false, itype>::build()
.with_factorization_factory(fact)
.with_factorization(fact)
.on(exec);
}},
{"ic",
Expand All @@ -174,7 +174,7 @@ const std::map<std::string, std::function<std::unique_ptr<gko::LinOpFactory>(
gko::factorization::Ic<etype, itype>::build().on(exec));
return gko::preconditioner::Ic<gko::solver::LowerTrs<etype, itype>,
itype>::build()
.with_factorization_factory(fact)
.with_factorization(fact)
.on(exec);
}},
{"ilu",
Expand All @@ -184,7 +184,7 @@ const std::map<std::string, std::function<std::unique_ptr<gko::LinOpFactory>(
return gko::preconditioner::
Ilu<gko::solver::LowerTrs<etype, itype>,
gko::solver::UpperTrs<etype, itype>, false, itype>::build()
.with_factorization_factory(fact)
.with_factorization(fact)
.on(exec);
}},
{"paric-isai",
Expand All @@ -201,8 +201,8 @@ const std::map<std::string, std::function<std::unique_ptr<gko::LinOpFactory>(
return gko::preconditioner::Ic<
gko::preconditioner::LowerIsai<etype, itype>,
itype>::build()
.with_factorization_factory(fact)
.with_l_solver_factory(lisai)
.with_factorization(fact)
.with_l_solver(lisai)
.on(exec);
}},
{"parict-isai",
Expand All @@ -221,8 +221,8 @@ const std::map<std::string, std::function<std::unique_ptr<gko::LinOpFactory>(
return gko::preconditioner::Ic<
gko::preconditioner::LowerIsai<etype, itype>,
itype>::build()
.with_factorization_factory(fact)
.with_l_solver_factory(lisai)
.with_factorization(fact)
.with_l_solver(lisai)
.on(exec);
}},
{"parilu-isai",
Expand All @@ -244,9 +244,9 @@ const std::map<std::string, std::function<std::unique_ptr<gko::LinOpFactory>(
gko::preconditioner::LowerIsai<etype, itype>,
gko::preconditioner::UpperIsai<etype, itype>, false,
itype>::build()
.with_factorization_factory(fact)
.with_l_solver_factory(lisai)
.with_u_solver_factory(uisai)
.with_factorization(fact)
.with_l_solver(lisai)
.with_u_solver(uisai)
.on(exec);
}},
{"parilut-isai",
Expand All @@ -270,9 +270,9 @@ const std::map<std::string, std::function<std::unique_ptr<gko::LinOpFactory>(
gko::preconditioner::LowerIsai<etype, itype>,
gko::preconditioner::UpperIsai<etype, itype>, false,
itype>::build()
.with_factorization_factory(fact)
.with_l_solver_factory(lisai)
.with_u_solver_factory(uisai)
.with_factorization(fact)
.with_l_solver(lisai)
.with_u_solver(uisai)
.on(exec);
}},
{"ic-isai",
Expand All @@ -286,8 +286,8 @@ const std::map<std::string, std::function<std::unique_ptr<gko::LinOpFactory>(
return gko::preconditioner::Ic<
gko::preconditioner::LowerIsai<etype, itype>,
itype>::build()
.with_factorization_factory(fact)
.with_l_solver_factory(lisai)
.with_factorization(fact)
.with_l_solver(lisai)
.on(exec);
}},
{"ilu-isai",
Expand All @@ -306,9 +306,9 @@ const std::map<std::string, std::function<std::unique_ptr<gko::LinOpFactory>(
gko::preconditioner::LowerIsai<etype, itype>,
gko::preconditioner::UpperIsai<etype, itype>, false,
itype>::build()
.with_factorization_factory(fact)
.with_l_solver_factory(lisai)
.with_u_solver_factory(uisai)
.with_factorization(fact)
.with_l_solver(lisai)
.with_u_solver(uisai)
.on(exec);
}},
{"general-isai",
Expand All @@ -326,8 +326,7 @@ const std::map<std::string, std::function<std::unique_ptr<gko::LinOpFactory>(
{"overhead", [](std::shared_ptr<const gko::Executor> exec) {
return gko::Overhead<etype>::build()
.with_criteria(gko::stop::ResidualNorm<etype>::build()
.with_reduction_factor(rc_etype{})
.on(exec))
.with_reduction_factor(rc_etype{}))
.on(exec);
}}};

Expand Down
4 changes: 2 additions & 2 deletions core/distributed/preconditioner/schwarz.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ template <typename ValueType, typename LocalIndexType, typename GlobalIndexType>
void Schwarz<ValueType, LocalIndexType, GlobalIndexType>::generate(
std::shared_ptr<const LinOp> system_matrix)
{
if (parameters_.local_solver_factory) {
this->local_solver_ = parameters_.local_solver_factory->generate(
if (parameters_.local_solver) {
this->local_solver_ = parameters_.local_solver->generate(
as<experimental::distributed::Matrix<ValueType, LocalIndexType,
GlobalIndexType>>(
system_matrix)
Expand Down
10 changes: 4 additions & 6 deletions core/preconditioner/isai.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,17 +230,15 @@
excess_solver_factory =
Gmres::build()
.with_preconditioner(
Bj::build().with_max_block_size(32u).on(exec))
Bj::build().with_max_block_size(32u))

Check warning on line 233 in core/preconditioner/isai.cpp

View check run for this annotation

Codecov / codecov/patch

core/preconditioner/isai.cpp#L233

Added line #L233 was not covered by tests
.with_criteria(
gko::stop::Iteration::build()
.with_max_iters(excess_dim)
.on(exec),
gko::stop::Iteration::build().with_max_iters(
excess_dim),
gko::stop::ResidualNorm<ValueType>::build()
.with_baseline(gko::stop::mode::rhs_norm)
.with_reduction_factor(
remove_complex<ValueType>{
excess_solver_reduction})
.on(exec))
excess_solver_reduction}))
.on(exec);
excess_solution->copy_from(excess_rhs);
} else if (is_lower) {
Expand Down
14 changes: 5 additions & 9 deletions core/solver/multigrid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -569,30 +569,26 @@
using absolute_value_type = remove_complex<value_type>;
return solver::Gmres<value_type>::build()
.with_criteria(
stop::Iteration::build()
.with_max_iters(matrix->get_size()[0])
.on(exec),
stop::Iteration::build().with_max_iters(
matrix->get_size()[0]),

Check warning on line 573 in core/solver/multigrid.cpp

View check run for this annotation

Codecov / codecov/patch

core/solver/multigrid.cpp#L573

Added line #L573 was not covered by tests
stop::ResidualNorm<value_type>::build()
.with_reduction_factor(
std::numeric_limits<
absolute_value_type>::epsilon() *
absolute_value_type{10})
.on(exec))
absolute_value_type{10}))
.with_krylov_dim(
std::min(size_type(100), matrix->get_size()[0]))
.with_preconditioner(
preconditioner::Jacobi<value_type>::build()
.with_max_block_size(1u)
.on(exec))
.with_max_block_size(1u))

Check warning on line 583 in core/solver/multigrid.cpp

View check run for this annotation

Codecov / codecov/patch

core/solver/multigrid.cpp#L583

Added line #L583 was not covered by tests
.on(exec)
->generate(matrix);
} else {
return experimental::solver::Direct<value_type,
int32>::build()
.with_factorization(
experimental::factorization::Lu<value_type,
int32>::build()
.on(exec))
int32>::build())
.on(exec)
->generate(matrix);
}
Expand Down
3 changes: 1 addition & 2 deletions core/test/log/convergence.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@ class Convergence : public ::testing::Test {
gko::initialize<AbsoluteDense>({6}, exec);
std::unique_ptr<gko::LinOp> system =
gko::solver::Ir<T>::build()
.with_criteria(
gko::stop::Iteration::build().with_max_iters(1u).on(exec))
.with_criteria(gko::stop::Iteration::build().with_max_iters(1u))
.on(exec)
->generate(gko::initialize<Dense>(I<I<T>>{{1, 2}, {0, 3}}, exec));
std::unique_ptr<Dense> rhs = gko::initialize<Dense>({15, 25}, exec);
Expand Down
6 changes: 2 additions & 4 deletions core/test/log/papi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -471,8 +471,7 @@ TYPED_TEST(Papi, CatchesLinOpFactoryGenerateStarted)
{
auto factory =
gko::solver::Bicgstab<TypeParam>::build()
.with_criteria(
gko::stop::Iteration::build().with_max_iters(3u).on(this->exec))
.with_criteria(gko::stop::Iteration::build().with_max_iters(3u))
.on(this->exec);
auto str = this->init(gko::log::Logger::linop_factory_generate_started_mask,
"linop_factory_generate_started", factory.get());
Expand All @@ -492,8 +491,7 @@ TYPED_TEST(Papi, CatchesLinOpFactoryGenerateCompleted)
{
auto factory =
gko::solver::Bicgstab<TypeParam>::build()
.with_criteria(
gko::stop::Iteration::build().with_max_iters(3u).on(this->exec))
.with_criteria(gko::stop::Iteration::build().with_max_iters(3u))
.on(this->exec);
TypeParam dummy;
auto str =
Expand Down
3 changes: 1 addition & 2 deletions core/test/log/profiler_hook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,7 @@ TEST(ProfilerHook, LogsIteration)
auto alpha = gko::share(gko::initialize<Vec>({1.0}, exec));
auto solver =
gko::solver::Ir<>::build()
.with_criteria(
gko::stop::Iteration::build().with_max_iters(1u).on(exec))
.with_criteria(gko::stop::Iteration::build().with_max_iters(1u))
.on(exec)
->generate(mtx);
logger->set_object_name(solver, "solver");
Expand Down
9 changes: 3 additions & 6 deletions core/test/log/record.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -440,8 +440,7 @@ TEST(Record, CatchesLinopFactoryGenerateStarted)
gko::log::Logger::linop_factory_generate_started_mask);
auto factory =
gko::solver::Bicgstab<>::build()
.with_criteria(
gko::stop::Iteration::build().with_max_iters(3u).on(exec))
.with_criteria(gko::stop::Iteration::build().with_max_iters(3u))
.on(exec);
auto input = factory->generate(gko::matrix::Dense<>::create(exec));

Expand All @@ -462,8 +461,7 @@ TEST(Record, CatchesLinopFactoryGenerateCompleted)
gko::log::Logger::linop_factory_generate_completed_mask);
auto factory =
gko::solver::Bicgstab<>::build()
.with_criteria(
gko::stop::Iteration::build().with_max_iters(3u).on(exec))
.with_criteria(gko::stop::Iteration::build().with_max_iters(3u))
.on(exec);
auto input = factory->generate(gko::matrix::Dense<>::create(exec));
auto output = factory->generate(gko::matrix::Dense<>::create(exec));
Expand Down Expand Up @@ -569,8 +567,7 @@ TEST(Record, CatchesIterations)
gko::log::Record::create(gko::log::Logger::iteration_complete_mask);
auto factory =
gko::solver::Bicgstab<>::build()
.with_criteria(
gko::stop::Iteration::build().with_max_iters(3u).on(exec))
.with_criteria(gko::stop::Iteration::build().with_max_iters(3u))
.on(exec);
auto solver = factory->generate(gko::initialize<Dense>({1.1}, exec));
auto right_hand_side = gko::initialize<Dense>({-5.5}, exec);
Expand Down
9 changes: 3 additions & 6 deletions core/test/log/stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -606,8 +606,7 @@ TYPED_TEST(Stream, CatchesLinopFactoryGenerateStarted)
gko::log::Logger::linop_factory_generate_started_mask, out);
auto factory =
gko::solver::Bicgstab<TypeParam>::build()
.with_criteria(
gko::stop::Iteration::build().with_max_iters(3u).on(exec))
.with_criteria(gko::stop::Iteration::build().with_max_iters(3u))
.on(exec);
auto input = factory->generate(gko::matrix::Dense<TypeParam>::create(exec));
std::stringstream ptrstream_factory;
Expand All @@ -633,8 +632,7 @@ TYPED_TEST(Stream, CatchesLinopFactoryGenerateCompleted)
gko::log::Logger::linop_factory_generate_completed_mask, out);
auto factory =
gko::solver::Bicgstab<TypeParam>::build()
.with_criteria(
gko::stop::Iteration::build().with_max_iters(3u).on(exec))
.with_criteria(gko::stop::Iteration::build().with_max_iters(3u))
.on(exec);
auto input = factory->generate(gko::matrix::Dense<TypeParam>::create(exec));
auto output =
Expand Down Expand Up @@ -815,8 +813,7 @@ TYPED_TEST(Stream, CatchesIterationsWithVerbose)

auto factory =
gko::solver::Bicgstab<TypeParam>::build()
.with_criteria(
gko::stop::Iteration::build().with_max_iters(3u).on(exec))
.with_criteria(gko::stop::Iteration::build().with_max_iters(3u))
.on(exec);
auto solver = factory->generate(gko::initialize<Dense>({1.1}, exec));
auto right_hand_side = gko::initialize<Dense>({-5.5}, exec);
Expand Down
Loading