-
Notifications
You must be signed in to change notification settings - Fork 99
Improved CSR-to-COO conversion #1832
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
Open
upsj
wants to merge
2
commits into
transform_iterator
Choose a base branch
from
improved_coo_conversion
base: transform_iterator
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -1,4 +1,4 @@ | ||||||||
// SPDX-FileCopyrightText: 2017 - 2024 The Ginkgo authors | ||||||||
// SPDX-FileCopyrightText: 2017 - 2025 The Ginkgo authors | ||||||||
// | ||||||||
// SPDX-License-Identifier: BSD-3-Clause | ||||||||
|
||||||||
|
@@ -7,6 +7,9 @@ | |||||||
#include <ginkgo/core/base/types.hpp> | ||||||||
|
||||||||
#include "common/unified/base/kernel_launch.hpp" | ||||||||
#include "common/unified/components/bitvector.hpp" | ||||||||
#include "core/base/index_range.hpp" | ||||||||
#include "core/base/iterator_factory.hpp" | ||||||||
#include "core/components/fill_array_kernels.hpp" | ||||||||
|
||||||||
|
||||||||
|
@@ -21,16 +24,23 @@ void convert_ptrs_to_idxs(std::shared_ptr<const DefaultExecutor> exec, | |||||||
const RowPtrType* ptrs, size_type num_blocks, | ||||||||
IndexType* idxs) | ||||||||
{ | ||||||||
const auto num_elements = exec->copy_val_to_host(ptrs + num_blocks); | ||||||||
// transform the ptrs to a bitvector in unary delta encoding, i.e. | ||||||||
// every row with n elements is encoded as 1 0 ... n times ... 0 | ||||||||
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
|
||||||||
auto it = gko::detail::make_transform_iterator( | ||||||||
index_iterator<IndexType>{0}, | ||||||||
[ptrs] GKO_KERNEL(IndexType i) -> RowPtrType { return ptrs[i] + i; }); | ||||||||
auto bv = bitvector::from_sorted_indices(exec, it, num_blocks, | ||||||||
num_blocks + num_elements); | ||||||||
run_kernel( | ||||||||
exec, | ||||||||
[] GKO_KERNEL(auto block, auto ptrs, auto idxs) { | ||||||||
auto begin = ptrs[block]; | ||||||||
auto end = ptrs[block + 1]; | ||||||||
for (auto i = begin; i < end; i++) { | ||||||||
idxs[i] = block; | ||||||||
[] GKO_KERNEL(RowPtrType i, auto bv, auto idxs) { | ||||||||
if (!bv[i]) { | ||||||||
auto rank = bv.get_rank(i); | ||||||||
idxs[i - rank] = rank - 1; | ||||||||
} | ||||||||
}, | ||||||||
num_blocks, ptrs, idxs); | ||||||||
num_blocks + num_elements, bv.device_view(), idxs); | ||||||||
} | ||||||||
|
||||||||
GKO_INSTANTIATE_FOR_EACH_INDEX_TYPE(GKO_DECLARE_CONVERT_PTRS_TO_IDXS32); | ||||||||
|
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.
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.
maybe we just paste the idxs size from outside. We should have it already when allocating the idxs array