fix: write memory for resident allocations in simulation mode

- refactor and call proceesFlushResdiency() on memoryOperationsHandler
- call free() to remove allocation from resident allocations when
graphics allocation is released

Related-To: NEO-11719

Signed-off-by: Mateusz Hoppe <mateusz.hoppe@intel.com>
This commit is contained in:
Mateusz Hoppe
2024-06-14 14:15:14 +00:00
committed by Compute-Runtime-Automation
parent 9954002db1
commit b3d72ddd3d
15 changed files with 285 additions and 73 deletions

View File

@@ -36,6 +36,7 @@
#include "shared/source/memory_manager/memory_banks.h"
#include "shared/source/memory_manager/memory_manager.h"
#include "shared/source/memory_manager/page_table.h"
#include "shared/source/os_interface/aub_memory_operations_handler.h"
#include "shared/source/os_interface/product_helper.h"
#include "aubstream/aubstream.h"
@@ -779,6 +780,10 @@ SubmissionStatus AUBCommandStreamReceiverHw<GfxFamily>::processResidency(const R
gfxAllocation->updateResidencyTaskCount(this->taskCount + 1, this->osContext->getContextId());
}
if (this->executionEnvironment.rootDeviceEnvironments[this->rootDeviceIndex]->memoryOperationsInterface) {
this->executionEnvironment.rootDeviceEnvironments[this->rootDeviceIndex]->memoryOperationsInterface->processFlushResidency(this);
}
dumpAubNonWritable = false;
return SubmissionStatus::success;
}

View File

@@ -27,6 +27,7 @@
#include "shared/source/helpers/hw_info.h"
#include "shared/source/helpers/ptr_math.h"
#include "shared/source/memory_manager/graphics_allocation.h"
#include "shared/source/os_interface/aub_memory_operations_handler.h"
#include "shared/source/os_interface/product_helper.h"
#include <cstring>
@@ -539,6 +540,10 @@ SubmissionStatus TbxCommandStreamReceiverHw<GfxFamily>::processResidency(const R
gfxAllocation->updateResidencyTaskCount(this->taskCount + 1, this->osContext->getContextId());
}
if (this->executionEnvironment.rootDeviceEnvironments[this->rootDeviceIndex]->memoryOperationsInterface) {
this->executionEnvironment.rootDeviceEnvironments[this->rootDeviceIndex]->memoryOperationsInterface->processFlushResidency(this);
}
dumpTbxNonWritable = false;
return SubmissionStatus::success;
}

View File

