Revert "feature: Implement appendMemoryPrefetch for Shared System USM Allocat...

This reverts commit 97799b3faf.

Signed-off-by: Compute-Runtime-Validation <compute-runtime-validation@intel.com>
This commit is contained in:
Compute-Runtime-Validation
2025-03-12 05:18:52 +01:00
committed by Compute-Runtime-Automation
parent 0d5baa2c30
commit fa2e3adad3
29 changed files with 128 additions and 568 deletions

View File

@@ -218,12 +218,6 @@ class MockMemoryManager : public MemoryManagerCreate<OsAgnosticMemoryManager> {
return MemoryManager::setMemPrefetch(gfxAllocation, subDeviceIds, rootDeviceIndex);
}
bool prefetchSharedSystemAlloc(const void *ptr, const size_t size, SubDeviceIdsVec &subDeviceIds, uint32_t rootDeviceIndex) override {
memPrefetchSubDeviceIds = subDeviceIds;
prefetchSharedSystemAllocCalled = true;
return MemoryManager::prefetchSharedSystemAlloc(ptr, size, subDeviceIds, rootDeviceIndex);
}
bool hasPageFaultsEnabled(const Device &neoDevice) override;
bool isKmdMigrationAvailable(uint32_t rootDeviceIndex) override;
@@ -336,7 +330,6 @@ class MockMemoryManager : public MemoryManagerCreate<OsAgnosticMemoryManager> {
bool failLockResource = false;
bool failSetMemAdvise = false;
bool setMemPrefetchCalled = false;
bool prefetchSharedSystemAllocCalled = false;
bool cpuCopyRequired = false;
bool forceCompressed = false;
bool forceFailureInPrimaryAllocation = false;

View File

@@ -25,8 +25,8 @@ struct MockSVMAllocsManager : public SVMAllocsManager {
using SVMAllocsManager::usmDeviceAllocationsCache;
using SVMAllocsManager::usmHostAllocationsCache;
void prefetchMemory(Device &device, CommandStreamReceiver &commandStreamReceiver, const void *ptr, const size_t size) override {
SVMAllocsManager::prefetchMemory(device, commandStreamReceiver, ptr, size);
void prefetchMemory(Device &device, CommandStreamReceiver &commandStreamReceiver, SvmAllocationData &svmData) override {
SVMAllocsManager::prefetchMemory(device, commandStreamReceiver, svmData);
prefetchMemoryCalled = true;
}
bool prefetchMemoryCalled = false;

View File

@@ -6,7 +6,6 @@
*/
#include "shared/source/memory_manager/prefetch_manager.h"
#include "shared/source/unified_memory/usm_memory_support.h"
#include "shared/test/common/helpers/debug_manager_state_restore.h"
#include "shared/test/common/memory_manager/mock_prefetch_manager.h"
#include "shared/test/common/mocks/mock_command_stream_receiver.h"
@@ -28,74 +27,24 @@ TEST(PrefetchManagerTests, givenPrefetchManagerWhenCallingInterfaceFunctionsThen
auto prefetchManager = std::make_unique<MockPrefetchManager>();
PrefetchContext prefetchContext;
DebugManagerStateRestore restore;
SVMAllocsManager::UnifiedMemoryProperties unifiedMemoryProperties(InternalMemoryType::sharedUnifiedMemory, 1, rootDeviceIndices, deviceBitfields);
auto ptr = svmManager->createSharedUnifiedMemoryAllocation(4096u, unifiedMemoryProperties, nullptr);
ASSERT_NE(nullptr, ptr);
auto ptr2 = malloc(1024);
auto &hwInfo = *device->getRootDeviceEnvironment().getMutableHardwareInfo();
VariableBackup<uint64_t> sharedSystemMemCapabilities{&hwInfo.capabilityTable.sharedSystemMemCapabilities};
sharedSystemMemCapabilities = UnifiedSharedMemoryFlags::access | UnifiedSharedMemoryFlags::sharedSystemPageFaultEnabled;
auto svmData = svmManager->getSVMAlloc(ptr);
ASSERT_NE(nullptr, svmData);
EXPECT_EQ(0u, prefetchContext.allocations.size());
prefetchManager->insertAllocation(prefetchContext, *svmManager.get(), *device, ptr, 4096);
prefetchManager->insertAllocation(prefetchContext, ptr, *svmData);
EXPECT_EQ(1u, prefetchContext.allocations.size());
debugManager.flags.EnableRecoverablePageFaults.set(0);
prefetchManager->insertAllocation(prefetchContext, *svmManager.get(), *device, ptr2, 1024);
EXPECT_EQ(1u, prefetchContext.allocations.size());
debugManager.flags.EnableRecoverablePageFaults.set(1);
prefetchManager->insertAllocation(prefetchContext, *svmManager.get(), *device, ptr2, 1024);
EXPECT_EQ(2u, prefetchContext.allocations.size());
prefetchManager->migrateAllocationsToGpu(prefetchContext, *svmManager.get(), *device, *csr.get());
EXPECT_EQ(2u, prefetchContext.allocations.size());
EXPECT_EQ(1u, prefetchContext.allocations.size());
prefetchManager->removeAllocations(prefetchContext);
EXPECT_EQ(0u, prefetchContext.allocations.size());
svmManager->freeSVMAlloc(ptr);
free(ptr2);
}
TEST(PrefetchManagerTests, givenPrefetchManagerWhenCallingInterfaceFunctionsThenNoUpdateAllocationsInPrefetchContextForInvalidAllocations) {
std::unique_ptr<UltDeviceFactory> deviceFactory(new UltDeviceFactory(1, 1));
RootDeviceIndicesContainer rootDeviceIndices = {mockRootDeviceIndex};
std::map<uint32_t, DeviceBitfield> deviceBitfields{{mockRootDeviceIndex, mockDeviceBitfield}};
auto device = deviceFactory->rootDevices[0];
auto csr = std::make_unique<MockCommandStreamReceiver>(*device->getExecutionEnvironment(), device->getRootDeviceIndex(), device->getDeviceBitfield());
auto svmManager = std::make_unique<MockSVMAllocsManager>(device->getMemoryManager(), false);
auto prefetchManager = std::make_unique<MockPrefetchManager>();
PrefetchContext prefetchContext;
DebugManagerStateRestore restore;
SVMAllocsManager::UnifiedMemoryProperties unifiedMemoryProperties(InternalMemoryType::sharedUnifiedMemory, 1, rootDeviceIndices, deviceBitfields);
auto ptr = svmManager->createSharedUnifiedMemoryAllocation(4096u, unifiedMemoryProperties, nullptr);
ASSERT_NE(nullptr, ptr);
auto svmData = svmManager->getSVMAlloc(ptr);
svmData->memoryType = InternalMemoryType::deviceUnifiedMemory;
ASSERT_NE(nullptr, svmData);
EXPECT_EQ(0u, prefetchContext.allocations.size());
prefetchManager->insertAllocation(prefetchContext, *svmManager.get(), *device, ptr, 4096);
EXPECT_EQ(0u, prefetchContext.allocations.size());
prefetchManager->migrateAllocationsToGpu(prefetchContext, *svmManager.get(), *device, *csr.get());
EXPECT_EQ(0u, prefetchContext.allocations.size());
svmManager->freeSVMAlloc(ptr);
}
@@ -119,7 +68,7 @@ TEST(PrefetchManagerTests, givenPrefetchManagerWhenCallingMigrateAllocationsToGp
auto svmData = svmManager->getSVMAlloc(ptr);
ASSERT_NE(nullptr, svmData);
prefetchManager->insertAllocation(prefetchContext, *svmManager.get(), *device, ptr, 4096);
prefetchManager->insertAllocation(prefetchContext, ptr, *svmData);
EXPECT_FALSE(prefetchManager->migrateAllocationsToGpuCalled);
EXPECT_FALSE(svmManager->prefetchMemoryCalled);
@@ -129,4 +78,11 @@ TEST(PrefetchManagerTests, givenPrefetchManagerWhenCallingMigrateAllocationsToGp
EXPECT_TRUE(svmManager->prefetchMemoryCalled);
svmManager->freeSVMAlloc(ptr);
prefetchManager->migrateAllocationsToGpuCalled = false;
svmManager->prefetchMemoryCalled = false;
prefetchManager->migrateAllocationsToGpu(prefetchContext, *svmManager.get(), *device, *csr.get());
EXPECT_TRUE(prefetchManager->migrateAllocationsToGpuCalled);
EXPECT_FALSE(svmManager->prefetchMemoryCalled);
}

View File

@@ -7,7 +7,6 @@
#include "shared/source/helpers/aligned_memory.h"
#include "shared/source/helpers/gfx_core_helper.h"
#include "shared/source/unified_memory/usm_memory_support.h"
#include "shared/test/common/helpers/debug_manager_state_restore.h"
#include "shared/test/common/mocks/mock_command_stream_receiver.h"
#include "shared/test/common/mocks/mock_device.h"
@@ -257,8 +256,10 @@ TEST_F(SVMLocalMemoryAllocatorTest, givenKmdMigratedSharedAllocationWhenPrefetch
auto ptr = svmManager->createSharedUnifiedMemoryAllocation(4096, unifiedMemoryProperties, &cmdQ);
EXPECT_NE(nullptr, ptr);
auto svmData = svmManager->getSVMAlloc(ptr);
csr->setActivePartitions(2);
svmManager->prefetchMemory(*device, *csr, ptr, 4096);
svmManager->prefetchMemory(*device, *csr, *svmData);
auto mockMemoryManager = static_cast<MockMemoryManager *>(device->getMemoryManager());
EXPECT_TRUE(mockMemoryManager->setMemPrefetchCalled);
@@ -271,107 +272,34 @@ TEST_F(SVMLocalMemoryAllocatorTest, givenKmdMigratedSharedAllocationWhenPrefetch
svmManager->freeSVMAlloc(ptr);
}
TEST_F(SVMLocalMemoryAllocatorTest, givenNonKmdMigratedSharedAllocationWhenPrefetchMemoryIsCalledThenSetMemPrefetchNotCalled) {
DebugManagerStateRestore restore;
debugManager.flags.UseKmdMigration.set(0);
std::unique_ptr<UltDeviceFactory> deviceFactory(new UltDeviceFactory(1, 2));
auto device = deviceFactory->rootDevices[0];
auto svmManager = std::make_unique<MockSVMAllocsManager>(device->getMemoryManager(), false);
auto csr = std::make_unique<MockCommandStreamReceiver>(*device->getExecutionEnvironment(), device->getRootDeviceIndex(), device->getDeviceBitfield());
csr->setupContext(*device->getDefaultEngine().osContext);
void *cmdQ = reinterpret_cast<void *>(0x12345);
SVMAllocsManager::UnifiedMemoryProperties unifiedMemoryProperties(InternalMemoryType::sharedUnifiedMemory, 1, rootDeviceIndices, deviceBitfields);
auto ptr = svmManager->createSharedUnifiedMemoryAllocation(4096, unifiedMemoryProperties, &cmdQ);
EXPECT_NE(nullptr, ptr);
csr->setActivePartitions(2);
svmManager->prefetchMemory(*device, *csr, ptr, 4096);
auto mockMemoryManager = static_cast<MockMemoryManager *>(device->getMemoryManager());
EXPECT_FALSE(mockMemoryManager->setMemPrefetchCalled);
EXPECT_EQ(0u, mockMemoryManager->memPrefetchSubDeviceIds.size());
svmManager->freeSVMAlloc(ptr);
}
TEST_F(SVMLocalMemoryAllocatorTest, givenNonSharedUnifiedMemoryAllocationWhenPrefetchMemoryIsCalledThenSetMemPrefetchNotCalled) {
TEST_F(SVMLocalMemoryAllocatorTest, givenEnableBOChunkingPrefetchWhenPrefetchMemoryIsCalledThenSetMemPrefetchCalled) {
DebugManagerStateRestore restore;
debugManager.flags.UseKmdMigration.set(1);
debugManager.flags.EnableBOChunkingDevMemPrefetch.set(true);
std::unique_ptr<UltDeviceFactory> deviceFactory(new UltDeviceFactory(1, 2));
auto device = deviceFactory->rootDevices[0];
auto svmManager = std::make_unique<MockSVMAllocsManager>(device->getMemoryManager(), false);
auto csr = std::make_unique<MockCommandStreamReceiver>(*device->getExecutionEnvironment(), device->getRootDeviceIndex(), device->getDeviceBitfield());
csr->setupContext(*device->getDefaultEngine().osContext);
void *cmdQ = reinterpret_cast<void *>(0x12345);
SVMAllocsManager::UnifiedMemoryProperties unifiedMemoryProperties(InternalMemoryType::sharedUnifiedMemory, 1, rootDeviceIndices, deviceBitfields);
SVMAllocsManager::UnifiedMemoryProperties unifiedMemoryProperties(InternalMemoryType::deviceUnifiedMemory, 1, rootDeviceIndices, deviceBitfields);
unifiedMemoryProperties.device = device;
auto ptr = svmManager->createSharedUnifiedMemoryAllocation(4096, unifiedMemoryProperties, &cmdQ);
auto ptr = svmManager->createUnifiedMemoryAllocation(4096, unifiedMemoryProperties);
EXPECT_NE(nullptr, ptr);
auto svmData = svmManager->getSVMAlloc(ptr);
svmData->memoryType = InternalMemoryType::deviceUnifiedMemory;
csr->setActivePartitions(2);
svmManager->prefetchMemory(*device, *csr, ptr, 4096);
svmManager->prefetchMemory(*device, *csr, *svmData);
auto mockMemoryManager = static_cast<MockMemoryManager *>(device->getMemoryManager());
EXPECT_FALSE(mockMemoryManager->setMemPrefetchCalled);
EXPECT_EQ(0u, mockMemoryManager->memPrefetchSubDeviceIds.size());
EXPECT_TRUE(mockMemoryManager->setMemPrefetchCalled);
svmManager->freeSVMAlloc(ptr);
}
TEST_F(SVMLocalMemoryAllocatorTest, givenSharedSystemAllocationWhenPrefetchMemoryIsCalledThenPrefetchAllocationToSystemMemory) {
DebugManagerStateRestore restore;
std::unique_ptr<UltDeviceFactory> deviceFactory(new UltDeviceFactory(1, 2));
auto device = deviceFactory->rootDevices[0];
auto svmManager = std::make_unique<MockSVMAllocsManager>(device->getMemoryManager(), false);
auto csr = std::make_unique<MockCommandStreamReceiver>(*device->getExecutionEnvironment(), device->getRootDeviceIndex(), device->getDeviceBitfield());
auto &hwInfo = *device->getRootDeviceEnvironment().getMutableHardwareInfo();
VariableBackup<uint64_t> sharedSystemMemCapabilities{&hwInfo.capabilityTable.sharedSystemMemCapabilities};
sharedSystemMemCapabilities = UnifiedSharedMemoryFlags::access | UnifiedSharedMemoryFlags::sharedSystemPageFaultEnabled;
csr->setupContext(*device->getDefaultEngine().osContext);
auto ptr = malloc(4096);
EXPECT_NE(nullptr, ptr);
svmManager->prefetchMemory(*device, *csr, ptr, 4096);
auto mockMemoryManager = static_cast<MockMemoryManager *>(device->getMemoryManager());
EXPECT_TRUE(mockMemoryManager->prefetchSharedSystemAllocCalled);
free(ptr);
}
TEST_F(SVMLocalMemoryAllocatorTest, givenSharedSystemAllocationWhenPrefetchMemoryIsCalledAndNotEnabledThenNoPrefetchAllocationToSystemMemory) {
DebugManagerStateRestore restore;
debugManager.flags.EnableSharedSystemUsmSupport.set(0);
std::unique_ptr<UltDeviceFactory> deviceFactory(new UltDeviceFactory(1, 2));
auto device = deviceFactory->rootDevices[0];
auto svmManager = std::make_unique<MockSVMAllocsManager>(device->getMemoryManager(), false);
auto csr = std::make_unique<MockCommandStreamReceiver>(*device->getExecutionEnvironment(), device->getRootDeviceIndex(), device->getDeviceBitfield());
csr->setupContext(*device->getDefaultEngine().osContext);
auto ptr = malloc(4096);
EXPECT_NE(nullptr, ptr);
svmManager->prefetchMemory(*device, *csr, ptr, 4096);
auto mockMemoryManager = static_cast<MockMemoryManager *>(device->getMemoryManager());
EXPECT_FALSE(mockMemoryManager->prefetchSharedSystemAllocCalled);
free(ptr);
}
TEST_F(SVMLocalMemoryAllocatorTest, givenForceMemoryPrefetchForKmdMigratedSharedAllocationsWhenSVMAllocsIsCalledThenPrefetchSharedUnifiedMemoryInSvmAllocsManager) {
DebugManagerStateRestore restore;
debugManager.flags.UseKmdMigration.set(1);

View File

@@ -5966,50 +5966,6 @@ TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerWhenSetMemPrefetchFailsToBindB
EXPECT_FALSE(drmAllocation.prefetchBOCalled);
}
TEST_F(DrmMemoryManagerTest, givenPrefetchSharedSystemAllocIsCalledThenReturnTrue) {
SubDeviceIdsVec subDeviceIds{0};
class MyMockIoctlHelper : public MockIoctlHelper {
public:
using MockIoctlHelper::MockIoctlHelper;
bool setVmPrefetch(uint64_t start, uint64_t length, uint32_t region, uint32_t vmId) override {
return true;
}
};
auto mockIoctlHelper = new MyMockIoctlHelper(*mock);
auto &drm = static_cast<DrmMockCustom &>(memoryManager->getDrm(mockRootDeviceIndex));
drm.ioctlHelper.reset(mockIoctlHelper);
auto ptr = malloc(1024);
EXPECT_TRUE(memoryManager->prefetchSharedSystemAlloc(ptr, 1024, subDeviceIds, rootDeviceIndex));
free(ptr);
}
TEST_F(DrmMemoryManagerTest, givenPrefetchSharedSystemAllocIsCalledThenReturnFalse) {
SubDeviceIdsVec subDeviceIds{0};
class MyMockIoctlHelper : public MockIoctlHelper {
public:
using MockIoctlHelper::MockIoctlHelper;
bool setVmPrefetch(uint64_t start, uint64_t length, uint32_t region, uint32_t vmId) override {
return false;
}
};
auto mockIoctlHelper = new MyMockIoctlHelper(*mock);
auto &drm = static_cast<DrmMockCustom &>(memoryManager->getDrm(mockRootDeviceIndex));
drm.ioctlHelper.reset(mockIoctlHelper);
auto ptr = malloc(1024);
EXPECT_TRUE(memoryManager->prefetchSharedSystemAlloc(ptr, 1024, subDeviceIds, rootDeviceIndex));
free(ptr);
}
TEST_F(DrmMemoryManagerTest, givenPageFaultIsUnSupportedWhenCallingBindBoOnBufferAllocationThenAllocationShouldNotPageFaultAndExplicitResidencyIsNotRequired) {
auto executionEnvironment = std::make_unique<MockExecutionEnvironment>();
executionEnvironment->rootDeviceEnvironments[0]->initGmm();

View File

@@ -2464,10 +2464,8 @@ TEST_F(IoctlHelperXeTest, givenIoctlHelperXeWhenCallingSetVmPrefetchThenVmBindIs
MemoryClassInstance targetMemoryRegion = memoryInfo->getLocalMemoryRegions()[subDeviceId].region;
ASSERT_NE(nullptr, memoryInfo);
drm->memoryInfo.reset(memoryInfo.release());
int memoryClassDevice = static_cast<int>(DrmParam::memoryClassDevice);
uint32_t region = (memoryClassDevice << 16u) | subDeviceId;
EXPECT_TRUE(xeIoctlHelper->setVmPrefetch(start, length, region, vmId));
EXPECT_TRUE(xeIoctlHelper->setVmPrefetch(start, length, subDeviceId, vmId));
EXPECT_EQ(1u, drm->vmBindInputs.size());
EXPECT_EQ(drm->vmBindInputs[0].vm_id, vmId);
@@ -2495,10 +2493,7 @@ TEST_F(IoctlHelperXeTest, givenIoctlHelperXeWhenCallingSetVmPrefetchOnSecondTile
ASSERT_NE(nullptr, memoryInfo);
drm->memoryInfo.reset(memoryInfo.release());
int memoryClassDevice = static_cast<int>(DrmParam::memoryClassDevice);
uint32_t region = (memoryClassDevice << 16u) | subDeviceId;
EXPECT_TRUE(xeIoctlHelper->setVmPrefetch(start, length, region, vmId));
EXPECT_TRUE(xeIoctlHelper->setVmPrefetch(start, length, subDeviceId, vmId));
EXPECT_EQ(1u, drm->vmBindInputs.size());
EXPECT_EQ(drm->vmBindInputs[0].vm_id, vmId);
@@ -2644,7 +2639,6 @@ TEST_F(IoctlHelperXeTest, whenQueryDeviceIdAndRevisionConfigFlagHasGpuAddrMirror
EXPECT_TRUE(IoctlHelperXe::queryDeviceIdAndRevision(*drm));
EXPECT_TRUE(drm->isSharedSystemAllocEnabled());
EXPECT_TRUE(drm->hasPageFaultSupport());
}
TEST_F(IoctlHelperXeTest, whenQueryDeviceIdAndRevisionAndConfigFlagHasGpuAddrMirrorClearThenSharedSystemAllocEnableFalse) {
@@ -2676,7 +2670,7 @@ TEST_F(IoctlHelperXeTest, whenQueryDeviceIdAndRevisionAndSharedSystemUsmSupportD
MockExecutionEnvironment executionEnvironment{};
std::unique_ptr<Drm> drm{Drm::create(std::make_unique<HwDeviceIdDrm>(0, ""), *executionEnvironment.rootDeviceEnvironments[0])};
DebugManagerStateRestore restore;
debugManager.flags.EnableRecoverablePageFaults.set(0);
debugManager.flags.EnableSharedSystemUsmSupport.set(0);
mockIoctl = [](int fileDescriptor, unsigned long int request, void *arg) -> int {
if (request == DRM_IOCTL_XE_DEVICE_QUERY) {
struct drm_xe_device_query *deviceQuery = static_cast<struct drm_xe_device_query *>(arg);
@@ -2696,7 +2690,6 @@ TEST_F(IoctlHelperXeTest, whenQueryDeviceIdAndRevisionAndSharedSystemUsmSupportD
EXPECT_TRUE(IoctlHelperXe::queryDeviceIdAndRevision(*drm));
EXPECT_FALSE(drm->isSharedSystemAllocEnabled());
EXPECT_FALSE(drm->hasPageFaultSupport());
}
TEST_F(IoctlHelperXeTest, givenXeIoctlHelperAndDeferBackingFlagSetToTrueWhenMakeResidentBeforeLockNeededIsCalledThenVerifyTrueIsReturned) {