-
Notifications
You must be signed in to change notification settings - Fork 808
[SYCL] Implement SYCL part of sycl_ext_oneapi_prefetch #11458
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
Merged
Changes from 21 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
6ab79b1
Initial
KornevNikita c4123e9
clang format
KornevNikita 549f9e8
Add joint_prefetch
KornevNikita 19e19a8
Fix comment
KornevNikita 30e531a
Use structured bindings
KornevNikita 42de79f
Remove redundant is_valid_property
KornevNikita 2d5a360
Add explicit enum values
KornevNikita c40e4bd
Ignore unused vars on host
KornevNikita 5de267d
Use enable_if as ret type
KornevNikita 7afe1c9
Use single_task in test
KornevNikita 886f2ab
clang-format
KornevNikita a8e907b
Rename first and second
KornevNikita 01a8b5a
Fix warning
KornevNikita 154660a
Delete comments
KornevNikita 82badcc
Fix
KornevNikita 7ecdbb1
Merge remote-tracking branch 'intel_llvm/sycl' into prefetch
KornevNikita ebc3b23
Add helper
KornevNikita a3dbe96
Remove redundant C-style casts
KornevNikita 9e81d89
Change helper
KornevNikita 3e554ac
Drop void in enable_if
KornevNikita 024c901
Remove sycl-post-link & test in favor on a follow-up patch
KornevNikita c796b9e
use capital initial letters
KornevNikita bf3d6c9
Move prefetch.hpp to experimental/ dir
KornevNikita 6d9de5a
Improve impl
KornevNikita 9ff283e
Add new test
KornevNikita 9b2ecc8
small fix
KornevNikita 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
KornevNikita marked this conversation as resolved.
Show resolved
Hide resolved
|
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,263 @@ | ||
| //==--------------- prefetch.hpp --- SYCL prefetch extension ---------------==// | ||
| // | ||
| // 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 <CL/__spirv/spirv_ops.hpp> | ||
| #include <sycl/ext/oneapi/properties/properties.hpp> | ||
|
|
||
| namespace sycl { | ||
| inline namespace _V1 { | ||
| namespace ext::oneapi::experimental { | ||
|
|
||
| enum class cache_level { L1 = 0, L2 = 1, L3 = 2, L4 = 3 }; | ||
|
|
||
| struct nontemporal; | ||
|
|
||
| struct prefetch_hint_key { | ||
| template <cache_level Level, typename Hint> | ||
| using value_t = | ||
| property_value<prefetch_hint_key, | ||
| std::integral_constant<cache_level, Level>, Hint>; | ||
| }; | ||
|
|
||
| template <cache_level Level, typename Hint> | ||
| inline constexpr prefetch_hint_key::value_t<Level, Hint> prefetch_hint; | ||
|
|
||
| inline constexpr prefetch_hint_key::value_t<cache_level::L1, void> | ||
| prefetch_hint_L1; | ||
| inline constexpr prefetch_hint_key::value_t<cache_level::L2, void> | ||
| prefetch_hint_L2; | ||
| inline constexpr prefetch_hint_key::value_t<cache_level::L3, void> | ||
| prefetch_hint_L3; | ||
| inline constexpr prefetch_hint_key::value_t<cache_level::L4, void> | ||
| prefetch_hint_L4; | ||
|
|
||
| inline constexpr prefetch_hint_key::value_t<cache_level::L1, nontemporal> | ||
| prefetch_hint_L1_nt; | ||
| inline constexpr prefetch_hint_key::value_t<cache_level::L2, nontemporal> | ||
| prefetch_hint_L2_nt; | ||
| inline constexpr prefetch_hint_key::value_t<cache_level::L3, nontemporal> | ||
| prefetch_hint_L3_nt; | ||
| inline constexpr prefetch_hint_key::value_t<cache_level::L4, nontemporal> | ||
| prefetch_hint_L4_nt; | ||
|
|
||
| namespace detail { | ||
| template <> struct IsCompileTimeProperty<prefetch_hint_key> : std::true_type {}; | ||
|
|
||
| template <cache_level Level, typename Hint> | ||
| struct PropertyMetaInfo<prefetch_hint_key::value_t<Level, Hint>> { | ||
| static constexpr const char *name = std::is_same_v<Hint, nontemporal> | ||
| ? "sycl-prefetch-hint-nt" | ||
| : "sycl-prefetch-hint"; | ||
| static constexpr int value = static_cast<int>(Level); | ||
KornevNikita marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| }; | ||
|
|
||
| template <access::address_space AS> | ||
| inline constexpr bool check_prefetch_AS = | ||
| AS == access::address_space::global_space || | ||
| AS == access::address_space::generic_space; | ||
|
|
||
| template <access_mode mode> | ||
| inline constexpr bool check_prefetch_acc_mode = | ||
| mode == access_mode::read || mode == access_mode::read_write; | ||
|
|
||
| template <typename Properties> | ||
| void prefetch_impl(void *ptr, size_t bytes, Properties properties) { | ||
| #ifdef __SYCL_DEVICE_ONLY__ | ||
KornevNikita marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| auto *ptrGlobalAS = __SYCL_GenericCastToPtrExplicit_ToGlobal<char>(ptr); | ||
| __attribute__((opencl_global)) char *ptrAnnotated = nullptr; | ||
| if constexpr (!properties.template has_property<prefetch_hint_key>()) { | ||
| ptrAnnotated = __builtin_intel_sycl_ptr_annotation( | ||
| ptrGlobalAS, "sycl-prefetch-hint", static_cast<int>(cache_level::L1)); | ||
| } else { | ||
| auto prop = properties.template get_property<prefetch_hint_key>(); | ||
| ptrAnnotated = __builtin_intel_sycl_ptr_annotation( | ||
| ptrGlobalAS, PropertyMetaInfo<decltype(prop)>::name, | ||
| PropertyMetaInfo<decltype(prop)>::value); | ||
| } | ||
| __spirv_ocl_prefetch(ptrAnnotated, bytes); | ||
| #else | ||
| std::ignore = ptr; | ||
| std::ignore = bytes; | ||
| std::ignore = properties; | ||
| #endif | ||
| } | ||
| } // namespace detail | ||
|
|
||
| template <typename Properties = empty_properties_t> | ||
| void prefetch(void *ptr, Properties properties = {}) { | ||
| detail::prefetch_impl(ptr, 1, properties); | ||
| } | ||
|
|
||
| template <typename Properties = empty_properties_t> | ||
| void prefetch(void *ptr, size_t bytes, Properties properties = {}) { | ||
| detail::prefetch_impl(ptr, bytes, properties); | ||
| } | ||
|
|
||
| template <typename T, typename Properties = empty_properties_t> | ||
| void prefetch(T *ptr, Properties properties = {}) { | ||
| prefetch(ptr, sizeof(T), properties); | ||
| } | ||
|
|
||
| template <typename T, typename Properties = empty_properties_t> | ||
| void prefetch(T *ptr, size_t count, Properties properties = {}) { | ||
| prefetch(ptr, count * sizeof(T), properties); | ||
| } | ||
|
|
||
| template <access::address_space AddressSpace, access::decorated IsDecorated, | ||
| typename Properties = empty_properties_t> | ||
| std::enable_if_t<detail::check_prefetch_AS<AddressSpace>> | ||
| prefetch(multi_ptr<void, AddressSpace, IsDecorated> ptr, | ||
| Properties properties = {}) { | ||
| prefetch(ptr.get(), properties); | ||
| } | ||
|
|
||
| template <access::address_space AddressSpace, access::decorated IsDecorated, | ||
| typename Properties = empty_properties_t> | ||
| std::enable_if_t<detail::check_prefetch_AS<AddressSpace>> | ||
| prefetch(multi_ptr<void, AddressSpace, IsDecorated> ptr, size_t bytes, | ||
| Properties properties = {}) { | ||
| prefetch(ptr.get(), bytes, properties); | ||
| } | ||
|
|
||
| template <typename T, access::address_space AddressSpace, | ||
| access::decorated IsDecorated, | ||
| typename Properties = empty_properties_t> | ||
| std::enable_if_t<detail::check_prefetch_AS<AddressSpace>> | ||
| prefetch(multi_ptr<T, AddressSpace, IsDecorated> ptr, | ||
| Properties properties = {}) { | ||
| prefetch(ptr.get(), properties); | ||
| } | ||
|
|
||
| template <typename T, access::address_space AddressSpace, | ||
| access::decorated IsDecorated, | ||
| typename Properties = empty_properties_t> | ||
| std::enable_if_t<detail::check_prefetch_AS<AddressSpace>> | ||
| prefetch(multi_ptr<T, AddressSpace, IsDecorated> ptr, size_t count, | ||
| Properties properties = {}) { | ||
| prefetch(ptr.get(), count, properties); | ||
| } | ||
|
|
||
| template <typename DataT, int Dimensions, access_mode AccessMode, | ||
| access::placeholder IsPlaceholder, | ||
| typename Properties = empty_properties_t> | ||
| std::enable_if_t<detail::check_prefetch_acc_mode<AccessMode> && | ||
| (Dimensions > 0)> | ||
| prefetch( | ||
| accessor<DataT, Dimensions, AccessMode, target::device, IsPlaceholder> acc, | ||
| id<Dimensions> offset, Properties properties = {}) { | ||
| prefetch(&acc[offset], sizeof(DataT), properties); | ||
| } | ||
|
|
||
| template <typename DataT, int Dimensions, access_mode AccessMode, | ||
| access::placeholder IsPlaceholder, | ||
| typename Properties = empty_properties_t> | ||
| std::enable_if_t<detail::check_prefetch_acc_mode<AccessMode> && | ||
| (Dimensions > 0)> | ||
| prefetch( | ||
| accessor<DataT, Dimensions, AccessMode, target::device, IsPlaceholder> acc, | ||
| size_t offset, size_t count, Properties properties = {}) { | ||
| prefetch(&acc[offset], count * sizeof(DataT), properties); | ||
| } | ||
|
|
||
| template <typename Group, typename Properties = empty_properties_t> | ||
| std::enable_if_t<sycl::is_group_v<std::decay_t<Group>>> | ||
| joint_prefetch(Group g, void *ptr, Properties properties = {}) { | ||
| std::ignore = g; | ||
| detail::prefetch_impl(ptr, 1, properties); | ||
| } | ||
|
|
||
| template <typename Group, typename Properties = empty_properties_t> | ||
| std::enable_if_t<sycl::is_group_v<std::decay_t<Group>>> | ||
| joint_prefetch(Group g, void *ptr, size_t bytes, Properties properties = {}) { | ||
| std::ignore = g; | ||
| detail::prefetch_impl(ptr, bytes, properties); | ||
| } | ||
|
|
||
| template <typename Group, typename T, typename Properties = empty_properties_t> | ||
| std::enable_if_t<sycl::is_group_v<std::decay_t<Group>>> | ||
| joint_prefetch(Group g, T *ptr, Properties properties = {}) { | ||
| std::ignore = g; | ||
| joint_prefetch(ptr, sizeof(T), properties); | ||
| } | ||
|
|
||
| template <typename Group, typename T, typename Properties = empty_properties_t> | ||
| std::enable_if_t<sycl::is_group_v<std::decay_t<Group>>> | ||
| joint_prefetch(Group g, T *ptr, size_t count, Properties properties = {}) { | ||
| std::ignore = g; | ||
| joint_prefetch(ptr, count * sizeof(T), properties); | ||
| } | ||
|
|
||
| template <typename Group, access::address_space AddressSpace, | ||
| access::decorated IsDecorated, | ||
| typename Properties = empty_properties_t> | ||
| std::enable_if_t<detail::check_prefetch_AS<AddressSpace> && | ||
| sycl::is_group_v<std::decay_t<Group>>> | ||
| joint_prefetch(Group g, multi_ptr<void, AddressSpace, IsDecorated> ptr, | ||
| Properties properties = {}) { | ||
| joint_prefetch(g, ptr.get(), properties); | ||
| } | ||
|
|
||
| template <typename Group, access::address_space AddressSpace, | ||
| access::decorated IsDecorated, | ||
| typename Properties = empty_properties_t> | ||
| std::enable_if_t<detail::check_prefetch_AS<AddressSpace> && | ||
| sycl::is_group_v<std::decay_t<Group>>> | ||
| joint_prefetch(Group g, multi_ptr<void, AddressSpace, IsDecorated> ptr, | ||
| size_t bytes, Properties properties = {}) { | ||
| joint_prefetch(g, ptr.get(), bytes, properties); | ||
| } | ||
|
|
||
| template <typename Group, typename T, access::address_space AddressSpace, | ||
| access::decorated IsDecorated, | ||
| typename Properties = empty_properties_t> | ||
| std::enable_if_t<detail::check_prefetch_AS<AddressSpace> && | ||
| sycl::is_group_v<std::decay_t<Group>>> | ||
| joint_prefetch(Group g, multi_ptr<T, AddressSpace, IsDecorated> ptr, | ||
| Properties properties = {}) { | ||
| joint_prefetch(g, ptr.get(), properties); | ||
| } | ||
|
|
||
| template <typename Group, typename T, access::address_space AddressSpace, | ||
| access::decorated IsDecorated, | ||
| typename Properties = empty_properties_t> | ||
| std::enable_if_t<detail::check_prefetch_AS<AddressSpace> && | ||
| sycl::is_group_v<std::decay_t<Group>>> | ||
| joint_prefetch(Group g, multi_ptr<T, AddressSpace, IsDecorated> ptr, | ||
| size_t count, Properties properties = {}) { | ||
| joint_prefetch(g, ptr.get(), count, properties); | ||
| } | ||
|
|
||
| template <typename Group, typename DataT, int Dimensions, | ||
| access_mode AccessMode, access::placeholder IsPlaceholder, | ||
| typename Properties = empty_properties_t> | ||
| std::enable_if_t<detail::check_prefetch_acc_mode<AccessMode> && | ||
| (Dimensions > 0) && sycl::is_group_v<std::decay_t<Group>>> | ||
| joint_prefetch( | ||
| Group g, | ||
| accessor<DataT, Dimensions, AccessMode, target::device, IsPlaceholder> acc, | ||
| size_t offset, Properties properties = {}) { | ||
| joint_prefetch(g, &acc[offset], sizeof(DataT), properties); | ||
| } | ||
|
|
||
| template <typename Group, typename DataT, int Dimensions, | ||
| access_mode AccessMode, access::placeholder IsPlaceholder, | ||
| typename Properties = empty_properties_t> | ||
| std::enable_if_t<detail::check_prefetch_acc_mode<AccessMode> && | ||
| (Dimensions > 0) && sycl::is_group_v<std::decay_t<Group>>> | ||
| joint_prefetch( | ||
| Group g, | ||
| accessor<DataT, Dimensions, AccessMode, target::device, IsPlaceholder> acc, | ||
| size_t offset, size_t count, Properties properties = {}) { | ||
| joint_prefetch(g, &acc[offset], count * sizeof(DataT), properties); | ||
| } | ||
|
|
||
| } // namespace ext::oneapi::experimental | ||
| } // 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
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.