Skip to content

Commit 49bb7fe

Browse files
Add DPCTLEvent_Copy func
1 parent 521d277 commit 49bb7fe

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

dpctl-capi/include/dpctl_sycl_event_interface.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,16 @@ void DPCTLEvent_Wait(__dpctl_keep DPCTLSyclEventRef ERef);
5757
DPCTL_API
5858
void DPCTLEvent_Delete(__dpctl_take DPCTLSyclEventRef ERef);
5959

60+
/*!
61+
 * @brief Returns a copy of the DPCTLSyclEventRef object.
62+
 *
63+
 * @param    ERef           DPCTLSyclEventRef object to be copied.
64+
 * @return   A new DPCTLSyclEventRef created by copying the passed in
65+
 * DPCTLSyclEventRef object.
66+
 * @ingroup EventInterface
67+
 */
68+
DPCTL_API
69+
__dpctl_give DPCTLSyclEventRef
70+
DPCTLEvent_Copy(__dpctl_keep const DPCTLSyclEventRef ERef);
71+
6072
DPCTL_C_EXTERN_C_END

dpctl-capi/source/dpctl_sycl_event_interface.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,21 @@ void DPCTLEvent_Delete(__dpctl_take DPCTLSyclEventRef ERef)
4747
{
4848
delete unwrap(ERef);
4949
}
50+
51+
__dpctl_give DPCTLSyclEventRef
52+
DPCTLEvent_Copy(__dpctl_keep DPCTLSyclEventRef ERef)
53+
{
54+
auto SyclEvent = unwrap(ERef);
55+
if (!SyclEvent) {
56+
std::cerr << "Cannot copy DPCTLSyclEventRef as input is a nullptr\n";
57+
return nullptr;
58+
}
59+
try {
60+
auto CopiedSyclEvent = new event(*SyclEvent);
61+
return wrap(CopiedSyclEvent);
62+
} catch (std::bad_alloc const &ba) {
63+
// \todo log error
64+
std::cerr << ba.what() << '\n';
65+
return nullptr;
66+
}
67+
}

0 commit comments

Comments
 (0)