diff --git a/runtime/device/device.cpp b/runtime/device/device.cpp index aaa8969e2c..d5bc93253b 100644 --- a/runtime/device/device.cpp +++ b/runtime/device/device.cpp @@ -87,11 +87,6 @@ Device::~Device() { performanceCounters->shutdown(); } delete commandStreamReceiver; - if (memoryManager) { - memoryManager->freeGraphicsMemory(tagAllocation); - } - tagAllocation = nullptr; - commandStreamReceiver = nullptr; if (memoryManager) { if (preemptionAllocation) { memoryManager->freeGraphicsMemory(preemptionAllocation); @@ -99,6 +94,11 @@ Device::~Device() { } memoryManager->waitForDeletions(); } + if (memoryManager) { + memoryManager->freeGraphicsMemory(tagAllocation); + } + tagAllocation = nullptr; + commandStreamReceiver = nullptr; delete memoryManager; memoryManager = nullptr; alignedFree(this->slmWindowStartAddress); diff --git a/runtime/device/device.h b/runtime/device/device.h index 0f7f123004..cee7e875d6 100644 --- a/runtime/device/device.h +++ b/runtime/device/device.h @@ -90,6 +90,8 @@ class Device : public BaseObject<_cl_device_id> { } CommandStreamReceiver &getCommandStreamReceiver(); + CommandStreamReceiver *peekCommandStreamReceiver(); + volatile uint32_t *getTagAddress() const; const char *getProductAbbrev() const; @@ -176,6 +178,10 @@ inline CommandStreamReceiver &Device::getCommandStreamReceiver() { return *commandStreamReceiver; } +inline CommandStreamReceiver *Device::peekCommandStreamReceiver() { + return commandStreamReceiver; +} + inline volatile uint32_t *Device::getTagAddress() const { return tagAddress; } diff --git a/runtime/os_interface/windows/wddm_memory_manager.cpp b/runtime/os_interface/windows/wddm_memory_manager.cpp index 1925980f0b..8259e0fd67 100644 --- a/runtime/os_interface/windows/wddm_memory_manager.cpp +++ b/runtime/os_interface/windows/wddm_memory_manager.cpp @@ -20,6 +20,8 @@ * OTHER DEALINGS IN THE SOFTWARE. */ +#include "runtime/command_stream/command_stream_receiver_hw.h" +#include "runtime/device/device.h" #include "runtime/helpers/aligned_memory.h" #include "runtime/helpers/ptr_math.h" #include "runtime/gmm_helper/gmm_helper.h" @@ -268,6 +270,8 @@ void WddmMemoryManager::freeGraphicsMemoryImpl(GraphicsAllocation *gfxAllocation releaseResidencyLock(); + UNRECOVERABLE_IF(gfxAllocation->taskCount != ObjectNotUsed && this->device && this->device->peekCommandStreamReceiver() && gfxAllocation->taskCount > *this->device->getCommandStreamReceiver().getTagAddress()); + if (input->gmm) { if (input->gmm->isRenderCompressed) { status = unmapAuxVA(input->gmm, input->gpuPtr); diff --git a/unit_tests/device/device_tests.cpp b/unit_tests/device/device_tests.cpp index 9bcb71b5eb..0f300e1284 100644 --- a/unit_tests/device/device_tests.cpp +++ b/unit_tests/device/device_tests.cpp @@ -54,6 +54,10 @@ TEST_F(DeviceTest, getCommandStreamReceiver) { EXPECT_NE(nullptr, &pDevice->getCommandStreamReceiver()); } +TEST_F(DeviceTest, givenDeviceWhenPeekCommandStreamReceiverIsCalledThenCommandStreamReceiverIsReturned) { + EXPECT_NE(nullptr, pDevice->peekCommandStreamReceiver()); +} + TEST_F(DeviceTest, getSupportedClVersion) { auto version = pDevice->getSupportedClVersion(); auto version2 = pDevice->getHardwareInfo().capabilityTable.clVersionSupport;