Skip to content

Commit ec74a5c

Browse files
authored
[SYCL] Add error handling for sycl::event::get_profiling_info() (#5623)
This patch implements a throwing of `sycl::exception` if `sycl::event::get_profiling_info()` called when `sycl::queue` does not have a `property::queue::enable_profiling` in its `sycl::property_list`. This PR fixes #5574
1 parent 6d3b95a commit ec74a5c

File tree

5 files changed

+348
-10
lines changed

5 files changed

+348
-10
lines changed

sycl/source/detail/event_impl.cpp

+14-9
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,9 @@ event_impl::event_impl(RT::PiEvent Event, const context &SyclContext)
127127
getPlugin().call<PiApiKind::piEventRetain>(MEvent);
128128
}
129129

130-
event_impl::event_impl(const QueueImplPtr &Queue) : MQueue{Queue} {
130+
event_impl::event_impl(const QueueImplPtr &Queue)
131+
: MQueue{Queue}, MIsProfilingEnabled{Queue->is_host() ||
132+
Queue->MIsProfilingEnabled} {
131133
if (Queue->is_host()) {
132134
MState.store(HES_NotComplete);
133135

@@ -136,10 +138,8 @@ event_impl::event_impl(const QueueImplPtr &Queue) : MQueue{Queue} {
136138
if (!MHostProfilingInfo)
137139
throw runtime_error("Out of host memory", PI_OUT_OF_HOST_MEMORY);
138140
}
139-
140141
return;
141142
}
142-
143143
MState.store(HES_Complete);
144144
}
145145

@@ -250,16 +250,23 @@ void event_impl::cleanupCommand(
250250
detail::Scheduler::getInstance().cleanupFinishedCommands(std::move(Self));
251251
}
252252

253+
void event_impl::checkProfilingPreconditions() const {
254+
if (!MIsProfilingEnabled) {
255+
throw sycl::exception(make_error_code(sycl::errc::invalid),
256+
"get_profiling_info() can't be used without set "
257+
"'enable_profiling' queue property");
258+
}
259+
}
260+
253261
template <>
254262
cl_ulong
255263
event_impl::get_profiling_info<info::event_profiling::command_submit>() const {
264+
checkProfilingPreconditions();
256265
if (!MHostEvent) {
257266
if (MEvent)
258267
return get_event_profiling_info<
259268
info::event_profiling::command_submit>::get(this->getHandleRef(),
260269
this->getPlugin());
261-
// TODO this should throw an exception if the queue the dummy event is
262-
// bound to does not support profiling info.
263270
return 0;
264271
}
265272
if (!MHostProfilingInfo)
@@ -271,13 +278,12 @@ event_impl::get_profiling_info<info::event_profiling::command_submit>() const {
271278
template <>
272279
cl_ulong
273280
event_impl::get_profiling_info<info::event_profiling::command_start>() const {
281+
checkProfilingPreconditions();
274282
if (!MHostEvent) {
275283
if (MEvent)
276284
return get_event_profiling_info<
277285
info::event_profiling::command_start>::get(this->getHandleRef(),
278286
this->getPlugin());
279-
// TODO this should throw an exception if the queue the dummy event is
280-
// bound to does not support profiling info.
281287
return 0;
282288
}
283289
if (!MHostProfilingInfo)
@@ -289,12 +295,11 @@ event_impl::get_profiling_info<info::event_profiling::command_start>() const {
289295
template <>
290296
cl_ulong
291297
event_impl::get_profiling_info<info::event_profiling::command_end>() const {
298+
checkProfilingPreconditions();
292299
if (!MHostEvent) {
293300
if (MEvent)
294301
return get_event_profiling_info<info::event_profiling::command_end>::get(
295302
this->getHandleRef(), this->getPlugin());
296-
// TODO this should throw an exception if the queue the dummy event is
297-
// bound to does not support profiling info.
298303
return 0;
299304
}
300305
if (!MHostProfilingInfo)

sycl/source/detail/event_impl.hpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -214,14 +214,15 @@ class event_impl {
214214
// Uses events generated by the Prolog and emits event wait done event
215215
void instrumentationEpilog(void *TelementryEvent, const std::string &Name,
216216
int32_t StreamID, uint64_t IId) const;
217-
217+
void checkProfilingPreconditions() const;
218218
RT::PiEvent MEvent = nullptr;
219219
ContextImplPtr MContext;
220220
bool MOpenCLInterop = false;
221221
bool MHostEvent = true;
222222
std::unique_ptr<HostProfilingInfo> MHostProfilingInfo;
223223
void *MCommand = nullptr;
224224
std::weak_ptr<queue_impl> MQueue;
225+
const bool MIsProfilingEnabled = false;
225226

226227
/// Dependency events prepared for waiting by backend.
227228
std::vector<EventImplPtr> MPreparedDepsEvents;

sycl/source/detail/queue_impl.hpp

+3
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ class queue_impl {
9797
MIsInorder(has_property<property::queue::in_order>()),
9898
MDiscardEvents(
9999
has_property<ext::oneapi::property::queue::discard_events>()),
100+
MIsProfilingEnabled(has_property<property::queue::enable_profiling>()),
100101
MHasDiscardEventsSupport(
101102
MDiscardEvents &&
102103
(MHostQueue ? true
@@ -135,6 +136,7 @@ class queue_impl {
135136
MIsInorder(has_property<property::queue::in_order>()),
136137
MDiscardEvents(
137138
has_property<ext::oneapi::property::queue::discard_events>()),
139+
MIsProfilingEnabled(has_property<property::queue::enable_profiling>()),
138140
MHasDiscardEventsSupport(
139141
MDiscardEvents &&
140142
(MHostQueue ? true
@@ -584,6 +586,7 @@ class queue_impl {
584586
public:
585587
// Queue constructed with the discard_events property
586588
const bool MDiscardEvents;
589+
const bool MIsProfilingEnabled;
587590

588591
private:
589592
// This flag says if we can discard events based on a queue "setup" which will

sycl/unittests/queue/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ add_sycl_unittest(QueueTests OBJECT
22
EventClear.cpp
33
USM.cpp
44
Wait.cpp
5+
GetProfilingInfo.cpp
56
)

0 commit comments

Comments
 (0)