From a711a498818d98cc7a2aea0eac0d1addac55dd9a Mon Sep 17 00:00:00 2001 From: Satyanvesh Dittakavi Date: Mon, 1 Mar 2021 06:27:52 -0500 Subject: [PATCH] SWDEV-264244 - Hide Notifications from HIP This fixes hipStreamQuery returning hipErrorNotReady when idle Change-Id: I3f77666a00bc6a7162b6c660d79e76c09669d94f --- rocclr/platform/command.cpp | 3 ++- rocclr/platform/command.hpp | 15 +++++++-------- rocclr/platform/commandqueue.cpp | 29 ++++++++++++++++------------- 3 files changed, 25 insertions(+), 22 deletions(-) diff --git a/rocclr/platform/command.cpp b/rocclr/platform/command.cpp index 2f5cffa535..6c3dcad82e 100644 --- a/rocclr/platform/command.cpp +++ b/rocclr/platform/command.cpp @@ -254,12 +254,13 @@ const Event::EventWaitList Event::nullWaitList(0); // ================================================================================================ Command::Command(HostQueue& queue, cl_command_type type, - const EventWaitList& eventWaitList, uint32_t commandWaitBits) + const EventWaitList& eventWaitList, uint32_t commandWaitBits, const Event* waitingEvent) : Event(queue), queue_(&queue), next_(nullptr), type_(type), data_(nullptr), + waitingEvent_(waitingEvent), eventWaitList_(eventWaitList), commandWaitBits_(commandWaitBits) { // Retain the commands from the event wait list. diff --git a/rocclr/platform/command.hpp b/rocclr/platform/command.hpp index 01ae5c6324..4a377ce52c 100644 --- a/rocclr/platform/command.hpp +++ b/rocclr/platform/command.hpp @@ -223,6 +223,7 @@ class Command : public Event { Command* batch_head_ = nullptr; //!< The head of the batch commands cl_command_type type_; //!< This command's OpenCL type. void* data_; + const Event* waitingEvent_; //!< Waiting event associated with the marker protected: //! The Events that need to complete before this command is submitted. @@ -234,7 +235,7 @@ class Command : public Event { //! Construct a new command of the given OpenCL type. Command(HostQueue& queue, cl_command_type type, const EventWaitList& eventWaitList = nullWaitList, - uint32_t commandWaitBits = 0); + uint32_t commandWaitBits = 0, const Event* waitingEvent = nullptr); //! Construct a new command of the given OpenCL type. Command(cl_command_type type) @@ -243,6 +244,7 @@ class Command : public Event { next_(nullptr), type_(type), data_(nullptr), + waitingEvent_(nullptr), eventWaitList_(nullWaitList), commandWaitBits_(0) {} @@ -306,6 +308,8 @@ class Command : public Event { //! Returns the current batch head Command* GetBatchHead() const { return batch_head_; } + + const Event* waitingEvent() const { return waitingEvent_; } }; class UserEvent : public Command { @@ -946,17 +950,12 @@ class Marker : public Command { public: //! Create a new Marker Marker(HostQueue& queue, bool userVisible, const EventWaitList& eventWaitList = nullWaitList, - const Event* waitingEvent = NULL) - : Command(queue, userVisible ? CL_COMMAND_MARKER : 0, eventWaitList), - waitingEvent_(waitingEvent) {} + const Event* waitingEvent = nullptr) + : Command(queue, userVisible ? CL_COMMAND_MARKER : 0, eventWaitList, 0, waitingEvent) {} //! The actual command implementation. virtual void submit(device::VirtualDevice& device) { device.submitMarker(*this); } - const Event* waitingEvent() const { return waitingEvent_; } - - private: - const Event* waitingEvent_; //!< Waiting event associated with the marker }; /*! \brief Maps CL objects created from external ones and syncs the contents (blocking). diff --git a/rocclr/platform/commandqueue.cpp b/rocclr/platform/commandqueue.cpp index 2031ad44e8..c5fdad469f 100644 --- a/rocclr/platform/commandqueue.cpp +++ b/rocclr/platform/commandqueue.cpp @@ -200,21 +200,24 @@ void HostQueue::append(Command& command) { if (!IS_HIP) { return; } - // Set last submitted command - Command* prevLastEnqueueCommand; - command.retain(); - { - // lastCmdLock_ ensures that lastEnqueueCommand() can retain the command before it is swapped - // out. We want to keep this critical section as short as possible, so the command should be - // released outside this section. - ScopedLock l(lastCmdLock_); - prevLastEnqueueCommand = lastEnqueueCommand_; - lastEnqueueCommand_ = &command; - } + if (command.waitingEvent() == nullptr) { + // Set last submitted command + Command* prevLastEnqueueCommand; + command.retain(); + { + // lastCmdLock_ ensures that lastEnqueueCommand() can retain the command before it is swapped + // out. We want to keep this critical section as short as possible, so the command should be + // released outside this section. + ScopedLock l(lastCmdLock_); - if (prevLastEnqueueCommand != nullptr) { - prevLastEnqueueCommand->release(); + prevLastEnqueueCommand = lastEnqueueCommand_; + lastEnqueueCommand_ = &command; + } + + if (prevLastEnqueueCommand != nullptr) { + prevLastEnqueueCommand->release(); + } } }