Skip to content

Commit 3fc0bf4

Browse files
Add DPCTLEvent_WaitAndThrow func (#513)
1 parent b283185 commit 3fc0bf4

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

dpctl-capi/include/dpctl_sycl_event_interface.h

+9
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,15 @@ __dpctl_give DPCTLSyclEventRef DPCTLEvent_Create(void);
5757
DPCTL_API
5858
void DPCTLEvent_Wait(__dpctl_keep DPCTLSyclEventRef ERef);
5959

60+
/*!
61+
* @brief C-API wrapper for 'sycl::event.wait_and_throw'.
62+
*
63+
* @param ERef Opaque pointer to a ``sycl::event``
64+
* @ingroup EventInterface
65+
*/
66+
DPCTL_API
67+
void DPCTLEvent_WaitAndThrow(__dpctl_keep DPCTLSyclEventRef ERef);
68+
6069
/*!
6170
* @brief Deletes the DPCTLSyclEventRef after casting it to a ``sycl::event``.
6271
*

dpctl-capi/source/dpctl_sycl_event_interface.cpp

+14
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,20 @@ void DPCTLEvent_Wait(__dpctl_keep DPCTLSyclEventRef ERef)
6363
}
6464
}
6565

66+
void DPCTLEvent_WaitAndThrow(__dpctl_keep DPCTLSyclEventRef ERef)
67+
{
68+
if (ERef) {
69+
auto SyclEvent = unwrap(ERef);
70+
if (SyclEvent)
71+
SyclEvent->wait_and_throw();
72+
}
73+
else {
74+
std::cerr << "Cannot wait_and_throw for the event. DPCTLSyclEventRef "
75+
"as input is "
76+
"a nullptr\n";
77+
}
78+
}
79+
6680
void DPCTLEvent_Delete(__dpctl_take DPCTLSyclEventRef ERef)
6781
{
6882
delete unwrap(ERef);

dpctl-capi/tests/test_sycl_event_interface.cpp

+12
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,18 @@ TEST_F(TestDPCTLSyclEventInterface, CheckWait_Invalid)
6868
EXPECT_NO_FATAL_FAILURE(DPCTLEvent_Delete(E));
6969
}
7070

71+
TEST_F(TestDPCTLSyclEventInterface, CheckEvent_WaitAndThrow)
72+
{
73+
EXPECT_NO_FATAL_FAILURE(DPCTLEvent_WaitAndThrow(ERef));
74+
}
75+
76+
TEST_F(TestDPCTLSyclEventInterface, CheckWaitAndThrow_Invalid)
77+
{
78+
DPCTLSyclEventRef E = nullptr;
79+
EXPECT_NO_FATAL_FAILURE(DPCTLEvent_WaitAndThrow(E));
80+
EXPECT_NO_FATAL_FAILURE(DPCTLEvent_Delete(E));
81+
}
82+
7183
TEST_F(TestDPCTLSyclEventInterface, CheckEvent_Copy)
7284
{
7385
DPCTLSyclEventRef Copied_ERef = nullptr;

0 commit comments

Comments
 (0)