Skip to content

Commit ef38b9c

Browse files
Add DPCTLEvent_GetBackend func
1 parent 91e869d commit ef38b9c

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed

dpctl-capi/include/dpctl_sycl_event_interface.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "Support/ExternC.h"
3030
#include "Support/MemOwnershipAttrs.h"
3131
#include "dpctl_data_types.h"
32+
#include "dpctl_sycl_enum_types.h"
3233
#include "dpctl_sycl_types.h"
3334

3435
DPCTL_C_EXTERN_C_BEGIN
@@ -78,4 +79,16 @@ DPCTL_API
7879
__dpctl_give DPCTLSyclEventRef
7980
DPCTLEvent_Copy(__dpctl_keep const DPCTLSyclEventRef ERef);
8081

82+
/*!
83+
* @brief Returns a DPCTLSyclBackendType enum value identifying the SYCL
84+
* backend associated with the event.
85+
*
86+
* @param ERef Opaque pointer to a ``sycl::event``
87+
* @return A DPCTLSyclBackendType enum value identifying the SYCL backend
88+
* associated with the event.
89+
* @ingroup EventInterface
90+
*/
91+
DPCTL_API
92+
DPCTLSyclBackendType DPCTLEvent_GetBackend(__dpctl_keep DPCTLSyclEventRef ERef);
93+
8194
DPCTL_C_EXTERN_C_END

dpctl-capi/source/dpctl_sycl_event_interface.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
//===----------------------------------------------------------------------===//
2626

2727
#include "dpctl_sycl_event_interface.h"
28+
#include "../helper/include/dpctl_utils_helper.h"
2829
#include "Support/CBindingWrapping.h"
2930
#include <CL/sycl.hpp> /* SYCL headers */
3031

@@ -77,3 +78,16 @@ DPCTLEvent_Copy(__dpctl_keep DPCTLSyclEventRef ERef)
7778
return nullptr;
7879
}
7980
}
81+
82+
DPCTLSyclBackendType DPCTLEvent_GetBackend(__dpctl_keep DPCTLSyclEventRef ERef)
83+
{
84+
DPCTLSyclBackendType BTy = DPCTLSyclBackendType::DPCTL_UNKNOWN_BACKEND;
85+
auto E = unwrap(ERef);
86+
if (E) {
87+
BTy = DPCTL_SyclBackendToDPCTLBackendType(E->get_backend());
88+
}
89+
else {
90+
std::cerr << "Backend cannot be looked up for a NULL event\n";
91+
}
92+
return BTy;
93+
}

dpctl-capi/tests/test_sycl_event_interface.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,31 @@ TEST_F(TestDPCTLSyclEventInterface, CheckCopy_Invalid)
7272
EXPECT_NO_FATAL_FAILURE(DPCTLEvent_Delete(E1));
7373
EXPECT_NO_FATAL_FAILURE(DPCTLEvent_Delete(E2));
7474
}
75+
76+
TEST_F(TestDPCTLSyclEventInterface, CheckEvent_GetBackend)
77+
{
78+
DPCTLSyclBackendType BTy = DPCTLSyclBackendType::DPCTL_UNKNOWN_BACKEND;
79+
EXPECT_NO_FATAL_FAILURE(BTy = DPCTLEvent_GetBackend(ERef));
80+
EXPECT_TRUE([BTy] {
81+
switch (BTy) {
82+
case DPCTLSyclBackendType::DPCTL_CUDA:
83+
return true;
84+
case DPCTLSyclBackendType::DPCTL_HOST:
85+
return true;
86+
case DPCTLSyclBackendType::DPCTL_LEVEL_ZERO:
87+
return true;
88+
case DPCTLSyclBackendType::DPCTL_OPENCL:
89+
return true;
90+
default:
91+
return false;
92+
}
93+
}());
94+
}
95+
96+
TEST_F(TestDPCTLSyclEventInterface, CheckGetBackend_Invalid)
97+
{
98+
DPCTLSyclEventRef E = nullptr;
99+
DPCTLSyclBackendType Bty = DPCTL_UNKNOWN_BACKEND;
100+
EXPECT_NO_FATAL_FAILURE(Bty = DPCTLEvent_GetBackend(E));
101+
EXPECT_TRUE(Bty == DPCTL_UNKNOWN_BACKEND);
102+
}

0 commit comments

Comments
 (0)