Skip to content

Commit 9b03fec

Browse files
committed
[SYCL] Move reduce/scan functors to functional.hpp
Avoid duplicated code in sub_group.hpp and sub_group_host.hpp. Signed-off-by: John Pennycook <john.pennycook@intel.com>
1 parent 5c83647 commit 9b03fec

File tree

3 files changed

+53
-72
lines changed

3 files changed

+53
-72
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
//==----------- functional.hpp --- SYCL functional -------------------------==//
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+
11+
namespace cl {
12+
namespace sycl {
13+
namespace intel {
14+
15+
template <typename T = void> struct minimum {
16+
T operator()(const T &lhs, const T &rhs) const {
17+
return (lhs <= rhs) ? lhs : rhs;
18+
}
19+
};
20+
21+
template <> struct minimum<void> {
22+
template <typename T> T operator()(const T &lhs, const T &rhs) const {
23+
return (lhs <= rhs) ? lhs : rhs;
24+
}
25+
};
26+
27+
template <typename T = void> struct maximum {
28+
T operator()(const T &lhs, const T &rhs) const {
29+
return (lhs >= rhs) ? lhs : rhs;
30+
}
31+
};
32+
33+
template <> struct maximum<void> {
34+
template <typename T> T operator()(const T &lhs, const T &rhs) const {
35+
return (lhs >= rhs) ? lhs : rhs;
36+
}
37+
};
38+
39+
template <typename T = void> struct plus {
40+
T operator()(const T &lhs, const T &rhs) const { return lhs + rhs; }
41+
};
42+
43+
template <> struct plus<void> {
44+
template <typename T> T operator()(const T &lhs, const T &rhs) const {
45+
return lhs + rhs;
46+
}
47+
};
48+
49+
} // namespace intel
50+
} // namespace sycl
51+
} // namespace cl

sycl/include/CL/sycl/intel/sub_group.hpp

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -15,49 +15,13 @@
1515
#include <CL/sycl/id.hpp>
1616
#include <CL/sycl/range.hpp>
1717
#include <CL/sycl/types.hpp>
18+
#include <CL/sycl/intel/functional.hpp>
1819
#include <type_traits>
1920
#ifdef __SYCL_DEVICE_ONLY__
2021

2122
namespace cl {
2223
namespace sycl {
2324
template <typename T, access::address_space Space> class multi_ptr;
24-
namespace intel {
25-
26-
template <typename T = void> struct minimum {
27-
T operator()(const T &lhs, const T &rhs) const {
28-
return (lhs <= rhs) ? lhs : rhs;
29-
}
30-
};
31-
32-
template <> struct minimum<void> {
33-
template <typename T> T operator()(const T &lhs, const T &rhs) const {
34-
return (lhs <= rhs) ? lhs : rhs;
35-
}
36-
};
37-
38-
template <typename T = void> struct maximum {
39-
T operator()(const T &lhs, const T &rhs) const {
40-
return (lhs >= rhs) ? lhs : rhs;
41-
}
42-
};
43-
44-
template <> struct maximum<void> {
45-
template <typename T> T operator()(const T &lhs, const T &rhs) const {
46-
return (lhs >= rhs) ? lhs : rhs;
47-
}
48-
};
49-
50-
template <typename T = void> struct plus {
51-
T operator()(const T &lhs, const T &rhs) const { return lhs + rhs; }
52-
};
53-
54-
template <> struct plus<void> {
55-
template <typename T> T operator()(const T &lhs, const T &rhs) const {
56-
return lhs + rhs;
57-
}
58-
};
59-
60-
} // namespace intel
6125

6226
namespace detail {
6327

sycl/include/CL/sycl/intel/sub_group_host.hpp

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -12,47 +12,13 @@
1212
#include <CL/sycl/id.hpp>
1313
#include <CL/sycl/range.hpp>
1414
#include <CL/sycl/types.hpp>
15+
#include <CL/sycl/intel/functional.hpp>
1516
#ifndef __SYCL_DEVICE_ONLY__
1617

1718
namespace cl {
1819
namespace sycl {
1920
template <typename T, access::address_space Space> class multi_ptr;
2021
namespace intel {
21-
22-
template <typename T = void> struct minimum {
23-
T operator()(const T &lhs, const T &rhs) const {
24-
return (lhs <= rhs) ? lhs : rhs;
25-
}
26-
};
27-
28-
template <> struct minimum<void> {
29-
template <typename T> T operator()(const T &lhs, const T &rhs) const {
30-
return (lhs <= rhs) ? lhs : rhs;
31-
}
32-
};
33-
34-
template <typename T = void> struct maximum {
35-
T operator()(const T &lhs, const T &rhs) const {
36-
return (lhs >= rhs) ? lhs : rhs;
37-
}
38-
};
39-
40-
template <> struct maximum<void> {
41-
template <typename T> T operator()(const T &lhs, const T &rhs) const {
42-
return (lhs >= rhs) ? lhs : rhs;
43-
}
44-
};
45-
46-
template <typename T = void> struct plus {
47-
T operator()(const T &lhs, const T &rhs) const { return lhs + rhs; }
48-
};
49-
50-
template <> struct plus<void> {
51-
template <typename T> T operator()(const T &lhs, const T &rhs) const {
52-
return lhs + rhs;
53-
}
54-
};
55-
5622
struct sub_group {
5723
/* --- common interface members --- */
5824

0 commit comments

Comments
 (0)