From 6a416008aa3c3548297aa5fd210b07692bb4f22b Mon Sep 17 00:00:00 2001 From: Saleel Kudchadker Date: Wed, 8 Jan 2025 02:42:02 +0000 Subject: [PATCH] SWDEV-508004 - Improve hipEventRecord - Resolve stream once for event record. We should avoid calling getStream again in addMarker Change-Id: I78448c4f151ae10a5c8e8c248b2f4078b84191cb [ROCm/clr commit: a22c45d635605b5dec5eb713312d740de34ba6b8] --- projects/clr/hipamd/src/hip_event.cpp | 8 ++++++-- projects/clr/hipamd/src/hip_event.hpp | 1 - projects/clr/hipamd/src/hip_mempool_impl.cpp | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/projects/clr/hipamd/src/hip_event.cpp b/projects/clr/hipamd/src/hip_event.cpp index 28574c2753..405da38913 100644 --- a/projects/clr/hipamd/src/hip_event.cpp +++ b/projects/clr/hipamd/src/hip_event.cpp @@ -237,7 +237,9 @@ hipError_t Event::recordCommand(amd::Command*& command, amd::HostQueue* stream, // ================================================================================================ hipError_t Event::enqueueRecordCommand(hipStream_t stream, amd::Command* command, bool record) { command->enqueue(); - if (event_ == &command->event()) return hipSuccess; + if (event_ == &command->event()) { + return hipSuccess; + } if (event_ != nullptr) { event_->release(); } @@ -250,7 +252,9 @@ hipError_t Event::enqueueRecordCommand(hipStream_t stream, amd::Command* command // ================================================================================================ hipError_t Event::addMarker(hipStream_t stream, amd::Command* command, bool record, bool batch_flush) { - hip::Stream* hip_stream = hip::getStream(stream); + // Skip wait as we should not be resolving stream in this sub + constexpr bool kSkipWait = true; + hip::Stream* hip_stream = hip::getStream(stream, kSkipWait); // Keep the lock always at the beginning of this to avoid a race. SWDEV-277847 amd::ScopedLock lock(lock_); hipError_t status = recordCommand(command, hip_stream, 0, batch_flush); diff --git a/projects/clr/hipamd/src/hip_event.hpp b/projects/clr/hipamd/src/hip_event.hpp index 2b75ab869e..66025eff7c 100644 --- a/projects/clr/hipamd/src/hip_event.hpp +++ b/projects/clr/hipamd/src/hip_event.hpp @@ -106,7 +106,6 @@ class Event { Event(uint32_t flags) : flags_(flags), lock_(true) /* hipEvent_t lock*/, event_(nullptr), unrecorded_(false), stream_(nullptr) { - // No need to init event_ here as addMarker does that device_id_ = hip::getCurrentDevice()->deviceId(); // Created in current device ctx } diff --git a/projects/clr/hipamd/src/hip_mempool_impl.cpp b/projects/clr/hipamd/src/hip_mempool_impl.cpp index a1c0ef9b54..bb2b839ffc 100644 --- a/projects/clr/hipamd/src/hip_mempool_impl.cpp +++ b/projects/clr/hipamd/src/hip_mempool_impl.cpp @@ -97,7 +97,7 @@ Heap::SortedMap::iterator Heap::EraseAllocaton(Heap::SortedMap::iterator& it) { const device::Memory* dev_mem = memory->getDeviceMemory(*device_->devices()[0]); void* dev_mem_vaddr = reinterpret_cast(dev_mem->virtualAddress()); total_size_ -= it->first.first; - + if (dev_mem_vaddr != nullptr) { amd::SvmBuffer::free(memory->getContext(), dev_mem_vaddr); } else {