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
Definition of the CGS2 version of finish_arnoldi method, for omp and …
…cuda executors.

For omp, the omp is trying to move to the outer loop
For cuda, the loop of kernels is change to a kernels with a loop.
  * The main routines (loop of dots and loop of axpy) are still too expensive.
  • Loading branch information
josealiaga authored and Thomas Grützmacher committed Feb 19, 2021
commit f2b5a3ae2bdc6657b382a7ffe5c0d2bec5995980
144 changes: 141 additions & 3 deletions common/solver/gmres_mixed_kernels.hpp.inc
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,75 @@ __global__ __launch_bounds__(default_dot_size) void multidot_kernel_num_iters(
}


template <typename ValueType, typename ValueTypeKrylovBases>
__global__
__launch_bounds__(default_dot_size) void multidot_kernel_num_iters_new(
size_type num_iters, size_type num_rows, size_type num_cols,
const ValueType *__restrict__ next_krylov_basis,
size_type stride_next_krylov,
const ValueTypeKrylovBases *__restrict__ krylov_bases,
size_type stride_krylov, ValueType *__restrict__ hessenberg_iter,
size_type stride_hessenberg,
const stopping_status *__restrict__ stop_status)
{
const auto mult = 1;
const auto tidx = threadIdx.x;
const auto tidy = threadIdx.y;
const auto col_idx = blockIdx.x * default_dot_dim + tidx;
const auto num = ceildiv(num_rows, gridDim.y);
const auto start_row = blockIdx.y * num;
const auto end_row =
((blockIdx.y + 1) * num > num_rows) ? num_rows : (blockIdx.y + 1) * num;
// Used that way to get around dynamic initialization warning and
// template error when using `reduction_helper_array` directly in `reduce`
__shared__
UninitializedArray<ValueType, default_dot_dim *(default_dot_dim + 1)>
reduction_helper_array;
ValueType *__restrict__ reduction_helper = reduction_helper_array;

for (size_type k = 0; k < num_iters; ++k) {
ValueType local_res = zero<ValueType>();
const auto krylov_col = k * num_cols + col_idx;
if (col_idx < num_cols && !stop_status[col_idx].has_stopped()) {
for (size_type i = start_row + tidy; i < end_row;
i += default_dot_dim * mult) {
const auto next_krylov_idx =
i * stride_next_krylov * mult + col_idx;
const auto krylov_idx = i * stride_krylov * mult + krylov_col;
local_res += next_krylov_basis[next_krylov_idx] *
krylov_bases[krylov_idx];
if (mult > 1) {
const auto next_krylov_idx_2 =
next_krylov_idx +
default_dot_size * stride_next_krylov * mult;
const auto krylov_idx_2 =
krylov_idx + default_dot_size * stride_krylov * mult;
local_res += ((i + default_dot_size) < end_row)
? next_krylov_basis[next_krylov_idx_2] *
krylov_bases[krylov_idx_2]
: 0.0;
}
}

reduction_helper[tidx * (default_dot_dim + 1) + tidy] = local_res;
__syncthreads();
local_res = reduction_helper[tidy * (default_dot_dim + 1) + tidx];
const auto tile_block = group::tiled_partition<default_dot_dim>(
group::this_thread_block());
const auto sum = reduce(
tile_block, local_res,
[](const ValueType &a, const ValueType &b) { return a + b; });
const auto new_col_idx = blockIdx.x * default_dot_dim + tidy;
if (tidx == 0 && new_col_idx < num_cols &&
!stop_status[new_col_idx].has_stopped()) {
const auto hessenberg_idx = k * stride_hessenberg + new_col_idx;
atomic_add(hessenberg_iter + hessenberg_idx, sum);
}
}
}
}


// Must be called with at least `num_rows * stride_next_krylov` threads in
// total.
template <int block_size, typename ValueType, typename ValueTypeKrylovBases>
Expand Down Expand Up @@ -280,6 +349,37 @@ __global__ __launch_bounds__(block_size) void update_next_krylov_kernel(
}


// Must be called with at least `num_rows * stride_next_krylov` threads in
// total.
template <int block_size, typename ValueType, typename ValueTypeKrylovBases>
__global__
__launch_bounds__(block_size) void update_next_krylov_kernel_num_iters(
size_type num_iters, size_type num_rows, size_type num_cols,
ValueType *__restrict__ next_krylov_basis, size_type stride_next_krylov,
const ValueTypeKrylovBases *__restrict__ krylov_bases,
size_type stride_krylov, const ValueType *__restrict__ hessenberg_iter,
size_type stride_hessenberg,
const stopping_status *__restrict__ stop_status)
{
const auto global_id = thread::get_thread_id_flat();
const auto row_idx = global_id / stride_next_krylov;
const auto col_idx = global_id % stride_next_krylov;

if (row_idx < num_rows && col_idx < num_cols &&
!stop_status[col_idx].has_stopped()) {
const auto next_krylov_idx = row_idx * stride_next_krylov + col_idx;
for (size_type k = 0; k < num_iters; ++k) {
const auto krylov_idx =
row_idx * stride_krylov + k * num_cols + col_idx;
const auto hessenberg_idx = k * stride_hessenberg + col_idx;

next_krylov_basis[next_krylov_idx] -=
hessenberg_iter[hessenberg_idx] * krylov_bases[krylov_idx];
}
}
}


// Must be called with at least `num_rows * stride_next_krylov` threads in
// total.
template <int block_size, typename ValueType, typename ValueTypeKrylovBases>
Expand Down Expand Up @@ -356,6 +456,43 @@ __global__ __launch_bounds__(block_size) void update_next_krylov_kernel_and_add(
}


