Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
87 commits
Select commit Hold shift + click to select a range
cd1ffc9
First commit for the GmresMixed class:
Apr 27, 2020
d7ba04c
Inclusion of the omp executor in the repository:
Apr 27, 2020
969358f
Inclusion of the cuda executor in the repository:
Apr 29, 2020
2b7122f
The test files are finally included, but:
Apr 29, 2020
6dc6470
The first unoptimized version is done. Next tasks:
Apr 30, 2020
4d4fab1
The default value for ValueTypeKrylovBasis has been changed to avoid …
josealiaga Apr 30, 2020
e0d39a6
Definition of the CG2 variant of the finish_arnoldi routine for omp a…
josealiaga May 3, 2020
27019da
Add GMRES_mixed to benchmark
May 7, 2020
f2b5a3a
Definition of the CGS2 version of finish_arnoldi method, for omp and …
josealiaga May 7, 2020
bfd4196
Finally a good implementation of the multidot_kernels_num_iters_1 is …
josealiaga May 12, 2020
4ad491e
Add Accessor support and extend reference test
May 13, 2020
fbcc4f2
Made GmresMixed compile with complex types
May 13, 2020
911fd5c
The update routines have been improved. Now the computational time is…
josealiaga May 19, 2020
db081ac
Add specialization for integer types for Accessor
May 19, 2020
7db4796
Make the scale work with integer types
May 20, 2020
9bbcf87
Add helper to determine if we need a scale or not
May 20, 2020
97689ab
Add a helper structure to manage the scale writing in common
May 20, 2020
c0aa2ed
Testing the push command
josealiaga May 20, 2020
da8a56e
Definition of norm2 and norminf routines in CUDA. Only the first one …
josealiaga May 22, 2020
23efe7a
remove_complex has been added to the norms variables, and multinorm2_…
josealiaga May 24, 2020
f3cdbd7
Fixed cuda step2 to take a view into account
May 25, 2020
d4865f2
Change const accessor to non-const in check_arnoldi_norms_new
May 25, 2020
42a779b
The set_scale method finally works!!
josealiaga May 27, 2020
6b25d2e
Change storage layout of krylov_bases
Jun 1, 2020
e3ca7cc
Make memory access to krylov_bases coalesced again
Jun 2, 2020
911fccb
Transpose grid when launching singledot kernel
Jun 4, 2020
5dd8bf2
Reversed the transpose of the grid dim
Jun 4, 2020
b214a5f
Add half precision support to GmresMixed
Jun 15, 2020
f1f178e
Hopefully improve singledot performance
Jun 15, 2020
fb64f5c
Infinity norm only computed when scale is present
Jun 17, 2020
155c552
Add another RHS generation in the benchmark
Jun 23, 2020
d660c47
Fix residual_norm calculation in GmresMixed
Jun 23, 2020
8ede6d6
Make sure GmresMixed does not exit early
Jun 25, 2020
af6fb48
Add benchmark parameter for GMRES krylov_dim
Jun 26, 2020
49f1763
Add forced iterations when convergence is detected
Jun 26, 2020
188ff18
Add debug output to forced iterations
Jun 26, 2020
297004b
Fix reference bug in GmresMixed
Jul 8, 2020
b7765c3
DEBUG: Add write output for integral accessor
Jul 30, 2020
f31e87d
DEBUG: Move towards `at` with accessor
Aug 14, 2020
6f82f47
Remove Accessor3dConst
Aug 17, 2020
c385a2b
Adopt OpenMP support to new Accessor
Aug 17, 2020
9a0a0f0
Remove unused GMRES_mixed code from Ref & OMP
Aug 17, 2020
3d44a21
Adopt CUDA to the new accessor format (NOT `at`)
Aug 17, 2020
e1654b4
Make HIP and CUDA work with new accessor (NOT at)
Aug 17, 2020
5d09f2a
Remove unused code from CUDA
Aug 17, 2020
48e0899
CUDA implementation is now using `at`
Aug 18, 2020
b542646
Re-add ConstAccessor
Aug 18, 2020
b0a2ac3
Fix accessor by adding additional __restrict__
Aug 19, 2020
5d1f173
GmresMixed storage prec is now a factory parameter
Aug 25, 2020
267bbf1
Improve reference test and include the enum there
Aug 25, 2020
6b92a4f
Fix the reference test to pass
Aug 26, 2020
1d4a773
Adopt to new parameter macros
Sep 1, 2020
30381e2
Update the helper to throw when complex
Sep 7, 2020
6d30e36
Make GmresMixed work properly with multiple RHS
Sep 9, 2020
7f86d9c
Fix benchmark to work with new GmresMixed layout
Sep 10, 2020
b2b9ebc
Use new reduced_row_major Accessor in GmresMixed
Sep 11, 2020
db3046f
Remove unnecessary code from CUDA GmresMixed
Sep 14, 2020
da87d06
Add HIP kernels
Sep 14, 2020
65a8a8b
Fix GmresMixed core problem
Sep 17, 2020
a9646e8
Improve force-reset behavior
Dec 12, 2020
c6020db
Rename GmresMixed to CbGmres
Jan 22, 2021
36a1a19
Format files
ginkgo-bot Jan 23, 2021
c4a7335
Add DPCPP stubs to allow compilation
Jan 24, 2021
fa1fc39
Make cb-gmres benchmarks dependent on etype
Jan 28, 2021
c509263
Fix implementation and reference test for CB-GMRES
Feb 1, 2021
6bb09da
Update tolerance for one reference CB-GMRES test
Feb 1, 2021
3655021
Update atomic_max
Feb 2, 2021
5270478
Remove unnecessary kernels and properly name them
Feb 2, 2021
2f0a32e
Review update
Feb 2, 2021
58e1104
Add Helper INSTANTIATE macro for CB-GMRES
Feb 3, 2021
c47a4ca
Remove CB-GMRES and GMRES example
Feb 3, 2021
2b587ba
Review update
Feb 3, 2021
da8a6b4
Remove unnecessary includes of iostream and time.h
Feb 3, 2021
c4c1270
Remove circular dependency of compute_norm2 in (CB)-GMRES
Feb 3, 2021
00d33b5
Update solver generation in benchmark
Feb 3, 2021
b163893
Update eta and arnoldi_norms in CB-GMRES
Feb 4, 2021
342957a
Remove CUDA 9.0 exception for constexpr parameter
Feb 4, 2021
370d208
Review Update
Feb 5, 2021
1b2071d
Sonarcloud update
Feb 6, 2021
b4a6fc9
Review update; Improve run_all_benchmarks.sh
Feb 8, 2021
599e261
Put storage_precision enum into cb_gmres namespace
Feb 9, 2021
5126858
Add CB-GMRES example
Feb 9, 2021
169040d
Remove unnecessary included files for CB-GMRES
Feb 9, 2021
05374fd
Review update
Feb 15, 2021
389d038
Review update
Feb 16, 2021
6d6bbab
Update contributors.txt
josealiaga Feb 19, 2021
4d722f1
Update contributors.txt
josealiaga Feb 19, 2021
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
Prev Previous commit
Next Next commit
Fix implementation and reference test for CB-GMRES
Having forced iteration for small matrices can lead to NaN values during
CB-GMRES. To prevent that, forced iterations now only happen after the
10th total iteration. Before that, a vector is immediately declared as
converged as soon as the stopping criterion said so.

