Skip to content

Commit f107044

Browse files
Implementation of DPCTLQueue_Fill8/16/32/64/128 function
Also added tests and docstrings.
1 parent f0a4f63 commit f107044

File tree

3 files changed

+488
-35
lines changed

3 files changed

+488
-35
lines changed

libsyclinterface/include/dpctl_sycl_queue_interface.h

Lines changed: 114 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ DPCTLQueue_GetDevice(__dpctl_keep const DPCTLSyclQueueRef QRef);
205205
* @ingroup QueueInterface
206206
*/
207207
DPCTL_API
208-
DPCTLSyclEventRef
208+
__dpctl_give DPCTLSyclEventRef
209209
DPCTLQueue_SubmitRange(__dpctl_keep const DPCTLSyclKernelRef KRef,
210210
__dpctl_keep const DPCTLSyclQueueRef QRef,
211211
__dpctl_keep void **Args,
@@ -253,7 +253,7 @@ DPCTLQueue_SubmitRange(__dpctl_keep const DPCTLSyclKernelRef KRef,
253253
* @ingroup QueueInterface
254254
*/
255255
DPCTL_API
256-
DPCTLSyclEventRef
256+
__dpctl_give DPCTLSyclEventRef
257257
DPCTLQueue_SubmitNDRange(__dpctl_keep const DPCTLSyclKernelRef KRef,
258258
__dpctl_keep const DPCTLSyclQueueRef QRef,
259259
__dpctl_keep void **Args,
@@ -287,10 +287,11 @@ void DPCTLQueue_Wait(__dpctl_keep const DPCTLSyclQueueRef QRef);
287287
* @ingroup QueueInterface
288288
*/
289289
DPCTL_API
290-
DPCTLSyclEventRef DPCTLQueue_Memcpy(__dpctl_keep const DPCTLSyclQueueRef QRef,
291-
void *Dest,
292-
const void *Src,
293-
size_t Count);
290+
__dpctl_give DPCTLSyclEventRef
291+
DPCTLQueue_Memcpy(__dpctl_keep const DPCTLSyclQueueRef QRef,
292+
void *Dest,
293+
const void *Src,
294+
size_t Count);
294295

295296
/*!
296297
* @brief C-API wrapper for ``sycl::queue::prefetch``.
@@ -303,9 +304,10 @@ DPCTLSyclEventRef DPCTLQueue_Memcpy(__dpctl_keep const DPCTLSyclQueueRef QRef,
303304
* @ingroup QueueInterface
304305
*/
305306
DPCTL_API
306-
DPCTLSyclEventRef DPCTLQueue_Prefetch(__dpctl_keep DPCTLSyclQueueRef QRef,
307-
const void *Ptr,
308-
size_t Count);
307+
__dpctl_give DPCTLSyclEventRef
308+
DPCTLQueue_Prefetch(__dpctl_keep DPCTLSyclQueueRef QRef,
309+
const void *Ptr,
310+
size_t Count);
309311

310312
/*!
311313
* @brief C-API wrapper for ``sycl::queue::mem_advise``.
@@ -321,10 +323,11 @@ DPCTLSyclEventRef DPCTLQueue_Prefetch(__dpctl_keep DPCTLSyclQueueRef QRef,
321323
* @ingroup QueueInterface
322324
*/
323325
DPCTL_API
324-
DPCTLSyclEventRef DPCTLQueue_MemAdvise(__dpctl_keep DPCTLSyclQueueRef QRef,
325-
const void *Ptr,
326-
size_t Count,
327-
int Advice);
326+
__dpctl_give DPCTLSyclEventRef
327+
DPCTLQueue_MemAdvise(__dpctl_keep DPCTLSyclQueueRef QRef,
328+
const void *Ptr,
329+
size_t Count,
330+
int Advice);
328331

329332
/*!
330333
* @brief C-API wrapper for sycl::queue::is_in_order that indicates whether
@@ -365,7 +368,7 @@ size_t DPCTLQueue_Hash(__dpctl_keep const DPCTLSyclQueueRef QRef);
365368
* ``sycl::queue::submit_barrier()`` function.
366369
*/
367370
DPCTL_API
368-
DPCTLSyclEventRef
371+
__dpctl_give DPCTLSyclEventRef
369372
DPCTLQueue_SubmitBarrier(__dpctl_keep const DPCTLSyclQueueRef QRef);
370373

371374
/*!
@@ -380,7 +383,7 @@ DPCTLQueue_SubmitBarrier(__dpctl_keep const DPCTLSyclQueueRef QRef);
380383
* ``sycl::queue::submit_barrier()`` function.
381384
*/
382385
DPCTL_API
383-
DPCTLSyclEventRef DPCTLQueue_SubmitBarrierForEvents(
386+
__dpctl_give DPCTLSyclEventRef DPCTLQueue_SubmitBarrierForEvents(
384387
__dpctl_keep const DPCTLSyclQueueRef QRef,
385388
__dpctl_keep const DPCTLSyclEventRef *DepEvents,
386389
size_t NDepEvents);
@@ -397,9 +400,101 @@ DPCTLSyclEventRef DPCTLQueue_SubmitBarrierForEvents(
397400
* @ingroup QueueInterface
398401
*/
399402
DPCTL_API
400-
DPCTLSyclEventRef DPCTLQueue_Memset(__dpctl_keep const DPCTLSyclQueueRef QRef,
401-
void *USMRef,
402-
uint8_t Value,
403-
size_t Count);
403+
__dpctl_give DPCTLSyclEventRef
404+
DPCTLQueue_Memset(__dpctl_keep const DPCTLSyclQueueRef QRef,
405+
void *USMRef,
406+
uint8_t Value,
407+
size_t Count);
408+
409+
/*!
410+
* @brief C-API wrapper for ``sycl::queue::fill``.
411+
*
412+
* @param QRef An opaque pointer to the ``sycl::queue``.
413+
* @param USMRef An USM pointer to the memory to fill.
414+
* @param Value A uint8_t value to fill.
415+
* @param Count A number of uint8_t elements to fill.
416+
* @return An opaque pointer to the ``sycl::event`` returned by the
417+
* ``sycl::queue::fill`` function.
418+
* @ingroup QueueInterface
419+
*/
420+
DPCTL_API
421+
__dpctl_give DPCTLSyclEventRef
422+
DPCTLQueue_Fill8(__dpctl_keep const DPCTLSyclQueueRef QRef,
423+
void *USMRef,
424+
uint8_t Value,
425+
size_t Count);
426+
427+
/*!
428+
* @brief C-API wrapper for ``sycl::queue::fill``.
429+
*
430+
* @param QRef An opaque pointer to the ``sycl::queue``.
431+
* @param USMRef An USM pointer to the memory to fill.
432+
* @param Value A uint16_t value to fill.
433+
* @param Count A number of uint16_t elements to fill.
434+
* @return An opaque pointer to the ``sycl::event`` returned by the
435+
* ``sycl::queue::fill`` function.
436+
* @ingroup QueueInterface
437+
*/
438+
DPCTL_API
439+
__dpctl_give DPCTLSyclEventRef
440+
DPCTLQueue_Fill16(__dpctl_keep const DPCTLSyclQueueRef QRef,
441+
void *USMRef,
442+
uint16_t Value,
443+
size_t Count);
444+
445+
/*!
446+
* @brief C-API wrapper for ``sycl::queue::fill``.
447+
*
448+
* @param QRef An opaque pointer to the ``sycl::queue``.
449+
* @param USMRef An USM pointer to the memory to fill.
450+
* @param Value A uint32_t value to fill.
451+
* @param Count A number of uint32_t elements to fill.
452+
* @return An opaque pointer to the ``sycl::event`` returned by the
453+
* ``sycl::queue::fill`` function.
454+
* @ingroup QueueInterface
455+
*/
456+
DPCTL_API
457+
__dpctl_give DPCTLSyclEventRef
458+
DPCTLQueue_Fill32(__dpctl_keep const DPCTLSyclQueueRef QRef,
459+
void *USMRef,
460+
uint32_t Value,
461+
size_t Count);
462+
463+
/*!
464+
* @brief C-API wrapper for ``sycl::queue::fill``.
465+
*
466+
* @param QRef An opaque pointer to the ``sycl::queue``.
467+
* @param USMRef An USM pointer to the memory to fill.
468+
* @param Value A uint64_t value to fill.
469+
* @param Count A number of uint64_t elements to fill.
470+
* @return An opaque pointer to the ``sycl::event`` returned by the
471+
* ``sycl::queue::fill`` function.
472+
* @ingroup QueueInterface
473+
*/
474+
DPCTL_API
475+
__dpctl_give DPCTLSyclEventRef
476+
DPCTLQueue_Fill64(__dpctl_keep const DPCTLSyclQueueRef QRef,
477+
void *USMRef,
478+
uint64_t Value,
479+
size_t Count);
480+
481+
/*!
482+
* @brief C-API wrapper for ``sycl::queue::fill``.
483+
*
484+
* @param QRef An opaque pointer to the ``sycl::queue``.
485+
* @param USMRef An USM pointer to the memory to fill.
486+
* @param Value A pointer to uint64_t array of 2 elements with value
487+
* to fill.
488+
* @param Count A number of 128-bit elements to fill.
489+
* @return An opaque pointer to the ``sycl::event`` returned by the
490+
* ``sycl::queue::fill`` function.
491+
* @ingroup QueueInterface
492+
*/
493+
DPCTL_API
494+
__dpctl_give DPCTLSyclEventRef
495+
DPCTLQueue_Fill128(__dpctl_keep const DPCTLSyclQueueRef QRef,
496+
void *USMRef,
497+
uint64_t *Value,
498+
size_t Count);
404499

405500
DPCTL_C_EXTERN_C_END

libsyclinterface/source/dpctl_sycl_queue_interface.cpp

Lines changed: 152 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ DPCTLQueue_SubmitRange(__dpctl_keep const DPCTLSyclKernelRef KRef,
399399
return wrap(new event(e));
400400
}
401401

402-
DPCTLSyclEventRef
402+
__dpctl_give DPCTLSyclEventRef
403403
DPCTLQueue_SubmitNDRange(__dpctl_keep const DPCTLSyclKernelRef KRef,
404404
__dpctl_keep const DPCTLSyclQueueRef QRef,
405405
__dpctl_keep void **Args,
@@ -469,10 +469,11 @@ void DPCTLQueue_Wait(__dpctl_keep DPCTLSyclQueueRef QRef)
469469
}
470470
}
471471

472-
DPCTLSyclEventRef DPCTLQueue_Memcpy(__dpctl_keep const DPCTLSyclQueueRef QRef,
473-
void *Dest,
474-
const void *Src,
475-
size_t Count)
472+
__dpctl_give DPCTLSyclEventRef
473+
DPCTLQueue_Memcpy(__dpctl_keep const DPCTLSyclQueueRef QRef,
474+
void *Dest,
475+
const void *Src,
476+
size_t Count)
476477
{
477478
auto Q = unwrap(QRef);
478479
if (Q) {
@@ -492,9 +493,10 @@ DPCTLSyclEventRef DPCTLQueue_Memcpy(__dpctl_keep const DPCTLSyclQueueRef QRef,
492493
}
493494
}
494495

495-
DPCTLSyclEventRef DPCTLQueue_Prefetch(__dpctl_keep DPCTLSyclQueueRef QRef,
496-
const void *Ptr,
497-
size_t Count)
496+
__dpctl_give DPCTLSyclEventRef
497+
DPCTLQueue_Prefetch(__dpctl_keep DPCTLSyclQueueRef QRef,
498+
const void *Ptr,
499+
size_t Count)
498500
{
499501
auto Q = unwrap(QRef);
500502
if (Q) {
@@ -521,10 +523,11 @@ DPCTLSyclEventRef DPCTLQueue_Prefetch(__dpctl_keep DPCTLSyclQueueRef QRef,
521523
}
522524
}
523525

524-
DPCTLSyclEventRef DPCTLQueue_MemAdvise(__dpctl_keep DPCTLSyclQueueRef QRef,
525-
const void *Ptr,
526-
size_t Count,
527-
int Advice)
526+
__dpctl_give DPCTLSyclEventRef
527+
DPCTLQueue_MemAdvise(__dpctl_keep DPCTLSyclQueueRef QRef,
528+
const void *Ptr,
529+
size_t Count,
530+
int Advice)
528531
{
529532
auto Q = unwrap(QRef);
530533
if (Q) {
@@ -613,10 +616,11 @@ DPCTLQueue_SubmitBarrier(__dpctl_keep const DPCTLSyclQueueRef QRef)
613616
return DPCTLQueue_SubmitBarrierForEvents(QRef, nullptr, 0);
614617
}
615618

616-
DPCTLSyclEventRef DPCTLQueue_Memset(__dpctl_keep const DPCTLSyclQueueRef QRef,
617-
void *USMRef,
618-
uint8_t Value,
619-
size_t Count)
619+
__dpctl_give DPCTLSyclEventRef
620+
DPCTLQueue_Memset(__dpctl_keep const DPCTLSyclQueueRef QRef,
621+
void *USMRef,
622+
uint8_t Value,
623+
size_t Count)
620624
{
621625
auto Q = unwrap(QRef);
622626
if (Q && USMRef) {
@@ -634,4 +638,136 @@ DPCTLSyclEventRef DPCTLQueue_Memset(__dpctl_keep const DPCTLSyclQueueRef QRef,
634638
__func__, __LINE__);
635639
return nullptr;
636640
}
641+
};
642+
643+
__dpctl_give DPCTLSyclEventRef
644+
DPCTLQueue_Fill8(__dpctl_keep const DPCTLSyclQueueRef QRef,
645+
void *USMRef,
646+
uint8_t Value,
647+
size_t Count)
648+
{
649+
auto Q = unwrap(QRef);
650+
if (Q && USMRef) {
651+
sycl::event ev;
652+
try {
653+
ev = Q->fill<uint8_t>(USMRef, Value, Count);
654+
} catch (std::exception const &e) {
655+
error_handler(e, __FILE__, __func__, __LINE__);
656+
return nullptr;
657+
}
658+
return wrap(new event(ev));
659+
}
660+
else {
661+
error_handler("QRef or USMRef passed to fill8 were NULL.", __FILE__,
662+
__func__, __LINE__);
663+
return nullptr;
664+
}
665+
}
666+
667+
__dpctl_give DPCTLSyclEventRef
668+
DPCTLQueue_Fill16(__dpctl_keep const DPCTLSyclQueueRef QRef,
669+
void *USMRef,
670+
uint16_t Value,
671+
size_t Count)
672+
{
673+
auto Q = unwrap(QRef);
674+
if (Q && USMRef) {
675+
sycl::event ev;
676+
try {
677+
ev = Q->fill<uint16_t>(USMRef, Value, Count);
678+
} catch (std::exception const &e) {
679+
error_handler(e, __FILE__, __func__, __LINE__);
680+
return nullptr;
681+
}
682+
return wrap(new event(ev));
683+
}
684+
else {
685+
error_handler("QRef or USMRef passed to fill16 were NULL.", __FILE__,
686+
__func__, __LINE__);
687+
return nullptr;
688+
}
689+
}
690+
691+
__dpctl_give DPCTLSyclEventRef
692+
DPCTLQueue_Fill32(__dpctl_keep const DPCTLSyclQueueRef QRef,
693+
void *USMRef,
694+
uint32_t Value,
695+
size_t Count)
696+
{
697+
auto Q = unwrap(QRef);
698+
if (Q && USMRef) {
699+
sycl::event ev;
700+
try {
701+
ev = Q->fill<uint32_t>(USMRef, Value, Count);
702+
} catch (std::exception const &e) {
703+
error_handler(e, __FILE__, __func__, __LINE__);
704+
return nullptr;
705+
}
706+
return wrap(new event(ev));
707+
}
708+
else {
709+
error_handler("QRef or USMRef passed to fill32 were NULL.", __FILE__,
710+
__func__, __LINE__);
711+
return nullptr;
712+
}
713+
}
714+
715+
__dpctl_give DPCTLSyclEventRef
716+
DPCTLQueue_Fill64(__dpctl_keep const DPCTLSyclQueueRef QRef,
717+
void *USMRef,
718+
uint64_t Value,
719+
size_t Count)
720+
{
721+
auto Q = unwrap(QRef);
722+
if (Q && USMRef) {
723+
sycl::event ev;
724+
try {
725+
ev = Q->fill<uint64_t>(USMRef, Value, Count);
726+
} catch (std::exception const &e) {
727+
error_handler(e, __FILE__, __func__, __LINE__);
728+
return nullptr;
729+
}
730+
return wrap(new event(ev));
731+
}
732+
else {
733+
error_handler("QRef or USMRef passed to fill64 were NULL.", __FILE__,
734+
__func__, __LINE__);
735+
return nullptr;
736+
}
737+
}
738+
739+
namespace
740+
{
741+
typedef struct complex
742+
{
743+
uint64_t real;
744+
uint64_t imag;
745+
} coplexNumber;
746+
} // namespace
747+
748+
__dpctl_give DPCTLSyclEventRef
749+
DPCTLQueue_Fill128(__dpctl_keep const DPCTLSyclQueueRef QRef,
750+
void *USMRef,
751+
uint64_t *Value,
752+
size_t Count)
753+
{
754+
auto Q = unwrap(QRef);
755+
if (Q && USMRef) {
756+
sycl::event ev;
757+
try {
758+
coplexNumber Val;
759+
Val.real = Value[0];
760+
Val.imag = Value[1];
761+
ev = Q->fill(USMRef, Val, Count);
762+
} catch (std::exception const &e) {
763+
error_handler(e, __FILE__, __func__, __LINE__);
764+
return nullptr;
765+
}
766+
return wrap(new event(ev));
767+
}
768+
else {
769+
error_handler("QRef or USMRef passed to fill128 were NULL.", __FILE__,
770+
__func__, __LINE__);
771+
return nullptr;
772+
}
637773
}

0 commit comments

Comments
 (0)