-
Notifications
You must be signed in to change notification settings - Fork 795
[SYCL] Implement reduction properties extension #15804
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
sarnex
merged 16 commits into
intel:sycl
from
Pennycook:sycl_ext_oneapi_reduction_properties
Oct 29, 2024
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
b94cb3f
[SYCL] Implement reduction properties extension
Pennycook 75197db
[SYCL] Add basic tests of reduction properties
Pennycook 8df293c
[SYCL][Doc] Mark reduction properties experimental
Pennycook 94f9b70
Remove operator names
Pennycook d87de38
Remove sycl/sycl.hpp from tests
Pennycook 7e05778
Fix use of host pointer on device
Pennycook 427a98f
Implement new properties via inheritance
Pennycook 56c149c
Rewrite tests to use host_accessor
Pennycook c39e14f
Rewrite tests to use std::array instead of heap
Pennycook 503c2e9
Replace is_like with IsKnownOp
Pennycook c5193fb
Update status to correct experimental wording
Pennycook 79f4805
Fix namespace in extension synopsis
Pennycook b465652
Add mandate for known identity values
Pennycook f9185fa
Fix constraints and mandates
Pennycook dfd5a1b
Merge branch 'sycl' into sycl_ext_oneapi_reduction_properties
Pennycook 3ea5c47
Remove property exception behavior
Pennycook 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
gmlueck marked this conversation as resolved.
Show resolved
Hide resolved
gmlueck 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
143 changes: 143 additions & 0 deletions
143
sycl/include/sycl/ext/oneapi/experimental/reduction_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,143 @@ | ||
//==------- properties.hpp - SYCL properties associated with reductions ----==// | ||
// | ||
// 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 | ||
#define SYCL_EXT_ONEAPI_REDUCTION_PROPERTIES | ||
|
||
#include <sycl/ext/oneapi/properties/property.hpp> | ||
#include <sycl/ext/oneapi/properties/property_value.hpp> | ||
#include <sycl/reduction.hpp> | ||
|
||
namespace sycl { | ||
inline namespace _V1 { | ||
namespace ext { | ||
namespace oneapi { | ||
namespace experimental { | ||
|
||
struct deterministic_key | ||
: detail::compile_time_property_key<detail::PropKind::Deterministic> { | ||
using value_t = property_value<deterministic_key>; | ||
}; | ||
inline constexpr deterministic_key::value_t deterministic; | ||
|
||
struct initialize_to_identity_key | ||
: detail::compile_time_property_key< | ||
detail::PropKind::InitializeToIdentity> { | ||
using value_t = property_value<initialize_to_identity_key>; | ||
}; | ||
inline constexpr initialize_to_identity_key::value_t initialize_to_identity; | ||
|
||
} // namespace experimental | ||
} // namespace oneapi | ||
} // namespace ext | ||
|
||
namespace detail { | ||
|
||
template <typename BinaryOperation, typename PropertyList> | ||
auto WrapOp(BinaryOperation combiner, PropertyList properties) { | ||
if constexpr (properties.template has_property< | ||
ext::oneapi::experimental::deterministic_key>()) { | ||
return DeterministicOperatorWrapper(combiner); | ||
} else { | ||
return combiner; | ||
} | ||
} | ||
|
||
template <typename T, typename BinaryOperation, typename PropertyList> | ||
void CheckReductionIdentity(PropertyList properties) { | ||
if constexpr (properties.template has_property< | ||
ext::oneapi::experimental::initialize_to_identity_key>()) { | ||
static_assert(has_known_identity_v<BinaryOperation, T>, | ||
"initialize_to_identity requires an identity value."); | ||
} | ||
} | ||
|
||
template <typename PropertyList> | ||
property_list GetReductionPropertyList(PropertyList properties) { | ||
if constexpr (properties.template has_property< | ||
ext::oneapi::experimental::initialize_to_identity_key>()) { | ||
return sycl::property::reduction::initialize_to_identity{}; | ||
} | ||
return {}; | ||
} | ||
|
||
template <typename BinaryOperation> struct DeterministicOperatorWrapper { | ||
|
||
DeterministicOperatorWrapper(BinaryOperation BinOp = BinaryOperation()) | ||
: BinOp(BinOp) {} | ||
|
||
template <typename... Args> | ||
std::invoke_result_t<BinaryOperation, Args...> operator()(Args... args) { | ||
return BinOp(std::forward<Args>(args)...); | ||
} | ||
|
||
BinaryOperation BinOp; | ||
}; | ||
|
||
template <typename BinaryOperation> | ||
struct IsDeterministicOperator<DeterministicOperatorWrapper<BinaryOperation>> | ||
: std::true_type {}; | ||
|
||
} // namespace detail | ||
|
||
template <typename BufferT, typename BinaryOperation, typename PropertyList> | ||
auto reduction(BufferT vars, handler &cgh, BinaryOperation combiner, | ||
PropertyList properties) { | ||
detail::CheckReductionIdentity<typename BufferT::value_type, BinaryOperation>( | ||
properties); | ||
auto WrappedOp = detail::WrapOp(combiner, properties); | ||
auto RuntimeProps = detail::GetReductionPropertyList(properties); | ||
return reduction(vars, cgh, WrappedOp, RuntimeProps); | ||
} | ||
|
||
template <typename T, typename BinaryOperation, typename PropertyList> | ||
auto reduction(T *var, BinaryOperation combiner, PropertyList properties) { | ||
detail::CheckReductionIdentity<T, BinaryOperation>(properties); | ||
auto WrappedOp = detail::WrapOp(combiner, properties); | ||
auto RuntimeProps = detail::GetReductionPropertyList(properties); | ||
return reduction(var, WrappedOp, RuntimeProps); | ||
} | ||
|
||
template <typename T, size_t Extent, typename BinaryOperation, | ||
typename PropertyList> | ||
auto reduction(span<T, Extent> vars, BinaryOperation combiner, | ||
PropertyList properties) { | ||
detail::CheckReductionIdentity<T, BinaryOperation>(properties); | ||
auto WrappedOp = detail::WrapOp(combiner, properties); | ||
auto RuntimeProps = detail::GetReductionPropertyList(properties); | ||
return reduction(vars, WrappedOp, RuntimeProps); | ||
} | ||
|
||
template <typename BufferT, typename BinaryOperation, typename PropertyList> | ||
auto reduction(BufferT vars, handler &cgh, | ||
const typename BufferT::value_type &identity, | ||
BinaryOperation combiner, PropertyList properties) { | ||
auto WrappedOp = detail::WrapOp(combiner, properties); | ||
auto RuntimeProps = detail::GetReductionPropertyList(properties); | ||
return reduction(vars, cgh, identity, WrappedOp, RuntimeProps); | ||
} | ||
|
||
template <typename T, typename BinaryOperation, typename PropertyList> | ||
auto reduction(T *var, const T &identity, BinaryOperation combiner, | ||
PropertyList properties) { | ||
auto WrappedOp = detail::WrapOp(combiner, properties); | ||
auto RuntimeProps = detail::GetReductionPropertyList(properties); | ||
return reduction(var, identity, WrappedOp, RuntimeProps); | ||
} | ||
|
||
template <typename T, size_t Extent, typename BinaryOperation, | ||
typename PropertyList> | ||
auto reduction(span<T, Extent> vars, const T &identity, | ||
BinaryOperation combiner, PropertyList properties) { | ||
auto WrappedOp = detail::WrapOp(combiner, properties); | ||
auto RuntimeProps = detail::GetReductionPropertyList(properties); | ||
return reduction(vars, identity, WrappedOp, RuntimeProps); | ||
} | ||
|
||
} // 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
Oops, something went wrong.
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.