Skip to content

Commit df9c728

Browse files
committed
Added sycl function objects
1 parent f133539 commit df9c728

File tree

3 files changed

+47
-7
lines changed

3 files changed

+47
-7
lines changed

sycl/include/CL/sycl/ONEAPI/functional.hpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@
1111

1212
__SYCL_INLINE_NAMESPACE(cl) {
1313
namespace sycl {
14-
15-
template <typename T = void> using plus = std::plus<T>;
16-
1714
namespace ONEAPI {
1815

1916
template <typename T = void> struct minimum {

sycl/include/CL/sycl/stl.hpp

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,5 +72,48 @@ unique_ptr_class<T> make_unique_ptr(ArgsT &&... Args) {
7272
return unique_ptr_class<T>(new T(std::forward<ArgsT>(Args)...));
7373
}
7474

75+
template <typename T = void> using plus = std::plus<T>;
76+
template <typename T = void> using multiplies = std::multiplies<T>;
77+
template <typename T = void> using bit_or = std::bit_or<T>;
78+
template <typename T = void> using bit_xor = std::bit_xor<T>;
79+
template <typename T = void> using bit_and = std::bit_and<T>;
80+
template <typename T = void> using logical_and = std::logical_and<T>;
81+
template <typename T = void> using logical_or = std::logical_or<T>;
82+
83+
template <typename T = void> struct minimum {
84+
T operator()(const T &lhs, const T &rhs) const {
85+
return std::less<T>()(lhs, rhs) ? lhs : rhs;
86+
}
87+
};
88+
89+
template <> struct minimum<void> {
90+
struct is_transparent {};
91+
template <typename T, typename U>
92+
auto operator()(T &&lhs, U &&rhs) const ->
93+
typename std::common_type<T &&, U &&>::type {
94+
return std::less<>()(std::forward<const T>(lhs), std::forward<const U>(rhs))
95+
? std::forward<T>(lhs)
96+
: std::forward<U>(rhs);
97+
}
98+
};
99+
100+
template <typename T = void> struct maximum {
101+
T operator()(const T &lhs, const T &rhs) const {
102+
return std::greater<T>()(lhs, rhs) ? lhs : rhs;
103+
}
104+
};
105+
106+
template <> struct maximum<void> {
107+
struct is_transparent {};
108+
template <typename T, typename U>
109+
auto operator()(T &&lhs, U &&rhs) const ->
110+
typename std::common_type<T &&, U &&>::type {
111+
return std::greater<>()(std::forward<const T>(lhs),
112+
std::forward<const U>(rhs))
113+
? std::forward<T>(lhs)
114+
: std::forward<U>(rhs);
115+
}
116+
};
117+
75118
} // namespace sycl
76119
} // __SYCL_INLINE_NAMESPACE(cl)

sycl/test/extensions/group-algorithm.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ void test(queue q, InputContainer input, OutputContainer output,
5858
out[3] = exclusive_scan(g, in[lid], binary_op);
5959
out[4] = broadcast(g, in[lid]);
6060
out[5] = any_of(g, in.get_pointer(), in.get_pointer() + N, pred);
61-
out[6] = all_of(g, pred(in[lid]));
61+
out[6] = all_of_group(g, pred(in[lid]));
6262
if (leader(g)) {
6363
out[7]++;
6464
}
@@ -76,13 +76,13 @@ int main() {
7676
std::iota(input.begin(), input.end(), 0);
7777
std::fill(output.begin(), output.end(), 0);
7878

79-
test<class KernelNamePlusV>(q, input, output, sycl::plus<>(), 0, GeZero());
80-
test<class KernelNameMinimumV>(q, input, output, minimum<>(),
79+
test<class KernelNamePlusV>(q, input, output, ONEAPI::plus<>(), 0, GeZero());
80+
test<class KernelNameMinimumV>(q, input, output, ONEAPI::minimum<>(),
8181
std::numeric_limits<int>::max(), IsEven());
8282

8383
#ifdef SPIRV_1_3
8484
test<class KernelName_WonwuUVPUPOTKRKIBtT>(q, input, output,
85-
multiplies<int>(), 1, LtZero());
85+
ONEAPI::multiplies<int>(), 1, LtZero());
8686
#endif // SPIRV_1_3
8787

8888
std::cout << "Test passed." << std::endl;

0 commit comments

Comments
 (0)