-
Notifications
You must be signed in to change notification settings - Fork 801
[SYCL] Implement subset of sycl_ext_oneapi_kernel_properties #7018
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
Merged
steffenlarsen
merged 9 commits into
intel:sycl
from
steffenlarsen:steffen/kernel_props_rtheader_parts
Oct 18, 2022
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
a4a2924
[SYCL] Implement subset of sycl_ext_oneapi_kernel_properties
steffenlarsen 98a704b
Merge remote-tracking branch 'intel/sycl' into steffen/kernel_props_r…
steffenlarsen 2495f7c
Add TODOs and a note about same-kernel-conflict
steffenlarsen 69319af
Fix formatting
steffenlarsen b12797d
Fix test after formatting
steffenlarsen d914486
Change warning diagnostics
steffenlarsen b61de74
Add comment about PropKindSize
steffenlarsen 3659d11
Merge remote-tracking branch 'intel/sycl' into steffen/kernel_props_r…
steffenlarsen 2581d47
Fix mecro warning on Windows
steffenlarsen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
195 changes: 195 additions & 0 deletions
195
sycl/include/sycl/ext/oneapi/kernel_properties/properties.hpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,195 @@ | ||
| //==------- properties.hpp - SYCL properties associated with kernels -------==// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <sycl/ext/oneapi/properties/property.hpp> | ||
| #include <sycl/ext/oneapi/properties/property_value.hpp> | ||
|
|
||
| #include <array> | ||
|
|
||
| namespace sycl { | ||
| __SYCL_INLINE_VER_NAMESPACE(_V1) { | ||
| namespace ext { | ||
| namespace oneapi { | ||
| namespace experimental { | ||
| namespace detail { | ||
| // Trait for checking that all size_t values are non-zero. | ||
| template <size_t... Xs> struct AllNonZero { | ||
| static inline constexpr bool value = true; | ||
| }; | ||
| template <size_t X, size_t... Xs> struct AllNonZero<X, Xs...> { | ||
| static inline constexpr bool value = X > 0 && AllNonZero<Xs...>::value; | ||
| }; | ||
|
|
||
| // Simple helpers for containing primitive types as template arguments. | ||
| template <size_t... Sizes> struct SizeList {}; | ||
| template <char... Sizes> struct CharList {}; | ||
|
|
||
| // Helper for converting characters to a constexpr string. | ||
| template <char... Chars> struct CharsToStr { | ||
| static inline constexpr const char value[] = {Chars..., '\0'}; | ||
| }; | ||
|
|
||
| // Helper for converting a list of size_t values to a comma-separated string | ||
| // representation. This is done by extracting the digit one-by-one and when | ||
| // finishing a value, the parsed result is added to a separate list of | ||
| // "parsed" characters with the delimiter. | ||
| template <typename List, typename ParsedList, char... Chars> | ||
| struct SizeListToStrHelper; | ||
| template <size_t Value, size_t... Values, char... ParsedChars, char... Chars> | ||
| struct SizeListToStrHelper<SizeList<Value, Values...>, CharList<ParsedChars...>, | ||
| Chars...> | ||
| : SizeListToStrHelper<SizeList<Value / 10, Values...>, | ||
| CharList<ParsedChars...>, '0' + (Value % 10), | ||
| Chars...> {}; | ||
| template <size_t... Values, char... ParsedChars, char... Chars> | ||
| struct SizeListToStrHelper<SizeList<0, Values...>, CharList<ParsedChars...>, | ||
| Chars...> | ||
| : SizeListToStrHelper<SizeList<Values...>, | ||
| CharList<ParsedChars..., Chars..., ','>> {}; | ||
| template <char... ParsedChars, char... Chars> | ||
| struct SizeListToStrHelper<SizeList<0>, CharList<ParsedChars...>, Chars...> | ||
| : CharsToStr<ParsedChars..., Chars...> {}; | ||
|
|
||
| // Converts size_t values to a comma-separated string representation. | ||
| template <size_t... Sizes> | ||
| struct SizeListToStr : SizeListToStrHelper<SizeList<Sizes...>, CharList<>> {}; | ||
| } // namespace detail | ||
|
|
||
| struct properties_tag {}; | ||
|
|
||
| struct work_group_size_key { | ||
| template <size_t... Dims> | ||
| using value_t = property_value<work_group_size_key, | ||
| std::integral_constant<size_t, Dims>...>; | ||
| }; | ||
|
|
||
| struct work_group_size_hint_key { | ||
| template <size_t... Dims> | ||
| using value_t = property_value<work_group_size_hint_key, | ||
| std::integral_constant<size_t, Dims>...>; | ||
| }; | ||
|
|
||
| struct sub_group_size_key { | ||
| template <uint32_t Size> | ||
| using value_t = property_value<sub_group_size_key, | ||
| std::integral_constant<uint32_t, Size>>; | ||
| }; | ||
|
|
||
| template <size_t Dim0, size_t... Dims> | ||
| struct property_value<work_group_size_key, std::integral_constant<size_t, Dim0>, | ||
| std::integral_constant<size_t, Dims>...> { | ||
| static_assert( | ||
| sizeof...(Dims) + 1 <= 3, | ||
| "work_group_size property currently only supports up to three values."); | ||
| static_assert(detail::AllNonZero<Dim0, Dims...>::value, | ||
| "work_group_size property must only contain non-zero values."); | ||
|
|
||
| using key_t = work_group_size_key; | ||
|
|
||
| constexpr size_t operator[](int Dim) const { | ||
| return std::array<size_t, sizeof...(Dims) + 1>{Dim0, Dims...}[Dim]; | ||
| } | ||
| }; | ||
|
|
||
| template <size_t Dim0, size_t... Dims> | ||
| struct property_value<work_group_size_hint_key, | ||
| std::integral_constant<size_t, Dim0>, | ||
| std::integral_constant<size_t, Dims>...> { | ||
| static_assert(sizeof...(Dims) + 1 <= 3, | ||
| "work_group_size_hint property currently " | ||
| "only supports up to three values."); | ||
| static_assert( | ||
| detail::AllNonZero<Dim0, Dims...>::value, | ||
| "work_group_size_hint property must only contain non-zero values."); | ||
|
|
||
| using key_t = work_group_size_hint_key; | ||
|
|
||
| constexpr size_t operator[](int Dim) const { | ||
| return std::array<size_t, sizeof...(Dims) + 1>{Dim0, Dims...}[Dim]; | ||
| } | ||
| }; | ||
|
|
||
| template <uint32_t Size> | ||
| struct property_value<sub_group_size_key, | ||
| std::integral_constant<uint32_t, Size>> { | ||
| static_assert(Size != 0, | ||
| "sub_group_size_key property must contain a non-zero value."); | ||
|
|
||
| using key_t = sub_group_size_key; | ||
| using value_t = std::integral_constant<uint32_t, Size>; | ||
| static constexpr uint32_t value = Size; | ||
| }; | ||
|
|
||
| template <size_t Dim0, size_t... Dims> | ||
| inline constexpr work_group_size_key::value_t<Dim0, Dims...> work_group_size; | ||
|
|
||
| template <size_t Dim0, size_t... Dims> | ||
| inline constexpr work_group_size_hint_key::value_t<Dim0, Dims...> | ||
| work_group_size_hint; | ||
|
|
||
| template <uint32_t Size> | ||
| inline constexpr sub_group_size_key::value_t<Size> sub_group_size; | ||
|
|
||
| template <> struct is_property_key<work_group_size_key> : std::true_type {}; | ||
| template <> | ||
| struct is_property_key<work_group_size_hint_key> : std::true_type {}; | ||
| template <> struct is_property_key<sub_group_size_key> : std::true_type {}; | ||
|
|
||
| namespace detail { | ||
| template <> struct PropertyToKind<work_group_size_key> { | ||
| static constexpr PropKind Kind = PropKind::WorkGroupSize; | ||
| }; | ||
| template <> struct PropertyToKind<work_group_size_hint_key> { | ||
| static constexpr PropKind Kind = PropKind::WorkGroupSizeHint; | ||
| }; | ||
| template <> struct PropertyToKind<sub_group_size_key> { | ||
| static constexpr PropKind Kind = PropKind::SubGroupSize; | ||
| }; | ||
|
|
||
| template <> | ||
| struct IsCompileTimeProperty<work_group_size_key> : std::true_type {}; | ||
| template <> | ||
| struct IsCompileTimeProperty<work_group_size_hint_key> : std::true_type {}; | ||
| template <> | ||
| struct IsCompileTimeProperty<sub_group_size_key> : std::true_type {}; | ||
|
|
||
| template <size_t Dim0, size_t... Dims> | ||
| struct PropertyMetaInfo<work_group_size_key::value_t<Dim0, Dims...>> { | ||
| static constexpr const char *name = "sycl-work-group-size"; | ||
| static constexpr const char *value = SizeListToStr<Dim0, Dims...>::value; | ||
| }; | ||
| template <size_t Dim0, size_t... Dims> | ||
| struct PropertyMetaInfo<work_group_size_hint_key::value_t<Dim0, Dims...>> { | ||
| static constexpr const char *name = "sycl-work-group-size-hint"; | ||
| static constexpr const char *value = SizeListToStr<Dim0, Dims...>::value; | ||
| }; | ||
| template <uint32_t Size> | ||
| struct PropertyMetaInfo<sub_group_size_key::value_t<Size>> { | ||
| static constexpr const char *name = "sycl-sub-group-size"; | ||
| static constexpr uint32_t value = Size; | ||
| }; | ||
|
|
||
| template <typename T, typename = void> | ||
| struct HasKernelPropertiesGetMethod : std::false_type {}; | ||
|
|
||
| template <typename T> | ||
| struct HasKernelPropertiesGetMethod< | ||
| T, sycl::detail::void_t<decltype(std::declval<T>().get( | ||
| std::declval<properties_tag>()))>> : std::true_type { | ||
| using properties_t = | ||
| decltype(std::declval<T>().get(std::declval<properties_tag>())); | ||
| }; | ||
|
|
||
| } // namespace detail | ||
| } // namespace experimental | ||
| } // namespace oneapi | ||
| } // namespace ext | ||
| } // __SYCL_INLINE_VER_NAMESPACE(_V1) | ||
| } // namespace sycl |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.