diff --git a/projects/clr/rocclr/runtime/platform/command.cpp b/projects/clr/rocclr/runtime/platform/command.cpp index 1d7d11254d..99873ac981 100644 --- a/projects/clr/rocclr/runtime/platform/command.cpp +++ b/projects/clr/rocclr/runtime/platform/command.cpp @@ -213,6 +213,9 @@ void Command::enqueue() { Agent::postEventCreate(as_cl(static_cast(this)), type_); } + if (IS_HIP) { + queue_->setLastQueuedCommand(this); + } queue_->append(*this); queue_->flush(); if (queue_->device().settings().waitCommand_ && (type_ != 0)) { diff --git a/projects/clr/rocclr/runtime/platform/commandqueue.cpp b/projects/clr/rocclr/runtime/platform/commandqueue.cpp index 3d6148f6fc..2990271e18 100644 --- a/projects/clr/rocclr/runtime/platform/commandqueue.cpp +++ b/projects/clr/rocclr/runtime/platform/commandqueue.cpp @@ -21,7 +21,8 @@ HostQueue::HostQueue(Context& context, Device& device, cl_command_queue_properti uint queueRTCUs, Priority priority) : CommandQueue(context, device, properties, device.info().queueProperties_ | CL_QUEUE_COMMAND_INTERCEPT_ENABLE_AMD, - queueRTCUs, priority) { + queueRTCUs, priority), + lastEnqueueCommand_(nullptr) { if (thread_.state() >= Thread::INITIALIZED) { ScopedLock sl(queueLock_); thread_.start(this); @@ -163,12 +164,32 @@ void HostQueue::append(Command& command) { queue_.enqueue(&command); } - bool HostQueue::isEmpty() { // Get a snapshot of queue size return queue_.empty(); } +void HostQueue::setLastQueuedCommand(Command* lastCommand) { + // Set last submitted command + ScopedLock sl(queueLock_); + if (lastEnqueueCommand_ != nullptr) { + lastEnqueueCommand_->release(); + } + lastEnqueueCommand_ = lastCommand; + if (lastCommand != nullptr) { + lastEnqueueCommand_->retain(); + } +} + +Command* HostQueue::getLastQueuedCommand(bool retain) { + // Get last submitted command + ScopedLock sl(queueLock_); + if (retain) { + lastEnqueueCommand_->retain(); + } + return lastEnqueueCommand_; +} + DeviceQueue::~DeviceQueue() { delete virtualDevice_; ScopedLock lock(context().lock()); diff --git a/projects/clr/rocclr/runtime/platform/commandqueue.hpp b/projects/clr/rocclr/runtime/platform/commandqueue.hpp index 85563746bf..8413a02112 100644 --- a/projects/clr/rocclr/runtime/platform/commandqueue.hpp +++ b/projects/clr/rocclr/runtime/platform/commandqueue.hpp @@ -163,6 +163,8 @@ class HostQueue : public CommandQueue { private: ConcurrentLinkedQueue queue_; //!< The queue. + Command* lastEnqueueCommand_; //!< The last submitted command + //! Await commands and execute them as they become ready. void loop(device::VirtualDevice* virtualDevice); @@ -204,6 +206,12 @@ class HostQueue : public CommandQueue { //! Return the current queue as the HostQueue virtual HostQueue* asHostQueue() { return this; } + + //! Get last enqueued command + Command* getLastQueuedCommand(bool retain); + + //! Set last enqueued command + void setLastQueuedCommand(Command* lastCommand); };