Skip to content

Commit b283185

Browse files
Merge pull request #516 from vlad-perevezentsev/event_getinfo
Add a new DPCTLEvent_GetCommandExecutionStatus function
2 parents 3475ed4 + 9aff276 commit b283185

File tree

6 files changed

+76
-0
lines changed

6 files changed

+76
-0
lines changed

dpctl-capi/helper/include/dpctl_utils_helper.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,3 +196,16 @@ DPCTLPartitionAffinityDomainType DPCTL_SyclPartitionAffinityDomainToDPCTLType(
196196
*/
197197
DPCTL_API
198198
int64_t DPCTL_GetRelativeDeviceId(const sycl::device &Device);
199+
200+
/*!
201+
* @brief Converts a ``sycl::info::event_command_status`` enum value to
202+
* corresponding DPCTLSyclEventStatusType enum value.
203+
*
204+
* @param SyclESTy ``sycl::info::event_command_status`` to be
205+
* converted to DPCTLSyclEventStatusType enum.
206+
* @return A DPCTLSyclEventStatusType enum value for the input
207+
* ``sycl::info::event_command_status`` enum value.
208+
*/
209+
DPCTL_API
210+
DPCTLSyclEventStatusType DPCTL_SyclEventStatusToDPCTLEventStatusType(
211+
sycl::info::event_command_status SyclESTy);

dpctl-capi/helper/source/dpctl_utils_helper.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,3 +447,18 @@ int64_t DPCTL_GetRelativeDeviceId(const device &Device)
447447
}
448448
return relid;
449449
}
450+
451+
DPCTLSyclEventStatusType
452+
DPCTL_SyclEventStatusToDPCTLEventStatusType(info::event_command_status E)
453+
{
454+
switch (E) {
455+
case info::event_command_status::submitted:
456+
return DPCTLSyclEventStatusType::DPCTL_SUBMITTED;
457+
case info::event_command_status::running:
458+
return DPCTLSyclEventStatusType::DPCTL_RUNNING;
459+
case info::event_command_status::complete:
460+
return DPCTLSyclEventStatusType::DPCTL_COMPLETE;
461+
default:
462+
return DPCTLSyclEventStatusType::DPCTL_UNKNOWN_STATUS;
463+
}
464+
}

dpctl-capi/include/dpctl_sycl_enum_types.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,4 +151,12 @@ typedef enum
151151
// clang-format on
152152
} DPCTLQueuePropertyType;
153153

154+
typedef enum
155+
{
156+
DPCTL_UNKNOWN_STATUS,
157+
DPCTL_SUBMITTED,
158+
DPCTL_RUNNING,
159+
DPCTL_COMPLETE
160+
} DPCTLSyclEventStatusType;
161+
154162
DPCTL_C_EXTERN_C_END

dpctl-capi/include/dpctl_sycl_event_interface.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,4 +91,16 @@ DPCTLEvent_Copy(__dpctl_keep const DPCTLSyclEventRef ERef);
9191
DPCTL_API
9292
DPCTLSyclBackendType DPCTLEvent_GetBackend(__dpctl_keep DPCTLSyclEventRef ERef);
9393

94+
/*!
95+
* @brief Returns the DPCTLSyclEventStatusType enum value for the
96+
* DPCTLSyclEventRef argument.
97+
*
98+
* @param ERef Opaque pointer to a ``sycl::event``
99+
* @return The DPCTLSyclDEventStatusType value corresponding to the event.
100+
* @ingroup EventInterface
101+
*/
102+
DPCTL_API
103+
DPCTLSyclEventStatusType
104+
DPCTLEvent_GetCommandExecutionStatus(__dpctl_keep DPCTLSyclEventRef ERef);
105+
94106
DPCTL_C_EXTERN_C_END

dpctl-capi/source/dpctl_sycl_event_interface.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,3 +98,22 @@ DPCTLSyclBackendType DPCTLEvent_GetBackend(__dpctl_keep DPCTLSyclEventRef ERef)
9898
}
9999
return BTy;
100100
}
101+
102+
DPCTLSyclEventStatusType
103+
DPCTLEvent_GetCommandExecutionStatus(__dpctl_keep DPCTLSyclEventRef ERef)
104+
{
105+
DPCTLSyclEventStatusType ESTy =
106+
DPCTLSyclEventStatusType::DPCTL_UNKNOWN_STATUS;
107+
auto E = unwrap(ERef);
108+
if (E) {
109+
try {
110+
auto SyclESTy =
111+
E->get_info<sycl::info::event::command_execution_status>();
112+
ESTy = DPCTL_SyclEventStatusToDPCTLEventStatusType(SyclESTy);
113+
} catch (runtime_error const &re) {
114+
// \todo log error
115+
std::cerr << re.what() << '\n';
116+
}
117+
}
118+
return ESTy;
119+
}

dpctl-capi/tests/test_sycl_event_interface.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,3 +112,12 @@ TEST_F(TestDPCTLSyclEventInterface, CheckGetBackend_Invalid)
112112
EXPECT_NO_FATAL_FAILURE(Bty = DPCTLEvent_GetBackend(E));
113113
EXPECT_TRUE(Bty == DPCTL_UNKNOWN_BACKEND);
114114
}
115+
116+
TEST_F(TestDPCTLSyclEventInterface, ChkGetCommandExecutionStatus)
117+
{
118+
DPCTLSyclEventStatusType ESTy =
119+
DPCTLSyclEventStatusType::DPCTL_UNKNOWN_STATUS;
120+
EXPECT_NO_FATAL_FAILURE(ESTy = DPCTLEvent_GetCommandExecutionStatus(ERef));
121+
EXPECT_TRUE(ESTy != DPCTLSyclEventStatusType::DPCTL_UNKNOWN_STATUS);
122+
EXPECT_TRUE(ESTy == DPCTLSyclEventStatusType::DPCTL_COMPLETE);
123+
}

0 commit comments

Comments
 (0)