Skip to content

Commit b6710ed

Browse files
Implemented DPCTLQueue_SubmitBarrier, DPCTLQueue_SubmitBarrierForEvents
1 parent e5c50ea commit b6710ed

File tree

3 files changed

+121
-0
lines changed

3 files changed

+121
-0
lines changed

dpctl-capi/include/dpctl_sycl_queue_interface.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,4 +343,32 @@ bool DPCTLQueue_IsInOrder(__dpctl_keep const DPCTLSyclQueueRef QRef);
343343
DPCTL_API
344344
size_t DPCTLQueue_Hash(__dpctl_keep const DPCTLSyclQueueRef QRef);
345345

346+
/*!
347+
* @brief C-API wraper for ``sycl::queue::submit_barrier()``.
348+
*
349+
* @param QRef An opaque pointer to the ``sycl::queue``.
350+
* @return An opaque pointer to the ``sycl::event`` returned by the
351+
* ``sycl::queue::submit_barrier()`` function.
352+
*/
353+
DPCTL_API
354+
DPCTLSyclEventRef
355+
DPCTLQueue_SubmitBarrier(__dpctl_keep const DPCTLSyclQueueRef QRef);
356+
357+
/*!
358+
* @brief C-API wraper for ``sycl::queue::submit_barrier(event_vector)``.
359+
*
360+
* @param QRef An opaque pointer to the ``sycl::queue``.
361+
* @param DepEvents List of dependent DPCTLSyclEventRef objects (events)
362+
* for the barrier. We call ``sycl::handler.depends_on``
363+
* for each of the provided events.
364+
* @param NDepEvents Size of the DepEvents list.
365+
* @return An opaque pointer to the ``sycl::event`` returned by the
366+
* ``sycl::queue::submit_barrier()`` function.
367+
*/
368+
DPCTL_API
369+
DPCTLSyclEventRef DPCTLQueue_SubmitBarrierForEvents(
370+
__dpctl_keep const DPCTLSyclQueueRef QRef,
371+
__dpctl_keep const DPCTLSyclEventRef *DepEvents,
372+
size_t NDepEvents);
373+
346374
DPCTL_C_EXTERN_C_END

dpctl-capi/source/dpctl_sycl_queue_interface.cpp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,3 +533,44 @@ size_t DPCTLQueue_Hash(__dpctl_keep const DPCTLSyclQueueRef QRef)
533533
return 0;
534534
}
535535
}
536+
537+
__dpctl_give DPCTLSyclEventRef DPCTLQueue_SubmitBarrierForEvents(
538+
__dpctl_keep const DPCTLSyclQueueRef QRef,
539+
__dpctl_keep const DPCTLSyclEventRef *DepEvents,
540+
size_t NDepEvents)
541+
{
542+
auto Q = unwrap(QRef);
543+
event e;
544+
if (Q) {
545+
try {
546+
e = Q->submit([&](handler &cgh) {
547+
// Depend on any event that was specified by the caller.
548+
if (NDepEvents)
549+
for (auto i = 0ul; i < NDepEvents; ++i)
550+
cgh.depends_on(*unwrap(DepEvents[i]));
551+
552+
cgh.barrier();
553+
});
554+
} catch (runtime_error &re) {
555+
// \todo fix error handling
556+
std::cerr << re.what() << '\n';
557+
return nullptr;
558+
} catch (std::runtime_error &sre) {
559+
std::cerr << sre.what() << '\n';
560+
return nullptr;
561+
}
562+
563+
return wrap(new event(e));
564+
}
565+
else {
566+
// todo: log error
567+
std::cerr << "Argument QRef is null" << '\n';
568+
return nullptr;
569+
}
570+
}
571+
572+
__dpctl_give DPCTLSyclEventRef
573+
DPCTLQueue_SubmitBarrier(__dpctl_keep const DPCTLSyclQueueRef QRef)
574+
{
575+
return DPCTLQueue_SubmitBarrierForEvents(QRef, nullptr, 0);
576+
}

dpctl-capi/tests/test_sycl_queue_submit.cpp

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,4 +356,56 @@ TEST_F(TestQueueSubmitNDRange, ChkSubmitNDRangeDouble)
356356
EXPECT_TRUE(worked);
357357
}
358358

359+
struct TestQueueSubmitBarrier : public ::testing::Test
360+
{
361+
DPCTLSyclQueueRef QRef = nullptr;
362+
363+
TestQueueSubmitBarrier()
364+
{
365+
DPCTLSyclDeviceSelectorRef DSRef = nullptr;
366+
DPCTLSyclDeviceRef DRef = nullptr;
367+
368+
EXPECT_NO_FATAL_FAILURE(DSRef = DPCTLDefaultSelector_Create());
369+
EXPECT_NO_FATAL_FAILURE(DRef = DPCTLDevice_CreateFromSelector(DSRef));
370+
EXPECT_NO_FATAL_FAILURE(QRef = DPCTLQueue_CreateForDevice(
371+
DRef, nullptr, DPCTL_DEFAULT_PROPERTY));
372+
EXPECT_NO_FATAL_FAILURE(DPCTLDevice_Delete(DRef));
373+
EXPECT_NO_FATAL_FAILURE(DPCTLDeviceSelector_Delete(DSRef));
374+
}
375+
~TestQueueSubmitBarrier()
376+
{
377+
EXPECT_NO_FATAL_FAILURE(DPCTLQueue_Delete(QRef));
378+
}
379+
};
380+
381+
TEST_F(TestQueueSubmitBarrier, ChkSubmitBarrier)
382+
{
383+
DPCTLSyclEventRef ERef = nullptr;
384+
385+
ASSERT_TRUE(QRef != nullptr);
386+
EXPECT_NO_FATAL_FAILURE(ERef = DPCTLQueue_SubmitBarrier(QRef));
387+
ASSERT_TRUE(ERef != nullptr);
388+
EXPECT_NO_FATAL_FAILURE(DPCTLEvent_Wait(ERef));
389+
EXPECT_NO_FATAL_FAILURE(DPCTLEvent_Delete(ERef));
390+
}
391+
392+
TEST_F(TestQueueSubmitBarrier, ChkSubmitBarrierWithEvents)
393+
{
394+
DPCTLSyclEventRef ERef = nullptr;
395+
DPCTLSyclEventRef DepsERefs[2] = {nullptr, nullptr};
396+
397+
EXPECT_NO_FATAL_FAILURE(DepsERefs[0] = DPCTLEvent_Create());
398+
EXPECT_NO_FATAL_FAILURE(DepsERefs[1] = DPCTLEvent_Create());
399+
400+
ASSERT_TRUE(QRef != nullptr);
401+
EXPECT_NO_FATAL_FAILURE(
402+
ERef = DPCTLQueue_SubmitBarrierForEvents(QRef, DepsERefs, 2));
403+
404+
ASSERT_TRUE(ERef != nullptr);
405+
EXPECT_NO_FATAL_FAILURE(DPCTLEvent_Wait(ERef));
406+
EXPECT_NO_FATAL_FAILURE(DPCTLEvent_Delete(ERef));
407+
EXPECT_NO_FATAL_FAILURE(DPCTLEvent_Delete(DepsERefs[0]));
408+
EXPECT_NO_FATAL_FAILURE(DPCTLEvent_Delete(DepsERefs[1]));
409+
}
410+
359411
#endif

0 commit comments

Comments
 (0)