Skip to content

Add a new DPCTLEvent_GetBackend function #507

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions dpctl-capi/include/dpctl_sycl_event_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "Support/ExternC.h"
#include "Support/MemOwnershipAttrs.h"
#include "dpctl_data_types.h"
#include "dpctl_sycl_enum_types.h"
#include "dpctl_sycl_types.h"

DPCTL_C_EXTERN_C_BEGIN
Expand Down Expand Up @@ -78,4 +79,16 @@ DPCTL_API
__dpctl_give DPCTLSyclEventRef
DPCTLEvent_Copy(__dpctl_keep const DPCTLSyclEventRef ERef);

/*!
* @brief Returns a DPCTLSyclBackendType enum value identifying the SYCL
* backend associated with the event.
*
* @param ERef Opaque pointer to a ``sycl::event``
* @return A DPCTLSyclBackendType enum value identifying the SYCL backend
* associated with the event.
* @ingroup EventInterface
*/
DPCTL_API
DPCTLSyclBackendType DPCTLEvent_GetBackend(__dpctl_keep DPCTLSyclEventRef ERef);

DPCTL_C_EXTERN_C_END
14 changes: 14 additions & 0 deletions dpctl-capi/source/dpctl_sycl_event_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
//===----------------------------------------------------------------------===//

#include "dpctl_sycl_event_interface.h"
#include "../helper/include/dpctl_utils_helper.h"
#include "Support/CBindingWrapping.h"
#include <CL/sycl.hpp> /* SYCL headers */

Expand Down Expand Up @@ -77,3 +78,16 @@ DPCTLEvent_Copy(__dpctl_keep DPCTLSyclEventRef ERef)
return nullptr;
}
}

DPCTLSyclBackendType DPCTLEvent_GetBackend(__dpctl_keep DPCTLSyclEventRef ERef)
{
DPCTLSyclBackendType BTy = DPCTLSyclBackendType::DPCTL_UNKNOWN_BACKEND;
auto E = unwrap(ERef);
if (E) {
BTy = DPCTL_SyclBackendToDPCTLBackendType(E->get_backend());
}
else {
std::cerr << "Backend cannot be looked up for a NULL event\n";
}
return BTy;
}
28 changes: 28 additions & 0 deletions dpctl-capi/tests/test_sycl_event_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,31 @@ TEST_F(TestDPCTLSyclEventInterface, CheckCopy_Invalid)
EXPECT_NO_FATAL_FAILURE(DPCTLEvent_Delete(E1));
EXPECT_NO_FATAL_FAILURE(DPCTLEvent_Delete(E2));
}

TEST_F(TestDPCTLSyclEventInterface, CheckEvent_GetBackend)
{
DPCTLSyclBackendType BTy = DPCTLSyclBackendType::DPCTL_UNKNOWN_BACKEND;
EXPECT_NO_FATAL_FAILURE(BTy = DPCTLEvent_GetBackend(ERef));
EXPECT_TRUE([BTy] {
switch (BTy) {
case DPCTLSyclBackendType::DPCTL_CUDA:
return true;
case DPCTLSyclBackendType::DPCTL_HOST:
return true;
case DPCTLSyclBackendType::DPCTL_LEVEL_ZERO:
return true;
case DPCTLSyclBackendType::DPCTL_OPENCL:
return true;
default:
return false;
}
}());
}

TEST_F(TestDPCTLSyclEventInterface, CheckGetBackend_Invalid)
{
DPCTLSyclEventRef E = nullptr;
DPCTLSyclBackendType Bty = DPCTL_UNKNOWN_BACKEND;
EXPECT_NO_FATAL_FAILURE(Bty = DPCTLEvent_GetBackend(E));
EXPECT_TRUE(Bty == DPCTL_UNKNOWN_BACKEND);
}