Skip to content

Commit d7da43f

Browse files
Add 3 wrapper func for event::get_profiling_info
1 parent b283185 commit d7da43f

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
@@ -103,4 +103,42 @@ DPCTL_API
103103
DPCTLSyclEventStatusType
104104
DPCTLEvent_GetCommandExecutionStatus(__dpctl_keep DPCTLSyclEventRef ERef);
105105

106+
/*!
107+
* @brief Wrapper over
108+
* ``event.get_profiling_info<info::event_profiling::command_submit>()``
109+
*
110+
* @param ERef Opaque pointer to a ``sycl::event``
111+
* @return Returns a value describing the time in nanoseconds
112+
* when the associated command group was submitted to the queue.
113+
* @ingroup EventInterface
114+
*/
115+
DPCTL_API
116+
uint64_t DPCTLEvent_GetProfilingInfoSubmit(__dpctl_keep DPCTLSyclEventRef ERef);
117+
118+
/*!
119+
* @brief Wrapper over
120+
* ``event.get_profiling_info<info::event_profiling::command_start>()``
121+
*
122+
* @param ERef Opaque pointer to a ``sycl::event``
123+
* @return Returns a value describing the time in nanoseconds
124+
* when the action associated with the command group (e.g. kernel invocation)
125+
* started executing on the device.
126+
* @ingroup EventInterface
127+
*/
128+
DPCTL_API
129+
uint64_t DPCTLEvent_GetProfilingInfoStart(__dpctl_keep DPCTLSyclEventRef ERef);
130+
131+
/*!
132+
* @brief Wrapper over
133+
* ``event.get_profiling_info<info::event_profiling::command_end>()``
134+
*
135+
* @param ERef Opaque pointer to a ``sycl::event``
136+
* @return Returns a value describing the time in nanoseconds
137+
* when the action associated with the command group (e.g. kernel invocation)
138+
* finished executing on the device.
139+
* @ingroup EventInterface
140+
*/
141+
DPCTL_API
142+
uint64_t DPCTLEvent_GetProfilingInfoEnd(__dpctl_keep DPCTLSyclEventRef ERef);
143+
106144
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
@@ -117,3 +117,54 @@ DPCTLEvent_GetCommandExecutionStatus(__dpctl_keep DPCTLSyclEventRef ERef)
117117
}
118118
return ESTy;
119119
}
120+
121+
uint64_t DPCTLEvent_GetProfilingInfoSubmit(__dpctl_keep DPCTLSyclEventRef ERef)
122+
{
123+
uint64_t profilingInfoSubmit = 0;
124+
auto E = unwrap(ERef);
125+
if (E) {
126+
try {
127+
E->wait();
128+
profilingInfoSubmit = E->get_profiling_info<
129+
sycl::info::event_profiling::command_submit>();
130+
} catch (invalid_object_error &e) {
131+
// \todo log error
132+
std::cerr << e.what() << '\n';
133+
}
134+
}
135+
return profilingInfoSubmit;
136+
}
137+
138+
uint64_t DPCTLEvent_GetProfilingInfoStart(__dpctl_keep DPCTLSyclEventRef ERef)
139+
{
140+
uint64_t profilingInfoStart = 0;
141+
auto E = unwrap(ERef);
142+
if (E) {
143+
try {
144+
E->wait();
145+
profilingInfoStart = E->get_profiling_info<
146+
sycl::info::event_profiling::command_start>();
147+
} catch (invalid_object_error &e) {
148+
// \todo log error
149+
std::cerr << e.what() << '\n';
150+
}
151+
}
152+
return profilingInfoStart;
153+
}
154+
155+
uint64_t DPCTLEvent_GetProfilingInfoEnd(__dpctl_keep DPCTLSyclEventRef ERef)
156+
{
157+
uint64_t profilingInfoEnd = 0;
158+
auto E = unwrap(ERef);
159+
if (E) {
160+
try {
161+
E->wait();
162+
profilingInfoEnd = E->get_profiling_info<
163+
sycl::info::event_profiling::command_end>();
164+
} catch (invalid_object_error &e) {
165+
// \todo log error
166+
std::cerr << e.what() << '\n';
167+
}
168+
}
169+
return profilingInfoEnd;
170+
}

dpctl-capi/tests/test_sycl_event_interface.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,3 +121,33 @@ TEST_F(TestDPCTLSyclEventInterface, ChkGetCommandExecutionStatus)
121121
EXPECT_TRUE(ESTy != DPCTLSyclEventStatusType::DPCTL_UNKNOWN_STATUS);
122122
EXPECT_TRUE(ESTy == DPCTLSyclEventStatusType::DPCTL_COMPLETE);
123123
}
124+
125+
#ifndef DPCTL_COVERAGE
126+
TEST_F(TestDPCTLSyclEventInterface, CheckGetProfiling)
127+
{
128+
property_list propList{property::queue::enable_profiling()};
129+
queue Q(cpu_selector(), propList);
130+
auto eA = Q.submit(
131+
[&](handler &h) { h.parallel_for(1000, [=](id<1>) { /*...*/ }); });
132+
DPCTLSyclEventRef ERef = reinterpret_cast<DPCTLSyclEventRef>(&eA);
133+
134+
auto eStart = DPCTLEvent_GetProfilingInfoStart(ERef);
135+
auto eEnd = DPCTLEvent_GetProfilingInfoEnd(ERef);
136+
auto eSubmit = DPCTLEvent_GetProfilingInfoSubmit(ERef);
137+
138+
EXPECT_TRUE(eStart);
139+
EXPECT_TRUE(eEnd);
140+
EXPECT_TRUE(eSubmit);
141+
}
142+
#endif
143+
144+
TEST_F(TestDPCTLSyclEventInterface, CheckGetProfiling_Invalid)
145+
{
146+
auto eStart = DPCTLEvent_GetProfilingInfoStart(ERef);
147+
auto eEnd = DPCTLEvent_GetProfilingInfoEnd(ERef);
148+
auto eSubmit = DPCTLEvent_GetProfilingInfoSubmit(ERef);
149+
150+
EXPECT_FALSE(eStart);
151+
EXPECT_FALSE(eEnd);
152+
EXPECT_FALSE(eSubmit);
153+
}

0 commit comments

Comments
 (0)