// Must be called with at least `num_rows * stride_next_krylov` threads in
// total.
template <int block_size, typename ValueType, typename ValueTypeKrylovBases>
__global__
__launch_bounds__(block_size) void update_next_krylov_kernel_num_iters_and_add(
size_type num_iters, size_type num_rows, size_type num_cols,
ValueType *__restrict__ next_krylov_basis, size_type stride_next_krylov,
const ValueTypeKrylovBases *__restrict__ krylov_bases,
size_type stride_krylov, ValueType *__restrict__ hessenberg_iter,
size_type stride_hessenberg, const ValueType *__restrict__ buffer_iter,
size_type stride_buffer,
const stopping_status *__restrict__ stop_status,
const stopping_status *__restrict__ reorth_status)
{
const auto global_id = thread::get_thread_id_flat();
const auto row_idx = global_id / stride_next_krylov;
const auto col_idx = global_id % stride_next_krylov;

if (row_idx < num_rows && col_idx < num_cols &&
!stop_status[col_idx].has_stopped() &&
!reorth_status[col_idx].has_stopped()) {
const auto next_krylov_idx = row_idx * stride_next_krylov + col_idx;
for (size_type k = 0; k < num_iters; ++k) {
const auto krylov_idx =
row_idx * stride_krylov + k * num_cols + col_idx;
const auto hessenberg_idx = k * stride_hessenberg + col_idx;
const auto buffer_idx = k * stride_buffer + col_idx;
next_krylov_basis[next_krylov_idx] -=
buffer_iter[buffer_idx] * krylov_bases[krylov_idx];
if ((row_idx == 0) && !reorth_status[col_idx].has_stopped()) {
hessenberg_iter[hessenberg_idx] += buffer_iter[buffer_idx];
}
}
}
}


// Must be called with at least `num_cols` blocks, each with `block_size`
// threads. `block_size` must be a power of 2.
template <int block_size, typename ValueType>
Expand Down Expand Up @@ -396,7 +533,8 @@ __global__ __launch_bounds__(block_size) void update_hessenberg_2_kernel(
const auto col_idx = blockIdx.x;

// Used that way to get around dynamic initialization warning and
// template error when using `reduction_helper_array` directly in `reduce`
// template error when using `reduction_helper_array` directly in
// `reduce`
__shared__ UninitializedArray<ValueType, block_size> reduction_helper_array;
ValueType *__restrict__ reduction_helper = reduction_helper_array;

Expand Down Expand Up @@ -608,8 +746,8 @@ __global__ __launch_bounds__(block_size) void solve_upper_triangular_kernel(
}


// Must be called with at least `stride_preconditioner * num_rows` threads in
// total.
// Must be called with at least `stride_preconditioner * num_rows` threads
// in total.
template <size_type block_size, typename ValueType,
typename ValueTypeKrylovBases>
__global__ __launch_bounds__(block_size) void calculate_Qy_kernel(
Expand Down
47 changes: 47 additions & 0 deletions core/solver/gmres_mixed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,12 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "core/solver/gmres_mixed_kernels.hpp"


// #define TIMING 1


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


namespace gko {
Expand Down Expand Up @@ -161,7 +166,11 @@ void GmresMixed<ValueType, ValueTypeKrylovBases>::apply_impl(const LinOp *b,
auto after_preconditioner =
matrix::Dense<ValueType>::create_with_config_of(dense_x);

#ifdef TIMING
auto start = std::chrono::steady_clock::now();
auto time_SPMV = start - start;
auto time_STEP1 = start - start;
#endif

while (true) {
++total_iter;
Expand Down Expand Up @@ -220,17 +229,29 @@ void GmresMixed<ValueType, ValueTypeKrylovBases>::apply_impl(const LinOp *b,
auto buffer_iter = buffer->create_submatrix(
span{0, restart_iter + 2}, span{0, dense_b->get_size()[1]});

#ifdef TIMING
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
time_SPMV += std::chrono::steady_clock::now() - t_aux_1;
#endif

#ifdef TIMING
auto t_aux_2 = std::chrono::steady_clock::now();
#endif
exec->run(gmres_mixed::make_step_1(
next_krylov_basis.get(), givens_sin.get(), givens_cos.get(),
residual_norm.get(), residual_norm_collection.get(),
krylov_bases.get(), hessenberg_iter.get(), buffer_iter.get(),
b_norm.get(), arnoldi_norm.get(), restart_iter, &final_iter_nums,
&stop_status, &reorth_status, &num_reorth));
#ifdef TIMING
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 -= hessenberg(restart_iter,
Expand Down Expand Up @@ -259,6 +280,9 @@ void GmresMixed<ValueType, ValueTypeKrylovBases>::apply_impl(const LinOp *b,
}

// Solve x
#ifdef TIMING
auto t_aux_3 = std::chrono::steady_clock::now();
#endif
auto krylov_bases_small = krylov_bases->create_submatrix(
span{0, system_matrix_->get_size()[0]},
span{0, dense_b->get_size()[1] * (restart_iter + 1)});
Expand All @@ -270,21 +294,44 @@ void GmresMixed<ValueType, ValueTypeKrylovBases>::apply_impl(const LinOp *b,
residual_norm_collection.get(), krylov_bases_small.get(),
hessenberg_small.get(), y.get(), before_preconditioner.get(),
&final_iter_nums));
#ifdef TIMING
auto time_STEP2 = std::chrono::steady_clock::now() - t_aux_3;
#endif
// Solve upper triangular.
// y = hessenberg \ residual_norm_collection

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

#ifdef TIMING
auto time = std::chrono::steady_clock::now() - start;
std::cout << "total_iter = " << total_iter << std::endl;
std::cout << "time = "
<< std::chrono::duration_cast<double_seconds>(time).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;
write(std::cout, lend(residual_norm));
#endif
}


Expand Down
Loading