From 049e77b235272f464885aa74ac07d79b1e8394c2 Mon Sep 17 00:00:00 2001 From: Lukasz Jobczyk Date: Wed, 3 Feb 2021 14:53:13 +0000 Subject: [PATCH] Check if KMD migration is supported Related-To: NEO-3312 Signed-off-by: Lukasz Jobczyk --- .../linux/device_command_stream_fixture.h | 3 +- .../linux/drm_memory_manager_tests.cpp | 47 +++++++++++++++++++ .../test/unit_test/test_files/igdrcl.config | 2 +- .../debug_settings/debug_variables_base.inl | 2 +- shared/source/helpers/hw_helper.h | 3 ++ shared/source/helpers/hw_helper_base.inl | 5 ++ shared/source/memory_manager/memory_manager.h | 2 + .../memory_manager/unified_memory_manager.cpp | 8 +--- .../os_interface/linux/drm_memory_manager.cpp | 16 ++++++- .../os_interface/linux/drm_memory_manager.h | 4 +- 10 files changed, 81 insertions(+), 11 deletions(-) diff --git a/opencl/test/unit_test/os_interface/linux/device_command_stream_fixture.h b/opencl/test/unit_test/os_interface/linux/device_command_stream_fixture.h index d635191f29..90b95ec754 100644 --- a/opencl/test/unit_test/os_interface/linux/device_command_stream_fixture.h +++ b/opencl/test/unit_test/os_interface/linux/device_command_stream_fixture.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017-2020 Intel Corporation + * Copyright (C) 2017-2021 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -72,6 +72,7 @@ class DrmMockTime : public DrmMockSuccess { class DrmMockCustom : public Drm { public: + using Drm::bindAvailable; using Drm::memoryInfo; struct IoctlResExt { diff --git a/opencl/test/unit_test/os_interface/linux/drm_memory_manager_tests.cpp b/opencl/test/unit_test/os_interface/linux/drm_memory_manager_tests.cpp index 3d9e8bf757..b815c19f86 100644 --- a/opencl/test/unit_test/os_interface/linux/drm_memory_manager_tests.cpp +++ b/opencl/test/unit_test/os_interface/linux/drm_memory_manager_tests.cpp @@ -80,6 +80,53 @@ TEST_F(DrmMemoryManagerTest, givenDebugVariableWhenCreatingDrmMemoryManagerThenS } } +TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerWhenCheckForKmdMigrationThenCorrectValueIsReturned) { + DebugManagerStateRestore restorer; + auto drm = static_cast(executionEnvironment->rootDeviceEnvironments[rootDeviceIndex]->osInterface->get()->getDrm()); + + { + DebugManager.flags.UseKmdMigration.set(-1); + + drm->bindAvailable = false; + auto retVal = memoryManager->isKmdMigrationAvailable(rootDeviceIndex); + + EXPECT_FALSE(retVal); + + drm->bindAvailable = true; + retVal = memoryManager->isKmdMigrationAvailable(rootDeviceIndex); + + auto hwInfo = executionEnvironment->rootDeviceEnvironments[rootDeviceIndex]->getHardwareInfo(); + auto &hwHelper = NEO::HwHelper::get(hwInfo->platform.eRenderCoreFamily); + EXPECT_EQ(hwHelper.isKmdMigrationSupported(*hwInfo), retVal); + } + { + DebugManager.flags.UseKmdMigration.set(1); + + drm->bindAvailable = false; + auto retVal = memoryManager->isKmdMigrationAvailable(rootDeviceIndex); + + EXPECT_TRUE(retVal); + + drm->bindAvailable = true; + retVal = memoryManager->isKmdMigrationAvailable(rootDeviceIndex); + + EXPECT_TRUE(retVal); + } + { + DebugManager.flags.UseKmdMigration.set(0); + + drm->bindAvailable = false; + auto retVal = memoryManager->isKmdMigrationAvailable(rootDeviceIndex); + + EXPECT_FALSE(retVal); + + drm->bindAvailable = true; + retVal = memoryManager->isKmdMigrationAvailable(rootDeviceIndex); + + EXPECT_FALSE(retVal); + } +} + TEST_F(DrmMemoryManagerTest, GivenGraphicsAllocationWhenAddAndRemoveAllocationToHostPtrManagerThenfragmentHasCorrectValues) { void *cpuPtr = (void *)0x30000; size_t size = 0x1000; diff --git a/opencl/test/unit_test/test_files/igdrcl.config b/opencl/test/unit_test/test_files/igdrcl.config index 7acaf0de50..5863076948 100644 --- a/opencl/test/unit_test/test_files/igdrcl.config +++ b/opencl/test/unit_test/test_files/igdrcl.config @@ -29,7 +29,7 @@ AUBDumpAllocsOnEnqueueSVMMemcpyOnly = 0 AUBDumpForceAllToLocalMemory = 0 ForceDeviceId = unk ForceL1Caching = -1 -UseKmdMigration = -1 +UseKmdMigration = 0 SchedulerSimulationReturnInstance = 0 SchedulerGWS = 0 EnableExperimentalCommandBuffer = 0 diff --git a/shared/source/debug_settings/debug_variables_base.inl b/shared/source/debug_settings/debug_variables_base.inl index 0882eb840e..cc1871b087 100644 --- a/shared/source/debug_settings/debug_variables_base.inl +++ b/shared/source/debug_settings/debug_variables_base.inl @@ -214,7 +214,7 @@ DECLARE_DEBUG_VARIABLE(int32_t, OverrideThreadArbitrationPolicy, -1, "-1 (dont o DECLARE_DEBUG_VARIABLE(int32_t, OverrideAubDeviceId, -1, "-1 dont override, any other: use this value for AUB generation device id") DECLARE_DEBUG_VARIABLE(int32_t, EnableTimestampPacket, -1, "-1: default, 0: disable, 1:enable. Write Timestamp Packet for each set of gpu walkers") 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)") -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)") +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)") 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") 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") DECLARE_DEBUG_VARIABLE(int32_t, ForceUserptrAlignment, -1, "-1: no force (4kb), >0: n kb alignment") diff --git a/shared/source/helpers/hw_helper.h b/shared/source/helpers/hw_helper.h index b679c3f6c6..2649be190c 100644 --- a/shared/source/helpers/hw_helper.h +++ b/shared/source/helpers/hw_helper.h @@ -129,6 +129,7 @@ class HwHelper { virtual bool isSipWANeeded(const HardwareInfo &hwInfo) const = 0; virtual bool additionalKernelExecInfoSupported(const HardwareInfo &hwInfo) const = 0; virtual bool isCpuImageTransferPreferred(const HardwareInfo &hwInfo) const = 0; + virtual bool isKmdMigrationSupported(const HardwareInfo &hwInfo) const = 0; static uint32_t getSubDevicesCount(const HardwareInfo *pHwInfo); static uint32_t getEnginesCount(const HardwareInfo &hwInfo); @@ -318,6 +319,8 @@ class HwHelperHw : public HwHelper { bool isMediaBlockIOSupported(const HardwareInfo &hwInfo) const override; + bool isKmdMigrationSupported(const HardwareInfo &hwInfo) const override; + bool isCopyOnlyEngineType(EngineGroupType type) const override; void adjustAddressWidthForCanonize(uint32_t &addressWidth) const override; diff --git a/shared/source/helpers/hw_helper_base.inl b/shared/source/helpers/hw_helper_base.inl index 9a9f72408a..5eab340ea8 100644 --- a/shared/source/helpers/hw_helper_base.inl +++ b/shared/source/helpers/hw_helper_base.inl @@ -515,6 +515,11 @@ bool HwHelperHw::isMediaBlockIOSupported(const HardwareInfo &hwInfo) return hwInfo.capabilityTable.supportsImages; } +template +bool HwHelperHw::isKmdMigrationSupported(const HardwareInfo &hwInfo) const { + return false; +} + template bool HwHelperHw::isCopyOnlyEngineType(EngineGroupType type) const { return NEO::EngineGroupType::Copy == type; diff --git a/shared/source/memory_manager/memory_manager.h b/shared/source/memory_manager/memory_manager.h index f91f78d404..657c356b57 100644 --- a/shared/source/memory_manager/memory_manager.h +++ b/shared/source/memory_manager/memory_manager.h @@ -145,6 +145,8 @@ class MemoryManager { bool isLocalMemorySupported(uint32_t rootDeviceIndex) const; virtual bool isMemoryBudgetExhausted() const; + virtual bool isKmdMigrationAvailable(uint32_t rootDeviceIndex) { return false; } + virtual AlignedMallocRestrictions *getAlignedMallocRestrictions() { return nullptr; } diff --git a/shared/source/memory_manager/unified_memory_manager.cpp b/shared/source/memory_manager/unified_memory_manager.cpp index bbe02a5d0e..c43c4aff46 100644 --- a/shared/source/memory_manager/unified_memory_manager.cpp +++ b/shared/source/memory_manager/unified_memory_manager.cpp @@ -220,13 +220,9 @@ void *SVMAllocsManager::createSharedUnifiedMemoryAllocation(size_t size, } if (supportDualStorageSharedMemory) { - bool useKmdMigration = false; - - if (DebugManager.flags.UseKmdMigration.get() != -1) { - useKmdMigration = DebugManager.flags.UseKmdMigration.get(); - } - + bool useKmdMigration = memoryManager->isKmdMigrationAvailable(*memoryProperties.rootDeviceIndices.begin()); void *unifiedMemoryPointer = nullptr; + if (useKmdMigration) { unifiedMemoryPointer = createUnifiedKmdMigratedAllocation(size, {}, memoryProperties); if (!unifiedMemoryPointer) { diff --git a/shared/source/os_interface/linux/drm_memory_manager.cpp b/shared/source/os_interface/linux/drm_memory_manager.cpp index f42e3e06cb..2a4ce6e4df 100644 --- a/shared/source/os_interface/linux/drm_memory_manager.cpp +++ b/shared/source/os_interface/linux/drm_memory_manager.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017-2020 Intel Corporation + * Copyright (C) 2017-2021 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -175,6 +175,20 @@ void DrmMemoryManager::releaseGpuRange(void *address, size_t unmapSize, uint32_t gfxPartition->freeGpuAddressRange(graphicsAddress, unmapSize); } +bool DrmMemoryManager::isKmdMigrationAvailable(uint32_t rootDeviceIndex) { + auto hwInfo = executionEnvironment.rootDeviceEnvironments[rootDeviceIndex]->getHardwareInfo(); + auto &hwHelper = NEO::HwHelper::get(hwInfo->platform.eRenderCoreFamily); + + auto useKmdMigration = hwHelper.isKmdMigrationSupported(*hwInfo) && + this->getDrm(rootDeviceIndex).isVmBindAvailable(); + + if (DebugManager.flags.UseKmdMigration.get() != -1) { + useKmdMigration = DebugManager.flags.UseKmdMigration.get(); + } + + return useKmdMigration; +} + NEO::BufferObject *DrmMemoryManager::allocUserptr(uintptr_t address, size_t size, uint64_t flags, uint32_t rootDeviceIndex) { drm_i915_gem_userptr userptr = {}; userptr.user_ptr = address; diff --git a/shared/source/os_interface/linux/drm_memory_manager.h b/shared/source/os_interface/linux/drm_memory_manager.h index d860b9c609..2ec8fc345a 100644 --- a/shared/source/os_interface/linux/drm_memory_manager.h +++ b/shared/source/os_interface/linux/drm_memory_manager.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017-2020 Intel Corporation + * Copyright (C) 2017-2021 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -62,6 +62,8 @@ class DrmMemoryManager : public MemoryManager { void freeGpuAddress(AddressRange addressRange, uint32_t rootDeviceIndex) override; MOCKABLE_VIRTUAL BufferObject *createBufferObjectInMemoryRegion(Drm *drm, uint64_t gpuAddress, size_t size, uint32_t memoryBanks, size_t maxOsContextCount); + bool isKmdMigrationAvailable(uint32_t rootDeviceIndex) override; + std::unique_lock acquireAllocLock(); std::vector &getSysMemAllocs(); std::vector &getLocalMemAllocs(uint32_t rootDeviceIndex);