-
Notifications
You must be signed in to change notification settings - Fork 788
[SYCL] Implement queue::ext_oneapi_empty() API to get queue status #7583
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
Changes from 18 commits
0035ffd
cfe66d9
92e5286
7883ffe
da0de48
50977e4
133df85
1069bad
6dc2c24
2f39b72
565ba4d
e9b0355
fa4b120
fc838d1
b41149c
04d5549
54e624c
18f40f7
706b19e
93155e5
ebf7fe7
71ea2ba
bed1f70
8be6a14
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -499,6 +499,30 @@ struct _pi_queue { | |||||
return is_last_command && !has_been_synchronized(stream_token); | ||||||
} | ||||||
|
||||||
template <typename T> bool all_of(T &&f) { | ||||||
{ | ||||||
std::lock_guard<std::mutex> compute_guard(compute_stream_mutex_); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
unsigned int end = | ||||||
std::min(static_cast<unsigned int>(compute_streams_.size()), | ||||||
num_compute_streams_); | ||||||
for (unsigned int i = 0; i < end; i++) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This could be an algorithm. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for suggestions, fixed. |
||||||
if (!f(compute_streams_[i])) | ||||||
return false; | ||||||
} | ||||||
} | ||||||
{ | ||||||
std::lock_guard<std::mutex> transfer_guard(transfer_stream_mutex_); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
unsigned int end = | ||||||
std::min(static_cast<unsigned int>(transfer_streams_.size()), | ||||||
num_transfer_streams_); | ||||||
for (unsigned int i = 0; i < end; i++) { | ||||||
if (!f(transfer_streams_[i])) | ||||||
return false; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This déjà vu suggests more abstraction. |
||||||
} | ||||||
} | ||||||
return true; | ||||||
} | ||||||
|
||||||
template <typename T> void for_each_stream(T &&f) { | ||||||
{ | ||||||
std::lock_guard<std::mutex> compute_guard(compute_stream_mutex_); | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -478,6 +478,30 @@ struct _pi_queue { | |
return is_last_command && !has_been_synchronized(stream_token); | ||
} | ||
|
||
template <typename T> bool all_of(T &&f) { | ||
{ | ||
std::lock_guard<std::mutex> compute_guard(compute_stream_mutex_); | ||
unsigned int end = | ||
std::min(static_cast<unsigned int>(compute_streams_.size()), | ||
num_compute_streams_); | ||
for (unsigned int i = 0; i < end; i++) { | ||
if (!f(compute_streams_[i])) | ||
return false; | ||
} | ||
} | ||
{ | ||
std::lock_guard<std::mutex> transfer_guard(transfer_stream_mutex_); | ||
unsigned int end = | ||
std::min(static_cast<unsigned int>(transfer_streams_.size()), | ||
num_transfer_streams_); | ||
for (unsigned int i = 0; i < end; i++) { | ||
if (!f(transfer_streams_[i])) | ||
return false; | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We really need some heavy refactoring across the various back-ends some day... :-( |
||
return true; | ||
} | ||
|
||
template <typename T> void for_each_stream(T &&f) { | ||
{ | ||
std::lock_guard<std::mutex> compute_guard(compute_stream_mutex_); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -400,6 +400,48 @@ pi_native_handle queue_impl::getNative() const { | |
return Handle; | ||
} | ||
|
||
bool queue_impl::ext_oneapi_empty() const { | ||
// If we have in-order queue where events are not discarded then just check | ||
// the status of the last event. | ||
if (isInOrder() && !MDiscardEvents) { | ||
smaslov-intel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
std::lock_guard<std::mutex> Lock(MLastEventMtx); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use C++17 CTAD everywhere. There are still a lot in the new code. |
||
return MLastEvent.get_info<info::event::command_execution_status>() == | ||
info::event_command_status::complete; | ||
} | ||
|
||
// Check the status of the backend queue if this is not a host queue. | ||
if (!is_host()) { | ||
pi_bool IsReady = false; | ||
getPlugin().call<PiApiKind::piQueueGetInfo>( | ||
MQueues[0], PI_EXT_ONEAPI_QUEUE_INFO_EMPTY, sizeof(pi_bool), &IsReady, | ||
nullptr); | ||
if (!IsReady) | ||
return false; | ||
} | ||
|
||
// We may have events like host tasks which are not submitted to the backend | ||
// queue so we need to get their status separately. | ||
std::lock_guard<std::mutex> Lock(MMutex); | ||
for (event Event : MEventsShared) | ||
if (Event.get_info<info::event::command_execution_status>() != | ||
info::event_command_status::complete) | ||
return false; | ||
|
||
for (auto EventImplWeakPtrIt = MEventsWeak.begin(); | ||
EventImplWeakPtrIt != MEventsWeak.end(); ++EventImplWeakPtrIt) | ||
if (std::shared_ptr<event_impl> EventImplSharedPtr = | ||
EventImplWeakPtrIt->lock()) | ||
if (EventImplSharedPtr->is_host() && | ||
EventImplSharedPtr | ||
->get_info<info::event::command_execution_status>() != | ||
info::event_command_status::complete) | ||
return false; | ||
|
||
// If we didn't exit early above then it means that all events in the queue | ||
// are completed. | ||
return true; | ||
} | ||
|
||
} // namespace detail | ||
} // __SYCL_INLINE_VER_NAMESPACE(_V1) | ||
} // namespace sycl |
Uh oh!
There was an error while loading. Please reload this page.