Also done:
- Removed useless debug-output from CB-GMRES
- Changed the tolerances for the reference test to always pass
  • Loading branch information
Thomas Grützmacher committed Feb 19, 2021
commit c50926343b598882f567bcf3bee47685e80bbecf
163 changes: 21 additions & 142 deletions core/solver/cb_gmres.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <ginkgo/core/solver/cb_gmres.hpp>


#include <iostream>
#include <typeinfo>
#include <type_traits>


#include <ginkgo/core/base/array.hpp>
Expand All @@ -52,15 +51,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "core/solver/cb_gmres_kernels.hpp"


//#define TIMING 1


#ifdef TIMING
using double_seconds = std::chrono::duration<double>;
#define TIMING_STEPS 1
#endif


namespace gko {
namespace solver {

Expand All @@ -76,24 +66,6 @@ GKO_REGISTER_OPERATION(step_2, cb_gmres::step_2);

} // namespace cb_gmres

// TODO: Remove output
template <typename T>
struct type_string {
static const char *get() { return typeid(T).name(); }
};

#define GKO_SPECIALIZE_TYPE_STRING(type) \
template <> \
struct type_string<type> { \
static const char *get() { return #type; } \
}

GKO_SPECIALIZE_TYPE_STRING(int32);
GKO_SPECIALIZE_TYPE_STRING(int16);
GKO_SPECIALIZE_TYPE_STRING(double);
GKO_SPECIALIZE_TYPE_STRING(float);
GKO_SPECIALIZE_TYPE_STRING(half);


template <typename T>
struct to_integer_impl {
Expand Down Expand Up @@ -298,7 +270,6 @@ void CbGmres<ValueType>::apply_impl(const LinOp *b, LinOp *x) const
dense_b->get_size()[1]);
int num_restarts = 0, num_reorth_steps = 0, num_reorth_vectors = 0;

// std::cout << "Before initializate_1" << std::endl;
// Initialization
exec->run(cb_gmres::make_initialize_1(
dense_b, b_norm.get(), residual.get(), givens_sin.get(),
Expand All @@ -310,7 +281,6 @@ void CbGmres<ValueType>::apply_impl(const LinOp *b, LinOp *x) const
residual.get());
// residual = residual - Ax

// std::cout << "Before initializate_2" << std::endl;
exec->run(cb_gmres::make_initialize_2(
residual.get(), residual_norm.get(), residual_norm_collection.get(),
arnoldi_norm.get(), krylov_bases_range, next_krylov_basis.get(),
Expand All @@ -334,15 +304,6 @@ void CbGmres<ValueType>::apply_impl(const LinOp *b, LinOp *x) const
auto after_preconditioner =
matrix::Dense<ValueType>::create_with_config_of(dense_x);

#ifdef TIMING
exec->synchronize();
auto start = std::chrono::steady_clock::now();
#ifdef TIMING_STEPS
auto time_RSTRT = start - start;
auto time_SPMV = start - start;
auto time_STEP1 = start - start;
#endif
#endif
Array<bool> stop_encountered_rhs(exec->get_master(),
dense_b->get_size()[1]);
Array<bool> fully_converged_rhs(exec->get_master(),
Expand All @@ -353,20 +314,26 @@ void CbGmres<ValueType>::apply_impl(const LinOp *b, LinOp *x) const
stop_encountered_rhs.get_data()[i] = false;
fully_converged_rhs.get_data()[i] = false;
}
// Start only after this value with performing forced iterations after
// convergence detection
constexpr decltype(total_iter) start_force_reset{10};
bool perform_reset{false};
decltype(krylov_dim_) forced_iterations{0};
const decltype(forced_iterations) forced_limit{krylov_dim_ / 10};
decltype(krylov_dim_) total_checks{0}; // TODO: Remove debug output
const char *type_str = type_string<storage_type>::get();
// TODO: take care of multiple RHS. Currently, we restart
// everything,
// even though a lot of parts might have already converged!
// Use `one_changed` to take care of that!
// Fraction of the krylov_dim_ (or total_iter if it is lower),
// determining the number of forced iteration to perform
constexpr decltype(krylov_dim_) forced_iteration_fraction{10};
const decltype(krylov_dim_) forced_limit{krylov_dim_ /
forced_iteration_fraction};
// Counter for the forced iterations. Start at max in order to properly
// test convergence at the beginning
decltype(krylov_dim_) forced_iterations{forced_limit};

while (true) {
++total_iter;
this->template log<log::Logger::iteration_complete>(
this, total_iter, residual.get(), dense_x, residual_norm.get());
if (forced_iterations < forced_limit) {
// In the beginning, only force a fraction of the total iterations
if (forced_iterations < forced_limit &&
forced_iterations < total_iter / forced_iteration_fraction) {
++forced_iterations;
} else {
bool all_changed = stop_criterion->update()
Expand All @@ -377,25 +344,20 @@ void CbGmres<ValueType>::apply_impl(const LinOp *b, LinOp *x) const
.check(RelativeStoppingId, true,
&stop_status, &one_changed);
if (one_changed || all_changed) {
/*
std::cout << type_str << ": " << ++total_checks
<< ". check in iteration " << total_iter << ";
"
<< forced_iterations << " / " << forced_limit
<<
'\n';
*/
host_stop_status = stop_status;
bool host_array_changed{false};
for (size_type i = 0; i < host_stop_status.get_num_elems();
++i) {
auto local_status = host_stop_status.get_data() + i;
// TODO: ignore all actually converged ones!
// Ignore all actually converged ones!
if (fully_converged_rhs.get_data()[i]) {
continue;
}
if (local_status->has_converged()) {
if (stop_encountered_rhs.get_data()[i]) {
// If convergence was detected earlier, or
// at the very beginning:
if (stop_encountered_rhs.get_data()[i] ||
total_iter < start_force_reset) {
fully_converged_rhs.get_data()[i] = true;
} else {
stop_encountered_rhs.get_data()[i] = true;
Expand Down Expand Up @@ -425,10 +387,6 @@ void CbGmres<ValueType>::apply_impl(const LinOp *b, LinOp *x) const

if (perform_reset || restart_iter == krylov_dim_) {
perform_reset = false;
#ifdef TIMING_STEPS
exec->synchronize();
auto t_aux_0 = std::chrono::steady_clock::now();
#endif
num_restarts++;
// Restart
// use a view in case this is called earlier
Expand Down Expand Up @@ -465,10 +423,6 @@ void CbGmres<ValueType>::apply_impl(const LinOp *b, LinOp *x) const
// next_krylov_basis = residual / residual_norm
// final_iter_nums = {0, ..., 0}
restart_iter = 0;
#ifdef TIMING_STEPS
exec->synchronize();
time_RSTRT += std::chrono::steady_clock::now() - t_aux_0;
#endif
}

this->get_preconditioner()->apply(next_krylov_basis.get(),
Expand All @@ -484,34 +438,17 @@ void CbGmres<ValueType>::apply_impl(const LinOp *b, LinOp *x) const
auto buffer_iter = buffer->create_submatrix(
span{0, restart_iter + 2}, span{0, dense_b->get_size()[1]});

#ifdef TIMING_STEPS
exec->synchronize();
auto t_aux_1 = std::chrono::steady_clock::now();
#endif
// Start of arnoldi
system_matrix_->apply(preconditioned_vector.get(),
next_krylov_basis.get());
// next_krylov_basis = A * preconditioned_vector
#ifdef TIMING_STEPS
exec->synchronize();
time_SPMV += std::chrono::steady_clock::now() - t_aux_1;
#endif

#ifdef TIMING_STEPS
exec->synchronize();
auto t_aux_2 = std::chrono::steady_clock::now();
#endif
exec->run(cb_gmres::make_step_1(
next_krylov_basis.get(), givens_sin.get(), givens_cos.get(),
residual_norm.get(), residual_norm_collection.get(),
krylov_bases_range, hessenberg_iter.get(), buffer_iter.get(),
b_norm.get(), arnoldi_norm.get(), restart_iter,
&final_iter_nums, &stop_status, &reorth_status, &num_reorth,
&num_reorth_steps, &num_reorth_vectors));
#ifdef TIMING_STEPS
exec->synchronize();
time_STEP1 += std::chrono::steady_clock::now() - t_aux_2;
#endif
// for i in 0:restart_iter
// hessenberg(restart_iter, i) = next_krylov_basis' *
// krylov_bases(:, i) next_krylov_basis -=
Expand All @@ -537,15 +474,7 @@ void CbGmres<ValueType>::apply_impl(const LinOp *b, LinOp *x) const

restart_iter++;
}
Comment thread
thoasm marked this conversation as resolved.
Outdated
std::cout << type_str << ": " << total_checks
<< ": exiting in iteration " << total_iter << "; "
<< forced_iterations << " / " << forced_limit << '\n';

// Solve x
#ifdef TIMING_STEPS
exec->synchronize();
auto t_aux_3 = std::chrono::steady_clock::now();
#endif

auto hessenberg_small = hessenberg->create_submatrix(
span{0, restart_iter},
Expand All @@ -558,61 +487,11 @@ void CbGmres<ValueType>::apply_impl(const LinOp *b, LinOp *x) const
&final_iter_nums));
// Solve upper triangular.
// y = hessenberg \ residual_norm_collection
#ifdef TIMING_STEPS
exec->synchronize();
auto time_STEP2 = std::chrono::steady_clock::now() - t_aux_3;
#endif

#ifdef TIMING_STEPS
exec->synchronize();
auto t_aux_4 = std::chrono::steady_clock::now();
#endif
this->get_preconditioner()->apply(before_preconditioner.get(),
after_preconditioner.get());
dense_x->add_scaled(one_op.get(), after_preconditioner.get());
#ifdef TIMING_STEPS
exec->synchronize();
auto time_SOLVEX = std::chrono::steady_clock::now() - t_aux_4;
#endif
// Solve x
// x = x + get_preconditioner() * krylov_bases * y

#ifdef TIMING
exec->synchronize();
auto time = std::chrono::steady_clock::now() - start;
#endif
#ifdef TIMING
std::cout << "total_iter = " << total_iter << std::endl;
std::cout << "num_restarts = " << num_restarts << std::endl;
std::cout << "reorth_steps = " << num_reorth_steps << std::endl;
std::cout << "reorth_vectors = " << num_reorth_vectors << std::endl;
std::cout << "time = "
<< std::chrono::duration_cast<double_seconds>(time).count()
<< std::endl;
#ifdef TIMING_STEPS
std::cout
<< "time_RSTRT = "
<< std::chrono::duration_cast<double_seconds>(time_RSTRT).count()
<< std::endl;
std::cout
<< "time_SPMV = "
<< std::chrono::duration_cast<double_seconds>(time_SPMV).count()
<< std::endl;
std::cout
<< "time_STEP1 = "
<< std::chrono::duration_cast<double_seconds>(time_STEP1).count()
<< std::endl;
std::cout
<< "time_STEP2 = "
<< std::chrono::duration_cast<double_seconds>(time_STEP2).count()
<< std::endl;
std::cout
<< "time_SOLVEX = "
<< std::chrono::duration_cast<double_seconds>(time_SOLVEX).count()
<< std::endl;
#endif
write(std::cout, lend(residual_norm));
#endif
}; // End of apply_lambda

// Look which precision to use as the storage type
Expand Down
Loading