diff --git a/hipamd/src/hip_event.hpp b/hipamd/src/hip_event.hpp index ac05f2d4f3..6fdb67ef1d 100644 --- a/hipamd/src/hip_event.hpp +++ b/hipamd/src/hip_event.hpp @@ -98,6 +98,14 @@ class Event { hipError_t recordCommand(amd::Command*& command, amd::HostQueue* queue); hipError_t enqueueRecordCommand(hipStream_t stream, amd::Command* command, bool record); hipError_t addMarker(hipStream_t stream, amd::Command* command, bool record); + void BindCommand(amd::Command& command) { + amd::ScopedLock lock(lock_); + if (event_ != nullptr) { + event_->release(); + } + event_ = &command.event(); + command.retain(); + } bool isRecorded() { return recorded_; } amd::Monitor& lock() { return lock_; } diff --git a/hipamd/src/hip_module.cpp b/hipamd/src/hip_module.cpp index c3845e3e71..3d8658b778 100644 --- a/hipamd/src/hip_module.cpp +++ b/hipamd/src/hip_module.cpp @@ -388,22 +388,19 @@ hipError_t ihipModuleLaunchKernel(hipFunction_t f, uint32_t globalWorkSizeX, return status; } - hip::Event* eStart = reinterpret_cast(startEvent); - hip::Event* eStop = reinterpret_cast(stopEvent); - command->enqueue(); if (startEvent != nullptr) { - status = eStart->addMarker(hStream, command, false); - command->retain(); - } - if (status != hipSuccess) { - return status; + hip::Event* eStart = reinterpret_cast(startEvent); + status = eStart->addMarker(hStream, nullptr, false); + if (status != hipSuccess) { + return status; + } } + + command->enqueue(); + if (stopEvent != nullptr) { - status = eStop->addMarker(hStream, command, true); - command->retain(); - } - if (status != hipSuccess) { - return status; + hip::Event* eStop = reinterpret_cast(stopEvent); + eStop->BindCommand(*command); } command->release();