Skip to content

Commit c1d1464

Browse files
Add 3 wrapper func for event::get_profiling_info
1 parent 3fc0bf4 commit c1d1464

File tree

3 files changed

+119
-0
lines changed

3 files changed

+119
-0
lines changed

dpctl-capi/include/dpctl_sycl_event_interface.h

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,4 +112,42 @@ DPCTL_API
112112
DPCTLSyclEventStatusType
113113
DPCTLEvent_GetCommandExecutionStatus(__dpctl_keep DPCTLSyclEventRef ERef);
114114

115+
/*!
116+
* @brief Wrapper over
117+
* ``event.get_profiling_info<info::event_profiling::command_submit>()``
118+
*
119+
* @param ERef Opaque pointer to a ``sycl::event``
120+
* @return Returns a value describing the time in nanoseconds
121+
* when the associated command group was submitted to the queue.
122+
* @ingroup EventInterface
123+
*/
124+
DPCTL_API
125+
uint64_t DPCTLEvent_GetProfilingInfoSubmit(__dpctl_keep DPCTLSyclEventRef ERef);
126+
127+
/*!
128+
* @brief Wrapper over
129+
* ``event.get_profiling_info<info::event_profiling::command_start>()``
130+
*
131+
* @param ERef Opaque pointer to a ``sycl::event``
132+
* @return Returns a value describing the time in nanoseconds
133+
* when the action associated with the command group (e.g. kernel invocation)
134+
* started executing on the device.
135+
* @ingroup EventInterface
136+
*/
137+
DPCTL_API
138+
uint64_t DPCTLEvent_GetProfilingInfoStart(__dpctl_keep DPCTLSyclEventRef ERef);
139+
140+
/*!
141+
* @brief Wrapper over
142+
* ``event.get_profiling_info<info::event_profiling::command_end>()``
143+
*
144+
* @param ERef Opaque pointer to a ``sycl::event``
145+
* @return Returns a value describing the time in nanoseconds
146+
* when the action associated with the command group (e.g. kernel invocation)
147+
* finished executing on the device.
148+
* @ingroup EventInterface
149+
*/
150+
DPCTL_API
151+
uint64_t DPCTLEvent_GetProfilingInfoEnd(__dpctl_keep DPCTLSyclEventRef ERef);
152+
115153
DPCTL_C_EXTERN_C_END

dpctl-capi/source/dpctl_sycl_event_interface.cpp

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,3 +131,54 @@ DPCTLEvent_GetCommandExecutionStatus(__dpctl_keep DPCTLSyclEventRef ERef)
131131
}
132132
return ESTy;
133133
}
134+
135+
uint64_t DPCTLEvent_GetProfilingInfoSubmit(__dpctl_keep DPCTLSyclEventRef ERef)
136+
{
137+
uint64_t profilingInfoSubmit = 0;
138+
auto E = unwrap(ERef);
139+
if (E) {
140+
try {
141+
E->wait();
142+
profilingInfoSubmit = E->get_profiling_info<
143+
sycl::info::event_profiling::command_submit>();
144+
} catch (invalid_object_error &e) {
145+
// \todo log error
146+
std::cerr << e.what() << '\n';
147+
}
148+
}
149+
return profilingInfoSubmit;
150+
}
151+
152+
uint64_t DPCTLEvent_GetProfilingInfoStart(__dpctl_keep DPCTLSyclEventRef ERef)
153+
{
154+
uint64_t profilingInfoStart = 0;
155+
auto E = unwrap(ERef);
156+
if (E) {
157+
try {
158+
E->wait();
159+
profilingInfoStart = E->get_profiling_info<
160+
sycl::info::event_profiling::command_start>();
161+
} catch (invalid_object_error &e) {
162+
// \todo log error
163+
std::cerr << e.what() << '\n';
164+
}
165+
}
166+
return profilingInfoStart;
167+
}
168+
169+
uint64_t DPCTLEvent_GetProfilingInfoEnd(__dpctl_keep DPCTLSyclEventRef ERef)
170+
{
171+
uint64_t profilingInfoEnd = 0;
172+
auto E = unwrap(ERef);
173+
if (E) {
174+
try {
175+
E->wait();
176+
profilingInfoEnd = E->get_profiling_info<
177+
sycl::info::event_profiling::command_end>();
178+
} catch (invalid_object_error &e) {
179+
// \todo log error
180+
std::cerr << e.what() << '\n';
181+
}
182+
}
183+
return profilingInfoEnd;
184+
}

dpctl-capi/tests/test_sycl_event_interface.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,3 +133,33 @@ TEST_F(TestDPCTLSyclEventInterface, ChkGetCommandExecutionStatus)
133133
EXPECT_TRUE(ESTy != DPCTLSyclEventStatusType::DPCTL_UNKNOWN_STATUS);
134134
EXPECT_TRUE(ESTy == DPCTLSyclEventStatusType::DPCTL_COMPLETE);
135135
}
136+
137+
#ifndef DPCTL_COVERAGE
138+
TEST_F(TestDPCTLSyclEventInterface, CheckGetProfiling)
139+
{
140+
property_list propList{property::queue::enable_profiling()};
141+
queue Q(cpu_selector(), propList);
142+
auto eA = Q.submit(
143+
[&](handler &h) { h.parallel_for(1000, [=](id<1>) { /*...*/ }); });
144+
DPCTLSyclEventRef ERef = reinterpret_cast<DPCTLSyclEventRef>(&eA);
145+
146+
auto eStart = DPCTLEvent_GetProfilingInfoStart(ERef);
147+
auto eEnd = DPCTLEvent_GetProfilingInfoEnd(ERef);
148+
auto eSubmit = DPCTLEvent_GetProfilingInfoSubmit(ERef);
149+
150+
EXPECT_TRUE(eStart);
151+
EXPECT_TRUE(eEnd);
152+
EXPECT_TRUE(eSubmit);
153+
}
154+
#endif
155+
156+
TEST_F(TestDPCTLSyclEventInterface, CheckGetProfiling_Invalid)
157+
{
158+
auto eStart = DPCTLEvent_GetProfilingInfoStart(ERef);
159+
auto eEnd = DPCTLEvent_GetProfilingInfoEnd(ERef);
160+
auto eSubmit = DPCTLEvent_GetProfilingInfoSubmit(ERef);
161+
162+
EXPECT_FALSE(eStart);
163+
EXPECT_FALSE(eEnd);
164+
EXPECT_FALSE(eSubmit);
165+
}

0 commit comments

Comments
 (0)