DPC++ Runtime
Runtime libraries for oneAPI Data Parallel C++
reduction.hpp
Go to the documentation of this file.
1 //==---------------- reduction.hpp - SYCL reduction ------------*- C++ -*---==//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 // ===--------------------------------------------------------------------=== //
8 
9 #pragma once
10 
12 
14 
16 namespace sycl {
17 
20 template <typename T, typename AllocatorT, typename BinaryOperation>
21 std::enable_if_t<has_known_identity<BinaryOperation, T>::value,
22  ext::oneapi::detail::reduction_impl<
23  T, BinaryOperation, 1, false, access::placeholder::true_t>>
24 reduction(buffer<T, 1, AllocatorT> Var, handler &CGH, BinaryOperation,
25  const property_list &PropList = {}) {
27  PropList.has_property<property::reduction::initialize_to_identity>();
28  return {Var, CGH, InitializeToIdentity};
29 }
30 
35 template <typename T, typename AllocatorT, typename BinaryOperation>
36 std::enable_if_t<!has_known_identity<BinaryOperation, T>::value,
37  ext::oneapi::detail::reduction_impl<
38  T, BinaryOperation, 1, false, access::placeholder::true_t>>
40  const property_list &PropList = {}) {
41  // TODO: implement reduction that works even when identity is not known.
42  (void)PropList;
43  throw runtime_error("Identity-less reductions with unknown identity are not "
44  "supported yet.",
46 }
47 
51 template <typename T, typename BinaryOperation>
53  has_known_identity<BinaryOperation, T>::value,
54  ext::oneapi::detail::reduction_impl<T, BinaryOperation, 1, true>>
55 reduction(T *Var, BinaryOperation, const property_list &PropList = {}) {
57  PropList.has_property<property::reduction::initialize_to_identity>();
58  return {Var, InitializeToIdentity};
59 }
60 
66 template <typename T, typename BinaryOperation>
68  !has_known_identity<BinaryOperation, T>::value,
69  ext::oneapi::detail::reduction_impl<T, BinaryOperation, 1, true>>
70 reduction(T *, BinaryOperation, const property_list &PropList = {}) {
71  // TODO: implement reduction that works even when identity is not known.
72  (void)PropList;
73  throw runtime_error("Identity-less reductions with unknown identity are not "
74  "supported yet.",
76 }
77 
81 template <typename T, typename AllocatorT, typename BinaryOperation>
82 ext::oneapi::detail::reduction_impl<T, BinaryOperation, 1, false,
83  access::placeholder::true_t>
84 reduction(buffer<T, 1, AllocatorT> Var, handler &CGH, const T &Identity,
85  BinaryOperation Combiner, const property_list &PropList = {}) {
87  PropList.has_property<property::reduction::initialize_to_identity>();
88  return {Var, CGH, Identity, Combiner, InitializeToIdentity};
89 }
90 
94 template <typename T, typename BinaryOperation>
95 ext::oneapi::detail::reduction_impl<T, BinaryOperation, 1, true>
96 reduction(T *Var, const T &Identity, BinaryOperation Combiner,
97  const property_list &PropList = {}) {
99  PropList.has_property<property::reduction::initialize_to_identity>();
100  return {Var, Identity, Combiner, InitializeToIdentity};
101 }
102 
103 } // namespace sycl
104 } // __SYCL_INLINE_NAMESPACE(cl)
cl::sycl::ext::oneapi::reduction
std::enable_if_t< detail::IsKnownIdentityOp< T, BinaryOperation >::value, detail::reduction_impl< T, BinaryOperation, 1, true > > reduction(T *VarPtr, BinaryOperation)
Creates and returns an object implementing the reduction functionality.
Definition: reduction.hpp:2047
T
cl::sycl::property_list
Objects of the property_list class are containers for the SYCL properties.
Definition: property_list.hpp:26
cl::sycl::buffer
Defines a shared array that can be used by kernels in queues.
Definition: buffer.hpp:46
cl
We provide new interfaces for matrix muliply in this patch:
Definition: access.hpp:13
reduction.hpp
cl::sycl::handler
Command group handler class.
Definition: handler.hpp:361
cl::sycl::detail::InitializeToIdentity
@ InitializeToIdentity
Definition: property_helper.hpp:34
PI_INVALID_VALUE
@ PI_INVALID_VALUE
Definition: pi.h:88
cl::sycl::detail::enable_if_t
typename std::enable_if< B, T >::type enable_if_t
Definition: stl_type_traits.hpp:24
known_identity.hpp
__SYCL_INLINE_NAMESPACE
#define __SYCL_INLINE_NAMESPACE(X)
Definition: defines_elementary.hpp:12