Skip to content

Commit 4914621

Browse files
Add 3 wrapper func for event::get_profiling_info
1 parent 3475ed4 commit 4914621

File tree

3 files changed

+117
-0
lines changed

3 files changed

+117
-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
@@ -91,4 +91,42 @@ DPCTLEvent_Copy(__dpctl_keep const DPCTLSyclEventRef ERef);
9191
DPCTL_API
9292
DPCTLSyclBackendType DPCTLEvent_GetBackend(__dpctl_keep DPCTLSyclEventRef ERef);
9393

94+
/*!
95+
* @brief Wrapper over
96+
* ``event.get_profiling_info<info::event_profiling::command_submit>()``
97+
*
98+
* @param ERef Opaque pointer to a ``sycl::event``
99+
* @return Returns a value describing the time in nanoseconds
100+
* when the associated command group was submitted to the queue.
101+
* @ingroup EventInterface
102+
*/
103+
DPCTL_API
104+
uint64_t DPCTLEvent_GetProfilingInfoSubmit(__dpctl_keep DPCTLSyclEventRef ERef);
105+
106+
/*!
107+
* @brief Wrapper over
108+
* ``event.get_profiling_info<info::event_profiling::command_start>()``
109+
*
110+
* @param ERef Opaque pointer to a ``sycl::event``
111+
* @return Returns a value describing the time in nanoseconds
112+
* when the action associated with the command group (e.g. kernel invocation)
113+
* started executing on the device.
114+
* @ingroup EventInterface
115+
*/
116+
DPCTL_API
117+
uint64_t DPCTLEvent_GetProfilingInfoStart(__dpctl_keep DPCTLSyclEventRef ERef);
118+
119+
/*!
120+
* @brief Wrapper over
121+
* ``event.get_profiling_info<info::event_profiling::command_end>()``
122+
*
123+
* @param ERef Opaque pointer to a ``sycl::event``
124+
* @return Returns a value describing the time in nanoseconds
125+
* when the action associated with the command group (e.g. kernel invocation)
126+
* finished executing on the device.
127+
* @ingroup EventInterface
128+
*/
129+
DPCTL_API
130+
uint64_t DPCTLEvent_GetProfilingInfoEnd(__dpctl_keep DPCTLSyclEventRef ERef);
131+
94132
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
@@ -98,3 +98,54 @@ DPCTLSyclBackendType DPCTLEvent_GetBackend(__dpctl_keep DPCTLSyclEventRef ERef)
9898
}
9999
return BTy;
100100
}
101+
102+
uint64_t DPCTLEvent_GetProfilingInfoSubmit(__dpctl_keep DPCTLSyclEventRef ERef)
103+
{
104+
uint64_t profilingInfoSubmit = 0;
105+
auto E = unwrap(ERef);
106+
if (E) {
107+
try {
108+
E->wait();
109+
profilingInfoSubmit = E->get_profiling_info<
110+
sycl::info::event_profiling::command_submit>();
111+
} catch (invalid_object_error &e) {
112+
// \todo log error
113+
std::cerr << e.what() << '\n';
114+
}
115+
}
116+
return profilingInfoSubmit;
117+
}
118+
119+
uint64_t DPCTLEvent_GetProfilingInfoStart(__dpctl_keep DPCTLSyclEventRef ERef)
120+
{
121+
uint64_t profilingInfoStart = 0;
122+
auto E = unwrap(ERef);
123+
if (E) {
124+
try {
125+
E->wait();
126+
profilingInfoStart = E->get_profiling_info<
127+
sycl::info::event_profiling::command_start>();
128+
} catch (invalid_object_error &e) {
129+
// \todo log error
130+
std::cerr << e.what() << '\n';
131+
}
132+
}
133+
return profilingInfoStart;
134+
}
135+
136+
uint64_t DPCTLEvent_GetProfilingInfoEnd(__dpctl_keep DPCTLSyclEventRef ERef)
137+
{
138+
uint64_t profilingInfoEnd = 0;
139+
auto E = unwrap(ERef);
140+
if (E) {
141+
try {
142+
E->wait();
143+
profilingInfoEnd = E->get_profiling_info<
144+
sycl::info::event_profiling::command_end>();
145+
} catch (invalid_object_error &e) {
146+
// \todo log error
147+
std::cerr << e.what() << '\n';
148+
}
149+
}
150+
return profilingInfoEnd;
151+
}

dpctl-capi/tests/test_sycl_event_interface.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,3 +112,31 @@ 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, CheckGetProfiling)
117+
{
118+
property_list propList{property::queue::enable_profiling()};
119+
queue Q(cpu_selector(), propList);
120+
auto eA = Q.submit(
121+
[&](handler &h) { h.parallel_for(1000, [=](id<1>) { /*...*/ }); });
122+
DPCTLSyclEventRef ERef = reinterpret_cast<DPCTLSyclEventRef>(&eA);
123+
124+
auto eStart = DPCTLEvent_GetProfilingInfoStart(ERef);
125+
auto eEnd = DPCTLEvent_GetProfilingInfoEnd(ERef);
126+
auto eSubmit = DPCTLEvent_GetProfilingInfoSubmit(ERef);
127+
128+
EXPECT_TRUE(eStart);
129+
EXPECT_TRUE(eEnd);
130+
EXPECT_TRUE(eSubmit);
131+
}
132+
133+
TEST_F(TestDPCTLSyclEventInterface, CheckGetProfiling_Invalid)
134+
{
135+
auto eStart = DPCTLEvent_GetProfilingInfoStart(ERef);
136+
auto eEnd = DPCTLEvent_GetProfilingInfoEnd(ERef);
137+
auto eSubmit = DPCTLEvent_GetProfilingInfoSubmit(ERef);
138+
139+
EXPECT_FALSE(eStart);
140+
EXPECT_FALSE(eEnd);
141+
EXPECT_FALSE(eSubmit);
142+
}

0 commit comments

Comments
 (0)