Skip to content
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 CSR batched matrix format, CUDA, HIP and DPCPP kernels #1450

Merged
merged 18 commits into from
Dec 12, 2023

Conversation

pratikvn
Copy link
Member

@pratikvn pratikvn commented Nov 5, 2023

This PR adds a batched Csr matrix format, that stores the same sparsity pattern for all entries, but different values for each batch. Only simple and advanced apply to batch::MultiVector are supported for now.

TODO

  • Add CUDA/HIP kernels
  • Add DPCPP kernels
  • Add to batch::Bicgstab dispatch
  • Update docs

@pratikvn pratikvn added 1:ST:WIP This PR is a work in progress. Not ready for review. type:batched-functionality This is related to the batched functionality in Ginkgo labels Nov 5, 2023
@pratikvn pratikvn self-assigned this Nov 5, 2023
@ginkgo-bot ginkgo-bot added reg:build This is related to the build system. reg:testing This is related to testing. type:solver This is related to the solvers type:preconditioner This is related to the preconditioners type:matrix-format This is related to the Matrix formats type:stopping-criteria This is related to the stopping criteria mod:all This touches all Ginkgo modules. labels Nov 5, 2023
@pratikvn pratikvn force-pushed the batch-bicgstab-device branch 2 times, most recently from f600023 to 79e68b3 Compare November 5, 2023 16:17
upsj
upsj previously requested changes Nov 5, 2023
Copy link
Member

@upsj upsj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR is pretty late, so I only went over the implementation, not the tests. Most of it LGTM, there is just a behavioral change in here that I believe overshoots in fixing a specific edge case.

common/cuda_hip/matrix/batch_csr_kernels.hpp.inc Outdated Show resolved Hide resolved
common/cuda_hip/matrix/batch_csr_kernels.hpp.inc Outdated Show resolved Hide resolved
core/matrix/csr.cpp Outdated Show resolved Hide resolved
core/test/matrix/batch_csr.cpp Outdated Show resolved Hide resolved
dpcpp/matrix/batch_csr_kernels.hpp.inc Outdated Show resolved Hide resolved
@@ -37,7 +37,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


#include <ginkgo/core/base/batch_multi_vector.hpp>
#include <ginkgo/core/matrix/batch_dense.hpp>
#include <ginkgo/core/matrix/batch_ell.hpp>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

leftover?

@pratikvn
Copy link
Member Author

pratikvn commented Nov 5, 2023

@upsj , this was not meant to be in the release. I had a bit of time, so decided to work on it. Thanks for reviewing, but this is still a WIP, that is why I havent requested any reviews or marked it ready-for-review yet.

@upsj
Copy link
Member

upsj commented Nov 5, 2023

@pratikvn phew, thank you, that would have been a night shift otherwise 😄

@pratikvn
Copy link
Member Author

pratikvn commented Nov 5, 2023

format!

@pratikvn pratikvn added 1:ST:ready-for-review This PR is ready for review and removed 1:ST:WIP This PR is a work in progress. Not ready for review. labels Nov 5, 2023
@pratikvn pratikvn requested a review from a team November 5, 2023 22:04
Base automatically changed from batch-bicgstab-device to develop November 5, 2023 23:44
@pratikvn
Copy link
Member Author

pratikvn commented Nov 6, 2023

format!

Copy link
Member

@yhmtsai yhmtsai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

except for the core/matrix/csr, other LGTM

dpcpp/matrix/batch_csr_kernels.hpp.inc Outdated Show resolved Hide resolved
*
* @return the number of stored elements per batch item.
*/
size_type get_num_elements_per_item() const noexcept
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we use get_num_stored_elements() in other place.
should it be get_num_stored_elements_per_item() for consistence? it's quite long though

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think get_num_elements_per_item is clear here. With stored it gets too long. Maybe it can also be renamed to get_nnz_per_item to make it shorter ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we try to avoid nnz because the stored element can be zeros

