Skip to content

Conversation

@SergeyKopienko
Copy link
Contributor

@SergeyKopienko SergeyKopienko commented Nov 4, 2025

This PR adds compile-time checks to detect accidental use of std::ranges::ref_view : it contains raw-pointer inside with the address of referenced view. In the case of SYCL-kernel we still have here pointer with the address of host memory.

The changes introduce a new MinimalisticRange type and refactor the testing infrastructure to verify that oneDPL properly rejects ranges containing host pointers while allowing safe views.

  • Introduces __contains_host_pointer trait to detect ranges with host pointers at compile time
  • Refactors MinimalisticView to inherit from new MinimalisticRange base type
  • Adds comprehensive static assertion tests for various view types

Details

  1. The std::range::all API function can return std::ref_view as described here link1, link2
  2. Due implementation details the `std::ref_view' contains raw-pointer to referenced view. In the context of heterogeneous implementations of oneDPL range-based algorithms, this means that the pointer stores the address of host memory. Consequently, dereferencing this host pointer on the device side will lead to a runtime failure (crash).
  3. To highlight this restriction we add new compile-time check:
    static_assert(!__contains_host_pointer_on_any_layers<std::decay_t<_Rng>>::value,
                  "oneDPL does not support std::ranges::ref_view in SYCL-kernel code");

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 adds compile-time checks to detect accidental use of std::ranges::views like ref_view that contain host pointers in SYCL kernels. The changes introduce a new MinimalisticRange type and refactor the testing infrastructure to verify that oneDPL properly rejects ranges containing host pointers while allowing safe views.

  • Introduces __contains_host_pointer trait to detect ranges with host pointers at compile time
  • Refactors MinimalisticView to inherit from new MinimalisticRange base type
  • Adds comprehensive static assertion tests for various view types (ref_view, zip_view, take_view, drop_view)

Reviewed Changes

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

Show a summary per file
File Description
test/support/utils.h Splits MinimalisticView into base MinimalisticRange and derived MinimalisticView to support different test scenarios
test/parallel_api/ranges/range_minimal_type_requirements.pass.cpp Adds compile-time error generation macros and new test_count_if test case with PredRef helper
test/general/implementation_details/subscription_view.pass.cpp Adds extensive static assertion tests for host pointer detection across various view compositions
include/oneapi/dpl/pstl/utils_ranges.h Refactors pipeline_base_range to __pipeline_base_range with improved type extraction
include/oneapi/dpl/pstl/hetero/dpcpp/utils_ranges_sycl.h Implements __contains_host_pointer detection mechanism and integrates static assertions into access requirement logic

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

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 5 out of 5 changed files in this pull request and generated 4 comments.


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

…pe / std::false_type underneath the structure struct pipeline_base_range
… nested view into struct pipeline_base_range
…struct __contains_host_pointer_on_any_layers and etc. staff
…e-time validation to check if the View is reference-based
…tional checks to ensure the new compile-time validation to checks (if the View is reference-based)
…ntroduce generation of compile-time errors (under switched off defines)
@SergeyKopienko SergeyKopienko force-pushed the dev/skopienko/detect_ref_view_on_compile_time branch from 2f6678b to 34368c5 Compare November 4, 2025 15:21
@SergeyKopienko SergeyKopienko added this to the 2022.12.0 milestone Nov 4, 2025
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 5 out of 5 changed files in this pull request and generated 5 comments.


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

…oduce contains_host_pointer_on_any_layers_v for test purposes
…ra std::remove_cvref_t<_View> from struct __contains_host_pointer_on_any_layers
…range::get_range_on_next_layer() as unused in code
…std::true_type / std::false_type) instead of inheritance
…n_next_layer -> struct pipeline_base_range::next_layer_view_t
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 5 out of 5 changed files in this pull request and generated 1 comment.


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

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 5 out of 5 changed files in this pull request and generated 5 comments.


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

@SergeyKopienko SergeyKopienko force-pushed the dev/skopienko/detect_ref_view_on_compile_time branch from 9a7834c to fea0d4d Compare November 7, 2025 13:23
Comment on lines +364 to +365
static_assert(!__contains_host_pointer_on_any_layers<_BaseRange>::value,
"oneDPL does not support std::ranges::ref_view in SYCL-kernel code");
Copy link
Contributor

Choose a reason for hiding this comment

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

Will you add a corresponding comment into the release notes or oneDPL guide? I think it is worth mentioning.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@timmiesmith, what is the best place to document this compile-time check?

Copy link
Contributor

@dmitriy-sobolev dmitriy-sobolev Nov 7, 2025

Choose a reason for hiding this comment

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

To be more precise, it's not about the check per se, but about the fact that that one should not pass anything for execution with device policies which can create std::ranges::ref_view underneath, e.g. std::ranges::views::all wrapping a range which is not a view.

My recommendation is the release notes for the upcoming release if we believe it is temporary and known limitations in the library guide if its for long. I am inclined towards the later.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think for now it is better considered a temporary limitation.

dmitriy-sobolev
dmitriy-sobolev previously approved these changes Nov 7, 2025
Copy link
Contributor

@dmitriy-sobolev dmitriy-sobolev left a comment

Choose a reason for hiding this comment

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

Looks good as it is.

I'm ready to reapprove if the documentation note is added, but it can be done separately.

@SergeyKopienko SergeyKopienko modified the milestones: 2022.12.0, 2022.11.0 Nov 7, 2025
…_view specialization to accept variadic template parameters
@akukanov
Copy link
Contributor

akukanov commented Nov 7, 2025

No more questions for the implementation, but I have not reviewed the test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants