@@ -23,7 +23,27 @@ class handler;
23
23
class queue ;
24
24
template <int dimensions> class range ;
25
25
26
+ // Guard SYCL 2020 buffer_allocator with template arguments behind the
27
+ // SYCL2020_CONFORMANT_APIS macro.
28
+ #ifdef SYCL2020_CONFORMANT_APIS
29
+ template <typename DataT>
30
+ using buffer_allocator = detail::sycl_memory_object_allocator<DataT>;
31
+ #else
32
+ using buffer_allocator = detail::sycl_memory_object_allocator<char >;
33
+ #endif
34
+
26
35
namespace detail {
36
+
37
+ // Generalized implementation of the default allocator used by buffers.
38
+ // TODO: When the SYCL 1.2.1 version of buffer_allocator is removed, this should
39
+ // be removed.
40
+ #ifdef SYCL2020_CONFORMANT_APIS
41
+ template <typename DataT>
42
+ using default_buffer_allocator = buffer_allocator<std::remove_const_t <DataT>>;
43
+ #else
44
+ template <typename > using default_buffer_allocator = buffer_allocator;
45
+ #endif
46
+
27
47
template <typename T, int Dimensions, typename AllocatorT>
28
48
buffer<T, Dimensions, AllocatorT, void >
29
49
make_buffer_helper (pi_native_handle Handle, const context &Ctx, event Evt = {},
@@ -39,7 +59,7 @@ auto get_native_buffer(const buffer<DataT, Dimensions, Allocator, void> &Obj)
39
59
buffer<DataT, Dimensions, Allocator, void>>;
40
60
41
61
template <backend Backend, typename DataT, int Dimensions,
42
- typename AllocatorT = cl::sycl::buffer_allocator >
62
+ typename AllocatorT = detail::default_buffer_allocator<DataT> >
43
63
struct BufferInterop ;
44
64
} // namespace detail
45
65
@@ -52,7 +72,7 @@ struct BufferInterop;
52
72
// /
53
73
// / \ingroup sycl_api
54
74
template <typename T, int dimensions = 1 ,
55
- typename AllocatorT = cl::sycl::buffer_allocator ,
75
+ typename AllocatorT = detail::default_buffer_allocator<T> ,
56
76
typename __Enabled = typename detail::enable_if_t <(dimensions > 0 ) &&
57
77
(dimensions <= 3 )>>
58
78
class buffer {
@@ -96,7 +116,7 @@ class buffer {
96
116
: Range(bufferRange) {
97
117
impl = std::make_shared<detail::buffer_impl>(
98
118
size () * sizeof (T), detail::getNextPowerOfTwo (sizeof (T)), propList,
99
- make_unique_ptr<detail::SYCLMemObjAllocatorHolder<AllocatorT>>());
119
+ make_unique_ptr<detail::SYCLMemObjAllocatorHolder<AllocatorT, T >>());
100
120
impl->constructorNotification (CodeLoc, (void *)impl.get (), nullptr ,
101
121
(const void *)typeid (T).name (), dimensions,
102
122
sizeof (T), rangeToArray (Range).data ());
@@ -108,7 +128,7 @@ class buffer {
108
128
: Range(bufferRange) {
109
129
impl = std::make_shared<detail::buffer_impl>(
110
130
size () * sizeof (T), detail::getNextPowerOfTwo (sizeof (T)), propList,
111
- make_unique_ptr<detail::SYCLMemObjAllocatorHolder<AllocatorT>>(
131
+ make_unique_ptr<detail::SYCLMemObjAllocatorHolder<AllocatorT, T >>(
112
132
allocator));
113
133
impl->constructorNotification (CodeLoc, (void *)impl.get (), nullptr ,
114
134
(const void *)typeid (T).name (), dimensions,
@@ -122,7 +142,7 @@ class buffer {
122
142
impl = std::make_shared<detail::buffer_impl>(
123
143
hostData, size () * sizeof (T), detail::getNextPowerOfTwo (sizeof (T)),
124
144
propList,
125
- make_unique_ptr<detail::SYCLMemObjAllocatorHolder<AllocatorT>>());
145
+ make_unique_ptr<detail::SYCLMemObjAllocatorHolder<AllocatorT, T >>());
126
146
impl->constructorNotification (CodeLoc, (void *)impl.get (), hostData,
127
147
(const void *)typeid (T).name (), dimensions,
128
148
sizeof (T), rangeToArray (Range).data ());
@@ -135,7 +155,7 @@ class buffer {
135
155
impl = std::make_shared<detail::buffer_impl>(
136
156
hostData, size () * sizeof (T), detail::getNextPowerOfTwo (sizeof (T)),
137
157
propList,
138
- make_unique_ptr<detail::SYCLMemObjAllocatorHolder<AllocatorT>>(
158
+ make_unique_ptr<detail::SYCLMemObjAllocatorHolder<AllocatorT, T >>(
139
159
allocator));
140
160
impl->constructorNotification (CodeLoc, (void *)impl.get (), hostData,
141
161
(const void *)typeid (T).name (), dimensions,
@@ -151,7 +171,7 @@ class buffer {
151
171
impl = std::make_shared<detail::buffer_impl>(
152
172
hostData, size () * sizeof (T), detail::getNextPowerOfTwo (sizeof (T)),
153
173
propList,
154
- make_unique_ptr<detail::SYCLMemObjAllocatorHolder<AllocatorT>>());
174
+ make_unique_ptr<detail::SYCLMemObjAllocatorHolder<AllocatorT, T >>());
155
175
impl->constructorNotification (CodeLoc, (void *)impl.get (), hostData,
156
176
(const void *)typeid (T).name (), dimensions,
157
177
sizeof (T), rangeToArray (Range).data ());
@@ -166,7 +186,7 @@ class buffer {
166
186
impl = std::make_shared<detail::buffer_impl>(
167
187
hostData, size () * sizeof (T), detail::getNextPowerOfTwo (sizeof (T)),
168
188
propList,
169
- make_unique_ptr<detail::SYCLMemObjAllocatorHolder<AllocatorT>>(
189
+ make_unique_ptr<detail::SYCLMemObjAllocatorHolder<AllocatorT, T >>(
170
190
allocator));
171
191
impl->constructorNotification (CodeLoc, (void *)impl.get (), hostData,
172
192
(const void *)typeid (T).name (), dimensions,
@@ -181,7 +201,7 @@ class buffer {
181
201
impl = std::make_shared<detail::buffer_impl>(
182
202
hostData, size () * sizeof (T), detail::getNextPowerOfTwo (sizeof (T)),
183
203
propList,
184
- make_unique_ptr<detail::SYCLMemObjAllocatorHolder<AllocatorT>>(
204
+ make_unique_ptr<detail::SYCLMemObjAllocatorHolder<AllocatorT, T >>(
185
205
allocator));
186
206
impl->constructorNotification (CodeLoc, (void *)impl.get (),
187
207
(void *)hostData.get (),
@@ -197,7 +217,7 @@ class buffer {
197
217
impl = std::make_shared<detail::buffer_impl>(
198
218
hostData, size () * sizeof (T), detail::getNextPowerOfTwo (sizeof (T)),
199
219
propList,
200
- make_unique_ptr<detail::SYCLMemObjAllocatorHolder<AllocatorT>>(
220
+ make_unique_ptr<detail::SYCLMemObjAllocatorHolder<AllocatorT, T >>(
201
221
allocator));
202
222
impl->constructorNotification (CodeLoc, (void *)impl.get (),
203
223
(void *)hostData.get (),
@@ -213,7 +233,7 @@ class buffer {
213
233
impl = std::make_shared<detail::buffer_impl>(
214
234
hostData, size () * sizeof (T), detail::getNextPowerOfTwo (sizeof (T)),
215
235
propList,
216
- make_unique_ptr<detail::SYCLMemObjAllocatorHolder<AllocatorT>>());
236
+ make_unique_ptr<detail::SYCLMemObjAllocatorHolder<AllocatorT, T >>());
217
237
impl->constructorNotification (CodeLoc, (void *)impl.get (),
218
238
(void *)hostData.get (),
219
239
(const void *)typeid (T).name (), dimensions,
@@ -228,7 +248,7 @@ class buffer {
228
248
impl = std::make_shared<detail::buffer_impl>(
229
249
hostData, size () * sizeof (T), detail::getNextPowerOfTwo (sizeof (T)),
230
250
propList,
231
- make_unique_ptr<detail::SYCLMemObjAllocatorHolder<AllocatorT>>());
251
+ make_unique_ptr<detail::SYCLMemObjAllocatorHolder<AllocatorT, T >>());
232
252
impl->constructorNotification (CodeLoc, (void *)impl.get (),
233
253
(void *)hostData.get (),
234
254
(const void *)typeid (T).name (), dimensions,
@@ -245,7 +265,7 @@ class buffer {
245
265
impl = std::make_shared<detail::buffer_impl>(
246
266
first, last, size () * sizeof (T), detail::getNextPowerOfTwo (sizeof (T)),
247
267
propList,
248
- make_unique_ptr<detail::SYCLMemObjAllocatorHolder<AllocatorT>>(
268
+ make_unique_ptr<detail::SYCLMemObjAllocatorHolder<AllocatorT, T >>(
249
269
allocator));
250
270
size_t r[3 ] = {Range[0 ], 0 , 0 };
251
271
impl->constructorNotification (CodeLoc, (void *)impl.get (), &first,
@@ -263,7 +283,7 @@ class buffer {
263
283
impl = std::make_shared<detail::buffer_impl>(
264
284
first, last, size () * sizeof (T), detail::getNextPowerOfTwo (sizeof (T)),
265
285
propList,
266
- make_unique_ptr<detail::SYCLMemObjAllocatorHolder<AllocatorT>>());
286
+ make_unique_ptr<detail::SYCLMemObjAllocatorHolder<AllocatorT, T >>());
267
287
size_t r[3 ] = {Range[0 ], 0 , 0 };
268
288
impl->constructorNotification (CodeLoc, (void *)impl.get (), &first,
269
289
(const void *)typeid (T).name (), dimensions,
@@ -281,7 +301,7 @@ class buffer {
281
301
impl = std::make_shared<detail::buffer_impl>(
282
302
container.data (), size () * sizeof (T),
283
303
detail::getNextPowerOfTwo (sizeof (T)), propList,
284
- make_unique_ptr<detail::SYCLMemObjAllocatorHolder<AllocatorT>>(
304
+ make_unique_ptr<detail::SYCLMemObjAllocatorHolder<AllocatorT, T >>(
285
305
allocator));
286
306
size_t r[3 ] = {Range[0 ], 0 , 0 };
287
307
impl->constructorNotification (CodeLoc, (void *)impl.get (), container.data (),
@@ -328,7 +348,7 @@ class buffer {
328
348
329
349
impl = std::make_shared<detail::buffer_impl>(
330
350
detail::pi::cast<pi_native_handle>(MemObject), SyclContext,
331
- make_unique_ptr<detail::SYCLMemObjAllocatorHolder<AllocatorT>>(),
351
+ make_unique_ptr<detail::SYCLMemObjAllocatorHolder<AllocatorT, T >>(),
332
352
/* OwnNativeHandle */ true , AvailableEvent);
333
353
Range[0 ] = impl->getSize () / sizeof (T);
334
354
impl->constructorNotification (CodeLoc, (void *)impl.get (), &MemObject,
@@ -556,7 +576,7 @@ class buffer {
556
576
557
577
impl = std::make_shared<detail::buffer_impl>(
558
578
MemObject, SyclContext,
559
- make_unique_ptr<detail::SYCLMemObjAllocatorHolder<AllocatorT>>(),
579
+ make_unique_ptr<detail::SYCLMemObjAllocatorHolder<AllocatorT, T >>(),
560
580
OwnNativeHandle, AvailableEvent);
561
581
Range[0 ] = impl->getSize () / sizeof (T);
562
582
impl->constructorNotification (CodeLoc, (void *)impl.get (), &MemObject,
0 commit comments