feature: KMD migration on access counters with no preferred location

Set no preference for KMD migrated shared allocation and rely on ACC to migrate.

Related-To: NEO-6839

Signed-off-by: Milczarek, Slawomir <slawomir.milczarek@intel.com>
This commit is contained in:
Milczarek, Slawomir
2023-06-16 04:47:01 +00:00
committed by Compute-Runtime-Automation
parent 7aff4e1bf4
commit f189f425ce
4 changed files with 100 additions and 7 deletions

View File

@@ -764,6 +764,97 @@ TEST_F(DrmMemoryManagerLocalMemoryPrelimTest, givenKmdMigratedSharedAllocationWh
unifiedMemoryManager.freeSVMAlloc(ptr);
}
TEST_F(DrmMemoryManagerLocalMemoryPrelimTest, givenCreateContextWithAccessCountersWhenCreatingKmdMigratedSharedAllocationThenDontSetPreferredLocation) {
DebugManagerStateRestore restorer;
DebugManager.flags.UseKmdMigration.set(1);
DebugManager.flags.CreateContextWithAccessCounters.set(1);
RootDeviceIndicesContainer rootDeviceIndices = {mockRootDeviceIndex};
std::map<uint32_t, DeviceBitfield> deviceBitfields{{mockRootDeviceIndex, mockDeviceBitfield}};
std::vector<MemoryRegion> regionInfo(2);
regionInfo[0].region = {drm_i915_gem_memory_class::I915_MEMORY_CLASS_SYSTEM, 0};
regionInfo[1].region = {drm_i915_gem_memory_class::I915_MEMORY_CLASS_DEVICE, DrmMockHelper::getEngineOrMemoryInstanceValue(0, 0)};
mock->memoryInfo.reset(new MemoryInfo(regionInfo, *mock));
mock->queryEngineInfo();
SVMAllocsManager unifiedMemoryManager(memoryManager, false);
SVMAllocsManager::UnifiedMemoryProperties unifiedMemoryProperties(InternalMemoryType::SHARED_UNIFIED_MEMORY, 1, rootDeviceIndices, deviceBitfields);
unifiedMemoryProperties.device = device.get();
auto ptr = unifiedMemoryManager.createSharedUnifiedMemoryAllocation(MemoryConstants::pageSize64k, unifiedMemoryProperties, nullptr);
ASSERT_NE(ptr, nullptr);
auto allocation = unifiedMemoryManager.getSVMAlloc(ptr)->gpuAllocations.getDefaultGraphicsAllocation();
ASSERT_NE(allocation, nullptr);
const auto &createExt = mock->context.receivedCreateGemExt.value();
EXPECT_EQ(1u, createExt.handle);
const auto &memRegions = createExt.memoryRegions;
ASSERT_EQ(memRegions.size(), 2u);
EXPECT_EQ(memRegions[0].memoryClass, drm_i915_gem_memory_class::I915_MEMORY_CLASS_SYSTEM);
EXPECT_EQ(memRegions[0].memoryInstance, 0u);
EXPECT_EQ(memRegions[1].memoryClass, drm_i915_gem_memory_class::I915_MEMORY_CLASS_DEVICE);
EXPECT_EQ(memRegions[1].memoryInstance, regionInfo[1].region.memoryInstance);
ASSERT_EQ(mock->context.receivedVmAdvise[1], std::nullopt);
unifiedMemoryManager.freeSVMAlloc(ptr);
}
TEST_F(DrmMemoryManagerLocalMemoryPrelimTest, givenCreateContextWithAccessCountersButOverridenWithSetVmAdvisePreferredLocationWhenCreatingKmdMigratedSharedAllocationThenSetPreferredLocation) {
DebugManagerStateRestore restorer;
DebugManager.flags.UseKmdMigration.set(1);
DebugManager.flags.CreateContextWithAccessCounters.set(1);
DebugManager.flags.SetVmAdvisePreferredLocation.set(1);
RootDeviceIndicesContainer rootDeviceIndices = {mockRootDeviceIndex};
std::map<uint32_t, DeviceBitfield> deviceBitfields{{mockRootDeviceIndex, mockDeviceBitfield}};
std::vector<MemoryRegion> regionInfo(2);
regionInfo[0].region = {drm_i915_gem_memory_class::I915_MEMORY_CLASS_SYSTEM, 0};
regionInfo[1].region = {drm_i915_gem_memory_class::I915_MEMORY_CLASS_DEVICE, DrmMockHelper::getEngineOrMemoryInstanceValue(0, 0)};
mock->memoryInfo.reset(new MemoryInfo(regionInfo, *mock));
mock->queryEngineInfo();
SVMAllocsManager unifiedMemoryManager(memoryManager, false);
SVMAllocsManager::UnifiedMemoryProperties unifiedMemoryProperties(InternalMemoryType::SHARED_UNIFIED_MEMORY, 1, rootDeviceIndices, deviceBitfields);
unifiedMemoryProperties.device = device.get();
auto ptr = unifiedMemoryManager.createSharedUnifiedMemoryAllocation(MemoryConstants::pageSize64k, unifiedMemoryProperties, nullptr);
ASSERT_NE(ptr, nullptr);
auto allocation = unifiedMemoryManager.getSVMAlloc(ptr)->gpuAllocations.getDefaultGraphicsAllocation();
ASSERT_NE(allocation, nullptr);
const auto &createExt = mock->context.receivedCreateGemExt.value();
EXPECT_EQ(1u, createExt.handle);
const auto &memRegions = createExt.memoryRegions;
ASSERT_EQ(memRegions.size(), 2u);
EXPECT_EQ(memRegions[0].memoryClass, drm_i915_gem_memory_class::I915_MEMORY_CLASS_SYSTEM);
EXPECT_EQ(memRegions[0].memoryInstance, 0u);
EXPECT_EQ(memRegions[1].memoryClass, drm_i915_gem_memory_class::I915_MEMORY_CLASS_DEVICE);
EXPECT_EQ(memRegions[1].memoryInstance, regionInfo[1].region.memoryInstance);
ASSERT_NE(mock->context.receivedVmAdvise[1], std::nullopt);
const auto &vmAdvise = mock->context.receivedVmAdvise[1].value();
EXPECT_EQ(static_cast<DrmAllocation *>(allocation)->getBO()->peekHandle(), static_cast<int>(vmAdvise.handle));
EXPECT_EQ(DrmPrelimHelper::getPreferredLocationAdvise(), vmAdvise.flags);
EXPECT_EQ(drm_i915_gem_memory_class::I915_MEMORY_CLASS_DEVICE, vmAdvise.memoryRegions.memoryClass);
EXPECT_EQ(0u, vmAdvise.memoryRegions.memoryInstance);
unifiedMemoryManager.freeSVMAlloc(ptr);
}
TEST_F(DrmMemoryManagerLocalMemoryPrelimTest, givenUseKmdMigrationAndUsmInitialPlacementSetToGpuWhenCreateUnifiedSharedMemoryWithOverridenMultiStoragePlacementThenKmdMigratedAllocationIsCreatedWithCorrectRegionsOrder) {
DebugManagerStateRestore restorer;
DebugManager.flags.UseKmdMigration.set(1);

View File

@@ -102,7 +102,7 @@ TEST(DrmQueryTest, givenForceRunAloneContextFlagSetWhenCreateDrmContextThenRunAl
TEST(DrmQueryTest, givenCreateContextWithAccessCountersWhenDrmContextIsCreatedThenProgramAccessCountersWithDefaultGranularity) {
DebugManagerStateRestore restorer;
DebugManager.flags.CreateContextWithAccessCounters.set(0);
DebugManager.flags.CreateContextWithAccessCounters.set(1);
auto executionEnvironment = std::make_unique<MockExecutionEnvironment>();
DrmQueryMock drm{*executionEnvironment->rootDeviceEnvironments[0]};
@@ -141,7 +141,7 @@ TEST(DrmQueryTest, GivenDrmWhenAskedForContextThatFailsThenFalseIsReturned) {
TEST(DrmQueryTest, givenCreateContextWithAccessCounterWhenDrmContextIsCreatedThenProgramAccessCountersWithSpecifiedTriggeringThreshold) {
DebugManagerStateRestore restorer;
DebugManager.flags.CreateContextWithAccessCounters.set(0);
DebugManager.flags.CreateContextWithAccessCounters.set(1);
auto executionEnvironment = std::make_unique<MockExecutionEnvironment>();
DrmQueryMock drm{*executionEnvironment->rootDeviceEnvironments[0]};
@@ -175,7 +175,7 @@ TEST(DrmQueryTest, givenCreateContextWithAccessCounterWhenDrmContextIsCreatedThe
TEST(DrmQueryTest, givenCreateContextWithAccessCounterWhenDrmContextIsCreatedThenProgramAccessCountersWithSpecifiedGranularity) {
DebugManagerStateRestore restorer;
DebugManager.flags.CreateContextWithAccessCounters.set(0);
DebugManager.flags.CreateContextWithAccessCounters.set(1);
auto executionEnvironment = std::make_unique<MockExecutionEnvironment>();
DrmQueryMock drm{*executionEnvironment->rootDeviceEnvironments[0]};