-
Notifications
You must be signed in to change notification settings - Fork 87
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
Add a batched block Jacobi preconditioner #1542
Merged
+2,578
−8
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
2defd18
Add batch::Jacobi class and core
pratikvn 2bc540e
Add core tests
pratikvn c67e2b8
Add reference dev classes and kernels
pratikvn 212b544
Add reference tests
pratikvn ebd3c5d
Add omp kernels and unified tests
pratikvn 18cad0f
Add device stubs
pratikvn b9eeab8
fix typos and add batch_item nnz getter
pratikvn e16098b
update batch_item struct
pratikvn 4b450f5
Format tests and fix docs
pratikvn 2bf139c
review updates
pratikvn 4263556
Move storage_scheme funcs to internal headers
pratikvn 14d6e70
Add jacobi precond to solver dispatch and test
pratikvn f0b471d
Rem batch_jacobi_apply, add solver-precond test
pratikvn 7903d8d
add dev classes, update dispatch
pratikvn 46622e5
wip review updates
pratikvn 26dc67c
add assert_near for arrays
pratikvn 31d8997
review updates
pratikvn 7642294
s/cumulative_storage/cumulative_offsets
pratikvn f50d306
move block_pointers to class
pratikvn a7c8b71
review updates
pratikvn 0b1aa1c
getters need to be in headers
pratikvn 5938aa7
add scalar_jac solver test
pratikvn 83a9280
doc fixes
pratikvn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// SPDX-FileCopyrightText: 2017 - 2024 The Ginkgo authors | ||
// | ||
// SPDX-License-Identifier: BSD-3-Clause | ||
|
||
/** | ||
* BlockJacobi preconditioner for batch solvers. | ||
*/ | ||
template <typename ValueType> | ||
class BlockJacobi final { | ||
public: | ||
using value_type = ValueType; | ||
using index_type = int; | ||
|
||
|
||
/** | ||
* | ||
* @param max_block_size Maximum block size | ||
* @param num_blocks Number of diagonal blocks in a matrix | ||
* @param blocks_cumulative_offsets the cumulative block storage array | ||
* @param blocks_arr_batch array of diagonal blocks for the batch | ||
* @param block_ptrs_arr array of block pointers | ||
* @param row_block_map array containing block indices of the | ||
* blocks that the individual rows of the matrix are a part of | ||
* | ||
*/ | ||
BlockJacobi(const uint32 max_block_size, const size_type num_blocks, | ||
const int* const blocks_cumulative_offsets, | ||
const value_type* const blocks_arr_batch, | ||
const int* const block_ptrs_arr, const int* const row_block_map) | ||
: max_block_size_{max_block_size}, | ||
num_blocks_{num_blocks}, | ||
blocks_cumulative_offsets_{blocks_cumulative_offsets}, | ||
blocks_arr_batch_{blocks_arr_batch}, | ||
block_ptrs_arr_{block_ptrs_arr}, | ||
row_block_map_{row_block_map} | ||
{} | ||
|
||
/** | ||
* The size of the work vector required in case of dynamic allocation. | ||
*/ | ||
__host__ __device__ static constexpr int dynamic_work_size( | ||
const int num_rows, int) | ||
{ | ||
return 0; | ||
} | ||
|
||
__device__ __forceinline__ void generate( | ||
size_type batch_id, | ||
const gko::batch::matrix::ell::batch_item<const value_type, | ||
const index_type>&, | ||
value_type* const __restrict__) | ||
{} | ||
|
||
__device__ __forceinline__ void generate( | ||
size_type batch_id, | ||
const gko::batch::matrix::csr::batch_item<const value_type, | ||
const index_type>&, | ||
value_type* const __restrict__) | ||
{} | ||
|
||
__device__ __forceinline__ void generate( | ||
size_type batch_id, | ||
const gko::batch::matrix::dense::batch_item<const value_type>&, | ||
value_type* const __restrict__) | ||
{} | ||
|
||
__device__ __forceinline__ void apply(const int num_rows, | ||
const value_type* const r, | ||
value_type* const z) const | ||
{} | ||
|
||
private: | ||
const uint32 max_block_size_; | ||
const size_type num_blocks_; | ||
const int* __restrict__ const blocks_cumulative_offsets_; | ||
const value_type* const blocks_arr_batch_; | ||
const value_type* __restrict__ blocks_arr_entry_; | ||
const int* __restrict__ const block_ptrs_arr_; | ||
const int* __restrict__ const row_block_map_; | ||
}; |
77 changes: 77 additions & 0 deletions
77
common/cuda_hip/preconditioner/batch_scalar_jacobi.hpp.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
// SPDX-FileCopyrightText: 2017 - 2024 The Ginkgo authors | ||
// | ||
// SPDX-License-Identifier: BSD-3-Clause | ||
|
||
/** | ||
* (Scalar) Jacobi preconditioner for batch solvers. | ||
*/ | ||
template <typename ValueType> | ||
class ScalarJacobi final { | ||
public: | ||
using value_type = ValueType; | ||
using index_type = int; | ||
|
||
/** | ||
* The size of the work vector required in case of dynamic allocation. | ||
*/ | ||
__host__ __device__ static constexpr int dynamic_work_size( | ||
const int num_rows, int) | ||
{ | ||
return num_rows; | ||
} | ||
|
||
/** | ||
* Sets the input and generates the preconditioner by storing the inverse | ||
* diagonal entries in the work vector. | ||
* | ||
* @param mat Matrix for which to build a Jacobi preconditioner. | ||
* @param work A 'work-vector', used here to store the inverse diagonal | ||
* entries. It must be allocated with at least the amount | ||
* of memory given by dynamic_work_size. | ||
*/ | ||
__device__ __forceinline__ void generate( | ||
size_type, | ||
const gko::batch::matrix::ell::batch_item<const value_type, | ||
const index_type>& mat, | ||
value_type* const __restrict__ work) | ||
{} | ||
|
||
/** | ||
* Sets the input and generates the preconditioner by storing the inverse | ||
* diagonal entries in the work vector. | ||
* | ||
* @param mat Matrix for which to build a Jacobi preconditioner. | ||
* @param work A 'work-vector', used here to store the inverse diagonal | ||
* entries. It must be allocated with at least the amount | ||
* of memory given by dynamic_work_size. | ||
*/ | ||
__device__ __forceinline__ void generate( | ||
size_type, | ||
const gko::batch::matrix::csr::batch_item<const value_type, | ||
const index_type>& mat, | ||
value_type* const __restrict__ work) | ||
{} | ||
|
||
/** | ||
* Sets the input and generates the preconditioner by storing the inverse | ||
* diagonal entries in the work vector. | ||
* | ||
* @param mat Matrix for which to build a Jacobi preconditioner. | ||
* @param work A 'work-vector', used here to store the inverse diagonal | ||
* entries. It must be allocated with at least the amount | ||
* of memory given by dynamic_work_size. | ||
*/ | ||
__device__ __forceinline__ void generate( | ||
size_type, | ||
const gko::batch::matrix::dense::batch_item<const value_type>& mat, | ||
value_type* const __restrict__ work) | ||
{} | ||
|
||
__device__ __forceinline__ void apply(const int num_rows, | ||
const value_type* const r, | ||
value_type* const z) const | ||
{} | ||
|
||
private: | ||
value_type* __restrict__ work_; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,12 @@ struct batch_item { | |
const index_type* row_ptrs; | ||
index_type num_rows; | ||
index_type num_cols; | ||
index_type num_nnz_per_item; | ||
|
||
inline size_type get_single_item_num_nnz() const | ||
{ | ||
return static_cast<size_type>(num_nnz_per_item); | ||
} | ||
}; | ||
|
||
|
||
|
@@ -75,6 +81,11 @@ struct batch_item { | |
int32 stride; | ||
int32 num_rows; | ||
int32 num_cols; | ||
|
||
inline size_type get_single_item_num_nnz() const | ||
{ | ||
return static_cast<size_type>(stride * num_rows); | ||
} | ||
}; | ||
|
||
|
||
|
@@ -119,6 +130,11 @@ struct batch_item { | |
index_type num_rows; | ||
index_type num_cols; | ||
index_type num_stored_elems_per_row; | ||
|
||
inline size_type get_single_item_num_nnz() const | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I find it a bit odd, that both |
||
{ | ||
return static_cast<size_type>(stride * num_stored_elems_per_row); | ||
} | ||
}; | ||
|
||
|
||
|
@@ -153,7 +169,8 @@ template <typename ValueType, typename IndexType> | |
GKO_ATTRIBUTES GKO_INLINE csr::batch_item<const ValueType, const IndexType> | ||
to_const(const csr::batch_item<ValueType, IndexType>& b) | ||
{ | ||
return {b.values, b.col_idxs, b.row_ptrs, b.num_rows, b.num_cols}; | ||
return {b.values, b.col_idxs, b.row_ptrs, | ||
b.num_rows, b.num_cols, b.num_nnz_per_item}; | ||
} | ||
|
||
|
||
|
@@ -171,8 +188,12 @@ GKO_ATTRIBUTES GKO_INLINE csr::batch_item<ValueType, IndexType> | |
extract_batch_item(const csr::uniform_batch<ValueType, IndexType>& batch, | ||
const size_type batch_idx) | ||
{ | ||
return {batch.values + batch_idx * batch.num_nnz_per_item, batch.col_idxs, | ||
batch.row_ptrs, batch.num_rows, batch.num_cols}; | ||
return {batch.values + batch_idx * batch.num_nnz_per_item, | ||
batch.col_idxs, | ||
batch.row_ptrs, | ||
batch.num_rows, | ||
batch.num_cols, | ||
batch.num_nnz_per_item}; | ||
} | ||
|
||
template <typename ValueType, typename IndexType> | ||
|
@@ -183,8 +204,12 @@ extract_batch_item(ValueType* const batch_values, | |
const int num_cols, int num_nnz_per_item, | ||
const size_type batch_idx) | ||
{ | ||
return {batch_values + batch_idx * num_nnz_per_item, batch_col_idxs, | ||
batch_row_ptrs, num_rows, num_cols}; | ||
return {batch_values + batch_idx * num_nnz_per_item, | ||
batch_col_idxs, | ||
batch_row_ptrs, | ||
num_rows, | ||
num_cols, | ||
num_nnz_per_item}; | ||
} | ||
|
||
|
||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be in another pr?