Skip to content

[SYCL] Add error handling for sycl::event::get_profiling_info() #5623

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Mar 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions sycl/source/detail/event_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,9 @@ event_impl::event_impl(RT::PiEvent Event, const context &SyclContext)
getPlugin().call<PiApiKind::piEventRetain>(MEvent);
}

event_impl::event_impl(const QueueImplPtr &Queue) : MQueue{Queue} {
event_impl::event_impl(const QueueImplPtr &Queue)
: MQueue{Queue}, MIsProfilingEnabled{Queue->is_host() ||
Queue->MIsProfilingEnabled} {
if (Queue->is_host()) {
MState.store(HES_NotComplete);

Expand All @@ -136,10 +138,8 @@ event_impl::event_impl(const QueueImplPtr &Queue) : MQueue{Queue} {
if (!MHostProfilingInfo)
throw runtime_error("Out of host memory", PI_OUT_OF_HOST_MEMORY);
}

return;
}

MState.store(HES_Complete);
}

Expand Down Expand Up @@ -250,16 +250,23 @@ void event_impl::cleanupCommand(
detail::Scheduler::getInstance().cleanupFinishedCommands(std::move(Self));
}

void event_impl::checkProfilingPreconditions() const {
if (!MIsProfilingEnabled) {
throw sycl::exception(make_error_code(sycl::errc::invalid),
"get_profiling_info() can't be used without set "
"'enable_profiling' queue property");
}
}

template <>
cl_ulong
event_impl::get_profiling_info<info::event_profiling::command_submit>() const {
checkProfilingPreconditions();
if (!MHostEvent) {
if (MEvent)
return get_event_profiling_info<
info::event_profiling::command_submit>::get(this->getHandleRef(),
this->getPlugin());
// TODO this should throw an exception if the queue the dummy event is
// bound to does not support profiling info.
return 0;
}
if (!MHostProfilingInfo)
Expand All @@ -271,13 +278,12 @@ event_impl::get_profiling_info<info::event_profiling::command_submit>() const {
template <>
cl_ulong
event_impl::get_profiling_info<info::event_profiling::command_start>() const {
checkProfilingPreconditions();
if (!MHostEvent) {
if (MEvent)
return get_event_profiling_info<
info::event_profiling::command_start>::get(this->getHandleRef(),
this->getPlugin());
// TODO this should throw an exception if the queue the dummy event is
// bound to does not support profiling info.
return 0;
}
if (!MHostProfilingInfo)
Expand All @@ -289,12 +295,11 @@ event_impl::get_profiling_info<info::event_profiling::command_start>() const {
template <>
cl_ulong
event_impl::get_profiling_info<info::event_profiling::command_end>() const {
checkProfilingPreconditions();
if (!MHostEvent) {
if (MEvent)
return get_event_profiling_info<info::event_profiling::command_end>::get(
this->getHandleRef(), this->getPlugin());
// TODO this should throw an exception if the queue the dummy event is
// bound to does not support profiling info.
return 0;
}
if (!MHostProfilingInfo)
Expand Down
3 changes: 2 additions & 1 deletion sycl/source/detail/event_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,14 +214,15 @@ class event_impl {
// Uses events generated by the Prolog and emits event wait done event
void instrumentationEpilog(void *TelementryEvent, const std::string &Name,
int32_t StreamID, uint64_t IId) const;

void checkProfilingPreconditions() const;
RT::PiEvent MEvent = nullptr;
ContextImplPtr MContext;
bool MOpenCLInterop = false;
bool MHostEvent = true;
std::unique_ptr<HostProfilingInfo> MHostProfilingInfo;
void *MCommand = nullptr;
std::weak_ptr<queue_impl> MQueue;
const bool MIsProfilingEnabled = false;

/// Dependency events prepared for waiting by backend.
std::vector<EventImplPtr> MPreparedDepsEvents;
Expand Down
3 changes: 3 additions & 0 deletions sycl/source/detail/queue_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ class queue_impl {
MIsInorder(has_property<property::queue::in_order>()),
MDiscardEvents(
has_property<ext::oneapi::property::queue::discard_events>()),
MIsProfilingEnabled(has_property<property::queue::enable_profiling>()),
MHasDiscardEventsSupport(
MDiscardEvents &&
(MHostQueue ? true
Expand Down Expand Up @@ -135,6 +136,7 @@ class queue_impl {
MIsInorder(has_property<property::queue::in_order>()),
MDiscardEvents(
has_property<ext::oneapi::property::queue::discard_events>()),
MIsProfilingEnabled(has_property<property::queue::enable_profiling>()),
MHasDiscardEventsSupport(
MDiscardEvents &&
(MHostQueue ? true
Expand Down Expand Up @@ -584,6 +586,7 @@ class queue_impl {
public:
// Queue constructed with the discard_events property
const bool MDiscardEvents;
const bool MIsProfilingEnabled;

private:
// This flag says if we can discard events based on a queue "setup" which will
Expand Down
1 change: 1 addition & 0 deletions sycl/unittests/queue/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ add_sycl_unittest(QueueTests OBJECT
EventClear.cpp
USM.cpp
Wait.cpp
GetProfilingInfo.cpp
)
Loading