fix: handle completion in OsAgnosticMemoryManager

- add pollForCompletion() for contexts that used allocation prior to
freeGraphicsMemory()

Related-To: NEO-2707

Signed-off-by: Mateusz Hoppe <mateusz.hoppe@intel.com>
This commit is contained in:
Mateusz Hoppe
2023-10-10 16:26:14 +00:00
committed by Compute-Runtime-Automation
parent af275ed341
commit 5558222337
3 changed files with 33 additions and 0 deletions

View File

@@ -9,6 +9,7 @@
#include "shared/source/aub/aub_center.h"
#include "shared/source/aub/aub_helper.h"
#include "shared/source/command_stream/command_stream_receiver.h"
#include "shared/source/execution_environment/execution_environment.h"
#include "shared/source/execution_environment/root_device_environment.h"
#include "shared/source/gmm_helper/cache_settings_helper.h"
@@ -25,6 +26,7 @@
#include "shared/source/memory_manager/host_ptr_manager.h"
#include "shared/source/memory_manager/memory_allocation.h"
#include "shared/source/memory_manager/residency.h"
#include "shared/source/os_interface/os_context.h"
namespace NEO {
struct OsHandleOsAgnostic : OsHandle {
@@ -657,4 +659,14 @@ double OsAgnosticMemoryManager::getPercentOfGlobalMemoryAvailable(uint32_t rootD
return 0.8;
}
void OsAgnosticMemoryManager::handleFenceCompletion(GraphicsAllocation *allocation) {
for (auto &engine : getRegisteredEngines(allocation->getRootDeviceIndex())) {
const auto usedByContext = allocation->isUsedByOsContext(engine.osContext->getContextId());
if (usedByContext) {
engine.commandStreamReceiver->pollForCompletion();
}
}
}
} // namespace NEO

View File

@@ -31,6 +31,7 @@ class OsAgnosticMemoryManager : public MemoryManager {
void removeAllocationFromHostPtrManager(GraphicsAllocation *gfxAllocation) override;
void freeGraphicsMemoryImpl(GraphicsAllocation *gfxAllocation) override;
void freeGraphicsMemoryImpl(GraphicsAllocation *gfxAllocation, bool isImportedAllocation) override;
void handleFenceCompletion(GraphicsAllocation *allocation) override;
AllocationStatus populateOsHandles(OsHandleStorage &handleStorage, uint32_t rootDeviceIndex) override;
void cleanOsHandles(OsHandleStorage &handleStorage, uint32_t rootDeviceIndex) override;

View File

@@ -679,6 +679,26 @@ TEST_F(MemoryAllocatorTest, givenOsHandleStorageAndFreeMemoryEnabledWhenOsHandle
EXPECT_TRUE(mockManager1->freeMemoryCalled);
}
HWTEST_F(MemoryAllocatorTest, givenAllocationUsedByContextWhenFreeingThenHandleCompletionIsCalled) {
DebugManagerStateRestore dbgRestore;
DebugManager.flags.EnableFreeMemory.set(true);
const uint32_t rootDeviceIndex = 0u;
auto mockManager0 = new MockAubManager();
auto mockAubCenter0 = new MockAubCenter(*executionEnvironment->rootDeviceEnvironments[rootDeviceIndex], false, "aubfile", CommandStreamReceiverType::CSR_AUB);
mockAubCenter0->aubManager.reset(mockManager0);
executionEnvironment->rootDeviceEnvironments[rootDeviceIndex]->aubCenter.reset(mockAubCenter0);
auto allocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{device->getRootDeviceIndex(), true, 0x1000, device->getDeviceBitfield()}, nullptr);
ASSERT_NE(nullptr, allocation);
allocation->updateTaskCount(0u, csr->getOsContext().getContextId());
memoryManager->freeGraphicsMemory(allocation);
EXPECT_TRUE(mockManager0->freeMemoryCalled);
EXPECT_TRUE(static_cast<UltCommandStreamReceiver<FamilyType> *>(csr)->pollForCompletionCalled);
}
TEST_F(MemoryAllocatorTest, GivenEmptyMemoryManagerAndMisalingedHostPtrWithHugeSizeWhenAskedForHostPtrAllocationThenGraphicsAllocationIsBeignCreatedWithAllFragmentsPresent) {
void *cpuPtr = (void *)0x1005;
auto size = MemoryConstants::pageSize * 10 - 1;