Skip to content

Commit 4095f94

Browse files
committed
[SYCL] Support functors as SYCL kernels (compiler part).
Signed-off-by: Vladimir Lazarev <[email protected]>
1 parent 1c93c84 commit 4095f94

File tree

6 files changed

+1058
-261
lines changed

6 files changed

+1058
-261
lines changed

clang/lib/Sema/SemaSYCL.cpp

Lines changed: 234 additions & 261 deletions
Large diffs are not rendered by default.
Lines changed: 281 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,281 @@
1+
#pragma once
2+
3+
#include <exception>
4+
#include <functional>
5+
#include <memory>
6+
#include <mutex>
7+
#include <string>
8+
#include <type_traits>
9+
#include <vector>
10+
11+
#ifndef __SYCL_DEVICE_ONLY__
12+
#define __global
13+
#endif
14+
15+
#define ATTR_SYCL_KERNEL __attribute__((sycl_kernel))
16+
17+
// Dummy runtime classes to model SYCL API.
18+
namespace cl {
19+
namespace sycl {
20+
21+
template < class T, class Alloc = std::allocator<T> >
22+
using vector_class = std::vector<T, Alloc>;
23+
24+
using string_class = std::string;
25+
26+
template<class R, class... ArgTypes>
27+
using function_class = std::function<R(ArgTypes...)>;
28+
29+
using mutex_class = std::mutex;
30+
31+
template <class T>
32+
using unique_ptr_class = std::unique_ptr<T>;
33+
34+
template <class T>
35+
using shared_ptr_class = std::shared_ptr<T>;
36+
37+
template <class T>
38+
using weak_ptr_class = std::weak_ptr<T>;
39+
40+
template <class T>
41+
using hash_class = std::hash<T>;
42+
43+
using exception_ptr_class = std::exception_ptr;
44+
45+
template <class T>
46+
using buffer_allocator = std::allocator<T>;
47+
48+
namespace access {
49+
50+
enum class target {
51+
global_buffer = 2014,
52+
constant_buffer,
53+
local,
54+
image,
55+
host_buffer,
56+
host_image,
57+
image_array
58+
};
59+
60+
enum class mode {
61+
read = 1024,
62+
write,
63+
read_write,
64+
discard_write,
65+
discard_read_write,
66+
atomic
67+
};
68+
69+
enum class placeholder {
70+
false_t,
71+
true_t
72+
};
73+
74+
enum class address_space : int {
75+
private_space = 0,
76+
global_space,
77+
constant_space,
78+
local_space
79+
};
80+
} // namespace access
81+
82+
namespace property {
83+
84+
enum prop_type {
85+
use_host_ptr = 0,
86+
use_mutex,
87+
context_bound,
88+
enable_profiling,
89+
base_prop
90+
};
91+
92+
struct property_base {
93+
virtual prop_type type() const = 0;
94+
};
95+
} // namespace property
96+
97+
namespace detail {
98+
template <typename... tail> struct allProperties : std::true_type {};
99+
template <typename T, typename... tail>
100+
struct allProperties<T, tail...>
101+
: std::conditional<
102+
std::is_base_of<cl::sycl::property::property_base, T>::value,
103+
allProperties<tail...>, std::false_type>::type {};
104+
} // namespace detail
105+
106+
class property_list {
107+
public:
108+
template <typename... propertyTN,
109+
typename = typename std::enable_if<
110+
detail::allProperties<propertyTN...>::value>::type>
111+
property_list(propertyTN... props) {}
112+
113+
template <typename propertyT> bool has_property() const { return true; }
114+
115+
template <typename propertyT> propertyT get_property() const {
116+
return propertyT{};
117+
}
118+
119+
bool operator==(const property_list &rhs) const { return false; }
120+
121+
bool operator!=(const property_list &rhs) const { return false; }
122+
};
123+
124+
template <int dim>
125+
struct id {
126+
};
127+
128+
template <int dim>
129+
struct range {
130+
template<typename ...T> range(T...args) {} // fake constructor
131+
};
132+
133+
template <int dim>
134+
struct nd_range {
135+
};
136+
137+
template <int dim>
138+
struct _ImplT {
139+
range<dim> Range;
140+
};
141+
142+
template <typename dataT, int dimensions, access::mode accessmode,
143+
access::target accessTarget = access::target::global_buffer,
144+
access::placeholder isPlaceholder = access::placeholder::false_t>
145+
class accessor {
146+
147+
public:
148+
149+
void __set_pointer(__global dataT *Ptr) { }
150+
void __set_range(range<dimensions> Range) {
151+
__impl.Range = Range;
152+
}
153+
void use(void) const {}
154+
template <typename ...T> void use(T...args) { }
155+
template <typename ...T> void use(T...args) const { }
156+
_ImplT<dimensions> __impl;
157+
158+
};
159+
160+
class kernel {};
161+
class context {};
162+
class device {};
163+
class event{};
164+
165+
class queue {
166+
public:
167+
template <typename T> event submit(T cgf) { return event{}; }
168+
169+
void wait() {}
170+
void wait_and_throw() {}
171+
void throw_asynchronous() {}
172+
};
173+
174+
class handler {
175+
public:
176+
template <typename KernelName, typename KernelType, int dimensions>
177+
ATTR_SYCL_KERNEL
178+
void parallel_for(range<dimensions> numWorkItems, KernelType kernelFunc) {}
179+
180+
template <typename KernelName, typename KernelType, int dimensions>
181+
ATTR_SYCL_KERNEL
182+
void parallel_for(nd_range<dimensions> executionRange,
183+
KernelType kernelFunc) {}
184+
185+
ATTR_SYCL_KERNEL
186+
void single_task(kernel syclKernel) {}
187+
188+
template <int dimensions>
189+
ATTR_SYCL_KERNEL
190+
void parallel_for(range<dimensions> numWorkItems, kernel syclKernel) {}
191+
192+
template <int dimensions>
193+
ATTR_SYCL_KERNEL
194+
void parallel_for(nd_range<dimensions> ndRange, kernel syclKernel) {}
195+
196+
template <typename KernelName, typename KernelType>
197+
ATTR_SYCL_KERNEL
198+
void single_task(kernel syclKernel, KernelType kernelFunc) {}
199+
200+
template <typename KernelType>
201+
ATTR_SYCL_KERNEL
202+
void single_task(KernelType kernelFunc) {}
203+
204+
template <typename KernelName, typename KernelType, int dimensions>
205+
ATTR_SYCL_KERNEL
206+
void parallel_for(range<dimensions> numWorkItems, kernel syclKernel,
207+
KernelType kernelFunc) {}
208+
209+
template <typename KernelType, int dimensions>
210+
ATTR_SYCL_KERNEL
211+
void parallel_for(range<dimensions> numWorkItems, KernelType kernelFunc) {}
212+
213+
template <typename KernelName, typename KernelType, int dimensions>
214+
ATTR_SYCL_KERNEL
215+
void parallel_for(nd_range<dimensions> ndRange, kernel syclKernel,
216+
KernelType kernelFunc) {}
217+
};
218+
219+
template <typename T, int dimensions = 1,
220+
typename AllocatorT = cl::sycl::buffer_allocator<T>>
221+
class buffer {
222+
public:
223+
using value_type = T;
224+
using reference = value_type &;
225+
using const_reference = const value_type &;
226+
using allocator_type = AllocatorT;
227+
228+
template <typename ...ParamTypes> buffer(ParamTypes...args) {} // fake constructor
229+
230+
buffer(const range<dimensions> &bufferRange,
231+
const property_list &propList = {}) {}
232+
233+
buffer(T *hostData, const range<dimensions> &bufferRange,
234+
const property_list &propList = {}) {}
235+
236+
buffer(const T *hostData, const range<dimensions> &bufferRange,
237+
const property_list &propList = {}) {}
238+
239+
buffer(const shared_ptr_class<T> &hostData,
240+
const range<dimensions> &bufferRange,
241+
const property_list &propList = {}) {}
242+
243+
buffer(const buffer &rhs) = default;
244+
245+
buffer(buffer &&rhs) = default;
246+
247+
buffer &operator=(const buffer &rhs) = default;
248+
249+
buffer &operator=(buffer &&rhs) = default;
250+
251+
~buffer() = default;
252+
253+
range<dimensions> get_range() const { return range<dimensions>{}; }
254+
255+
size_t get_count() const { return 0; }
256+
257+
size_t get_size() const { return 0; }
258+
259+
template <access::mode mode,
260+
access::target target = access::target::global_buffer>
261+
accessor<T, dimensions, mode, target, access::placeholder::false_t>
262+
get_access(handler &commandGroupHandler) {
263+
return accessor<T, dimensions, mode, target, access::placeholder::false_t>{};
264+
}
265+
266+
template <access::mode mode>
267+
accessor<T, dimensions, mode, access::target::host_buffer,
268+
access::placeholder::false_t>
269+
get_access() {
270+
accessor<T, dimensions, mode, access::target::host_buffer,
271+
access::placeholder::false_t>{};
272+
}
273+
274+
template <typename Destination = std::nullptr_t>
275+
void set_final_data(Destination finalData = nullptr) {}
276+
};
277+
278+
} // namespace sycl
279+
} // namespace cl
280+
281+

0 commit comments

Comments
 (0)