-
Notifications
You must be signed in to change notification settings - Fork 115
Add static_assert check for std::range::ref_view in SYCL-kernel code
#2505
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
base: main
Are you sure you want to change the base?
Changes from 51 commits
48c6c34
72f6bb8
20bd154
c831d48
2b13025
07e29f0
ec09a2b
34368c5
75c7319
69672db
bc8354f
2da3e63
9cff760
3c05b6d
7bfa70c
3896354
c180296
b0cad39
0c5c4a6
5b0a64f
ad5b8d9
aa66198
1885cc1
bf02fc2
8f877be
350143e
7a4814a
c517a5e
82648ad
c42b7be
a7e4d8d
39b8fab
176c783
a10051d
286d3c3
f5a7312
8ff1b07
6269b98
64322f6
2d1ce66
c4b9908
bb91e23
673809a
74f3830
596a8b6
ae32ca8
fea0d4d
8b98829
51bec86
553a5f7
610bf38
7775879
760a5dc
8c5cb5d
2429167
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -309,10 +309,60 @@ __require_access_range(sycl::handler& __cgh, oneapi::dpl::__internal::tuple<_Ran | |
| ::std::make_index_sequence<__num_ranges>()); | ||
| } | ||
|
|
||
| template <typename...> | ||
| constexpr auto | ||
| __contains_host_pointer_probe(...) -> std::false_type; | ||
|
|
||
| // for std::ranges::ref_view | ||
| #if _ONEDPL_CPP20_RANGES_PRESENT | ||
| template <std::ranges::range Rng> | ||
| constexpr auto | ||
| __contains_host_pointer_probe(std::ranges::ref_view<Rng>*) -> std::true_type; | ||
| #endif // _ONEDPL_CPP20_RANGES_PRESENT | ||
|
|
||
| template <typename T> | ||
| using __remove_cv_ref_t = typename std::remove_cv<typename std::remove_reference<T>::type>::type; | ||
|
|
||
| template <typename T> | ||
| struct __contains_host_pointer : decltype(__contains_host_pointer_probe(static_cast<T*>(nullptr))){}; | ||
dmitriy-sobolev marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
SergeyKopienko marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| template <typename...> | ||
| struct __contains_host_pointer_on_any_layers; | ||
|
|
||
| // 1. Checking the top-level view | ||
| // 2. Searching view with host pointer in internal views(layers) | ||
| template <typename _View> | ||
| struct __contains_host_pointer_on_any_layers<_View> | ||
| : std::disjunction< | ||
| __contains_host_pointer<__remove_cv_ref_t<_View>>, | ||
| std::conditional_t<oneapi::dpl::__ranges::pipeline_base_range<_View>::has_next_layer_t::value, | ||
| __contains_host_pointer_on_any_layers< | ||
| typename oneapi::dpl::__ranges::pipeline_base_range<_View>::next_layer_view_t>, | ||
| std::false_type>> | ||
| { | ||
| }; | ||
|
|
||
| // 1.1. Checking the top-level view | ||
| // 1.2. Searching view with host pointer in internal views(layers) | ||
| // 2.1. Searching view with host pointer in the rest of views | ||
| template <typename _View, typename... _Views> | ||
| struct __contains_host_pointer_on_any_layers<_View, _Views...> | ||
| : std::disjunction<__contains_host_pointer_on_any_layers<_View>, __contains_host_pointer_on_any_layers<_Views...>> | ||
| { | ||
| }; | ||
SergeyKopienko marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| template <typename _Range, typename... _Ranges> | ||
| struct __contains_host_pointer_on_any_layers<oneapi::dpl::__ranges::zip_view<_Range, _Ranges...>> | ||
| : std::disjunction<__contains_host_pointer_on_any_layers<_Range>, __contains_host_pointer_on_any_layers<_Ranges...>> | ||
| { | ||
| }; | ||
SergeyKopienko marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| template <typename _BaseRange> | ||
| void | ||
| __require_access_range(sycl::handler&, _BaseRange&) | ||
| { | ||
| static_assert(!__contains_host_pointer_on_any_layers<_BaseRange>::value, | ||
| "oneDPL does not support std::ranges::ref_view in SYCL-kernel code"); | ||
|
Comment on lines
+354
to
+355
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @timmiesmith, what is the best place to document this compile-time check?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 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.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think for now it is better considered a temporary limitation. |
||
| } | ||
|
|
||
| template <typename _Range, typename... _Ranges> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,177 @@ | ||
| // -*- C++ -*- | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // Copyright (C) Intel Corporation | ||
| // | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| // This file incorporates work covered by the following copyright and permission | ||
| // notice: | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #include "support/test_config.h" | ||
|
|
||
| #include "support/utils.h" | ||
|
|
||
| #if _ENABLE_STD_RANGES_TESTING && TEST_DPCPP_BACKEND_PRESENT | ||
| #include <oneapi/dpl/pstl/hetero/dpcpp/utils_ranges_sycl.h> | ||
|
|
||
| using IntVector = std::vector<int>; | ||
dmitriy-sobolev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| using IteratorOfIntVector = typename IntVector::iterator; | ||
|
|
||
| using MinimalisticRangeForIntVec = TestUtils::MinimalisticRange<IteratorOfIntVector>; | ||
| using MinimalisticRangeViewForIntVec = TestUtils::MinimalisticView <IteratorOfIntVector>; | ||
|
|
||
| template <typename RandomIt> | ||
| struct MinimalisticViewWithSubscription : TestUtils::MinimalisticView<RandomIt> | ||
| { | ||
| MinimalisticViewWithSubscription(RandomIt it_begin, RandomIt it_end) | ||
| : TestUtils::MinimalisticView<RandomIt>(it_begin, it_end) | ||
| { | ||
| } | ||
|
|
||
| auto operator[](std::size_t index) const | ||
| { | ||
| return *(oneapi::dpl::__ranges::__begin(*this) + index); | ||
| } | ||
| }; | ||
|
|
||
| template <typename _Rng> | ||
| inline constexpr bool contains_host_pointer_v = oneapi::dpl::__ranges::__contains_host_pointer<_Rng>::value; | ||
|
|
||
| template <typename... _Rng> | ||
| inline constexpr bool contains_host_pointer_on_any_layers_v = oneapi::dpl::__ranges::__contains_host_pointer_on_any_layers<_Rng...>::value; | ||
|
|
||
| // oneapi::dpl::__ranges::__contains_host_pointer functional | ||
| void | ||
| check_contains_host_pointer() | ||
| { | ||
| { | ||
| IntVector vec; | ||
| auto all_view = std::ranges::views::all(MinimalisticRangeForIntVec(vec.begin(), vec.end())); | ||
| static_assert(contains_host_pointer_v<decltype(all_view)> == false); | ||
| static_assert(contains_host_pointer_on_any_layers_v<decltype(all_view)> == false); | ||
| } | ||
|
|
||
| { | ||
| IntVector vec; | ||
| MinimalisticViewWithSubscription mr_view(vec.begin(), vec.end()); | ||
| auto all_view = std::ranges::views::all(mr_view); | ||
| static_assert(contains_host_pointer_v<decltype(all_view)> == false); | ||
| static_assert(contains_host_pointer_on_any_layers_v<decltype(all_view)> == false); | ||
| } | ||
|
|
||
| { | ||
| IntVector vec; | ||
|
|
||
| MinimalisticViewWithSubscription mr_view(vec.begin(), vec.end()); | ||
| auto all_view1 = std::ranges::views::all(mr_view); | ||
|
|
||
| MinimalisticRangeForIntVec mr(vec.begin(), vec.end()); | ||
| auto all_view2 = std::ranges::views::all(mr); | ||
|
|
||
| static_assert(contains_host_pointer_on_any_layers_v<decltype(all_view1)> == false); | ||
| static_assert(contains_host_pointer_on_any_layers_v<decltype(all_view2)> == true); | ||
| static_assert(contains_host_pointer_on_any_layers_v<decltype(all_view1), decltype(all_view2)> == true); | ||
| } | ||
| } | ||
|
|
||
| // oneapi::dpl::__ranges::__contains_host_pointer functional with oneapi::dpl::__ranges::zip_view | ||
| void | ||
| check_contains_host_pointer_in_zip_view() | ||
| { | ||
| { | ||
| IntVector vec; | ||
|
|
||
| MinimalisticRangeForIntVec mr(vec.begin(), vec.end()); | ||
| auto all_view = std::ranges::views::all(mr); | ||
|
|
||
| auto zip_view = oneapi::dpl::__ranges::make_zip_view(all_view, all_view); | ||
|
|
||
| static_assert(contains_host_pointer_v<decltype(all_view)> == true); | ||
| static_assert(contains_host_pointer_v<decltype(zip_view)> == false); | ||
| static_assert(contains_host_pointer_on_any_layers_v<decltype(zip_view)> == true); | ||
| } | ||
|
|
||
| { | ||
| IntVector vec; | ||
|
|
||
| MinimalisticViewWithSubscription mrv(vec.begin(), vec.end()); | ||
| auto all_view1 = std::ranges::views::all(mrv); | ||
|
|
||
| MinimalisticRangeForIntVec mr(vec.begin(), vec.end()); | ||
| auto all_view2 = std::ranges::views::all(mr); | ||
|
|
||
| auto zip_view = oneapi::dpl::__ranges::make_zip_view(all_view1, all_view2); | ||
|
|
||
| static_assert(contains_host_pointer_v<decltype(all_view1)> == false); | ||
| static_assert(contains_host_pointer_v<decltype(all_view2)> == true); | ||
| static_assert(contains_host_pointer_v<decltype(zip_view)> == false); | ||
| static_assert(contains_host_pointer_on_any_layers_v<decltype(zip_view)> == true); | ||
| } | ||
|
|
||
| { | ||
| IntVector vec; | ||
|
|
||
| MinimalisticViewWithSubscription mrv(vec.begin(), vec.end()); | ||
| auto all_view = std::ranges::views::all(mrv); | ||
|
|
||
| auto zip_view = oneapi::dpl::__ranges::make_zip_view(all_view, all_view); | ||
|
|
||
| static_assert(contains_host_pointer_v<decltype(all_view)> == false); | ||
| static_assert(contains_host_pointer_v<decltype(zip_view)> == false); | ||
| static_assert(contains_host_pointer_on_any_layers_v<decltype(zip_view)> == false); | ||
| } | ||
| } | ||
|
|
||
| // oneapi::dpl::__ranges::__contains_host_pointer functional with std::ranges::take_view | ||
| void | ||
| check_contains_host_pointer_in_take_view() | ||
| { | ||
| IntVector vec; | ||
| MinimalisticRangeForIntVec mr(vec.begin(), vec.end()); | ||
| auto all_view = std::ranges::views::all(mr); | ||
| auto taken_view = std::ranges::take_view(all_view, all_view.size()); | ||
|
|
||
| static_assert(contains_host_pointer_v<decltype(all_view)> == true); | ||
| static_assert(contains_host_pointer_v<decltype(taken_view)> == false); | ||
| static_assert(contains_host_pointer_on_any_layers_v<decltype(taken_view)> == true); | ||
| } | ||
|
|
||
| // oneapi::dpl::__ranges::__contains_host_pointer functional with std::ranges::drop_view | ||
| void | ||
| check_contains_host_pointer_in_drop_view() | ||
| { | ||
| IntVector vec; | ||
| MinimalisticRangeForIntVec mr(vec.begin(), vec.end()); | ||
| auto all_view = std::ranges::views::all(mr); | ||
| auto dropped_view = std::ranges::drop_view(all_view, 0); | ||
|
|
||
| static_assert(contains_host_pointer_v<decltype(all_view)> == true); | ||
| static_assert(contains_host_pointer_v<decltype(dropped_view)> == false); | ||
| static_assert(contains_host_pointer_on_any_layers_v<decltype(dropped_view)> == true); | ||
| } | ||
| #endif // _ENABLE_STD_RANGES_TESTING && TEST_DPCPP_BACKEND_PRESENT | ||
|
|
||
| int | ||
| main() | ||
| { | ||
| bool bProcessed = false; | ||
|
|
||
| #if _ENABLE_STD_RANGES_TESTING && TEST_DPCPP_BACKEND_PRESENT | ||
|
|
||
| check_contains_host_pointer(); | ||
| check_contains_host_pointer_in_zip_view(); | ||
| check_contains_host_pointer_in_take_view(); | ||
| check_contains_host_pointer_in_drop_view(); | ||
|
|
||
| bProcessed = true; | ||
|
|
||
| #endif // _ENABLE_STD_RANGES_TESTING && TEST_DPCPP_BACKEND_PRESENT | ||
|
|
||
| return TestUtils::done(bProcessed); | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.