-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathdpctl_sycl_queue_interface.cpp
950 lines (897 loc) · 32.5 KB
/
dpctl_sycl_queue_interface.cpp
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
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
//===----- dpctl_sycl_queue_interface.cpp - Implements C API for sycl::queue =//
//
// 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 file implements the data types and functions declared in
/// dpctl_sycl_queue_interface.h.
///
//===----------------------------------------------------------------------===//
#include "dpctl_sycl_queue_interface.h"
#include "Config/dpctl_config.h"
#include "dpctl_error_handlers.h"
#include "dpctl_sycl_context_interface.h"
#include "dpctl_sycl_device_interface.h"
#include "dpctl_sycl_device_manager.h"
#include "dpctl_sycl_type_casters.hpp"
#include <stddef.h>
#include <stdint.h>
#include <cstdint>
#include <exception>
#include <sstream>
#include <stdexcept>
#include <sycl/sycl.hpp> /* SYCL headers */
#include <utility>
#ifdef SYCL_EXT_ONEAPI_WORK_GROUP_MEMORY
#include "dpctl_sycl_extension_interface.h"
#endif
using namespace sycl;
#define SET_LOCAL_ACCESSOR_ARG(CGH, NDIM, ARGTY, R, IDX) \
do { \
switch ((ARGTY)) { \
case DPCTL_INT8_T: \
{ \
auto la = local_accessor<std::int8_t, NDIM>(R, CGH); \
CGH.set_arg(IDX, la); \
return true; \
} \
case DPCTL_UINT8_T: \
{ \
auto la = local_accessor<std::uint8_t, NDIM>(R, CGH); \
CGH.set_arg(IDX, la); \
return true; \
} \
case DPCTL_INT16_T: \
{ \
auto la = local_accessor<std::int16_t, NDIM>(R, CGH); \
CGH.set_arg(IDX, la); \
return true; \
} \
case DPCTL_UINT16_T: \
{ \
auto la = local_accessor<std::uint16_t, NDIM>(R, CGH); \
CGH.set_arg(IDX, la); \
return true; \
} \
case DPCTL_INT32_T: \
{ \
auto la = local_accessor<std::int32_t, NDIM>(R, CGH); \
CGH.set_arg(IDX, la); \
return true; \
} \
case DPCTL_UINT32_T: \
{ \
auto la = local_accessor<std::uint32_t, NDIM>(R, CGH); \
CGH.set_arg(IDX, la); \
return true; \
} \
case DPCTL_INT64_T: \
{ \
auto la = local_accessor<std::int64_t, NDIM>(R, CGH); \
CGH.set_arg(IDX, la); \
return true; \
} \
case DPCTL_UINT64_T: \
{ \
auto la = local_accessor<std::uint64_t, NDIM>(R, CGH); \
CGH.set_arg(IDX, la); \
return true; \
} \
case DPCTL_FLOAT32_T: \
{ \
auto la = local_accessor<float, NDIM>(R, CGH); \
CGH.set_arg(IDX, la); \
return true; \
} \
case DPCTL_FLOAT64_T: \
{ \
auto la = local_accessor<double, NDIM>(R, CGH); \
CGH.set_arg(IDX, la); \
return true; \
} \
default: \
error_handler("Kernel argument could not be created.", __FILE__, \
__func__, __LINE__, error_level::error); \
return false; \
} \
} while (0);
namespace
{
static_assert(__SYCL_COMPILER_VERSION >= __SYCL_COMPILER_VERSION_REQUIRED,
"The compiler does not meet minimum version requirement");
using namespace dpctl::syclinterface;
typedef struct complex
{
std::uint64_t real;
std::uint64_t imag;
} complexNumber;
void set_dependent_events(handler &cgh,
__dpctl_keep const DPCTLSyclEventRef *DepEvents,
size_t NDepEvents)
{
for (auto i = 0ul; i < NDepEvents; ++i) {
auto ei = unwrap<event>(DepEvents[i]);
if (ei)
cgh.depends_on(*ei);
}
}
bool set_local_accessor_arg(handler &cgh,
size_t idx,
const MDLocalAccessor *mdstruct)
{
switch (mdstruct->ndim) {
case 1:
{
auto r = range<1>(mdstruct->dim0);
SET_LOCAL_ACCESSOR_ARG(cgh, 1, mdstruct->dpctl_type_id, r, idx);
}
case 2:
{
auto r = range<2>(mdstruct->dim0, mdstruct->dim1);
SET_LOCAL_ACCESSOR_ARG(cgh, 2, mdstruct->dpctl_type_id, r, idx);
}
case 3:
{
auto r = range<3>(mdstruct->dim0, mdstruct->dim1, mdstruct->dim2);
SET_LOCAL_ACCESSOR_ARG(cgh, 3, mdstruct->dpctl_type_id, r, idx);
}
default:
return false;
}
}
/*!
* @brief Set the kernel arg object
*
* @param cgh SYCL command group handler using which a kernel is going to
* be submitted.
* @param idx The position of the argument in the list of arguments passed
* to a kernel.
* @param Arg A void* representing a kernel argument.
* @param Argty A typeid specifying the C++ type of the Arg parameter.
*/
bool set_kernel_arg(handler &cgh,
size_t idx,
__dpctl_keep void *Arg,
DPCTLKernelArgType ArgTy)
{
bool arg_set = true;
switch (ArgTy) {
case DPCTL_INT8_T:
cgh.set_arg(idx, *(std::int8_t *)Arg);
break;
case DPCTL_UINT8_T:
cgh.set_arg(idx, *(std::uint8_t *)Arg);
break;
case DPCTL_INT16_T:
cgh.set_arg(idx, *(std::int16_t *)Arg);
break;
case DPCTL_UINT16_T:
cgh.set_arg(idx, *(std::uint16_t *)Arg);
break;
case DPCTL_INT32_T:
cgh.set_arg(idx, *(std::int32_t *)Arg);
break;
case DPCTL_UINT32_T:
cgh.set_arg(idx, *(std::uint32_t *)Arg);
break;
case DPCTL_INT64_T:
cgh.set_arg(idx, *(std::int64_t *)Arg);
break;
case DPCTL_UINT64_T:
cgh.set_arg(idx, *(std::uint64_t *)Arg);
break;
case DPCTL_FLOAT32_T:
cgh.set_arg(idx, *(float *)Arg);
break;
case DPCTL_FLOAT64_T:
cgh.set_arg(idx, *(double *)Arg);
break;
case DPCTL_VOID_PTR:
cgh.set_arg(idx, Arg);
break;
case DPCTL_LOCAL_ACCESSOR:
arg_set = set_local_accessor_arg(cgh, idx, (MDLocalAccessor *)Arg);
break;
#ifdef SYCL_EXT_ONEAPI_WORK_GROUP_MEMORY
case DPCTL_WORK_GROUP_MEMORY:
{
auto ref = static_cast<DPCTLSyclWorkGroupMemoryRef>(Arg);
RawWorkGroupMemory *raw_mem = unwrap<RawWorkGroupMemory>(ref);
size_t num_bytes = raw_mem->nbytes;
sycl::ext::oneapi::experimental::work_group_memory<char[]> mem{
num_bytes, cgh};
cgh.set_arg(idx, mem);
break;
}
#endif
default:
arg_set = false;
break;
}
return arg_set;
}
void set_kernel_args(handler &cgh,
__dpctl_keep void **Args,
__dpctl_keep const DPCTLKernelArgType *ArgTypes,
size_t NArgs)
{
for (auto i = 0ul; i < NArgs; ++i) {
if (!set_kernel_arg(cgh, i, Args[i], ArgTypes[i])) {
error_handler("Kernel argument could not be created.", __FILE__,
__func__, __LINE__);
throw std::invalid_argument(
"Kernel argument could not be created.");
}
}
}
std::unique_ptr<property_list> create_property_list(int properties)
{
std::unique_ptr<property_list> propList;
int _prop = properties;
if (_prop & DPCTL_ENABLE_PROFILING) {
_prop = _prop ^ DPCTL_ENABLE_PROFILING;
if (_prop & DPCTL_IN_ORDER) {
_prop = _prop ^ DPCTL_IN_ORDER;
propList = std::make_unique<property_list>(
sycl::property::queue::enable_profiling(),
sycl::property::queue::in_order());
}
else {
propList = std::make_unique<property_list>(
sycl::property::queue::enable_profiling());
}
}
else if (_prop & DPCTL_IN_ORDER) {
_prop = _prop ^ DPCTL_IN_ORDER;
propList =
std::make_unique<property_list>(sycl::property::queue::in_order());
}
else {
propList = std::make_unique<property_list>();
}
if (_prop) {
std::stringstream ss;
ss << "Invalid queue property argument (" << std::hex << properties
<< "), interpreted as (" << (properties ^ _prop) << ").";
error_handler(ss.str(), __FILE__, __func__, __LINE__);
}
return propList;
}
__dpctl_give DPCTLSyclQueueRef
getQueueImpl(__dpctl_keep DPCTLSyclContextRef cRef,
__dpctl_keep DPCTLSyclDeviceRef dRef,
error_handler_callback *handler,
int properties)
{
DPCTLSyclQueueRef qRef = nullptr;
qRef = DPCTLQueue_Create(cRef, dRef, handler, properties);
return qRef;
}
} /* end of anonymous namespace */
DPCTL_API
__dpctl_give DPCTLSyclQueueRef
DPCTLQueue_Create(__dpctl_keep const DPCTLSyclContextRef CRef,
__dpctl_keep const DPCTLSyclDeviceRef DRef,
error_handler_callback *handler,
int properties)
{
DPCTLSyclQueueRef q = nullptr;
auto dev = unwrap<device>(DRef);
auto ctx = unwrap<context>(CRef);
if (!(dev && ctx)) {
error_handler("Cannot create queue from DPCTLSyclContextRef and "
"DPCTLSyclDeviceRef as input is a nullptr.",
__FILE__, __func__, __LINE__);
return q;
}
auto propList = create_property_list(properties);
if (handler) {
try {
auto Queue = new queue(*ctx, *dev, DPCTL_AsyncErrorHandler(handler),
*propList);
q = wrap<queue>(Queue);
} catch (std::exception const &e) {
error_handler(e, __FILE__, __func__, __LINE__);
}
}
else {
try {
auto Queue = new queue(*ctx, *dev, *propList);
q = wrap<queue>(Queue);
} catch (std::exception const &e) {
error_handler(e, __FILE__, __func__, __LINE__);
}
}
return q;
}
__dpctl_give DPCTLSyclQueueRef
DPCTLQueue_CreateForDevice(__dpctl_keep const DPCTLSyclDeviceRef DRef,
error_handler_callback *handler,
int properties)
{
DPCTLSyclContextRef CRef = nullptr;
DPCTLSyclQueueRef QRef = nullptr;
auto Device = unwrap<device>(DRef);
if (!Device) {
error_handler("Cannot create queue from NULL device reference.",
__FILE__, __func__, __LINE__);
return QRef;
}
// Check if a cached default context exists for the device.
CRef = DPCTLDeviceMgr_GetCachedContext(DRef);
// If a cached default context was found, that context will be used to use
// create the new queue. When a default cached context was not found, as
// will be the case for non-root devices, i.e., sub-devices, a new context
// will be allocated. Note that any newly allocated context is not cached.
if (!CRef) {
context *ContextPtr = nullptr;
try {
ContextPtr = new context(*Device);
CRef = wrap<context>(ContextPtr);
} catch (std::exception const &e) {
error_handler(e, __FILE__, __func__, __LINE__);
delete ContextPtr;
return QRef;
}
}
// At this point we have a valid context and the queue can be allocated.
QRef = getQueueImpl(CRef, DRef, handler, properties);
// Free the context
DPCTLContext_Delete(CRef);
return QRef;
}
/*!
* Delete the passed in pointer after verifying it points to a sycl::queue.
*/
void DPCTLQueue_Delete(__dpctl_take DPCTLSyclQueueRef QRef)
{
delete unwrap<queue>(QRef);
}
/*!
* Make copy of sycl::queue referenced by passed pointer
*/
__dpctl_give DPCTLSyclQueueRef
DPCTLQueue_Copy(__dpctl_keep const DPCTLSyclQueueRef QRef)
{
auto Queue = unwrap<queue>(QRef);
if (Queue) {
try {
auto CopiedQueue = new queue(*Queue);
return wrap<queue>(CopiedQueue);
} catch (std::exception const &e) {
error_handler(e, __FILE__, __func__, __LINE__);
return nullptr;
}
}
else {
error_handler("Cannot copy DPCTLSyclQueueRef as input is a nullptr",
__FILE__, __func__, __LINE__);
return nullptr;
}
}
bool DPCTLQueue_AreEq(__dpctl_keep const DPCTLSyclQueueRef QRef1,
__dpctl_keep const DPCTLSyclQueueRef QRef2)
{
if (!(QRef1 && QRef2)) {
error_handler("DPCTLSyclQueueRefs are nullptr.", __FILE__, __func__,
__LINE__);
return false;
}
return (*unwrap<queue>(QRef1) == *unwrap<queue>(QRef2));
}
DPCTLSyclBackendType DPCTLQueue_GetBackend(__dpctl_keep DPCTLSyclQueueRef QRef)
{
auto Q = unwrap<queue>(QRef);
if (Q) {
try {
auto C = Q->get_context();
return DPCTLContext_GetBackend(wrap<context>(&C));
} catch (std::exception const &e) {
error_handler(e, __FILE__, __func__, __LINE__);
return DPCTL_UNKNOWN_BACKEND;
}
}
else
return DPCTL_UNKNOWN_BACKEND;
}
__dpctl_give DPCTLSyclDeviceRef
DPCTLQueue_GetDevice(__dpctl_keep const DPCTLSyclQueueRef QRef)
{
DPCTLSyclDeviceRef DRef = nullptr;
auto Q = unwrap<queue>(QRef);
if (Q) {
try {
auto Device = new device(Q->get_device());
DRef = wrap<device>(Device);
} catch (std::exception const &e) {
error_handler(e, __FILE__, __func__, __LINE__);
}
}
else {
error_handler("Could not get the device for this queue.", __FILE__,
__func__, __LINE__);
}
return DRef;
}
__dpctl_give DPCTLSyclContextRef
DPCTLQueue_GetContext(__dpctl_keep const DPCTLSyclQueueRef QRef)
{
auto Q = unwrap<queue>(QRef);
DPCTLSyclContextRef CRef = nullptr;
if (Q)
CRef = wrap<context>(new context(Q->get_context()));
else {
error_handler("Could not get the context for this queue.", __FILE__,
__func__, __LINE__);
}
return CRef;
}
__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 NDims,
__dpctl_keep const DPCTLSyclEventRef *DepEvents,
size_t NDepEvents)
{
auto Kernel = unwrap<kernel>(KRef);
auto Queue = unwrap<queue>(QRef);
event e;
try {
switch (NDims) {
case 1:
{
e = Queue->submit([&](handler &cgh) {
// Depend on any event that was specified by the caller.
set_dependent_events(cgh, DepEvents, NDepEvents);
set_kernel_args(cgh, Args, ArgTypes, NArgs);
cgh.parallel_for(range<1>{Range[0]}, *Kernel);
});
return wrap<event>(new event(std::move(e)));
}
case 2:
{
e = Queue->submit([&](handler &cgh) {
// Depend on any event that was specified by the caller.
set_dependent_events(cgh, DepEvents, NDepEvents);
set_kernel_args(cgh, Args, ArgTypes, NArgs);
cgh.parallel_for(range<2>{Range[0], Range[1]}, *Kernel);
});
return wrap<event>(new event(std::move(e)));
}
case 3:
{
e = Queue->submit([&](handler &cgh) {
// Depend on any event that was specified by the caller.
set_dependent_events(cgh, DepEvents, NDepEvents);
set_kernel_args(cgh, Args, ArgTypes, NArgs);
cgh.parallel_for(range<3>{Range[0], Range[1], Range[2]},
*Kernel);
});
return wrap<event>(new event(std::move(e)));
}
default:
error_handler("Range cannot be greater than three "
"dimensions.",
__FILE__, __func__, __LINE__, error_level::error);
return nullptr;
}
} catch (std::exception const &e) {
error_handler(e, __FILE__, __func__, __LINE__, error_level::error);
return nullptr;
} catch (...) {
error_handler("Unknown exception encountered", __FILE__, __func__,
__LINE__, error_level::error);
return nullptr;
}
}
__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)
{
auto Kernel = unwrap<kernel>(KRef);
auto Queue = unwrap<queue>(QRef);
event e;
try {
switch (NDims) {
case 1:
{
e = Queue->submit([&](handler &cgh) {
// Depend on any event that was specified by the caller.
set_dependent_events(cgh, DepEvents, NDepEvents);
set_kernel_args(cgh, Args, ArgTypes, NArgs);
cgh.parallel_for(nd_range<1>{{gRange[0]}, {lRange[0]}},
*Kernel);
});
return wrap<event>(new event(std::move(e)));
}
case 2:
{
e = Queue->submit([&](handler &cgh) {
// Depend on any event that was specified by the caller.
set_dependent_events(cgh, DepEvents, NDepEvents);
set_kernel_args(cgh, Args, ArgTypes, NArgs);
cgh.parallel_for(
nd_range<2>{{gRange[0], gRange[1]}, {lRange[0], lRange[1]}},
*Kernel);
});
return wrap<event>(new event(std::move(e)));
}
case 3:
{
e = Queue->submit([&](handler &cgh) {
// Depend on any event that was specified by the caller.
set_dependent_events(cgh, DepEvents, NDepEvents);
set_kernel_args(cgh, Args, ArgTypes, NArgs);
cgh.parallel_for(nd_range<3>{{gRange[0], gRange[1], gRange[2]},
{lRange[0], lRange[1], lRange[2]}},
*Kernel);
});
return wrap<event>(new event(std::move(e)));
}
default:
error_handler("Range cannot be greater than three "
"dimensions.",
__FILE__, __func__, __LINE__, error_level::error);
return nullptr;
}
} catch (std::exception const &e) {
error_handler(e, __FILE__, __func__, __LINE__, error_level::error);
return nullptr;
} catch (...) {
error_handler("Unknown exception encountered", __FILE__, __func__,
__LINE__, error_level::error);
return nullptr;
}
}
void DPCTLQueue_Wait(__dpctl_keep DPCTLSyclQueueRef QRef)
{
// \todo what happens if the QRef is null or a pointer to a valid sycl
// queue
if (QRef) {
auto SyclQueue = unwrap<queue>(QRef);
if (SyclQueue)
SyclQueue->wait();
}
else {
error_handler("Argument QRef is NULL.", __FILE__, __func__, __LINE__);
}
}
__dpctl_give DPCTLSyclEventRef
DPCTLQueue_Memcpy(__dpctl_keep const DPCTLSyclQueueRef QRef,
void *Dest,
const void *Src,
size_t Count)
{
auto Q = unwrap<queue>(QRef);
if (Q) {
sycl::event ev;
try {
ev = Q->memcpy(Dest, Src, Count);
} catch (std::exception const &e) {
error_handler(e, __FILE__, __func__, __LINE__);
return nullptr;
}
return wrap<event>(new event(std::move(ev)));
}
else {
error_handler("QRef passed to memcpy was NULL.", __FILE__, __func__,
__LINE__);
return nullptr;
}
}
__dpctl_give DPCTLSyclEventRef
DPCTLQueue_MemcpyWithEvents(__dpctl_keep const DPCTLSyclQueueRef QRef,
void *Dest,
const void *Src,
size_t Count,
const DPCTLSyclEventRef *DepEvents,
size_t DepEventsCount)
{
event ev;
auto Q = unwrap<queue>(QRef);
if (Q) {
try {
ev = Q->submit([&](handler &cgh) {
if (DepEvents)
for (size_t i = 0; i < DepEventsCount; ++i) {
event *ei = unwrap<event>(DepEvents[i]);
if (ei)
cgh.depends_on(*ei);
}
cgh.memcpy(Dest, Src, Count);
});
} catch (const std::exception &ex) {
error_handler(ex, __FILE__, __func__, __LINE__);
return nullptr;
}
}
else {
error_handler("QRef passed to memcpy was NULL.", __FILE__, __func__,
__LINE__);
return nullptr;
}
return wrap<event>(new event(ev));
}
__dpctl_give DPCTLSyclEventRef
DPCTLQueue_Prefetch(__dpctl_keep DPCTLSyclQueueRef QRef,
const void *Ptr,
size_t Count)
{
auto Q = unwrap<queue>(QRef);
if (Q) {
if (Ptr) {
sycl::event ev;
try {
ev = Q->prefetch(Ptr, Count);
} catch (std::exception const &e) {
error_handler(e, __FILE__, __func__, __LINE__);
return nullptr;
}
return wrap<event>(new event(std::move(ev)));
}
else {
error_handler("Attempt to prefetch USM-allocation at nullptr.",
__FILE__, __func__, __LINE__);
return nullptr;
}
}
else {
error_handler("QRef passed to prefetch was NULL.", __FILE__, __func__,
__LINE__);
return nullptr;
}
}
__dpctl_give DPCTLSyclEventRef
DPCTLQueue_MemAdvise(__dpctl_keep DPCTLSyclQueueRef QRef,
const void *Ptr,
size_t Count,
int Advice)
{
auto Q = unwrap<queue>(QRef);
if (Q) {
sycl::event ev;
try {
ev = Q->mem_advise(Ptr, Count, Advice);
} catch (std::exception const &e) {
error_handler(e, __FILE__, __func__, __LINE__);
return nullptr;
}
return wrap<event>(new event(std::move(ev)));
}
else {
error_handler("QRef passed to prefetch was NULL.", __FILE__, __func__,
__LINE__);
return nullptr;
}
}
bool DPCTLQueue_IsInOrder(__dpctl_keep const DPCTLSyclQueueRef QRef)
{
auto Q = unwrap<queue>(QRef);
if (Q) {
return Q->is_in_order();
}
else
return false;
}
bool DPCTLQueue_HasEnableProfiling(__dpctl_keep const DPCTLSyclQueueRef QRef)
{
auto Q = unwrap<queue>(QRef);
if (Q) {
return Q->has_property<sycl::property::queue::enable_profiling>();
}
else
return false;
}
size_t DPCTLQueue_Hash(__dpctl_keep const DPCTLSyclQueueRef QRef)
{
auto Q = unwrap<queue>(QRef);
if (Q) {
std::hash<queue> hash_fn;
return hash_fn(*Q);
}
else {
error_handler("Argument QRef is NULL.", __FILE__, __func__, __LINE__);
return 0;
}
}
__dpctl_give DPCTLSyclEventRef DPCTLQueue_SubmitBarrierForEvents(
__dpctl_keep const DPCTLSyclQueueRef QRef,
__dpctl_keep const DPCTLSyclEventRef *DepEvents,
size_t NDepEvents)
{
auto Q = unwrap<queue>(QRef);
event e;
if (Q) {
try {
e = Q->submit([&](handler &cgh) {
// Depend on any event that was specified by the caller.
if (NDepEvents)
for (auto i = 0ul; i < NDepEvents; ++i)
cgh.depends_on(*unwrap<event>(DepEvents[i]));
cgh.ext_oneapi_barrier();
});
} catch (std::exception const &e) {
error_handler(e, __FILE__, __func__, __LINE__);
return nullptr;
}
return wrap<event>(new event(std::move(e)));
}
else {
error_handler("Argument QRef is NULL", __FILE__, __func__, __LINE__);
return nullptr;
}
}
__dpctl_give DPCTLSyclEventRef
DPCTLQueue_SubmitBarrier(__dpctl_keep const DPCTLSyclQueueRef QRef)
{
return DPCTLQueue_SubmitBarrierForEvents(QRef, nullptr, 0);
}
__dpctl_give DPCTLSyclEventRef
DPCTLQueue_Memset(__dpctl_keep const DPCTLSyclQueueRef QRef,
void *USMRef,
uint8_t Value,
size_t Count)
{
auto Q = unwrap<queue>(QRef);
if (Q && USMRef) {
sycl::event ev;
try {
ev = Q->memset(USMRef, static_cast<int>(Value), Count);
} catch (std::exception const &e) {
error_handler(e, __FILE__, __func__, __LINE__);
return nullptr;
}
return wrap<event>(new event(std::move(ev)));
}
else {
error_handler("QRef or USMRef passed to fill8 were NULL.", __FILE__,
__func__, __LINE__);
return nullptr;
}
};
__dpctl_give DPCTLSyclEventRef
DPCTLQueue_Fill8(__dpctl_keep const DPCTLSyclQueueRef QRef,
void *USMRef,
uint8_t Value,
size_t Count)
{
auto Q = unwrap<queue>(QRef);
if (Q && USMRef) {
sycl::event ev;
try {
ev = Q->fill<uint8_t>(USMRef, Value, Count);
} catch (std::exception const &e) {
error_handler(e, __FILE__, __func__, __LINE__);
return nullptr;
}
return wrap<event>(new event(std::move(ev)));
}
else {
error_handler("QRef or USMRef passed to fill8 were NULL.", __FILE__,
__func__, __LINE__);
return nullptr;
}
}
__dpctl_give DPCTLSyclEventRef
DPCTLQueue_Fill16(__dpctl_keep const DPCTLSyclQueueRef QRef,
void *USMRef,
uint16_t Value,
size_t Count)
{
auto Q = unwrap<queue>(QRef);
if (Q && USMRef) {
sycl::event ev;
try {
ev = Q->fill<uint16_t>(USMRef, Value, Count);
} catch (std::exception const &e) {
error_handler(e, __FILE__, __func__, __LINE__);
return nullptr;
}
return wrap<event>(new event(std::move(ev)));
}
else {
error_handler("QRef or USMRef passed to fill16 were NULL.", __FILE__,
__func__, __LINE__);
return nullptr;
}
}
__dpctl_give DPCTLSyclEventRef
DPCTLQueue_Fill32(__dpctl_keep const DPCTLSyclQueueRef QRef,
void *USMRef,
uint32_t Value,
size_t Count)
{
auto Q = unwrap<queue>(QRef);
if (Q && USMRef) {
sycl::event ev;
try {
ev = Q->fill<uint32_t>(USMRef, Value, Count);
} catch (std::exception const &e) {
error_handler(e, __FILE__, __func__, __LINE__);
return nullptr;
}
return wrap<event>(new event(std::move(ev)));
}
else {
error_handler("QRef or USMRef passed to fill32 were NULL.", __FILE__,
__func__, __LINE__);
return nullptr;
}
}
__dpctl_give DPCTLSyclEventRef
DPCTLQueue_Fill64(__dpctl_keep const DPCTLSyclQueueRef QRef,
void *USMRef,
uint64_t Value,
size_t Count)
{
auto Q = unwrap<queue>(QRef);
if (Q && USMRef) {
sycl::event ev;
try {
ev = Q->fill<uint64_t>(USMRef, Value, Count);
} catch (std::exception const &e) {
error_handler(e, __FILE__, __func__, __LINE__);
return nullptr;
}
return wrap<event>(new event(std::move(ev)));
}
else {
error_handler("QRef or USMRef passed to fill64 were NULL.", __FILE__,
__func__, __LINE__);
return nullptr;
}
}
__dpctl_give DPCTLSyclEventRef
DPCTLQueue_Fill128(__dpctl_keep const DPCTLSyclQueueRef QRef,
void *USMRef,
uint64_t *Value,
size_t Count)
{
auto Q = unwrap<queue>(QRef);
if (Q && USMRef) {
sycl::event ev;
try {
complexNumber Val;
Val.real = Value[0];
Val.imag = Value[1];
ev = Q->fill(USMRef, Val, Count);
} catch (std::exception const &e) {
error_handler(e, __FILE__, __func__, __LINE__);
return nullptr;
}
return wrap<event>(new event(std::move(ev)));
}
else {
error_handler("QRef or USMRef passed to fill128 were NULL.", __FILE__,
__func__, __LINE__);
return nullptr;
}
}