Skip to content

Commit 049e77b

Browse files
Check if KMD migration is supported
Related-To: NEO-3312 Signed-off-by: Lukasz Jobczyk <[email protected]>
1 parent 320a404 commit 049e77b

File tree

10 files changed

+81
-11
lines changed

10 files changed

+81
-11
lines changed

opencl/test/unit_test/os_interface/linux/device_command_stream_fixture.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2017-2020 Intel Corporation
2+
* Copyright (C) 2017-2021 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -72,6 +72,7 @@ class DrmMockTime : public DrmMockSuccess {
7272

7373
class DrmMockCustom : public Drm {
7474
public:
75+
using Drm::bindAvailable;
7576
using Drm::memoryInfo;
7677

7778
struct IoctlResExt {

opencl/test/unit_test/os_interface/linux/drm_memory_manager_tests.cpp

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,53 @@ TEST_F(DrmMemoryManagerTest, givenDebugVariableWhenCreatingDrmMemoryManagerThenS
8080
}
8181
}
8282

83+
TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerWhenCheckForKmdMigrationThenCorrectValueIsReturned) {
84+
DebugManagerStateRestore restorer;
85+
auto drm = static_cast<DrmMockCustom *>(executionEnvironment->rootDeviceEnvironments[rootDeviceIndex]->osInterface->get()->getDrm());
86+
87+
{
88+
DebugManager.flags.UseKmdMigration.set(-1);
89+
90+
drm->bindAvailable = false;
91+
auto retVal = memoryManager->isKmdMigrationAvailable(rootDeviceIndex);
92+
93+
EXPECT_FALSE(retVal);
94+
95+
drm->bindAvailable = true;
96+
retVal = memoryManager->isKmdMigrationAvailable(rootDeviceIndex);
97+
98+
auto hwInfo = executionEnvironment->rootDeviceEnvironments[rootDeviceIndex]->getHardwareInfo();
99+
auto &hwHelper = NEO::HwHelper::get(hwInfo->platform.eRenderCoreFamily);
100+
EXPECT_EQ(hwHelper.isKmdMigrationSupported(*hwInfo), retVal);
101+
}
102+
{
103+
DebugManager.flags.UseKmdMigration.set(1);
104+
105+
drm->bindAvailable = false;
106+
auto retVal = memoryManager->isKmdMigrationAvailable(rootDeviceIndex);
107+
108+
EXPECT_TRUE(retVal);
109+
110+
drm->bindAvailable = true;
111+
retVal = memoryManager->isKmdMigrationAvailable(rootDeviceIndex);
112+
113+
EXPECT_TRUE(retVal);
114+
}
115+
{
116+
DebugManager.flags.UseKmdMigration.set(0);
117+
118+
drm->bindAvailable = false;
119+
auto retVal = memoryManager->isKmdMigrationAvailable(rootDeviceIndex);
120+
121+
EXPECT_FALSE(retVal);
122+
123+
drm->bindAvailable = true;
124+
retVal = memoryManager->isKmdMigrationAvailable(rootDeviceIndex);
125+
126+
EXPECT_FALSE(retVal);
127+
}
128+
}
129+
83130
TEST_F(DrmMemoryManagerTest, GivenGraphicsAllocationWhenAddAndRemoveAllocationToHostPtrManagerThenfragmentHasCorrectValues) {
84131
void *cpuPtr = (void *)0x30000;
85132
size_t size = 0x1000;

opencl/test/unit_test/test_files/igdrcl.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ AUBDumpAllocsOnEnqueueSVMMemcpyOnly = 0
2929
AUBDumpForceAllToLocalMemory = 0
3030
ForceDeviceId = unk
3131
ForceL1Caching = -1
32-
UseKmdMigration = -1
32+
UseKmdMigration = 0
3333
SchedulerSimulationReturnInstance = 0
3434
SchedulerGWS = 0
3535
EnableExperimentalCommandBuffer = 0

shared/source/debug_settings/debug_variables_base.inl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ DECLARE_DEBUG_VARIABLE(int32_t, OverrideThreadArbitrationPolicy, -1, "-1 (dont o
214214
DECLARE_DEBUG_VARIABLE(int32_t, OverrideAubDeviceId, -1, "-1 dont override, any other: use this value for AUB generation device id")
215215
DECLARE_DEBUG_VARIABLE(int32_t, EnableTimestampPacket, -1, "-1: default, 0: disable, 1:enable. Write Timestamp Packet for each set of gpu walkers")
216216
DECLARE_DEBUG_VARIABLE(int32_t, AllocateSharedAllocationsWithCpuAndGpuStorage, -1, "When enabled driver creates cpu & gpu storage for shared unified memory allocations. (-1 - devices default mode, 0 - disable, 1 - enable)")
217-
DECLARE_DEBUG_VARIABLE(int32_t, UseKmdMigration, -1, "-1: devices default mode (currently - disabled), 0: disable - pagefault handling by UMD using handler for SIGSEGV, 1: enable - pagefault handling by KMD, GEM objects migrated by KMD upon access)")
217+
DECLARE_DEBUG_VARIABLE(int32_t, UseKmdMigration, 0, "-1: devices default mode, 0: disable - pagefault handling by UMD using handler for SIGSEGV, 1: enable - pagefault handling by KMD, GEM objects migrated by KMD upon access)")
218218
DECLARE_DEBUG_VARIABLE(int32_t, ForceSemaphoreDelayBetweenWaits, -1, "Specifies the minimum number of microseconds allowed for command streamer to wait before re-fetching the data. 0 - poll interval will be equal to the memory latency of the read completion")
219219
DECLARE_DEBUG_VARIABLE(int32_t, ForceLocalMemoryAccessMode, -1, "-1: don't override, 0: default rules apply, 1: CPU can access local memory, 3: CPU never accesses local memory")
220220
DECLARE_DEBUG_VARIABLE(int32_t, ForceUserptrAlignment, -1, "-1: no force (4kb), >0: n kb alignment")

shared/source/helpers/hw_helper.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ class HwHelper {
129129
virtual bool isSipWANeeded(const HardwareInfo &hwInfo) const = 0;
130130
virtual bool additionalKernelExecInfoSupported(const HardwareInfo &hwInfo) const = 0;
131131
virtual bool isCpuImageTransferPreferred(const HardwareInfo &hwInfo) const = 0;
132+
virtual bool isKmdMigrationSupported(const HardwareInfo &hwInfo) const = 0;
132133

133134
static uint32_t getSubDevicesCount(const HardwareInfo *pHwInfo);
134135
static uint32_t getEnginesCount(const HardwareInfo &hwInfo);
@@ -318,6 +319,8 @@ class HwHelperHw : public HwHelper {
318319

319320
bool isMediaBlockIOSupported(const HardwareInfo &hwInfo) const override;
320321

322+
bool isKmdMigrationSupported(const HardwareInfo &hwInfo) const override;
323+
321324
bool isCopyOnlyEngineType(EngineGroupType type) const override;
322325

323326
void adjustAddressWidthForCanonize(uint32_t &addressWidth) const override;

shared/source/helpers/hw_helper_base.inl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,11 @@ bool HwHelperHw<GfxFamily>::isMediaBlockIOSupported(const HardwareInfo &hwInfo)
515515
return hwInfo.capabilityTable.supportsImages;
516516
}
517517

518+
template <typename GfxFamily>
519+
bool HwHelperHw<GfxFamily>::isKmdMigrationSupported(const HardwareInfo &hwInfo) const {
520+
return false;
521+
}
522+
518523
template <typename GfxFamily>
519524
bool HwHelperHw<GfxFamily>::isCopyOnlyEngineType(EngineGroupType type) const {
520525
return NEO::EngineGroupType::Copy == type;

shared/source/memory_manager/memory_manager.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ class MemoryManager {
145145
bool isLocalMemorySupported(uint32_t rootDeviceIndex) const;
146146
virtual bool isMemoryBudgetExhausted() const;
147147

148+
virtual bool isKmdMigrationAvailable(uint32_t rootDeviceIndex) { return false; }
149+
148150
virtual AlignedMallocRestrictions *getAlignedMallocRestrictions() {
149151
return nullptr;
150152
}

shared/source/memory_manager/unified_memory_manager.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -220,13 +220,9 @@ void *SVMAllocsManager::createSharedUnifiedMemoryAllocation(size_t size,
220220
}
221221

222222
if (supportDualStorageSharedMemory) {
223-
bool useKmdMigration = false;
224-
225-
if (DebugManager.flags.UseKmdMigration.get() != -1) {
226-
useKmdMigration = DebugManager.flags.UseKmdMigration.get();
227-
}
228-
223+
bool useKmdMigration = memoryManager->isKmdMigrationAvailable(*memoryProperties.rootDeviceIndices.begin());
229224
void *unifiedMemoryPointer = nullptr;
225+
230226
if (useKmdMigration) {
231227
unifiedMemoryPointer = createUnifiedKmdMigratedAllocation(size, {}, memoryProperties);
232228
if (!unifiedMemoryPointer) {

shared/source/os_interface/linux/drm_memory_manager.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2017-2020 Intel Corporation
2+
* Copyright (C) 2017-2021 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -175,6 +175,20 @@ void DrmMemoryManager::releaseGpuRange(void *address, size_t unmapSize, uint32_t
175175
gfxPartition->freeGpuAddressRange(graphicsAddress, unmapSize);
176176
}
177177

178+
bool DrmMemoryManager::isKmdMigrationAvailable(uint32_t rootDeviceIndex) {
179+
auto hwInfo = executionEnvironment.rootDeviceEnvironments[rootDeviceIndex]->getHardwareInfo();
180+
auto &hwHelper = NEO::HwHelper::get(hwInfo->platform.eRenderCoreFamily);
181+
182+
auto useKmdMigration = hwHelper.isKmdMigrationSupported(*hwInfo) &&
183+
this->getDrm(rootDeviceIndex).isVmBindAvailable();
184+
185+
if (DebugManager.flags.UseKmdMigration.get() != -1) {
186+
useKmdMigration = DebugManager.flags.UseKmdMigration.get();
187+
}
188+
189+
return useKmdMigration;
190+
}
191+
178192
NEO::BufferObject *DrmMemoryManager::allocUserptr(uintptr_t address, size_t size, uint64_t flags, uint32_t rootDeviceIndex) {
179193
drm_i915_gem_userptr userptr = {};
180194
userptr.user_ptr = address;

shared/source/os_interface/linux/drm_memory_manager.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2017-2020 Intel Corporation
2+
* Copyright (C) 2017-2021 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -62,6 +62,8 @@ class DrmMemoryManager : public MemoryManager {
6262
void freeGpuAddress(AddressRange addressRange, uint32_t rootDeviceIndex) override;
6363
MOCKABLE_VIRTUAL BufferObject *createBufferObjectInMemoryRegion(Drm *drm, uint64_t gpuAddress, size_t size, uint32_t memoryBanks, size_t maxOsContextCount);
6464

65+
bool isKmdMigrationAvailable(uint32_t rootDeviceIndex) override;
66+
6567
std::unique_lock<std::mutex> acquireAllocLock();
6668
std::vector<GraphicsAllocation *> &getSysMemAllocs();
6769
std::vector<GraphicsAllocation *> &getLocalMemAllocs(uint32_t rootDeviceIndex);

0 commit comments

Comments
 (0)