-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathdpctl_sycl_queue_interface.h
More file actions
575 lines (541 loc) · 22.2 KB
/
dpctl_sycl_queue_interface.h
File metadata and controls
575 lines (541 loc) · 22.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
//===----- dpctl_sycl_queue_interface.h - C API for sycl::queue -*-C++-*- ===//
//
// Data Parallel Control (dpctl)
//
// Copyright 2020-2025 Intel Corporation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
//===----------------------------------------------------------------------===//
///
/// \file
/// This header declares a C interface to sycl::queue member functions.
///
//===----------------------------------------------------------------------===//
#pragma once
#include "Support/DllExport.h"
#include "Support/ExternC.h"
#include "Support/MemOwnershipAttrs.h"
#include "dpctl_data_types.h"
#include "dpctl_error_handler_type.h"
#include "dpctl_sycl_enum_types.h"
#include "dpctl_sycl_types.h"
DPCTL_C_EXTERN_C_BEGIN
/**
* @defgroup QueueInterface Queue class C wrapper
*/
/*!
* @brief A wrapper for sycl::queue constructor to construct a new queue from
* the provided context, device, async handler and properties bit flags.
*
* @param CRef An opaque pointer to a sycl::context.
* @param DRef An opaque pointer to a sycl::device
* @param handler A callback function that will be invoked by the
* async_handler used during queue creation. Can be
* NULL if no async_handler is needed.
* @param properties A combination of bit flags using the values defined
* in the DPCTLQueuePropertyType enum. The bit flags
* are used to create a sycl::property_list that is
* passed to the SYCL queue constructor.
* @return An opaque DPCTLSyclQueueRef pointer containing the new sycl::queue
* object. A nullptr is returned if the queue could not be created.
* @ingroup QueueInterface
*/
DPCTL_API
__dpctl_give DPCTLSyclQueueRef
DPCTLQueue_Create(__dpctl_keep const DPCTLSyclContextRef CRef,
__dpctl_keep const DPCTLSyclDeviceRef DRef,
error_handler_callback *handler,
int properties);
/*!
* @brief Constructs a ``sycl::queue`` object of the specified SYCL device.
*
* Constructs a new SYCL queue for the specified SYCL device. The
* behavior of this function differs from the following queue constructor:
*
* @code
* queue(
* const device &syclDevice,
* const async_handler &asyncHandler,
* const property_list &propList = {}
* )
* @endcode
*
* Unlike the SYCL queue constructor, we try not to create a new SYCL
* context for the device and instead look to reuse a previously cached
* SYCL context for the device (refer dpctl_sycl_device_manager.cpp).
* DPCTL caches contexts only for root devices and for all custom devices the
* function behaves the same way as the SYCL constructor.
*
* @param DRef An opaque pointer to a ``sycl::device``.
* @param handler A callback function that will be invoked by the
* async_handler used during queue creation. Can be
* NULL if no async_handler is needed.
* @param properties A combination of bit flags using the values defined
* in the DPCTLQueuePropertyType enum. The bit flags
* are used to create a ``sycl::property_list`` that is
* passed to the SYCL queue constructor.
* @return An opaque DPCTLSyclQueueRef pointer containing the new
* ``sycl::queue`` object. A nullptr is returned if the queue could not be
* created.
* @ingroup QueueInterface
*/
DPCTL_API
__dpctl_give DPCTLSyclQueueRef
DPCTLQueue_CreateForDevice(__dpctl_keep const DPCTLSyclDeviceRef DRef,
error_handler_callback *handler,
int properties);
/*!
* @brief Delete the pointer after casting it to sycl::queue.
*
* @param QRef A DPCTLSyclQueueRef pointer that gets deleted.
* @ingroup QueueInterface
*/
DPCTL_API
void DPCTLQueue_Delete(__dpctl_take DPCTLSyclQueueRef QRef);
/*!
* @brief Returns a copy of the DPCTLSyclQueueRef object.
*
* @param QRef DPCTLSyclQueueRef object to be copied.
* @return A new DPCTLSyclQueueRef created by copying the passed in
* DPCTLSyclQueueRef object.
* @ingroup QueueInterface
*/
DPCTL_API
__dpctl_give DPCTLSyclQueueRef
DPCTLQueue_Copy(__dpctl_keep const DPCTLSyclQueueRef QRef);
/*!
* @brief Checks if two DPCTLSyclQueueRef objects point to the
* same ``sycl::queue``.
*
* @param QRef1 First opaque pointer to the ``sycl::queue``.
* @param QRef2 Second opaque pointer to the ``sycl::queue``.
* @return True if the underlying sycl::queue are same, false otherwise.
* @ingroup QueueInterface
*/
DPCTL_API
bool DPCTLQueue_AreEq(__dpctl_keep const DPCTLSyclQueueRef QRef1,
__dpctl_keep const DPCTLSyclQueueRef QRef2);
/*!
* @brief Returns the Sycl backend for the provided sycl::queue.
*
* @param QRef An opaque pointer to the sycl queue.
* @return A enum DPCTLSyclBackendType corresponding to the backed for the
* queue.
* @ingroup QueueInterface
*/
DPCTL_API
DPCTLSyclBackendType DPCTLQueue_GetBackend(__dpctl_keep DPCTLSyclQueueRef QRef);
/*!
* @brief Returns the Sycl context for the queue.
*
* @param QRef An opaque pointer to the sycl queue.
* @return A DPCTLSyclContextRef pointer to the sycl context for the queue.
* @ingroup QueueInterface
*/
DPCTL_API
__dpctl_give DPCTLSyclContextRef
DPCTLQueue_GetContext(__dpctl_keep const DPCTLSyclQueueRef QRef);
/*!
* @brief returns the Sycl device for the queue.
*
* @param QRef An opaque pointer to the sycl queue.
* @return A DPCTLSyclDeviceRef pointer to the sycl device for the queue.
* @ingroup QueueInterface
*/
DPCTL_API
__dpctl_give DPCTLSyclDeviceRef
DPCTLQueue_GetDevice(__dpctl_keep const DPCTLSyclQueueRef QRef);
/*! @brief Structure to be used to specify dimensionality and type of
* local_accessor kernel type argument.
*/
typedef struct MDLocalAccessorTy
{
size_t ndim;
DPCTLKernelArgType dpctl_type_id;
size_t dim0;
size_t dim1;
size_t dim2;
} MDLocalAccessor;
/*!
* @brief Submits the kernel to the specified queue with the provided range
* argument.
*
* A wrapper over ``sycl::queue.submit()``. The function takes an
* interoperability kernel, the kernel arguments, and a ``sycl::queue`` as
* input. The kernel is submitted as
* ``parallel_for(range<NRange>, *unwrap<kernel>(KRef))``.
*
* \todo ``sycl::buffer`` arguments are not supported yet.
* \todo Add support for id<Dims> WorkItemOffset
*
* @param KRef Opaque pointer to an OpenCL interoperability kernel
* wrapped inside a sycl::kernel.
* @param QRef Opaque pointer to the sycl::queue where the kernel
* will be enqueued.
* @param Args An array of void* pointers that represent the
* kernel arguments for the kernel.
* @param ArgTypes An array of DPCTLKernelArgType enum values that
* represent the type of each kernel argument.
* @param NArgs Size of Args and ArgTypes.
* @param Range Defines the overall dimension of the dispatch for
* the kernel. The array can have up to three
* dimensions.
* @param NRange Size of the gRange array.
* @param DepEvents List of dependent DPCTLSyclEventRef objects (events)
* for the kernel. We call ``sycl::handler.depends_on``
* for each of the provided events.
* @param NDepEvents Size of the DepEvents list.
* @return An opaque pointer to the ``sycl::event`` returned by the
* ``sycl::queue.submit()`` function.
* @ingroup QueueInterface
*/
DPCTL_API
__dpctl_give DPCTLSyclEventRef
DPCTLQueue_SubmitRange(__dpctl_keep const DPCTLSyclKernelRef KRef,
__dpctl_keep const DPCTLSyclQueueRef QRef,
__dpctl_keep void **Args,
__dpctl_keep const DPCTLKernelArgType *ArgTypes,
size_t NArgs,
__dpctl_keep const size_t Range[3],
size_t NRange,
__dpctl_keep const DPCTLSyclEventRef *DepEvents,
size_t NDepEvents);
/*!
* @brief Submits the kernel to the specified queue with the provided nd_range
* argument.
*
* A wrapper over ``sycl::queue.submit()``. The function takes an
* interoperability kernel, the kernel arguments, and a Sycl queue as input.
* The kernel is submitted as
* ``parallel_for(nd_range<NRange>, *unwrap<kernel>(KRef))``.
*
* \todo sycl::buffer arguments are not supported yet.
* \todo Add support for id<Dims> WorkItemOffset
*
* @param KRef Opaque pointer to an OpenCL interoperability kernel
* wrapped inside a sycl::kernel.
* @param QRef Opaque pointer to the sycl::queue where the kernel
* will be enqueued.
* @param Args An array of void* pointers that represent the
* kernel arguments for the kernel.
* @param ArgTypes An array of DPCTLKernelArgType enum values that
* represent the type of each kernel argument.
* @param NArgs Size of Args.
* @param gRange Defines the overall dimension of the dispatch for
* the kernel. The array can have up to three
* dimensions.
* @param lRange Defines the iteration domain of a single work-group
* in a parallel dispatch. The array can have up to
* three dimensions.
* @param NDims The number of dimensions for both local and global
* ranges.
* @param DepEvents List of dependent DPCTLSyclEventRef objects (events)
* for the kernel. We call ``sycl::handler.depends_on``
* for each of the provided events.
* @param NDepEvents Size of the DepEvents list.
* @return An opaque pointer to the ``sycl::event`` returned by the
* ``sycl::queue.submit()`` function.
* @ingroup QueueInterface
*/
DPCTL_API
__dpctl_give DPCTLSyclEventRef
DPCTLQueue_SubmitNDRange(__dpctl_keep const DPCTLSyclKernelRef KRef,
__dpctl_keep const DPCTLSyclQueueRef QRef,
__dpctl_keep void **Args,
__dpctl_keep const DPCTLKernelArgType *ArgTypes,
size_t NArgs,
__dpctl_keep const size_t gRange[3],
__dpctl_keep const size_t lRange[3],
size_t NDims,
__dpctl_keep const DPCTLSyclEventRef *DepEvents,
size_t NDepEvents);
/*!
* @brief Calls the ``sycl::queue::submit`` function to do a blocking wait on
* all enqueued tasks in the queue.
*
* @param QRef Opaque pointer to a ``sycl::queue``.
* @ingroup QueueInterface
*/
DPCTL_API
void DPCTLQueue_Wait(__dpctl_keep const DPCTLSyclQueueRef QRef);
/*!
* @brief C-API wrapper for ``sycl::queue::memcpy``.
*
* @param QRef An opaque pointer to the ``sycl::queue``.
* @param Dest An USM pointer to the destination memory.
* @param Src An USM pointer to the source memory.
* @param Count A number of bytes to copy.
* @return An opaque pointer to the ``sycl::event`` returned by the
* ``sycl::queue::memcpy`` function.
* @ingroup QueueInterface
*/
DPCTL_API
__dpctl_give DPCTLSyclEventRef
DPCTLQueue_Memcpy(__dpctl_keep const DPCTLSyclQueueRef QRef,
void *Dest,
const void *Src,
size_t Count);
/*!
* @brief C-API wrapper for ``sycl::queue::memcpy``.
*
* @param QRef An opaque pointer to the ``sycl::queue``.
* @param Dest An USM pointer to the destination memory.
* @param Src An USM pointer to the source memory.
* @param Count A number of bytes to copy.
* @param DepEvents A pointer to array of DPCTLSyclEventRef opaque
* pointers to dependent events.
* @param DepEventsCount A number of dependent events.
* @return An opaque pointer to the ``sycl::event`` returned by the
* ``sycl::queue::memcpy`` function.
* @ingroup QueueInterface
*/
DPCTL_API
__dpctl_give DPCTLSyclEventRef
DPCTLQueue_MemcpyWithEvents(__dpctl_keep const DPCTLSyclQueueRef QRef,
void *Dest,
const void *Src,
size_t Count,
__dpctl_keep const DPCTLSyclEventRef *DepEvents,
size_t DepEventsCount);
/*!
* @brief C-API wrapper for ``sycl::queue::copy``.
*
* @param QRef An opaque pointer to the ``sycl::queue``.
* @param Dest A destination pointer.
* @param Src A source pointer.
* @param Count A number of bytes to copy.
* @return An opaque pointer to the ``sycl::event`` returned by the
* ``sycl::queue::copy`` function.
* @ingroup QueueInterface
*/
DPCTL_API
__dpctl_give DPCTLSyclEventRef
DPCTLQueue_CopyData(__dpctl_keep const DPCTLSyclQueueRef QRef,
void *Dest,
const void *Src,
size_t Count);
/*!
* @brief C-API wrapper for ``sycl::queue::copy``.
*
* @param QRef An opaque pointer to the ``sycl::queue``.
* @param Dest A destination pointer.
* @param Src A source pointer.
* @param Count A number of bytes to copy.
* @param DepEvents A pointer to array of DPCTLSyclEventRef opaque
* pointers to dependent events.
* @param DepEventsCount A number of dependent events.
* @return An opaque pointer to the ``sycl::event`` returned by the
* ``sycl::queue::copy`` function.
* @ingroup QueueInterface
*/
DPCTL_API
__dpctl_give DPCTLSyclEventRef
DPCTLQueue_CopyDataWithEvents(__dpctl_keep const DPCTLSyclQueueRef QRef,
void *Dest,
const void *Src,
size_t Count,
__dpctl_keep const DPCTLSyclEventRef *DepEvents,
size_t DepEventsCount);
/*!
* @brief C-API wrapper for ``sycl::queue::prefetch``.
*
* @param QRef An opaque pointer to the ``sycl::queue``.
* @param Ptr An USM pointer to memory.
* @param Count A number of bytes to prefetch.
* @return An opaque pointer to the ``sycl::event`` returned by the
* ``sycl::queue::prefetch`` function.
* @ingroup QueueInterface
*/
DPCTL_API
__dpctl_give DPCTLSyclEventRef
DPCTLQueue_Prefetch(__dpctl_keep DPCTLSyclQueueRef QRef,
const void *Ptr,
size_t Count);
/*!
* @brief C-API wrapper for ``sycl::queue::mem_advise``.
*
* @param QRef An opaque pointer to the ``sycl::queue``.
* @param Ptr An USM pointer to memory.
* @param Count A number of bytes to prefetch.
* @param Advice Device-defined advice for the specified allocation.
* A value of 0 reverts the advice for Ptr to the
* default behavior.
* @return An opaque pointer to the ``sycl::event`` returned by the
* ``sycl::queue::mem_advise`` function.
* @ingroup QueueInterface
*/
DPCTL_API
__dpctl_give DPCTLSyclEventRef
DPCTLQueue_MemAdvise(__dpctl_keep DPCTLSyclQueueRef QRef,
const void *Ptr,
size_t Count,
int Advice);
/*!
* @brief C-API wrapper for sycl::queue::is_in_order that indicates whether
* the referenced queue is in-order or out-of-order.
*
* @param QRef An opaque pointer to the ``sycl::queue``.
* @ingroup QueueInterface
*/
DPCTL_API
bool DPCTLQueue_IsInOrder(__dpctl_keep const DPCTLSyclQueueRef QRef);
/*!
* @brief C-API wrapper for
* sycl::queue::has_property<sycl::property::queue::enable_profiling>() that
* indicates whether the referenced queue was constructed with this property.
*
* @param QRef An opaque pointer to the ``sycl::queue``.
* @ingroup QueueInterface
*/
DPCTL_API
bool DPCTLQueue_HasEnableProfiling(__dpctl_keep const DPCTLSyclQueueRef QRef);
/*!
* @brief C-API wrapper for std::hash<sycl::queue>'s operator().
*
* @param QRef An opaque pointer to the ``sycl::queue``.
* @return Hash value of the underlying ``sycl::queue`` instance.
* @ingroup QueueInterface
*/
DPCTL_API
size_t DPCTLQueue_Hash(__dpctl_keep const DPCTLSyclQueueRef QRef);
/*!
* @brief C-API wrapper for ``sycl::queue::submit_barrier()``.
*
* @param QRef An opaque pointer to the ``sycl::queue``.
* @return An opaque pointer to the ``sycl::event`` returned by the
* ``sycl::queue::submit_barrier()`` function.
*/
DPCTL_API
__dpctl_give DPCTLSyclEventRef
DPCTLQueue_SubmitBarrier(__dpctl_keep const DPCTLSyclQueueRef QRef);
/*!
* @brief C-API wrapper for ``sycl::queue::submit_barrier(event_vector)``.
*
* @param QRef An opaque pointer to the ``sycl::queue``.
* @param DepEvents List of dependent DPCTLSyclEventRef objects (events)
* for the barrier. We call ``sycl::handler.depends_on``
* for each of the provided events.
* @param NDepEvents Size of the DepEvents list.
* @return An opaque pointer to the ``sycl::event`` returned by the
* ``sycl::queue::submit_barrier()`` function.
*/
DPCTL_API
__dpctl_give DPCTLSyclEventRef DPCTLQueue_SubmitBarrierForEvents(
__dpctl_keep const DPCTLSyclQueueRef QRef,
__dpctl_keep const DPCTLSyclEventRef *DepEvents,
size_t NDepEvents);
/*!
* @brief C-API wrapper for ``sycl::queue::memset``.
*
* @param QRef An opaque pointer to the ``sycl::queue``.
* @param USMRef An USM pointer to the memory to fill.
* @param Value A value to fill.
* @param Count A number of uint8_t elements to fill.
* @return An opaque pointer to the ``sycl::event`` returned by the
* ``sycl::queue::fill`` function.
* @ingroup QueueInterface
*/
DPCTL_API
__dpctl_give DPCTLSyclEventRef
DPCTLQueue_Memset(__dpctl_keep const DPCTLSyclQueueRef QRef,
void *USMRef,
uint8_t Value,
size_t Count);
/*!
* @brief C-API wrapper for ``sycl::queue::fill``.
*
* @param QRef An opaque pointer to the ``sycl::queue``.
* @param USMRef An USM pointer to the memory to fill.
* @param Value A uint8_t value to fill.
* @param Count A number of uint8_t elements to fill.
* @return An opaque pointer to the ``sycl::event`` returned by the
* ``sycl::queue::fill`` function.
* @ingroup QueueInterface
*/
DPCTL_API
__dpctl_give DPCTLSyclEventRef
DPCTLQueue_Fill8(__dpctl_keep const DPCTLSyclQueueRef QRef,
void *USMRef,
uint8_t Value,
size_t Count);
/*!
* @brief C-API wrapper for ``sycl::queue::fill``.
*
* @param QRef An opaque pointer to the ``sycl::queue``.
* @param USMRef An USM pointer to the memory to fill.
* @param Value A uint16_t value to fill.
* @param Count A number of uint16_t elements to fill.
* @return An opaque pointer to the ``sycl::event`` returned by the
* ``sycl::queue::fill`` function.
* @ingroup QueueInterface
*/
DPCTL_API
__dpctl_give DPCTLSyclEventRef
DPCTLQueue_Fill16(__dpctl_keep const DPCTLSyclQueueRef QRef,
void *USMRef,
uint16_t Value,
size_t Count);
/*!
* @brief C-API wrapper for ``sycl::queue::fill``.
*
* @param QRef An opaque pointer to the ``sycl::queue``.
* @param USMRef An USM pointer to the memory to fill.
* @param Value A uint32_t value to fill.
* @param Count A number of uint32_t elements to fill.
* @return An opaque pointer to the ``sycl::event`` returned by the
* ``sycl::queue::fill`` function.
* @ingroup QueueInterface
*/
DPCTL_API
__dpctl_give DPCTLSyclEventRef
DPCTLQueue_Fill32(__dpctl_keep const DPCTLSyclQueueRef QRef,
void *USMRef,
uint32_t Value,
size_t Count);
/*!
* @brief C-API wrapper for ``sycl::queue::fill``.
*
* @param QRef An opaque pointer to the ``sycl::queue``.
* @param USMRef An USM pointer to the memory to fill.
* @param Value A uint64_t value to fill.
* @param Count A number of uint64_t elements to fill.
* @return An opaque pointer to the ``sycl::event`` returned by the
* ``sycl::queue::fill`` function.
* @ingroup QueueInterface
*/
DPCTL_API
__dpctl_give DPCTLSyclEventRef
DPCTLQueue_Fill64(__dpctl_keep const DPCTLSyclQueueRef QRef,
void *USMRef,
uint64_t Value,
size_t Count);
/*!
* @brief C-API wrapper for ``sycl::queue::fill``.
*
* @param QRef An opaque pointer to the ``sycl::queue``.
* @param USMRef An USM pointer to the memory to fill.
* @param Value A pointer to uint64_t array of 2 elements with value
* to fill.
* @param Count A number of 128-bit elements to fill.
* @return An opaque pointer to the ``sycl::event`` returned by the
* ``sycl::queue::fill`` function.
* @ingroup QueueInterface
*/
DPCTL_API
__dpctl_give DPCTLSyclEventRef
DPCTLQueue_Fill128(__dpctl_keep const DPCTLSyclQueueRef QRef,
void *USMRef,
uint64_t *Value,
size_t Count);
DPCTL_C_EXTERN_C_END