diff --git a/rocclr/runtime/device/pal/palresource.cpp b/rocclr/runtime/device/pal/palresource.cpp index 9448a1825e..7c4e5b440c 100644 --- a/rocclr/runtime/device/pal/palresource.cpp +++ b/rocclr/runtime/device/pal/palresource.cpp @@ -158,6 +158,7 @@ GpuMemoryReference::~GpuMemoryReference() { } } } else { + amd::ScopedLock l(gpu_->execution()); gpu_->releaseMemory(this, &events_[gpu_->index()]); } if (device_.vgpus().size() != 0) { @@ -1097,6 +1098,7 @@ void Resource::free() { } } else { + amd::ScopedLock l(memRef_->gpu_->execution()); memRef_->gpu_->waitForEvent(&memRef_->events_[memRef_->gpu_->index()]); } } @@ -1975,6 +1977,7 @@ bool ResourceCache::addGpuMemory(Resource::Descriptor* desc, GpuMemoryReference* // Add the current resource to the cache resCache_.push_front(std::make_pair(descCached, ref)); + ref->gpu_ = nullptr; cacheSize_ += size; result = true; } diff --git a/rocclr/runtime/device/pal/palvirtual.cpp b/rocclr/runtime/device/pal/palvirtual.cpp index 29d2bd0c63..0f4097a5b8 100644 --- a/rocclr/runtime/device/pal/palvirtual.cpp +++ b/rocclr/runtime/device/pal/palvirtual.cpp @@ -2281,7 +2281,6 @@ void VirtualGPU::submitMarker(amd::Marker& vcmd) { } void VirtualGPU::releaseMemory(GpuMemoryReference* mem, GpuEvent* event) { - waitForEvent(event); queues_[MainEngine]->removeCmdMemRef(mem); queues_[SdmaEngine]->removeCmdMemRef(mem); } diff --git a/rocclr/runtime/device/pal/palvirtual.hpp b/rocclr/runtime/device/pal/palvirtual.hpp index 15c375a23b..b6e9c4997a 100644 --- a/rocclr/runtime/device/pal/palvirtual.hpp +++ b/rocclr/runtime/device/pal/palvirtual.hpp @@ -104,7 +104,7 @@ class VirtualGPU : public device::VirtualDevice { if (!ibReuse) { start = amd::Os::timeNanos(); } - while (ibReuse || (Pal::Result::Success != (result = iCmdFences_[cbId]->GetStatus()))) { + while ((Pal::Result::Success != (result = iCmdFences_[cbId]->GetStatus())) || ibReuse) { if (result == Pal::Result::ErrorFenceNeverSubmitted) { result = Pal::Result::Success; break;