Comment on lines +30 to +33
* Csr is a general sparse matrix format that stores the column indices for each
* nonzero entry and a cumulative sum of the number of nonzeros in each row. It
* is one of the most popular sparse matrix formats due to its versatility and
* ability to store a wide range of sparsity patterns in an efficient fashion.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not update documentation with batch like batchEll?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should be updated. Or are you seeing something here that is incorrect ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's like CSR not batchCSR

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The note below clarifies that this is a batched matrix fomat, and how the batches are stored. I think being within the namespace also makes that clear. It is similar to batch::Ell. But I think can add more clarification to make it clear.

auto max_num_elems = this->get_common_size()[0] *
this->get_common_size()[1] *
this->get_num_batch_items();
GKO_ASSERT(values_.get_size() <= max_num_elems);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you need to check this? it is just unused from the batch csr

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, the get_num_stored_elements is based on values.size(), so it is required to only store the batch value

reference/test/matrix/batch_csr_kernels.cpp Outdated Show resolved Hide resolved
reference/test/matrix/batch_csr_kernels.cpp Show resolved Hide resolved
Copy link

codecov bot commented Dec 9, 2023

Codecov Report

Attention: 18 lines in your changes are missing coverage. Please review.

Comparison is base (310bb4c) 89.33% compared to head (6adf1a6) 89.37%.

❗ Current head 6adf1a6 differs from pull request most recent head c30aae8. Consider uploading reports for the commit c30aae8 to get more accurate results

Files Patch % Lines
core/matrix/batch_csr.cpp 86.27% 7 Missing ⚠️
core/test/matrix/batch_csr.cpp 96.80% 4 Missing ⚠️
include/ginkgo/core/matrix/batch_csr.hpp 88.46% 3 Missing ⚠️
core/device_hooks/common_kernels.inc.cpp 0.00% 2 Missing ⚠️
core/solver/batch_dispatch.hpp 75.00% 1 Missing ⚠️
reference/test/matrix/batch_csr_kernels.cpp 98.43% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1450      +/-   ##
===========================================
+ Coverage    89.33%   89.37%   +0.04%     
===========================================
  Files          688      696       +8     
  Lines        56555    56944     +389     
===========================================
+ Hits         50524    50895     +371     
- Misses        6031     6049      +18     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

sonarcloud bot commented Dec 12, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 14 Code Smells

68.6% 68.6% Coverage
16.2% 16.2% Duplication

warning The version of Java (11.0.3) you have used to run this analysis is deprecated and we will stop accepting it soon. Please update to at least Java 17.
Read more here

Copy link
Member

@MarcelKoch MarcelKoch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I think the testing strategy should be revisited at some point. A lot of tests in core test functionality that is composed of smaller parts, but the implementation is the same for all different matrix types. For example, batch::write only requires that the type has create_const_view_for_item. Because of that many tests are repetetive and could probably be unified.

core/test/matrix/batch_csr.cpp Outdated Show resolved Hide resolved
reference/test/matrix/batch_csr_kernels.cpp Outdated Show resolved Hide resolved
@pratikvn pratikvn added 1:ST:ready-to-merge This PR is ready to merge. and removed 1:ST:ready-for-review This PR is ready for review labels Dec 12, 2023
@pratikvn
Copy link
Member Author

As the previous pipeline had fully passed, and I only removed a couple of tests, I will just go ahead and merge this PR, not waiting for the whole pipeline to complete.

@pratikvn pratikvn merged commit 830c289 into develop Dec 12, 2023
13 of 15 checks passed
@pratikvn pratikvn deleted the batch-csr-upd branch December 12, 2023 14:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1:ST:ready-to-merge This PR is ready to merge. 1:ST:run-full-test mod:all This touches all Ginkgo modules. reg:build This is related to the build system. reg:testing This is related to testing. type:batched-functionality This is related to the batched functionality in Ginkgo type:matrix-format This is related to the Matrix formats type:preconditioner This is related to the preconditioners type:solver This is related to the solvers type:stopping-criteria This is related to the stopping criteria
Projects
Status: Completed
Development

Successfully merging this pull request may close these issues.

5 participants