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

@@ -31,7 +31,6 @@
#include "shared/source/os_interface/os_time.h"
#include "shared/source/program/sync_buffer_handler.h"
#include "shared/source/release_helper/release_helper.h"
#include "shared/source/unified_memory/usm_memory_support.h"
#include "shared/source/utilities/software_tags_manager.h"
namespace NEO {
@@ -669,14 +668,11 @@ Debugger *Device::getDebugger() const {
}
bool Device::areSharedSystemAllocationsAllowed() const {
if ((debugManager.flags.EnableRecoverablePageFaults.get() == 0) || (debugManager.flags.EnableSharedSystemUsmSupport.get() == 0)) {
return false;
auto sharedSystemAllocationsSupport = static_cast<bool>(getHardwareInfo().capabilityTable.sharedSystemMemCapabilities);
if (debugManager.flags.EnableSharedSystemUsmSupport.get() != -1) {
sharedSystemAllocationsSupport = debugManager.flags.EnableSharedSystemUsmSupport.get();
}
uint64_t mask = UnifiedSharedMemoryFlags::access | UnifiedSharedMemoryFlags::sharedSystemPageFaultEnabled;
if (((getHardwareInfo().capabilityTable.sharedSystemMemCapabilities) & mask) == mask) {
return true;
}
return false;
return sharedSystemAllocationsSupport;
}
size_t Device::getEngineGroupIndexFromEngineGroupType(EngineGroupType engineGroupType) const {

View File

@@ -14,7 +14,6 @@
#include "shared/source/helpers/hw_info.h"
#include "shared/source/os_interface/device_factory.h"
#include "shared/source/os_interface/linux/drm_neo.h"
#include "shared/source/unified_memory/usm_memory_support.h"
#include "hw_cmds.h"
@@ -62,11 +61,6 @@ Drm *Drm::create(std::unique_ptr<HwDeviceIdDrm> &&hwDeviceId, RootDeviceEnvironm
return nullptr;
}
if (drm->isSharedSystemAllocEnabled()) {
auto hwInfo = drm->getRootDeviceEnvironment().getMutableHardwareInfo();
hwInfo->capabilityTable.sharedSystemMemCapabilities |= UnifiedSharedMemoryFlags::sharedSystemPageFaultEnabled;
}
if (drm->enableTurboBoost()) {
printDebugString(debugManager.flags.PrintDebugMessages.get(), stderr, "%s", "WARNING: Failed to request OCL Turbo Boost\n");
}

View File

@@ -276,7 +276,6 @@ class MemoryManager {
virtual bool setMemAdvise(GraphicsAllocation *gfxAllocation, MemAdviseFlags flags, uint32_t rootDeviceIndex) { return true; }
virtual bool setMemPrefetch(GraphicsAllocation *gfxAllocation, SubDeviceIdsVec &subDeviceIds, uint32_t rootDeviceIndex) { return true; }
virtual bool prefetchSharedSystemAlloc(const void *ptr, const size_t size, SubDeviceIdsVec &subDeviceIds, uint32_t rootDeviceIndex) { return true; }
virtual bool setAtomicAccess(GraphicsAllocation *gfxAllocation, size_t size, AtomicAccessMode mode, uint32_t rootDeviceIndex) { return true; }
bool isExternalAllocation(AllocationType allocationType);

View File

@@ -16,22 +16,20 @@ std::unique_ptr<PrefetchManager> PrefetchManager::create() {
return std::make_unique<PrefetchManager>();
}
void PrefetchManager::insertAllocation(PrefetchContext &context, SVMAllocsManager &unifiedMemoryManager, Device &device, const void *usmPtr, const size_t size) {
void PrefetchManager::insertAllocation(PrefetchContext &context, const void *usmPtr, SvmAllocationData &allocData) {
std::unique_lock<SpinLock> lock{context.lock};
auto allocData = unifiedMemoryManager.getSVMAlloc(usmPtr);
if (!allocData) {
if (device.areSharedSystemAllocationsAllowed()) {
context.allocations.push_back({usmPtr, size});
}
} else if (allocData->memoryType == InternalMemoryType::sharedUnifiedMemory) {
context.allocations.push_back({usmPtr, size});
if (allocData.memoryType == InternalMemoryType::sharedUnifiedMemory) {
context.allocations.push_back(usmPtr);
}
}
void PrefetchManager::migrateAllocationsToGpu(PrefetchContext &context, SVMAllocsManager &unifiedMemoryManager, Device &device, CommandStreamReceiver &csr) {
std::unique_lock<SpinLock> lock{context.lock};
for (auto &allocation : context.allocations) {
unifiedMemoryManager.prefetchMemory(device, csr, allocation.ptr, allocation.size);
for (auto &ptr : context.allocations) {
auto allocData = unifiedMemoryManager.getSVMAlloc(ptr);
if (allocData) {
unifiedMemoryManager.prefetchMemory(device, csr, *allocData);
}
}
}

View File

@@ -20,13 +20,8 @@ class CommandStreamReceiver;
class Device;
class SVMAllocsManager;
struct Allocation {
const void *ptr;
const size_t size;
};
struct PrefetchContext {
std::vector<Allocation> allocations;
std::vector<const void *> allocations;
SpinLock lock;
};
@@ -36,7 +31,7 @@ class PrefetchManager : public NonCopyableAndNonMovableClass {
virtual ~PrefetchManager() = default;
void insertAllocation(PrefetchContext &context, SVMAllocsManager &unifiedMemoryManager, Device &device, const void *usmPtr, const size_t size);
void insertAllocation(PrefetchContext &context, const void *usmPtr, SvmAllocationData &allocData);
MOCKABLE_VIRTUAL void migrateAllocationsToGpu(PrefetchContext &context, SVMAllocsManager &unifiedMemoryManager, Device &device, CommandStreamReceiver &csr);

View File

@@ -1069,43 +1069,42 @@ AllocationType SVMAllocsManager::getGraphicsAllocationTypeAndCompressionPreferen
return allocationType;
}
static uint32_t getSubDeviceId(Device &device) {
if (!device.isSubDevice()) {
uint32_t deviceBitField = static_cast<uint32_t>(device.getDeviceBitfield().to_ulong());
if (device.getDeviceBitfield().count() > 1) {
deviceBitField &= ~deviceBitField + 1;
void SVMAllocsManager::prefetchMemory(Device &device, CommandStreamReceiver &commandStreamReceiver, SvmAllocationData &svmData) {
auto getSubDeviceId = [](Device &device) {
if (!device.isSubDevice()) {
uint32_t deviceBitField = static_cast<uint32_t>(device.getDeviceBitfield().to_ulong());
if (device.getDeviceBitfield().count() > 1) {
deviceBitField &= ~deviceBitField + 1;
}
return Math::log2(deviceBitField);
}
return Math::log2(deviceBitField);
}
return static_cast<NEO::SubDevice *>(&device)->getSubDeviceIndex();
};
return static_cast<NEO::SubDevice *>(&device)->getSubDeviceIndex();
};
static NEO::SubDeviceIdsVec getSubDeviceIds(CommandStreamReceiver &csr) {
SubDeviceIdsVec subDeviceIds;
for (auto subDeviceId = 0u; subDeviceId < csr.getOsContext().getDeviceBitfield().size(); subDeviceId++) {
if (csr.getOsContext().getDeviceBitfield().test(subDeviceId)) {
subDeviceIds.push_back(subDeviceId);
auto getSubDeviceIds = [](CommandStreamReceiver &csr) {
SubDeviceIdsVec subDeviceIds;
for (auto subDeviceId = 0u; subDeviceId < csr.getOsContext().getDeviceBitfield().size(); subDeviceId++) {
if (csr.getOsContext().getDeviceBitfield().test(subDeviceId)) {
subDeviceIds.push_back(subDeviceId);
}
}
}
return subDeviceIds;
};
return subDeviceIds;
};
void SVMAllocsManager::prefetchMemory(Device &device, CommandStreamReceiver &commandStreamReceiver, const void *ptr, const size_t size) {
auto svmData = getSVMAlloc(ptr);
if (!svmData) {
if (device.areSharedSystemAllocationsAllowed()) {
// Single vm_id for shared system USM allocation
auto subDeviceIds = SubDeviceIdsVec{getSubDeviceId(device)};
memoryManager->prefetchSharedSystemAlloc(ptr, size, subDeviceIds, device.getRootDeviceIndex());
}
return;
// Perform prefetch for chunks if EnableBOChunkingPrefetch is 1
// and if KMD migration is set, as current target is to use
// chunking only with KMD migration
bool isChunkingNeededForDeviceAllocations = false;
if (NEO::debugManager.flags.EnableBOChunkingDevMemPrefetch.get() &&
memoryManager->isKmdMigrationAvailable(device.getRootDeviceIndex()) &&
(svmData.memoryType == InternalMemoryType::deviceUnifiedMemory)) {
isChunkingNeededForDeviceAllocations = true;
}
if ((memoryManager->isKmdMigrationAvailable(device.getRootDeviceIndex()) &&
(svmData->memoryType == InternalMemoryType::sharedUnifiedMemory))) {
auto gfxAllocation = svmData->gpuAllocations.getGraphicsAllocation(device.getRootDeviceIndex());
(svmData.memoryType == InternalMemoryType::sharedUnifiedMemory)) ||
isChunkingNeededForDeviceAllocations) {
auto gfxAllocation = svmData.gpuAllocations.getGraphicsAllocation(device.getRootDeviceIndex());
auto subDeviceIds = commandStreamReceiver.getActivePartitions() > 1 ? getSubDeviceIds(commandStreamReceiver) : SubDeviceIdsVec{getSubDeviceId(device)};
memoryManager->setMemPrefetch(gfxAllocation, subDeviceIds, device.getRootDeviceIndex());
}
@@ -1113,17 +1112,9 @@ void SVMAllocsManager::prefetchMemory(Device &device, CommandStreamReceiver &com
void SVMAllocsManager::prefetchSVMAllocs(Device &device, CommandStreamReceiver &commandStreamReceiver) {
std::shared_lock<std::shared_mutex> lock(mtx);
auto subDeviceIds = commandStreamReceiver.getActivePartitions() > 1 ? getSubDeviceIds(commandStreamReceiver) : SubDeviceIdsVec{getSubDeviceId(device)};
if (memoryManager->isKmdMigrationAvailable(device.getRootDeviceIndex())) {
for (auto &allocation : this->svmAllocs.allocations) {
NEO::SvmAllocationData svmData = *allocation.second;
if (svmData.memoryType == InternalMemoryType::sharedUnifiedMemory) {
auto gfxAllocation = svmData.gpuAllocations.getGraphicsAllocation(device.getRootDeviceIndex());
memoryManager->setMemPrefetch(gfxAllocation, subDeviceIds, device.getRootDeviceIndex());
}
}
for (auto &allocation : this->svmAllocs.allocations) {
NEO::SvmAllocationData allocData = *allocation.second;
this->prefetchMemory(device, commandStreamReceiver, allocData);
}
}

View File

@@ -266,7 +266,7 @@ class SVMAllocsManager {
std::atomic<uint32_t> allocationsCounter = 0;
MOCKABLE_VIRTUAL void makeIndirectAllocationsResident(CommandStreamReceiver &commandStreamReceiver, TaskCountType taskCount);
void prepareIndirectAllocationForDestruction(SvmAllocationData *allocationData, bool isNonBlockingFree);
MOCKABLE_VIRTUAL void prefetchMemory(Device &device, CommandStreamReceiver &commandStreamReceiver, const void *ptr, const size_t size);
MOCKABLE_VIRTUAL void prefetchMemory(Device &device, CommandStreamReceiver &commandStreamReceiver, SvmAllocationData &svmData);
void prefetchSVMAllocs(Device &device, CommandStreamReceiver &commandStreamReceiver);
std::unique_lock<std::mutex> obtainOwnership();

View File

@@ -300,16 +300,6 @@ bool DrmMemoryManager::setAtomicAccess(GraphicsAllocation *gfxAllocation, size_t
return drmAllocation->setAtomicAccess(&this->getDrm(rootDeviceIndex), size, mode);
}
bool DrmMemoryManager::prefetchSharedSystemAlloc(const void *ptr, const size_t size, SubDeviceIdsVec &subDeviceIds, uint32_t rootDeviceIndex) {
auto &drm = this->getDrm(rootDeviceIndex);
auto ioctlHelper = drm.getIoctlHelper();
auto memoryClassDevice = ioctlHelper->getDrmParamValue(DrmParam::memoryClassDevice);
auto region = static_cast<uint32_t>((memoryClassDevice << 16u) | subDeviceIds[0]);
auto vmId = drm.getVirtualMemoryAddressSpace(subDeviceIds[0]);
return ioctlHelper->setVmPrefetch(reinterpret_cast<uint64_t>(ptr), size, region, vmId);
}
bool DrmMemoryManager::setMemPrefetch(GraphicsAllocation *gfxAllocation, SubDeviceIdsVec &subDeviceIds, uint32_t rootDeviceIndex) {
auto drmAllocation = static_cast<DrmAllocation *>(gfxAllocation);
auto osContextLinux = getDefaultOsContext(rootDeviceIndex);

View File

@@ -87,7 +87,6 @@ class DrmMemoryManager : public MemoryManager {
bool setMemAdvise(GraphicsAllocation *gfxAllocation, MemAdviseFlags flags, uint32_t rootDeviceIndex) override;
bool setMemPrefetch(GraphicsAllocation *gfxAllocation, SubDeviceIdsVec &subDeviceIds, uint32_t rootDeviceIndex) override;
bool prefetchSharedSystemAlloc(const void *ptr, const size_t size, SubDeviceIdsVec &subDeviceIds, uint32_t rootDeviceIndex) override;
bool setAtomicAccess(GraphicsAllocation *gfxAllocation, size_t size, AtomicAccessMode mode, uint32_t rootDeviceIndex) override;
[[nodiscard]] std::unique_lock<std::mutex> acquireAllocLock();
std::vector<GraphicsAllocation *> &getSysMemAllocs();

View File

@@ -165,7 +165,7 @@ class Drm : public DriverModel {
MOCKABLE_VIRTUAL bool isVmBindAvailable();
MOCKABLE_VIRTUAL bool registerResourceClasses();
MOCKABLE_VIRTUAL void setPageFaultSupported(bool value) { this->pageFaultSupported = value; }
MOCKABLE_VIRTUAL void queryPageFaultSupport();
bool hasPageFaultSupport() const;
bool hasKmdMigrationSupport() const;

View File

@@ -162,9 +162,8 @@ bool IoctlHelperXe::queryDeviceIdAndRevision(Drm &drm) {
hwInfo->platform.usDeviceID = config->info[DRM_XE_QUERY_CONFIG_REV_AND_DEVICE_ID] & 0xffff;
hwInfo->platform.usRevId = static_cast<int>((config->info[DRM_XE_QUERY_CONFIG_REV_AND_DEVICE_ID] >> 16) & 0xff);
if ((debugManager.flags.EnableRecoverablePageFaults.get() != 0) && (debugManager.flags.EnableSharedSystemUsmSupport.get() != 0) && (config->info[DRM_XE_QUERY_CONFIG_FLAGS] & DRM_XE_QUERY_CONFIG_FLAG_HAS_CPU_ADDR_MIRROR)) {
if ((debugManager.flags.EnableSharedSystemUsmSupport.get() != 0) && (config->info[DRM_XE_QUERY_CONFIG_FLAGS] & DRM_XE_QUERY_CONFIG_FLAG_HAS_CPU_ADDR_MIRROR)) {
drm.setSharedSystemAllocEnable(true);
drm.setPageFaultSupported(true);
}
return true;
}
@@ -837,8 +836,8 @@ bool IoctlHelperXe::setVmPrefetch(uint64_t start, uint64_t length, uint32_t regi
uint32_t subDeviceId = region & subDeviceMaskMax;
DeviceBitfield subDeviceMask = (1u << subDeviceId);
MemoryClassInstance regionInstanceClass = this->drm.getMemoryInfo()->getMemoryRegionClassAndInstance(subDeviceMask, *pHwInfo);
bind.bind.prefetch_mem_region_instance = regionInstanceClass.memoryInstance;
int ret = IoctlHelper::ioctl(DrmIoctl::gemVmBind, &bind);
xeLog(" vm=%d addr=0x%lx range=0x%lx region=0x%x operation=%d(%s) ret=%d\n",

View File

@@ -15,5 +15,5 @@ inline constexpr uint64_t access = 1 << 0;
inline constexpr uint64_t atomicAccess = 1 << 1;
inline constexpr uint64_t concurrentAccess = 1 << 2;
inline constexpr uint64_t concurrentAtomicAccess = 1 << 3;
inline constexpr uint64_t sharedSystemPageFaultEnabled = 1 << 4;
} // namespace UnifiedSharedMemoryFlags

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) {