SWDEV-434702 - get the nullstream in constant time in iHipWaitActiveStreams

Change-Id: Ib92cc4d2ca1b725cf30b24cdd711c873fd513d95
This commit is contained in:
Ioannis Assiouras
2023-11-30 16:02:25 +00:00
parent 44761fe89b
commit 8bdda90071
2 changed files with 33 additions and 30 deletions
+1 -1
View File
@@ -488,7 +488,7 @@ public:
void Reset();
hip::Stream* NullStream();
Stream* GetNullStream();
Stream* GetNullStream() const {return null_stream_;};
void SetActiveStatus() {
isActive_ = true;
+32 -29
View File
@@ -198,41 +198,44 @@ bool Stream::existsActiveStreamForDevice(hip::Device* device) {
void iHipWaitActiveStreams(hip::Stream* blocking_stream, bool wait_null_stream) {
amd::Command::EventWaitList eventWaitList(0);
bool submitMarker = 0;
{
auto waitForStream = [&submitMarker,
&eventWaitList](hip::Stream* stream) {
if (amd::Command *command = stream->getLastQueuedCommand(true)) {
amd::Event &event = command->event();
// Check HW status of the ROCcrl event.
// Note: not all ROCclr modes support HW status
bool ready = stream->device().IsHwEventReady(event);
if (!ready) {
ready = (command->status() == CL_COMPLETE);
}
submitMarker |= stream->vdev()->isFenceDirty();
// Check the current active status
if (!ready) {
command->notifyCmdQueue();
eventWaitList.push_back(command);
} else {
command->release();
}
}
};
if (wait_null_stream) {
if (hip::Stream* null_stream = blocking_stream->GetDevice()->GetNullStream()) {
waitForStream(null_stream);
}
} else {
amd::ScopedLock lock(streamSetLock);
for (const auto& active_stream : streamSet) {
// If it's the current device
if ((&active_stream->device() == &blocking_stream->device()) &&
// Make sure it's a default stream
((active_stream->Flags() & hipStreamNonBlocking) == 0) &&
// and it's not the current stream
(active_stream != blocking_stream) &&
// check for a wait on the null stream
(active_stream->Null() == wait_null_stream)) {
// Make sure it's a default stream
((active_stream->Flags() & hipStreamNonBlocking) == 0) &&
// and it's not the current stream
(active_stream != blocking_stream)) {
// Get the last valid command
amd::Command* command = active_stream->getLastQueuedCommand(true);
if (command != nullptr) {
amd::Event& event = command->event();
// Check HW status of the ROCcrl event.
// Note: not all ROCclr modes support HW status
bool ready = active_stream->device().IsHwEventReady(event);
if (!ready) {
ready = (command->status() == CL_COMPLETE);
}
submitMarker |= active_stream->vdev()->isFenceDirty();
// Check the current active status
if (!ready) {
command->notifyCmdQueue();
eventWaitList.push_back(command);
} else {
command->release();
}
}
// Nullstream, hence there is nothing else to wait
if (wait_null_stream) {
break;
}
waitForStream(active_stream);
}
}
}