-
Notifications
You must be signed in to change notification settings - Fork 99
Add Sor kernels #1634
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
Merged
Merged
Add Sor kernels #1634
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
9cb0ff4
[prec] split up common impl of sor
MarcelKoch c55811e
[prec] implement omp sor kernels
MarcelKoch 66b3aa3
[prec] implement sycl sor kernels
MarcelKoch 5d70bc8
[prec] implement cuda/hip sor kernels
MarcelKoch b3b8aab
[prec] add sor device test
MarcelKoch 2271b5f
[prec] add sor to benchmarks
MarcelKoch c2aad74
[test] add missing factorization tests
MarcelKoch 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 hidden or 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 hidden or 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
112 changes: 112 additions & 0 deletions
112
common/cuda_hip/factorization/factorization_helpers.hpp
This file contains hidden or 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,112 @@ | ||||||||
// SPDX-FileCopyrightText: 2017 - 2024 The Ginkgo authors | ||||||||
// | ||||||||
// SPDX-License-Identifier: BSD-3-Clause | ||||||||
|
||||||||
#include "common/cuda_hip/base/config.hpp" | ||||||||
#include "common/cuda_hip/base/runtime.hpp" | ||||||||
#include "common/cuda_hip/base/types.hpp" | ||||||||
#include "common/cuda_hip/components/thread_ids.hpp" | ||||||||
#include "core/factorization/factorization_helpers.hpp" | ||||||||
|
||||||||
|
||||||||
namespace gko { | ||||||||
namespace kernels { | ||||||||
namespace GKO_DEVICE_NAMESPACE { | ||||||||
namespace factorization { | ||||||||
namespace helpers { | ||||||||
|
||||||||
|
||||||||
using namespace ::gko::factorization; | ||||||||
|
||||||||
|
||||||||
constexpr int default_block_size{512}; | ||||||||
|
||||||||
|
||||||||
template <typename ValueType, typename IndexType, typename LClosure, | ||||||||
typename UClosure> | ||||||||
__global__ __launch_bounds__(default_block_size) void initialize_l_u( | ||||||||
size_type num_rows, const IndexType* __restrict__ row_ptrs, | ||||||||
const IndexType* __restrict__ col_idxs, | ||||||||
const ValueType* __restrict__ values, | ||||||||
const IndexType* __restrict__ l_row_ptrs, | ||||||||
IndexType* __restrict__ l_col_idxs, ValueType* __restrict__ l_values, | ||||||||
const IndexType* __restrict__ u_row_ptrs, | ||||||||
IndexType* __restrict__ u_col_idxs, ValueType* __restrict__ u_values, | ||||||||
LClosure l_closure, UClosure u_closure) | ||||||||
{ | ||||||||
const auto row = thread::get_thread_id_flat<IndexType>(); | ||||||||
if (row < num_rows) { | ||||||||
auto l_idx = l_row_ptrs[row]; | ||||||||
auto u_idx = u_row_ptrs[row] + 1; // we treat the diagonal separately | ||||||||
// default diagonal to one | ||||||||
auto diag_val = one<ValueType>(); | ||||||||
for (size_type i = row_ptrs[row]; i < row_ptrs[row + 1]; ++i) { | ||||||||
const auto col = col_idxs[i]; | ||||||||
const auto val = values[i]; | ||||||||
// save diagonal entry for later | ||||||||
if (col == row) { | ||||||||
diag_val = val; | ||||||||
} | ||||||||
if (col < row) { | ||||||||
l_col_idxs[l_idx] = col; | ||||||||
l_values[l_idx] = l_closure.map_off_diag(val); | ||||||||
++l_idx; | ||||||||
} | ||||||||
if (row < col) { | ||||||||
u_col_idxs[u_idx] = col; | ||||||||
u_values[u_idx] = u_closure.map_off_diag(val); | ||||||||
++u_idx; | ||||||||
} | ||||||||
} | ||||||||
// store diagonal entries | ||||||||
auto l_diag_idx = l_row_ptrs[row + 1] - 1; | ||||||||
auto u_diag_idx = u_row_ptrs[row]; | ||||||||
l_col_idxs[l_diag_idx] = row; | ||||||||
u_col_idxs[u_diag_idx] = row; | ||||||||
l_values[l_diag_idx] = l_closure.map_diag(diag_val); | ||||||||
u_values[u_diag_idx] = u_closure.map_diag(diag_val); | ||||||||
} | ||||||||
} | ||||||||
|
||||||||
|
||||||||
template <typename ValueType, typename IndexType, typename LClosure> | ||||||||
__global__ __launch_bounds__(default_block_size) void initialize_l( | ||||||||
size_type num_rows, const IndexType* __restrict__ row_ptrs, | ||||||||
const IndexType* __restrict__ col_idxs, | ||||||||
const ValueType* __restrict__ values, | ||||||||
const IndexType* __restrict__ l_row_ptrs, | ||||||||
IndexType* __restrict__ l_col_idxs, ValueType* __restrict__ l_values, | ||||||||
LClosure l_closure) | ||||||||
{ | ||||||||
const auto row = thread::get_thread_id_flat<IndexType>(); | ||||||||
if (row < num_rows) { | ||||||||
auto l_idx = l_row_ptrs[row]; | ||||||||
// if there was no diagonal entry, default to one | ||||||||
auto diag_val = one<ValueType>(); | ||||||||
for (size_type i = row_ptrs[row]; i < row_ptrs[row + 1]; ++i) { | ||||||||
const auto col = col_idxs[i]; | ||||||||
const auto val = values[i]; | ||||||||
// save diagonal entry for later | ||||||||
if (col == row) { | ||||||||
diag_val = val; | ||||||||
} | ||||||||
if (col < row) { | ||||||||
l_col_idxs[l_idx] = col; | ||||||||
l_values[l_idx] = l_closure.map_off_diag(val); | ||||||||
++l_idx; | ||||||||
} | ||||||||
} | ||||||||
// store diagonal entries | ||||||||
auto l_diag_idx = l_row_ptrs[row + 1] - 1; | ||||||||
l_col_idxs[l_diag_idx] = row; | ||||||||
l_values[l_diag_idx] = l_closure.map_diag(diag_val); | ||||||||
} | ||||||||
} | ||||||||
|
||||||||
|
||||||||
} // namespace helpers | ||||||||
} // namespace factorization | ||||||||
} // namespace GKO_DEVICE_NAMESPACE | ||||||||
|
||||||||
} // namespace kernels | ||||||||
} // namespace gko | ||||||||
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.
Suggested change
nit |
This file contains hidden or 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
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.
Uh oh!
There was an error while loading. Please reload this page.