Skip to content

Conversation

@danhoeflinger
Copy link
Contributor

@danhoeflinger danhoeflinger commented Dec 29, 2025

Summary

Move access mode resolution logic from scattered make_iter_mode calls to the leaf-level __get_sycl_range when processing sycl_iterator. This centralizes the mode resolution logic and ensures it properly recurses through nested iterator types.

Changes

Removed make_iter_mode pattern:

  • Removed iter_mode struct and make_iter_mode function from parallel_backend_sycl.h
  • Removed all make_iter_mode wrapper calls from algorithm implementations in algorithm_impl_hetero.h and async_impl_hetero.h

Refactored iter_mode_resolver:

  • Moved to utils_ranges_sycl.h as the authoritative location
  • Primary template is now undefined (SFINAE-friendly) instead of using static_assert
  • Added __is_iter_mode_resolvable_v trait for testable compile-time compatibility checking
  • Added third template parameter noInit to track whether algorithm allows skipping host→device copy

Fixed mode compatibility logic:

  • Removed incorrect specializations that claimed read or write iterators could satisfy read_write algorithm requirements
  • Removed incorrect specializations allowing discard_* modes with algorithms that dont have no_init
  • Valid combinations: exact match, read_writeread, read_writewrite, discard_read_write -> * (only when no_init=true), discard_write -> write (only when no_init=true).

Connected no_init property to accessors:

  • all_view now includes a template argument for _NoInit which connects to actual sycl accessor
  • Now properly uses backend buffer accessor system with no_init property when appropriate

NOTE: These changes could result in new build error for users where it was not before if it was relying upon improperly matched behavior. It seems like this could've resulted in silent problems or even segfaults in kernels where algorithms don't get the access modes they need.

Added tests:

  • test_is_iter_mode_resolvable_v() covering valid and invalid mode combinations

Targeted to land after #2519 and #2549 (final episode in the __get_sycl_range refactor trilogy)
Resolves Issue #2550

Future work:
There may be some opportunity to utilize no_init for our temporary buffers, though I'm not sure if that will result in any real savings, as the system should know when there is nothing to transfer to the device.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR centralizes access mode resolution logic for SYCL iterators by moving it from scattered make_iter_mode calls to the leaf-level __get_sycl_range implementation. The refactoring removes the iter_mode struct and make_iter_mode function, replacing them with compile-time mode resolution directly in __process_input_iter for sycl_iterator types.

Key Changes:

  • Removed make_iter_mode pattern and moved access mode resolution into __get_sycl_range's sycl_iterator specialization
  • Fixed incorrect mode compatibility logic (e.g., read/write iterators can no longer satisfy read_write algorithm requirements)
  • Added comprehensive test coverage for mode resolution compatibility checking

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
parallel_backend_sycl.h Removed deprecated iter_mode_resolver, iter_mode struct, and make_iter_mode function (~130 lines)
utils_ranges_sycl.h Added refactored iter_mode_resolver with corrected compatibility logic and new sycl_iterator specialization in __process_input_iter
algorithm_impl_hetero.h Removed make_iter_mode wrapper calls from fill, generate, partition_copy, inplace_merge, and partial_sort patterns
async_impl_hetero.h Removed make_iter_mode wrapper calls from async fill pattern
get_sycl_range.pass.cpp Added test_is_iter_mode_resolvable_v test function covering valid/invalid mode combinations

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@danhoeflinger danhoeflinger force-pushed the dev/dhoeflin/remove_make_iter_mode branch from e4040d0 to 5bf81d6 Compare December 31, 2025 21:50
@danhoeflinger danhoeflinger requested a review from Copilot January 2, 2026 12:56
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@danhoeflinger danhoeflinger linked an issue Jan 2, 2026 that may be closed by this pull request
@danhoeflinger danhoeflinger force-pushed the dev/dhoeflin/unitialized_refactors branch from 36ae926 to 03c83d1 Compare January 2, 2026 22:33
@danhoeflinger danhoeflinger force-pushed the dev/dhoeflin/remove_make_iter_mode branch from 044c431 to 728d20c Compare January 2, 2026 22:35
@danhoeflinger danhoeflinger added this to the 2022.12.0 milestone Jan 5, 2026
@danhoeflinger danhoeflinger force-pushed the dev/dhoeflin/unitialized_refactors branch from 03c83d1 to 08eb860 Compare January 5, 2026 18:12
@danhoeflinger danhoeflinger force-pushed the dev/dhoeflin/remove_make_iter_mode branch from 808f0de to be5fe30 Compare January 5, 2026 18:13
@MikeDvorskiy
Copy link
Contributor

MikeDvorskiy commented Jan 12, 2026

At first glance, I am in favor of the changes. I didn’t like iter_mode/iter_mode_resolver 3–4 years ago, since I had noticed needless structures. I’ve been wanting to cut these structures out of the oneDPL code for a long time.

Thank you!

//try searching for the first element which not equal to *__b
if (__b != __first1)
__b += __internal::__pstl_upper_bound(__b, _DifferenceType1{0}, __last1 - __b, __b, __comp, __proj1, __proj1);
__b += __internal::__pstl_upper_bound(__b, _DifferenceType1{0}, __last1 - __b, __b, __comp, __proj1,
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's save the previous format.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed these formatting only changes. thanks.

//try searching for the first element which not equal to *__e
if (__e != __last1)
__e += __internal::__pstl_upper_bound(__e, _DifferenceType1{0}, __last1 - __e, __e, __comp, __proj1, __proj1);
__e += __internal::__pstl_upper_bound(__e, _DifferenceType1{0}, __last1 - __e, __e, __comp, __proj1,
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's save the previous format.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed these formatting only changes. thanks.

@danhoeflinger danhoeflinger force-pushed the dev/dhoeflin/unitialized_refactors branch from 08eb860 to f02042d Compare January 13, 2026 13:50
fix access modes for uninitialized apis
remove unnecessary pattern

Signed-off-by: Dan Hoeflinger <[email protected]>
fix access modes for uninitialized apis
remove unnecessary pattern

Signed-off-by: Dan Hoeflinger <[email protected]>
Signed-off-by: Dan Hoeflinger <[email protected]>
Signed-off-by: Dan Hoeflinger <[email protected]>
Signed-off-by: Dan Hoeflinger <[email protected]>
@danhoeflinger danhoeflinger force-pushed the dev/dhoeflin/remove_make_iter_mode branch from be5fe30 to c0563c6 Compare January 13, 2026 14:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

iter_mode / make_iter_mode issues and potential cleanup

3 participants