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 single-value access functions for array access #1485

Merged
merged 12 commits into from
Dec 12, 2023
Merged

Add single-value access functions for array access #1485

merged 12 commits into from
Dec 12, 2023

Conversation

upsj
Copy link
Member

@upsj upsj commented Dec 4, 2023

This adds bounds-checked array::load_value(size_type) and array::store_value(size_type, T) functions and uses them where possible

@upsj upsj added the 1:ST:ready-for-review This PR is ready for review label Dec 4, 2023
@upsj upsj requested a review from a team December 4, 2023 13:07
@upsj upsj self-assigned this Dec 4, 2023
@ginkgo-bot ginkgo-bot added reg:testing This is related to testing. mod:core This is related to the core module. mod:cuda This is related to the CUDA module. reg:benchmarking This is related to benchmarking. 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 mod:hip This is related to the HIP module. type:factorization This is related to the Factorizations type:multigrid This is related to multigrid type:stopping-criteria This is related to the stopping criteria mod:dpcpp This is related to the DPC++ module. labels Dec 4, 2023
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.

More places to replace:

  • common/unified/matrix/dense_kernels.template.cpp:281
  • core/baser/index_set.cpp:84
  • core/factorization/par_ict.cpp:170|189|191
  • core/matrix/sparsity_csr.cpp:136
  • dpcpp/matrix/csr_kernels.dp.cpp:2632

@MarcelKoch MarcelKoch requested a review from a team December 4, 2023 15:48
@upsj upsj requested a review from MarcelKoch December 4, 2023 16:39
@upsj
Copy link
Member Author

upsj commented Dec 4, 2023

@MarcelKoch thanks, I replaced them

@upsj
Copy link
Member Author

upsj commented Dec 4, 2023

@pratikvn Our types are first and foremost used by our code, and an array class that doesn't provide access to its values is at least inconvenient. Thrust has device_vector, RAPIDS has device_uvector, all of which provide this kind of access and more. There are many ways of getting poor performance out of a high performance library - we have the same issue with automatic cross-executor and cross-precision copies. I don't believe this is sufficient reason to avoid adding this to our fundamental storage type. To me, the amount of simplifications this allows speaks for itself.
If people do encounter poor performance, we have both the ProfilerHook and PerformanceHint loggers to help them find the source of their performance issues.

@upsj upsj requested review from thoasm and pratikvn December 5, 2023 15:22
Copy link
Member

@pratikvn pratikvn left a comment

Choose a reason for hiding this comment

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

I still think the names load_value and store_value are misleading. In particular, because in my view load and store are verbs that are generally used for low level operations.

But I wont hold back the PR.

@upsj upsj 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 6, 2023
@upsj
Copy link
Member Author

upsj commented Dec 6, 2023

@pratikvn We have a kind of tendency in Ginkgo to give things elaborate names get_num_stored_elements, get_num_elems, copy_val_to_host, which I think we should cut back on. Arrays are a fundamental type, fundamental operations in fundamental types get short, concise (and established) names. This is also why I pushed against @thoasm suggestion of _to_host/_from_host suffixes.

I agree that load/store generally describe a lower abstraction level, but these functions should have concise names, and get/set_value wasn't considered clear enough.

@upsj
Copy link
Member Author

upsj commented Dec 9, 2023

In the latest state I added an accessor/device_reference-based interface, which has a slight readability advantage for writing values:

array.set_value(0, 1); // which is the index, which the value?
array.get_access()[0] = 0; // here it's clear

Still, these kinds of accessors bring all kinds of issues (e.g. the need to implement a lot of custom operators for cases where the matching operator is implemented with a template function, e.g. in std::complex)

@MarcelKoch
Copy link
Member

Maybe going back one step and just implement

void set_element(array, index, value);
T get_element(array, index);

in a private header would be the better choice right now. From the discussion, this would be rather uncontroversial and already fixes the use cases we want to target here.

@upsj upsj mentioned this pull request Dec 11, 2023
2 tasks
@upsj upsj added 1:ST:ready-for-review This PR is ready for review and removed 1:ST:do-not-merge Please do not merge PR this yet. labels Dec 11, 2023
@upsj upsj requested review from MarcelKoch and pratikvn December 11, 2023 16:29
@upsj
Copy link
Member Author

upsj commented Dec 11, 2023

As the least intrusive version, I now moved to an internal access function

Copy link
Member

@pratikvn pratikvn left a comment

Choose a reason for hiding this comment

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

LGTM!

@upsj upsj added the 1:ST:no-changelog-entry Skip the wiki check for changelog update label Dec 12, 2023
@upsj upsj 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
@upsj upsj merged commit deb7dda into develop Dec 12, 2023
@upsj upsj deleted the array_access branch December 12, 2023 23:05
Copy link

Quality Gate Passed Quality Gate passed

Kudos, no new issues were introduced!

0 New issues
0 Security Hotspots
No data about Coverage
No data about Duplication

See analysis details on SonarCloud

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1:ST:no-changelog-entry Skip the wiki check for changelog update 1:ST:ready-to-merge This PR is ready to merge. mod:core This is related to the core module. mod:cuda This is related to the CUDA module. mod:dpcpp This is related to the DPC++ module. mod:hip This is related to the HIP module. reg:benchmarking This is related to benchmarking. reg:testing This is related to testing. type:factorization This is related to the Factorizations type:matrix-format This is related to the Matrix formats type:multigrid This is related to multigrid 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
None yet
Development

Successfully merging this pull request may close these issues.

5 participants