Skip to content

Remove make_iter_mode and refactor access mode resolution#2551

Closed
danhoeflinger wants to merge 47 commits intomainfrom
dev/dhoeflin/remove_make_iter_mode
Closed

Remove make_iter_mode and refactor access mode resolution#2551
danhoeflinger wants to merge 47 commits intomainfrom
dev/dhoeflin/remove_make_iter_mode

Conversation

@danhoeflinger
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

Comment thread include/oneapi/dpl/pstl/hetero/dpcpp/utils_ranges_sycl.h Outdated
Comment thread include/oneapi/dpl/pstl/hetero/dpcpp/utils_ranges_sycl.h Outdated
Comment thread include/oneapi/dpl/pstl/hetero/dpcpp/utils_ranges_sycl.h
Comment thread include/oneapi/dpl/pstl/hetero/dpcpp/utils_ranges_sycl.h
Comment thread include/oneapi/dpl/pstl/hetero/dpcpp/utils_ranges_sycl.h
@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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
@danhoeflinger danhoeflinger force-pushed the dev/dhoeflin/remove_make_iter_mode branch from be5fe30 to c0563c6 Compare January 13, 2026 14:01
@danhoeflinger danhoeflinger force-pushed the dev/dhoeflin/unitialized_refactors branch from f02042d to e029ce4 Compare February 10, 2026 16:40
@danhoeflinger danhoeflinger force-pushed the dev/dhoeflin/remove_make_iter_mode branch from 267d03c to 1b39713 Compare February 10, 2026 17:07
@danhoeflinger danhoeflinger force-pushed the dev/dhoeflin/unitialized_refactors branch from e029ce4 to 46ff098 Compare February 20, 2026 16:41
@danhoeflinger danhoeflinger force-pushed the dev/dhoeflin/unitialized_refactors branch from 3060a9d to 90ff4fe Compare February 25, 2026 16:06
fix access modes for uninitialized apis
remove unnecessary pattern

Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com>
Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com>
danhoeflinger and others added 8 commits March 2, 2026 11:05
Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com>
Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com>
Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com>
Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com>
Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com>
Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com>
Co-authored-by: Alexey Kukanov <alexey.kukanov@intel.com>
@danhoeflinger danhoeflinger force-pushed the dev/dhoeflin/unitialized_refactors branch from 0b61bcf to 0a56ec7 Compare March 2, 2026 16:05
Copy link
Copy Markdown
Contributor

@MikeDvorskiy MikeDvorskiy left a comment

Choose a reason for hiding this comment

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

Left a comment/question.

Comment thread include/oneapi/dpl/pstl/hetero/dpcpp/utils_ranges_sycl.h
Base automatically changed from dev/dhoeflin/unitialized_refactors to main March 11, 2026 17:10
Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com>
Comment thread include/oneapi/dpl/pstl/memory_impl.h Outdated
Comment thread include/oneapi/dpl/pstl/hetero/dpcpp/utils_ranges_sycl.h Outdated
Comment thread include/oneapi/dpl/pstl/hetero/dpcpp/utils_ranges_sycl.h Outdated
Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com>
Comment thread include/oneapi/dpl/pstl/hetero/dpcpp/utils_ranges_sycl.h Outdated
Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com1>
@akukanov
Copy link
Copy Markdown
Contributor

akukanov commented Mar 13, 2026

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.

In other words, it is a potential breaking change for some users. We should not do this without analysis and discussion. And if we decide to do it in the future, we'll need to bump the major library version and perhaps even update the specification.

@danhoeflinger
Copy link
Copy Markdown
Contributor Author

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.

In other words, it is a potential breaking change for some users. We should not do this without analysis and discussion. And if we decide to do it in the future, we'll need to bump the major library version and perhaps even update the specification.

Yes, I suppose it is a breaking change, for users who had their access mode "hints" completely ignored and overridden. Both are valid implementations of the spec I believe, but you are right that it could break users code that currently works.
I'll revert those narrowing changes, and restore the previous access mode resolver which only rejects write with a read hint and vice versa.

Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com>
Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com>
@danhoeflinger
Copy link
Copy Markdown
Contributor Author

danhoeflinger commented Mar 13, 2026

In the review process, we have come to the conclusion that this should be considered a bit more robustly before merging. User provided hints are really only even considered for a small subset of algorithms currently. This PR would make them be resolved with algorithmic needs everywhere.

Also, it seems like the benefit of being stricter on conforming to user supplied hints is not worth the breaking changes that come from it due to poor coverage of using make_iter_mode prior to this PR.

It seems the best plan of action may be to consider hints for for_each and related APIs, but ignore them in all other cases.
for_each patterns could get some performance gain from a user providing more information about the usage pattern, allowing the implementation to skip copies to or from the device. All other APIs have known algorithmic needs, so hints don't make much sense, and should likely be ignored (which is allowed by the spec).

I have part of this proposal on a branch implemented, but it requires some more significant changes than can happen before code freeze, so I'm taking it out of the milestone. We lose out on connecting no_init to sycl buffer accessors, but we can include this in the next release.

@danhoeflinger danhoeflinger modified the milestones: 2022.12.0, 2022.13.0 Mar 13, 2026
@danhoeflinger
Copy link
Copy Markdown
Contributor Author

closing in favor of #2617.

@danhoeflinger danhoeflinger deleted the dev/dhoeflin/remove_make_iter_mode branch March 30, 2026 12:27
@akukanov akukanov removed this from the 2022.13.0 milestone Apr 20, 2026
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

5 participants