Skip to content

Add a new DPCTLEvent_GetCommandExecutionStatus function #516

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/helper/include/dpctl_utils_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,3 +196,16 @@ DPCTLPartitionAffinityDomainType DPCTL_SyclPartitionAffinityDomainToDPCTLType(
*/
DPCTL_API
int64_t DPCTL_GetRelativeDeviceId(const sycl::device &Device);

/*!
* @brief Converts a ``sycl::info::event_command_status`` enum value to
* corresponding DPCTLSyclEventStatusType enum value.
*
* @param SyclESTy ``sycl::info::event_command_status`` to be
* converted to DPCTLSyclEventStatusType enum.
* @return A DPCTLSyclEventStatusType enum value for the input
* ``sycl::info::event_command_status`` enum value.
*/
DPCTL_API
DPCTLSyclEventStatusType DPCTL_SyclEventStatusToDPCTLEventStatusType(
sycl::info::event_command_status SyclESTy);
15 changes: 15 additions & 0 deletions dpctl-capi/helper/source/dpctl_utils_helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -447,3 +447,18 @@ int64_t DPCTL_GetRelativeDeviceId(const device &Device)
}
return relid;
}

DPCTLSyclEventStatusType
DPCTL_SyclEventStatusToDPCTLEventStatusType(info::event_command_status E)
{
switch (E) {
case info::event_command_status::submitted:
return DPCTLSyclEventStatusType::DPCTL_SUBMITTED;
case info::event_command_status::running:
return DPCTLSyclEventStatusType::DPCTL_RUNNING;
case info::event_command_status::complete:
return DPCTLSyclEventStatusType::DPCTL_COMPLETE;
default:
return DPCTLSyclEventStatusType::DPCTL_UNKNOWN_STATUS;
}
}
8 changes: 8 additions & 0 deletions dpctl-capi/include/dpctl_sycl_enum_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,4 +151,12 @@ typedef enum
// clang-format on
} DPCTLQueuePropertyType;

typedef enum
{
DPCTL_UNKNOWN_STATUS,
DPCTL_SUBMITTED,
DPCTL_RUNNING,
DPCTL_COMPLETE
} DPCTLSyclEventStatusType;

DPCTL_C_EXTERN_C_END
12 changes: 12 additions & 0 deletions dpctl-capi/include/dpctl_sycl_event_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,16 @@ DPCTLEvent_Copy(__dpctl_keep const DPCTLSyclEventRef ERef);
DPCTL_API
DPCTLSyclBackendType DPCTLEvent_GetBackend(__dpctl_keep DPCTLSyclEventRef ERef);

/*!
* @brief Returns the DPCTLSyclEventStatusType enum value for the
* DPCTLSyclEventRef argument.
*
* @param ERef Opaque pointer to a ``sycl::event``
* @return The DPCTLSyclDEventStatusType value corresponding to the event.
* @ingroup EventInterface
*/
DPCTL_API
DPCTLSyclEventStatusType
DPCTLEvent_GetCommandExecutionStatus(__dpctl_keep DPCTLSyclEventRef ERef);

DPCTL_C_EXTERN_C_END
19 changes: 19 additions & 0 deletions dpctl-capi/source/dpctl_sycl_event_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,22 @@ DPCTLSyclBackendType DPCTLEvent_GetBackend(__dpctl_keep DPCTLSyclEventRef ERef)
}
return BTy;
}

DPCTLSyclEventStatusType
DPCTLEvent_GetCommandExecutionStatus(__dpctl_keep DPCTLSyclEventRef ERef)
{
DPCTLSyclEventStatusType ESTy =
DPCTLSyclEventStatusType::DPCTL_UNKNOWN_STATUS;
auto E = unwrap(ERef);
if (E) {
try {
auto SyclESTy =
E->get_info<sycl::info::event::command_execution_status>();
ESTy = DPCTL_SyclEventStatusToDPCTLEventStatusType(SyclESTy);
} catch (runtime_error const &re) {
// \todo log error
std::cerr << re.what() << '\n';
}
}
return ESTy;
}
9 changes: 9 additions & 0 deletions dpctl-capi/tests/test_sycl_event_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,12 @@ TEST_F(TestDPCTLSyclEventInterface, CheckGetBackend_Invalid)
EXPECT_NO_FATAL_FAILURE(Bty = DPCTLEvent_GetBackend(E));
EXPECT_TRUE(Bty == DPCTL_UNKNOWN_BACKEND);
}

TEST_F(TestDPCTLSyclEventInterface, ChkGetCommandExecutionStatus)
{
DPCTLSyclEventStatusType ESTy =
DPCTLSyclEventStatusType::DPCTL_UNKNOWN_STATUS;
EXPECT_NO_FATAL_FAILURE(ESTy = DPCTLEvent_GetCommandExecutionStatus(ERef));
EXPECT_TRUE(ESTy != DPCTLSyclEventStatusType::DPCTL_UNKNOWN_STATUS);
EXPECT_TRUE(ESTy == DPCTLSyclEventStatusType::DPCTL_COMPLETE);
}