@@ -35,6 +35,7 @@
#include "shared/source/memory_manager/host_ptr_manager.h"
#include "shared/source/memory_manager/internal_allocation_storage.h"
#include "shared/source/memory_manager/local_memory_usage.h"
#include "shared/source/memory_manager/memory_operations_handler.h"
#include "shared/source/memory_manager/multi_graphics_allocation.h"
#include "shared/source/memory_manager/prefetch_manager.h"
#include "shared/source/os_interface/os_context.h"
@@ -259,10 +260,18 @@ void MemoryManager::freeGraphicsMemory(GraphicsAllocation *gfxAllocation, bool i
if (!gfxAllocation) {
return;
}
bool rootEnvAvailable = executionEnvironment.rootDeviceEnvironments.size() > 0;
if (executionEnvironment.rootDeviceEnvironments.size() > 0 && executionEnvironment.rootDeviceEnvironments[gfxAllocation->getRootDeviceIndex()]->getBindlessHeapsHelper() != nullptr) {
if (rootEnvAvailable) {
if (executionEnvironment.rootDeviceEnvironments[gfxAllocation->getRootDeviceIndex()]->getBindlessHeapsHelper() != nullptr) {
executionEnvironment.rootDeviceEnvironments[gfxAllocation->getRootDeviceIndex()]->getBindlessHeapsHelper()->releaseSSToReusePool(gfxAllocation->getBindlessInfo());
}
if (this->peekExecutionEnvironment().rootDeviceEnvironments[gfxAllocation->getRootDeviceIndex()]->memoryOperationsInterface) {
this->peekExecutionEnvironment().rootDeviceEnvironments[gfxAllocation->getRootDeviceIndex()]->memoryOperationsInterface->free(nullptr, *gfxAllocation);
}
}
const bool hasFragments = gfxAllocation->fragmentsStorage.fragmentCount != 0;
const bool isLocked = gfxAllocation->isLocked();
DEBUG_BREAK_IF(hasFragments && isLocked);

View File

@@ -13,6 +13,7 @@ namespace NEO {
class Device;
class GraphicsAllocation;
class OsContext;
class CommandStreamReceiver;
class MemoryOperationsHandler {
public:
@@ -23,8 +24,10 @@ class MemoryOperationsHandler {
virtual MemoryOperationsStatus lock(Device *device, ArrayRef<GraphicsAllocation *> gfxAllocations) = 0;
virtual MemoryOperationsStatus evict(Device *device, GraphicsAllocation &gfxAllocation) = 0;
virtual MemoryOperationsStatus isResident(Device *device, GraphicsAllocation &gfxAllocation) = 0;
virtual MemoryOperationsStatus free(Device *device, GraphicsAllocation &gfxAllocation) { return MemoryOperationsStatus::success; }
virtual MemoryOperationsStatus makeResidentWithinOsContext(OsContext *osContext, ArrayRef<GraphicsAllocation *> gfxAllocations, bool evictable) = 0;
virtual MemoryOperationsStatus evictWithinOsContext(OsContext *osContext, GraphicsAllocation &gfxAllocation) = 0;
virtual void processFlushResidency(CommandStreamReceiver *csr) {}
};
} // namespace NEO

View File

@@ -83,6 +83,14 @@ MemoryOperationsStatus AubMemoryOperationsHandler::evict(Device *device, Graphic
return MemoryOperationsStatus::success;
}
}
MemoryOperationsStatus AubMemoryOperationsHandler::free(Device *device, GraphicsAllocation &gfxAllocation) {
auto lock = acquireLock(resourcesLock);
auto itor = std::find(residentAllocations.begin(), residentAllocations.end(), &gfxAllocation);
if (itor != residentAllocations.end()) {
residentAllocations.erase(itor, itor + 1);
}
return MemoryOperationsStatus::success;
}
MemoryOperationsStatus AubMemoryOperationsHandler::makeResidentWithinOsContext(OsContext *osContext, ArrayRef<GraphicsAllocation *> gfxAllocations, bool evictable) {
return makeResident(nullptr, gfxAllocations);
@@ -141,32 +149,10 @@ DeviceBitfield AubMemoryOperationsHandler::getMemoryBanksBitfield(GraphicsAlloca
return {};
}
void AubMemoryOperationsHandler::processFlushResidency(Device *device) {
void AubMemoryOperationsHandler::processFlushResidency(CommandStreamReceiver *csr) {
auto lock = acquireLock(resourcesLock);
for (const auto &allocation : this->residentAllocations) {
if (!isAubWritable(*allocation, device)) {
continue;
}
uint64_t gpuAddress = device->getGmmHelper()->decanonize(allocation->getGpuAddress());
aub_stream::AllocationParams params(gpuAddress,
allocation->getUnderlyingBuffer(),
allocation->getUnderlyingBufferSize(),
allocation->storageInfo.getMemoryBanks(),
AubMemDump::DataTypeHintValues::TraceNotype,
allocation->getUsedPageSize());
auto gmm = allocation->getDefaultGmm();
if (gmm) {
params.additionalParams.compressionEnabled = gmm->isCompressionEnabled();
params.additionalParams.uncached = CacheSettingsHelper::isUncachedType(gmm->resourceParams.Usage);
}
if (allocation->storageInfo.cloningOfPageTables || !allocation->isAllocatedInLocalMemoryPool()) {
aubManager->writeMemory2(params);
} else {
device->getDefaultEngine().commandStreamReceiver->writeMemoryAub(params);
}
csr->writeMemory(*allocation);
}
}

View File

@@ -26,17 +26,18 @@ class AubMemoryOperationsHandler : public MemoryOperationsHandler {
MemoryOperationsStatus lock(Device *device, ArrayRef<GraphicsAllocation *> gfxAllocations) override;
MemoryOperationsStatus evict(Device *device, GraphicsAllocation &gfxAllocation) override;
MemoryOperationsStatus isResident(Device *device, GraphicsAllocation &gfxAllocation) override;
MemoryOperationsStatus free(Device *device, GraphicsAllocation &gfxAllocation) override;
MemoryOperationsStatus makeResidentWithinOsContext(OsContext *osContext, ArrayRef<GraphicsAllocation *> gfxAllocations, bool evictable) override;
MemoryOperationsStatus evictWithinOsContext(OsContext *osContext, GraphicsAllocation &gfxAllocation) override;
void processFlushResidency(CommandStreamReceiver *csr) override;
void setAubManager(aub_stream::AubManager *aubManager);
bool isAubWritable(GraphicsAllocation &graphicsAllocation, Device *device) const;
void setAubWritable(bool writable, GraphicsAllocation &graphicsAllocation, Device *device);
void processFlushResidency(Device *device);
protected:
DeviceBitfield getMemoryBanksBitfield(GraphicsAllocation *allocation, Device *device) const;
[[nodiscard]] MOCKABLE_VIRTUAL std::unique_lock<SpinLock> acquireLock(SpinLock &lock) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2018-2023 Intel Corporation
* Copyright (C) 2018-2024 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -93,6 +93,10 @@ struct MockAubCsr : public AUBCommandStreamReceiverHw<GfxFamily> {
AUBCommandStreamReceiverHw<GfxFamily>::writeMemory(gpuAddress, cpuAddress, size, memoryBank, entryBits);
writeMemoryCalled = true;
}
bool writeMemory(GraphicsAllocation &gfxAllocation) override {
writeMemoryGfxAllocCalled = true;
return AUBCommandStreamReceiverHw<GfxFamily>::writeMemory(gfxAllocation);
}
void writeMMIO(uint32_t offset, uint32_t value) override {
AUBCommandStreamReceiverHw<GfxFamily>::writeMMIO(offset, value);
writeMMIOCalled = true;
@@ -146,6 +150,7 @@ struct MockAubCsr : public AUBCommandStreamReceiverHw<GfxFamily> {
bool initProgrammingFlagsCalled = false;
bool initializeEngineCalled = false;
bool writeMemoryCalled = false;
bool writeMemoryGfxAllocCalled = false;
bool writeMemoryWithAubManagerCalled = false;
bool writeMMIOCalled = false;
bool submitBatchBufferCalled = false;

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2023 Intel Corporation
* Copyright (C) 2023-2024 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -46,11 +46,17 @@ struct MockAubMemoryOperationsHandler : public AubMemoryOperationsHandler {
return AubMemoryOperationsHandler::evictWithinOsContext(osContext, gfxAllocation);
}
MemoryOperationsStatus free(Device *device, GraphicsAllocation &gfxAllocation) override {
freeCalled = true;
return AubMemoryOperationsHandler::free(device, gfxAllocation);
}
bool makeResidentCalled = false;
bool evictCalled = false;
bool isResidentCalled = false;
bool makeResidentWithinOsContextCalled = false;
bool evictWithinOsContextCalled = false;
bool freeCalled = false;
};
} // namespace NEO

View File

@@ -102,9 +102,23 @@ class MockMemoryOperations : public MemoryOperationsHandler {
return MemoryOperationsStatus::success;
}
MemoryOperationsStatus free(Device *device, GraphicsAllocation &gfxAllocation) override {
freeCalledCount++;
if (captureGfxAllocationsForMakeResident) {
auto itor = std::find(gfxAllocationsForMakeResident.begin(), gfxAllocationsForMakeResident.end(), &gfxAllocation);
if (itor != gfxAllocationsForMakeResident.end()) {
gfxAllocationsForMakeResident.erase(itor, itor + 1);
}
}
return MemoryOperationsStatus::success;
}
std::vector<GraphicsAllocation *> gfxAllocationsForMakeResident{};
int makeResidentCalledCount = 0;
int evictCalledCount = 0;
int freeCalledCount = 0;
uint32_t isResidentCalledCount = 0;
uint32_t lockCalledCount = 0;
uint32_t makeResidentContextId = std::numeric_limits<uint32_t>::max();

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2018-2023 Intel Corporation
* Copyright (C) 2018-2024 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -42,6 +42,11 @@ class MockTbxCsr : public TbxCommandStreamReceiverHw<GfxFamily> {
TbxCommandStreamReceiverHw<GfxFamily>::writeMemory(gpuAddress, cpuAddress, size, memoryBank, entryBits);
writeMemoryCalled = true;
}
bool writeMemory(GraphicsAllocation &graphicsAllocation) override {
writeMemoryGfxAllocCalled = true;
return TbxCommandStreamReceiverHw<GfxFamily>::writeMemory(graphicsAllocation);
}
void submitBatchBufferTbx(uint64_t batchBufferGpuAddress, const void *batchBuffer, size_t batchBufferSize, uint32_t memoryBank, uint64_t entryBits, bool overrideRingHead) override {
TbxCommandStreamReceiverHw<GfxFamily>::submitBatchBufferTbx(batchBufferGpuAddress, batchBuffer, batchBufferSize, memoryBank, entryBits, overrideRingHead);
overrideRingHeadPassed = overrideRingHead;
@@ -62,6 +67,7 @@ class MockTbxCsr : public TbxCommandStreamReceiverHw<GfxFamily> {
bool initializeEngineCalled = false;
bool writeMemoryWithAubManagerCalled = false;
bool writeMemoryCalled = false;
bool writeMemoryGfxAllocCalled = false;
bool submitBatchBufferCalled = false;
bool overrideRingHeadPassed = false;
bool pollForCompletionCalled = false;

View File

@@ -20,12 +20,14 @@
#include "shared/test/common/mocks/mock_aub_center.h"
#include "shared/test/common/mocks/mock_aub_csr.h"
#include "shared/test/common/mocks/mock_aub_manager.h"
#include "shared/test/common/mocks/mock_aub_memory_operations_handler.h"
#include "shared/test/common/mocks/mock_aub_subcapture_manager.h"
#include "shared/test/common/mocks/mock_execution_environment.h"
#include "shared/test/common/mocks/mock_gmm.h"
#include "shared/test/common/mocks/mock_graphics_allocation.h"
#include "shared/test/common/mocks/mock_os_context.h"
#include "shared/test/common/test_macros/hw_test.h"
using namespace NEO;
using AubCommandStreamReceiverTests = Test<AubCommandStreamReceiverFixture>;
@@ -336,6 +338,46 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverInSubCaptur
EXPECT_FALSE(aubCsr->writeMemoryCalled);
}
HWTEST_F(AubCommandStreamReceiverTests, givenAubCsrAndResidentAllocationWhenProcessResidencyIsCalledThenWriteMemoryIsCalledOnResidentAllocations) {
auto mockManager = new MockAubManager();
auto mockAubCenter = new MockAubCenter(*pDevice->getExecutionEnvironment()->rootDeviceEnvironments[0], false, "aubfile", CommandStreamReceiverType::aub);
mockAubCenter->aubManager.reset(mockManager);
pDevice->getExecutionEnvironment()->rootDeviceEnvironments[0]->aubCenter.reset(mockAubCenter);
auto memoryOperationsHandler = new NEO::MockAubMemoryOperationsHandler(mockManager);
pDevice->getExecutionEnvironment()->rootDeviceEnvironments[0]->memoryOperationsInterface.reset(memoryOperationsHandler);
auto commandStreamReceiver = std::make_unique<MockAubCsr<FamilyType>>("", true, *pDevice->getExecutionEnvironment(), 0, pDevice->getDeviceBitfield());
auto osContext = pDevice->getExecutionEnvironment()->memoryManager->createAndRegisterOsContext(commandStreamReceiver.get(),
EngineDescriptorHelper::getDefaultDescriptor({getChosenEngineType(*defaultHwInfo), EngineUsage::regular},
PreemptionHelper::getDefaultPreemptionMode(*defaultHwInfo)));
commandStreamReceiver->setupContext(*osContext);
commandStreamReceiver->initializeTagAllocation();
commandStreamReceiver->createGlobalFenceAllocation();
MockGraphicsAllocation allocation(reinterpret_cast<void *>(0x1000), 0x1000);
ResidencyContainer allocationsForResidency = {&allocation};
MockGraphicsAllocation allocation2(reinterpret_cast<void *>(0x5000), 0x5000, 0x1000);
GraphicsAllocation *allocPtr = &allocation2;
memoryOperationsHandler->makeResident(pDevice, ArrayRef<GraphicsAllocation *>(&allocPtr, 1));
EXPECT_TRUE(mockManager->writeMemory2Called);
mockManager->storeAllocationParams = true;
commandStreamReceiver->writeMemoryGfxAllocCalled = false;
mockManager->writeMemory2Called = false;
commandStreamReceiver->processResidency(allocationsForResidency, 0u);
EXPECT_TRUE(mockManager->writeMemory2Called);
EXPECT_TRUE(commandStreamReceiver->writeMemoryGfxAllocCalled);
ASSERT_EQ(2u, mockManager->storedAllocationParams.size());
EXPECT_EQ(allocation2.getGpuAddress(), mockManager->storedAllocationParams[1].gfxAddress);
ASSERT_EQ(1u, memoryOperationsHandler->residentAllocations.size());
EXPECT_EQ(&allocation2, memoryOperationsHandler->residentAllocations[0]);
}
HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverInSubCaptureModeWhenProcessResidencyIsCalledButAllocationSizeIsZeroThenItShouldntWriteMemory) {
DebugManagerStateRestore stateRestore;
AubSubCaptureCommon aubSubCaptureCommon;

View File

@@ -26,6 +26,7 @@
#include "shared/test/common/mocks/mock_allocation_properties.h"
#include "shared/test/common/mocks/mock_aub_center.h"
#include "shared/test/common/mocks/mock_aub_manager.h"
#include "shared/test/common/mocks/mock_aub_memory_operations_handler.h"
#include "shared/test/common/mocks/mock_aub_subcapture_manager.h"
#include "shared/test/common/mocks/mock_device.h"
#include "shared/test/common/mocks/mock_execution_environment.h"
@@ -344,6 +345,45 @@ HWTEST_F(TbxCommandSteamSimpleTest, givenTbxCsrWhenCallingMakeSurfacePackNonResi
EXPECT_EQ(expectedAllocationsForDownload, tbxCsr.allocationsForDownload);
}
HWTEST_F(TbxCommandSteamSimpleTest, givenTbxCsrAndResidentAllocationWhenProcessResidencyIsCalledThenWriteMemoryIsCalledOnResidentAllocations) {
auto mockManager = new MockAubManager();
auto mockAubCenter = new MockAubCenter(*pDevice->getExecutionEnvironment()->rootDeviceEnvironments[0], false, "aubfile", CommandStreamReceiverType::aub);
mockAubCenter->aubManager.reset(mockManager);
pDevice->getExecutionEnvironment()->rootDeviceEnvironments[0]->aubCenter.reset(mockAubCenter);
auto memoryOperationsHandler = new NEO::MockAubMemoryOperationsHandler(mockManager);
pDevice->getExecutionEnvironment()->rootDeviceEnvironments[0]->memoryOperationsInterface.reset(memoryOperationsHandler);
auto commandStreamReceiver = std::make_unique<MockTbxCsr<FamilyType>>(*pDevice->getExecutionEnvironment(), pDevice->getDeviceBitfield());
auto osContext = pDevice->getExecutionEnvironment()->memoryManager->createAndRegisterOsContext(commandStreamReceiver.get(),
EngineDescriptorHelper::getDefaultDescriptor({getChosenEngineType(*defaultHwInfo), EngineUsage::regular},
PreemptionHelper::getDefaultPreemptionMode(*defaultHwInfo)));
commandStreamReceiver->setupContext(*osContext);
commandStreamReceiver->initializeTagAllocation();
commandStreamReceiver->createGlobalFenceAllocation();
MockGraphicsAllocation allocation(reinterpret_cast<void *>(0x1000), 0x1000);
ResidencyContainer allocationsForResidency = {&allocation};
MockGraphicsAllocation allocation2(reinterpret_cast<void *>(0x5000), 0x5000, 0x1000);
GraphicsAllocation *allocPtr = &allocation2;
memoryOperationsHandler->makeResident(pDevice, ArrayRef<GraphicsAllocation *>(&allocPtr, 1));
EXPECT_TRUE(mockManager->writeMemory2Called);
mockManager->storeAllocationParams = true;
commandStreamReceiver->writeMemoryGfxAllocCalled = false;
mockManager->writeMemory2Called = false;
commandStreamReceiver->processResidency(allocationsForResidency, 0u);
EXPECT_TRUE(mockManager->writeMemory2Called);
EXPECT_TRUE(commandStreamReceiver->writeMemoryGfxAllocCalled);
ASSERT_EQ(2u, mockManager->storedAllocationParams.size());
EXPECT_EQ(allocation2.getGpuAddress(), mockManager->storedAllocationParams[1].gfxAddress);
ASSERT_EQ(1u, memoryOperationsHandler->residentAllocations.size());
EXPECT_EQ(&allocation2, memoryOperationsHandler->residentAllocations[0]);
}
HWTEST_F(TbxCommandSteamSimpleTest, givenTbxCsrWhenCallingWaitForTaskCountWithKmdNotifyFallbackThenTagAllocationAndScheduledAllocationsAreDownloaded) {
MockTbxCsrRegisterDownloadedAllocations<FamilyType> tbxCsr{*pDevice->executionEnvironment, pDevice->getRootDeviceIndex(), pDevice->getDeviceBitfield()};
MockOsContext osContext(0, EngineDescriptorHelper::getDefaultDescriptor(pDevice->getDeviceBitfield()));

View File

@@ -23,6 +23,7 @@
#include "shared/test/common/mocks/mock_allocation_properties.h"
#include "shared/test/common/mocks/mock_aub_center.h"
#include "shared/test/common/mocks/mock_aub_manager.h"
#include "shared/test/common/mocks/mock_aub_memory_operations_handler.h"
#include "shared/test/common/mocks/mock_csr.h"
#include "shared/test/common/mocks/mock_deferrable_deletion.h"
#include "shared/test/common/mocks/mock_deferred_deleter.h"
@@ -3163,6 +3164,37 @@ TEST(MemoryManagerTest, givenDuplicateRootDeviceIndicesWhenCreatingMultiGraphics
memoryManager.freeGraphicsMemory(allocation);
}
TEST(MemoryManagerTest, givenMemoryAllocationWhenFreedThenFreeCalledOnMemoryOperationsHandler) {
MockExecutionEnvironment executionEnvironment(defaultHwInfo.get());
executionEnvironment.initGmm();
auto mockManager = new MockAubManager();
auto mockAubCenter = new MockAubCenter(*executionEnvironment.rootDeviceEnvironments[0], false, "aubfile", CommandStreamReceiverType::aub);
mockAubCenter->aubManager.reset(mockManager);
executionEnvironment.rootDeviceEnvironments[0]->aubCenter.reset(mockAubCenter);
executionEnvironment.incRefInternal();
auto device = std::unique_ptr<MockDevice>(MockDevice::createWithExecutionEnvironment<MockDevice>(nullptr, &executionEnvironment, 0));
auto memoryOperationsHandler = new NEO::MockAubMemoryOperationsHandler(mockManager);
executionEnvironment.rootDeviceEnvironments[0]->memoryOperationsInterface.reset(memoryOperationsHandler);
MockMemoryManager memoryManager(true, true, executionEnvironment);
DeviceBitfield localMemoryBitfield{1};
AllocationProperties allocationProperties{mockRootDeviceIndex, MemoryConstants::pageSize, AllocationType::buffer, localMemoryBitfield};
auto memoryAllocation = memoryManager.allocateGraphicsMemoryWithProperties(allocationProperties);
EXPECT_NE(nullptr, memoryAllocation);
memoryOperationsHandler->makeResident(device.get(), ArrayRef<GraphicsAllocation *>(&memoryAllocation, 1));
EXPECT_EQ(1u, memoryOperationsHandler->residentAllocations.size());
memoryManager.freeGraphicsMemory(memoryAllocation);
EXPECT_TRUE(memoryOperationsHandler->freeCalled);
EXPECT_EQ(0u, memoryOperationsHandler->residentAllocations.size());
}
TEST(AllocationListTest, givenAllocationInListWhenFreeAllGraphicsAllocationsCalledThenHeadAndTailIsNullptr) {
AllocationsList allocList;
EXPECT_EQ(nullptr, allocList.peekHead());

View File

@@ -11,9 +11,14 @@
#include "shared/source/aub_mem_dump/aub_mem_dump.h"
#include "shared/test/common/helpers/engine_descriptor_helper.h"
#include "shared/test/common/helpers/variable_backup.h"
#include "shared/test/common/mocks/mock_aub_center.h"
#include "shared/test/common/mocks/mock_aub_csr.h"
#include "shared/test/common/mocks/mock_aub_manager.h"
#include "shared/test/common/mocks/mock_command_stream_receiver.h"
#include "shared/test/common/mocks/mock_csr.h"
#include "shared/test/common/mocks/mock_gmm.h"
#include "shared/test/common/mocks/mock_os_context.h"
#include "shared/test/common/test_macros/hw_test.h"
TEST_F(AubMemoryOperationsHandlerTests, givenNullPtrAsAubManagerWhenMakeResidentCalledThenFalseReturned) {
getMemoryOperationsHandler()->setAubManager(nullptr);
@@ -426,90 +431,141 @@ TEST_F(AubMemoryOperationsHandlerTests, givenGfxAllocationWhenSetAubWritableForN
EXPECT_TRUE(memoryOperationsInterface->isAubWritable(allocation, device.get()));
}
TEST_F(AubMemoryOperationsHandlerTests, givenGfxAllocationWriteableWhenProcessingFlushResidencyThenPerformAllocationWriteMemory) {
MockAubManager aubManager;
getMemoryOperationsHandler()->setAubManager(&aubManager);
HWTEST_F(AubMemoryOperationsHandlerTests, givenCloningOfPageTablesWhenProcessingFlushResidencyThenPerformAUbManagerWriteMemory) {
auto mockAubManager = std::make_unique<MockAubManager>();
auto *aubManager = mockAubManager.get();
auto memoryOperationsInterface = getMemoryOperationsHandler();
memoryOperationsInterface->setAubManager(aubManager);
auto executionEnvironment = std::unique_ptr<ExecutionEnvironment>(MockDevice::prepareExecutionEnvironment(defaultHwInfo.get(), 0u));
executionEnvironment->rootDeviceEnvironments[0]->initGmm();
executionEnvironment->rootDeviceEnvironments[0]->setHwInfoAndInitHelpers(&hardwareInfo);
executionEnvironment->initializeMemoryManager();
auto mockAubCenter = std::make_unique<MockAubCenter>();
mockAubCenter->aubManager.reset(mockAubManager.release());
executionEnvironment->rootDeviceEnvironments[0]->aubCenter.reset(mockAubCenter.release());
auto csr = std::make_unique<MockAubCsr<FamilyType>>("", true, *executionEnvironment, device->getRootDeviceIndex(), device->deviceBitfield);
auto osContext = executionEnvironment->memoryManager->createAndRegisterOsContext(csr.get(), EngineDescriptorHelper::getDefaultDescriptor());
csr->setupContext(*osContext);
allocPtr->storageInfo.cloningOfPageTables = true;
auto result = memoryOperationsInterface->makeResident(device.get(), ArrayRef<GraphicsAllocation *>(&allocPtr, 1));
EXPECT_EQ(result, MemoryOperationsStatus::success);
EXPECT_TRUE(aubManager.writeMemory2Called);
EXPECT_TRUE(aubManager->writeMemory2Called);
aubManager.writeMemory2Called = false;
memoryOperationsInterface->processFlushResidency(device.get());
EXPECT_TRUE(aubManager.writeMemory2Called);
aubManager->writeMemory2Called = false;
memoryOperationsInterface->processFlushResidency(csr.get());
EXPECT_TRUE(aubManager->writeMemory2Called);
}
TEST_F(AubMemoryOperationsHandlerTests, givenNonLocalGfxAllocationWriteableWhenProcessingFlushResidencyThenPerformAllocationAubManagerWriteMemory) {
MockAubManager aubManager;
getMemoryOperationsHandler()->setAubManager(&aubManager);
HWTEST_F(AubMemoryOperationsHandlerTests, givenNonLocalGfxAllocationWriteableWhenProcessingFlushResidencyThenPerformAubManagerWriteMemory) {
auto mockAubManager = std::make_unique<MockAubManager>();
auto *aubManager = mockAubManager.get();
auto memoryOperationsInterface = getMemoryOperationsHandler();
memoryOperationsInterface->setAubManager(aubManager);
auto executionEnvironment = std::unique_ptr<ExecutionEnvironment>(MockDevice::prepareExecutionEnvironment(defaultHwInfo.get(), 0u));
executionEnvironment->rootDeviceEnvironments[0]->initGmm();
executionEnvironment->rootDeviceEnvironments[0]->setHwInfoAndInitHelpers(&hardwareInfo);
executionEnvironment->initializeMemoryManager();
auto mockAubCenter = std::make_unique<MockAubCenter>();
mockAubCenter->aubManager.reset(mockAubManager.release());
executionEnvironment->rootDeviceEnvironments[0]->aubCenter.reset(mockAubCenter.release());
auto csr = std::make_unique<MockAubCsr<FamilyType>>("", true, *executionEnvironment, device->getRootDeviceIndex(), device->deviceBitfield);
auto osContext = executionEnvironment->memoryManager->createAndRegisterOsContext(csr.get(), EngineDescriptorHelper::getDefaultDescriptor());
csr->setupContext(*osContext);
MemoryAllocation allocation(0, AllocationType::unknown, nullptr, reinterpret_cast<void *>(0x1000), 0x1000u,
MemoryConstants::pageSize, 0, MemoryPool::system4KBPages, false, false, MemoryManager::maxOsContextCount);
allocPtr = &allocation;
allocPtr->storageInfo.cloningOfPageTables = false;
auto result = memoryOperationsInterface->makeResident(device.get(), ArrayRef<GraphicsAllocation *>(&allocPtr, 1));
EXPECT_EQ(result, MemoryOperationsStatus::success);
EXPECT_TRUE(aubManager.writeMemory2Called);
EXPECT_TRUE(aubManager->writeMemory2Called);
aubManager.writeMemory2Called = false;
aubManager->writeMemory2Called = false;
memoryOperationsInterface->processFlushResidency(device.get());
EXPECT_TRUE(aubManager.writeMemory2Called);
memoryOperationsInterface->processFlushResidency(csr.get());
EXPECT_TRUE(aubManager->writeMemory2Called);
}
TEST_F(AubMemoryOperationsHandlerTests, givenLocalGfxAllocationWriteableWhenProcessingFlushResidencyThenPerformAllocationDefaultCsrWriteMemory) {
HWTEST_F(AubMemoryOperationsHandlerTests, givenLocalGfxAllocationWriteableWhenProcessingFlushResidencyThenPerformAllocationDefaultCsrWriteMemory) {
auto mockAubManager = std::make_unique<MockAubManager>();
auto *aubManager = mockAubManager.get();
auto memoryOperationsInterface = getMemoryOperationsHandler();
memoryOperationsInterface->setAubManager(aubManager);
auto executionEnvironment = std::unique_ptr<ExecutionEnvironment>(MockDevice::prepareExecutionEnvironment(defaultHwInfo.get(), 0u));
executionEnvironment->rootDeviceEnvironments[0]->initGmm();
executionEnvironment->rootDeviceEnvironments[0]->setHwInfoAndInitHelpers(&hardwareInfo);
executionEnvironment->initializeMemoryManager();
auto mockAubCenter = std::make_unique<MockAubCenter>();
mockAubCenter->aubManager.reset(mockAubManager.release());
executionEnvironment->rootDeviceEnvironments[0]->aubCenter.reset(mockAubCenter.release());
auto csr = std::make_unique<MockAubCsr<FamilyType>>("", true, *executionEnvironment, device->getRootDeviceIndex(), device->deviceBitfield);
auto osContext = executionEnvironment->memoryManager->createAndRegisterOsContext(csr.get(), EngineDescriptorHelper::getDefaultDescriptor());
csr->setupContext(*osContext);
csr->localMemoryEnabled = true;
MemoryAllocation allocation(0, AllocationType::unknown, nullptr, reinterpret_cast<void *>(0x1000), 0x1000u,
MemoryConstants::pageSize, 0, MemoryPool::localMemory, false, false, MemoryManager::maxOsContextCount);
allocPtr = &allocation;
allocPtr->storageInfo.cloningOfPageTables = false;
DeviceBitfield deviceBitfield(1);
const auto csr = std::make_unique<MockCommandStreamReceiver>(*device->getExecutionEnvironment(), 0, deviceBitfield);
csr->localMemoryEnabled = true;
auto backupDefaultCsr = std::make_unique<VariableBackup<NEO::CommandStreamReceiver *>>(&device->getDefaultEngine().commandStreamReceiver);
device->getDefaultEngine().commandStreamReceiver = csr.get();
MockAubManager aubManager;
getMemoryOperationsHandler()->setAubManager(&aubManager);
auto memoryOperationsInterface = getMemoryOperationsHandler();
auto result = memoryOperationsInterface->makeResident(device.get(), ArrayRef<GraphicsAllocation *>(&allocPtr, 1));
EXPECT_EQ(result, MemoryOperationsStatus::success);
EXPECT_FALSE(aubManager.writeMemory2Called);
EXPECT_EQ(1u, csr->writeMemoryAubCalled);
EXPECT_FALSE(aubManager->writeMemory2Called);
memoryOperationsInterface->processFlushResidency(device.get());
EXPECT_FALSE(aubManager.writeMemory2Called);
EXPECT_EQ(2u, csr->writeMemoryAubCalled);
auto mockHwContext0 = static_cast<MockHardwareContext *>(csr->hardwareContextController->hardwareContexts[0].get());
EXPECT_TRUE(mockHwContext0->writeMemory2Called);
mockHwContext0->writeMemory2Called = false;
memoryOperationsInterface->processFlushResidency(csr.get());
EXPECT_FALSE(aubManager->writeMemory2Called);
EXPECT_TRUE(mockHwContext0->writeMemory2Called);
}
TEST_F(AubMemoryOperationsHandlerTests, givenGfxAllocationWriteableWithGmmPresentWhenProcessingFlushResidencyThenPerformAllocationWriteMemoryAndReflectGmmFlags) {
MockAubManager aubManager;
getMemoryOperationsHandler()->setAubManager(&aubManager);
HWTEST_F(AubMemoryOperationsHandlerTests, givenGfxAllocationWriteableWithGmmPresentWhenProcessingFlushResidencyThenPerformAllocationWriteMemoryAndReflectGmmFlags) {
auto mockAubManager = std::make_unique<MockAubManager>();
auto *aubManager = mockAubManager.get();
getMemoryOperationsHandler()->setAubManager(aubManager);
auto memoryOperationsInterface = getMemoryOperationsHandler();
allocPtr->storageInfo.cloningOfPageTables = true;
auto executionEnvironment = std::unique_ptr<ExecutionEnvironment>(MockDevice::prepareExecutionEnvironment(defaultHwInfo.get(), 0u));
executionEnvironment->rootDeviceEnvironments[0]->initGmm();
executionEnvironment->rootDeviceEnvironments[0]->setHwInfoAndInitHelpers(&hardwareInfo);
executionEnvironment->initializeMemoryManager();
MockGmm gmm(executionEnvironment->rootDeviceEnvironments[0]->getGmmHelper());
gmm.setCompressionEnabled(true);
allocPtr->setDefaultGmm(&gmm);
auto mockAubCenter = std::make_unique<MockAubCenter>();
mockAubCenter->aubManager.reset(mockAubManager.release());
executionEnvironment->rootDeviceEnvironments[0]->aubCenter.reset(mockAubCenter.release());
auto result = memoryOperationsInterface->makeResident(device.get(), ArrayRef<GraphicsAllocation *>(&allocPtr, 1));
EXPECT_EQ(result, MemoryOperationsStatus::success);
aubManager.writeMemory2Called = false;
aubManager.storeAllocationParams = true;
aubManager->writeMemory2Called = false;
aubManager->storeAllocationParams = true;
memoryOperationsInterface->processFlushResidency(device.get());
EXPECT_TRUE(aubManager.writeMemory2Called);
EXPECT_EQ(1u, aubManager.storedAllocationParams.size());
EXPECT_TRUE(aubManager.storedAllocationParams[0].additionalParams.compressionEnabled);
EXPECT_FALSE(aubManager.storedAllocationParams[0].additionalParams.uncached);
auto csr = std::make_unique<MockAubCsr<FamilyType>>("", true, *executionEnvironment, device->getRootDeviceIndex(), device->deviceBitfield);
auto osContext = executionEnvironment->memoryManager->createAndRegisterOsContext(csr.get(), EngineDescriptorHelper::getDefaultDescriptor());
csr->setupContext(*osContext);
memoryOperationsInterface->processFlushResidency(csr.get());
EXPECT_TRUE(aubManager->writeMemory2Called);
EXPECT_EQ(1u, aubManager->storedAllocationParams.size());
EXPECT_TRUE(aubManager->storedAllocationParams[0].additionalParams.compressionEnabled);
EXPECT_FALSE(aubManager->storedAllocationParams[0].additionalParams.uncached);
}
TEST_F(AubMemoryOperationsHandlerTests, givenDeviceNullWhenProcessingFlushResidencyThenAllocationIsNotWriteable) {
@@ -533,6 +589,8 @@ TEST_F(AubMemoryOperationsHandlerTests, givenDeviceNullWhenProcessingFlushReside
aubManager.writeMemory2Called = false;
memoryOperationsInterface->processFlushResidency(nullptr);
auto csr = std::make_unique<MockCommandStreamReceiver>(*device->getExecutionEnvironment(), 0, device->deviceBitfield);
memoryOperationsInterface->processFlushResidency(csr.get());
EXPECT_FALSE(aubManager.writeMemory2Called);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2019-2023 Intel Corporation
* Copyright (C) 2019-2024 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -36,7 +36,7 @@ class AubMemoryOperationsHandlerTests : public ::testing::Test {
return residencyHandler.get();
}
MockGraphicsAllocation allocation;
MockGraphicsAllocation allocation{reinterpret_cast<void *>(0x1000), 0x1000u, MemoryConstants::pageSize};
GraphicsAllocation *allocPtr;
DebugManagerStateRestore dbgRestore;
HardwareInfo hardwareInfo = {};