feature: Add product helper for shared system USM enabling

Related-To: NEO-16531

Signed-off-by: John Falkowski <john.falkowski@intel.com>
This commit is contained in:
John Falkowski
2025-11-17 15:22:19 +00:00
committed by Compute-Runtime-Automation
parent fda9c7d0b1
commit 02848968be
19 changed files with 126 additions and 13 deletions

View File

@@ -93,6 +93,8 @@ HWTEST2_F(AppendMemoryCopyTests, givenCopyOnlyCommandListWhenAppenBlitFillCalled
HWTEST_F(AppendMemoryCopyTests, givenCopyOnlyCommandListWhenAppenBlitFillToNotDeviceMemThenInvalidArgumentReturned) {
MockCommandListForMemFill<FamilyType::gfxCoreFamily> cmdList;
DebugManagerStateRestore restorer;
debugManager.flags.EnableSharedSystemUsmSupport.set(0);
cmdList.initialize(device, NEO::EngineGroupType::copy, 0u);
uint8_t pattern = 1;
void *ptr = reinterpret_cast<void *>(0x1234);

View File

@@ -258,9 +258,9 @@ HWTEST_F(AppendFillTest, givenAppendMemoryFillWithSharedSystemUsmAndTreatNonUsmF
delete[] ptr;
}
HWTEST_F(AppendFillTest, givenAppendMemoryFillWithSharedSystemUsmAndNoDebugFlagsSetReturnError) {
HWTEST_F(AppendFillTest, givenAppendMemoryFillWithSharedSystemUsmAndDebugFlagSetToDisableThenReturnError) {
DebugManagerStateRestore restore;
debugManager.flags.EnableSharedSystemUsmSupport.set(-1);
debugManager.flags.EnableSharedSystemUsmSupport.set(0);
debugManager.flags.TreatNonUsmForTransfersAsSharedSystem.set(-1);
auto commandList = std::make_unique<WhiteBox<MockCommandList<FamilyType::gfxCoreFamily>>>();

View File

@@ -1026,6 +1026,8 @@ TEST_F(MemoryTest, whenCallingSetAtomicAccessAttributeWithInvalidAllocationPtrEr
size_t size = 10;
size_t alignment = 1u;
void *ptr = reinterpret_cast<void *>(0x1234);
DebugManagerStateRestore restore;
debugManager.flags.EnableSharedSystemUsmSupport.set(0);
ze_device_mem_alloc_desc_t deviceDesc = {};
ze_host_mem_alloc_desc_t hostDesc = {};
@@ -1717,6 +1719,8 @@ TEST_F(MemoryTest, whenCallingGetAtomicAccessAttributeWithInvalidAllocationPtrEr
size_t size = 10;
size_t alignment = 1u;
void *ptr = reinterpret_cast<void *>(0x1234);
DebugManagerStateRestore restore;
debugManager.flags.EnableSharedSystemUsmSupport.set(0);
ze_device_mem_alloc_desc_t deviceDesc = {};
ze_host_mem_alloc_desc_t hostDesc = {};
@@ -4710,6 +4714,8 @@ HWTEST_F(MultipleDevicePeerAllocationTest, givenDeviceAllocationPassedToAppendBl
fixtureMemoryManager->failOnCreateGraphicsAllocationFromSharedHandle = true;
L0::Device *device0 = driverHandle->devices[0];
L0::Device *device1 = driverHandle->devices[1];
DebugManagerStateRestore restorer;
debugManager.flags.EnableSharedSystemUsmSupport.set(0);
size_t size = 1024;
size_t alignment = 1u;
@@ -4837,6 +4843,8 @@ HWTEST_F(MultipleDevicePeerAllocationTest, givenDeviceAllocationPassedToAppendBl
HWTEST_F(MultipleDevicePeerAllocationTest, givenHostPointerAllocationPassedToAppendBlitFillUsingDevice0ThenInvalidArgumentIsReturned) {
L0::Device *device0 = driverHandle->devices[0];
DebugManagerStateRestore restorer;
debugManager.flags.EnableSharedSystemUsmSupport.set(0);
size_t size = 1024;
uint8_t *ptr = new uint8_t[size];

View File

@@ -1115,7 +1115,7 @@ TEST_F(DeviceGetCapsTest, whenDeviceIsCreatedThenMaxParameterSizeIsSetCorrectly)
TEST_F(DeviceGetCapsTest, givenUnifiedMemorySharedSystemFlagWhenDeviceIsCreatedThenSystemMemoryIsSetCorrectly) {
DebugManagerStateRestore dbgRestore;
debugManager.flags.EnableSharedSystemUsmSupport.set(-1);
debugManager.flags.EnableSharedSystemUsmSupport.set(0);
auto device = std::make_unique<MockClDevice>(MockDevice::createWithNewExecutionEnvironment<MockDevice>(defaultHwInfo.get()));
device->getRootDeviceEnvironment().getMutableHardwareInfo()->capabilityTable.sharedSystemMemCapabilities = 0;
EXPECT_FALSE(device->areSharedSystemAllocationsAllowed());

View File

@@ -755,7 +755,7 @@ Debugger *Device::getDebugger() const {
}
bool Device::areSharedSystemAllocationsAllowed() const {
if ((debugManager.flags.EnableRecoverablePageFaults.get() == 0) || (debugManager.flags.EnableSharedSystemUsmSupport.get() != 1)) {
if ((debugManager.flags.EnableRecoverablePageFaults.get() == 0) || (debugManager.flags.EnableSharedSystemUsmSupport.get() == 0)) {
return false;
}
uint64_t mask = (UnifiedSharedMemoryFlags::access | UnifiedSharedMemoryFlags::atomicAccess | UnifiedSharedMemoryFlags::concurrentAccess | UnifiedSharedMemoryFlags::concurrentAtomicAccess);

View File

@@ -1919,22 +1919,31 @@ bool Drm::queryDeviceIdAndRevision() {
}
void Drm::adjustSharedSystemMemCapabilities() {
if (this->isSharedSystemAllocEnabled()) {
bool requestSharedSystemUsm = false;
auto &productHelper = rootDeviceEnvironment.getHelper<ProductHelper>();
if ((this->isSharedSystemAllocEnabled()) && ((debugManager.flags.EnableSharedSystemUsmSupport.get() == 1) || (productHelper.useSharedSystemUsm()))) {
requestSharedSystemUsm = true;
}
if (requestSharedSystemUsm) {
uint64_t gpuAddressLength = (this->getRootDeviceEnvironment().getMutableHardwareInfo()->capabilityTable.gpuAddressSpace + 1);
uint64_t cpuAddressLength = (0x1ull << (NEO::CpuInfo::getInstance().getVirtualAddressSize()));
if ((cpuAddressLength > (maxNBitValue(48) + 1)) && !(CpuInfo::getInstance().isCpuFlagPresent("la57"))) {
cpuAddressLength = (maxNBitValue(48) + 1);
}
if (gpuAddressLength < cpuAddressLength) {
this->setSharedSystemAllocEnable(false);
this->getRootDeviceEnvironment().getMutableHardwareInfo()->capabilityTable.sharedSystemMemCapabilities = 0;
requestSharedSystemUsm = false;
printDebugString(debugManager.flags.PrintDebugMessages.get(), stderr, "%s", "Shared System USM NOT allowed: CPU address range > GPU address range\n");
} else {
this->setSharedSystemAllocAddressRange(cpuAddressLength);
this->setPageFaultSupported(true);
}
} else {
}
if (!requestSharedSystemUsm) {
this->getRootDeviceEnvironment().getMutableHardwareInfo()->capabilityTable.sharedSystemMemCapabilities = 0;
this->setSharedSystemAllocEnable(false);
}
}

View File

@@ -170,7 +170,7 @@ 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() == 1) && (config->info[DRM_XE_QUERY_CONFIG_FLAGS] & DRM_XE_QUERY_CONFIG_FLAG_HAS_CPU_ADDR_MIRROR)) {
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)) {
drm.setSharedSystemAllocEnable(true);
} else {
printDebugString(debugManager.flags.PrintDebugMessages.get(), stderr, "%s", "Shared System USM NOT allowed: KMD does not support\n");

View File

@@ -262,6 +262,7 @@ class ProductHelper {
virtual uint32_t adjustMaxThreadsPerThreadGroup(uint32_t maxThreadsPerThreadGroup, uint32_t simt, uint32_t grfCount, bool isHeaplessModeEnabled) const = 0;
virtual uint64_t getPatIndex(CacheRegion cacheRegion, CachePolicy cachePolicy) const = 0;
virtual uint64_t getSharedSystemPatIndex() const = 0;
virtual bool useSharedSystemUsm() const = 0;
virtual uint32_t getGmmResourceUsageOverride(uint32_t usageType) const = 0;
virtual bool isSharingWith3dOrMediaAllowed() const = 0;
virtual bool isL3FlushAfterPostSyncSupported(bool heaplessEnabled) const = 0;

View File

@@ -192,7 +192,7 @@ uint64_t ProductHelperHw<gfxProduct>::getHostMemCapabilities(const HardwareInfo
template <PRODUCT_FAMILY gfxProduct>
uint64_t ProductHelperHw<gfxProduct>::getSharedSystemMemCapabilities(const HardwareInfo *hwInfo) const {
if ((debugManager.flags.EnableRecoverablePageFaults.get() == 0) || (debugManager.flags.EnableSharedSystemUsmSupport.get() != 1)) {
if ((debugManager.flags.EnableRecoverablePageFaults.get() == 0) || (debugManager.flags.EnableSharedSystemUsmSupport.get() == 0)) {
return 0;
}
@@ -951,6 +951,11 @@ uint64_t ProductHelperHw<gfxProduct>::getSharedSystemPatIndex() const {
return 0;
}
template <PRODUCT_FAMILY gfxProduct>
bool ProductHelperHw<gfxProduct>::useSharedSystemUsm() const {
return false;
}
template <PRODUCT_FAMILY gfxProduct>
uint32_t ProductHelperHw<gfxProduct>::getGmmResourceUsageOverride(uint32_t usageType) const {
return 0u;

View File

@@ -199,6 +199,7 @@ class ProductHelperHw : public ProductHelper {
uint32_t adjustMaxThreadsPerThreadGroup(uint32_t maxThreadsPerThreadGroup, uint32_t simt, uint32_t grfCount, bool isHeaplessModeEnabled) const override;
uint64_t getPatIndex(CacheRegion cacheRegion, CachePolicy cachePolicy) const override;
uint64_t getSharedSystemPatIndex() const override;
bool useSharedSystemUsm() const override;
uint32_t getGmmResourceUsageOverride(uint32_t usageType) const override;
bool isSharingWith3dOrMediaAllowed() const override;
bool isL3FlushAfterPostSyncSupported(bool heaplessEnabled) const override;

View File

@@ -44,5 +44,10 @@ uint64_t ProductHelperHw<gfxProduct>::getSharedSystemPatIndex() const {
return 0;
}
template <>
bool ProductHelperHw<gfxProduct>::useSharedSystemUsm() const {
return false;
}
template class ProductHelperHw<gfxProduct>;
} // namespace NEO

View File

@@ -50,5 +50,10 @@ uint64_t ProductHelperHw<gfxProduct>::getSharedSystemPatIndex() const {
return 1;
}
template <>
bool ProductHelperHw<gfxProduct>::useSharedSystemUsm() const {
return false;
}
template class ProductHelperHw<gfxProduct>;
} // namespace NEO

View File

@@ -45,5 +45,10 @@ uint64_t ProductHelperHw<gfxProduct>::getSharedSystemPatIndex() const {
return 1;
}
template <>
bool ProductHelperHw<gfxProduct>::useSharedSystemUsm() const {
return false;
}
template class ProductHelperHw<gfxProduct>;
} // namespace NEO

View File

@@ -2622,6 +2622,8 @@ TEST(DrmTest, GivenDebugFlagClearAndCallgetSharedSytemBindFlagsThenAutoresetIsSe
}
TEST(DrmTest, GivenGpuAddressRangeAndCpuAddressRangeSharedSystemAllocEnableIsTrue) {
DebugManagerStateRestore restore;
debugManager.flags.EnableSharedSystemUsmSupport.set(1);
auto executionEnvironment = std::make_unique<MockExecutionEnvironment>();
DrmMock drm{*executionEnvironment->rootDeviceEnvironments[0]};
executionEnvironment->rootDeviceEnvironments[0]->getMutableHardwareInfo()->capabilityTable.gpuAddressSpace = maxNBitValue(48);
@@ -2637,6 +2639,8 @@ TEST(DrmTest, GivenGpuAddressRangeAndCpuAddressRangeSharedSystemAllocEnableIsTru
}
TEST(DrmTest, GivenGpuAddressRangeAndCpuAddressRangeSharedSystemAllocEnableIsFalse) {
DebugManagerStateRestore restore;
debugManager.flags.EnableSharedSystemUsmSupport.set(1);
auto executionEnvironment = std::make_unique<MockExecutionEnvironment>();
DrmMock drm{*executionEnvironment->rootDeviceEnvironments[0]};
executionEnvironment->rootDeviceEnvironments[0]->getMutableHardwareInfo()->capabilityTable.gpuAddressSpace = maxNBitValue(32);

View File

@@ -3341,7 +3341,7 @@ TEST_F(IoctlHelperXeTest, whenQueryDeviceIdAndRevisionConfigFlagHasGpuAddrMirror
EXPECT_TRUE(drm->isSharedSystemAllocEnabled());
}
TEST_F(IoctlHelperXeTest, whenQueryDeviceIdAndRevisionConfigFlagHasGpuAddrMirrorSetButDebugFlagNotSetThenSharedSystemAllocEnableFalse) {
TEST_F(IoctlHelperXeTest, whenQueryDeviceIdAndRevisionConfigFlagHasGpuAddrMirrorSetButDebugFlagNotSetThenSharedSystemAllocEnableTrue) {
MockExecutionEnvironment executionEnvironment{};
std::unique_ptr<Drm> drm{Drm::create(std::make_unique<HwDeviceIdDrm>(0, ""), *executionEnvironment.rootDeviceEnvironments[0])};
DebugManagerStateRestore restore;
@@ -3363,6 +3363,58 @@ TEST_F(IoctlHelperXeTest, whenQueryDeviceIdAndRevisionConfigFlagHasGpuAddrMirror
return -1;
};
EXPECT_TRUE(IoctlHelperXe::queryDeviceIdAndRevision(*drm));
EXPECT_TRUE(drm->isSharedSystemAllocEnabled());
}
TEST_F(IoctlHelperXeTest, whenQueryDeviceIdAndRevisionConfigFlagHasGpuAddrMirrorSetAndUsmSupportDebugFlagClearThenSharedSystemAllocEnableFalse) {
MockExecutionEnvironment executionEnvironment{};
std::unique_ptr<Drm> drm{Drm::create(std::make_unique<HwDeviceIdDrm>(0, ""), *executionEnvironment.rootDeviceEnvironments[0])};
DebugManagerStateRestore restore;
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);
if (deviceQuery->query == DRM_XE_DEVICE_QUERY_CONFIG) {
if (deviceQuery->data) {
struct drm_xe_query_config *config = reinterpret_cast<struct drm_xe_query_config *>(deviceQuery->data);
config->num_params = DRM_XE_QUERY_CONFIG_REV_AND_DEVICE_ID + 1;
config->info[DRM_XE_QUERY_CONFIG_FLAGS] = DRM_XE_QUERY_CONFIG_FLAG_HAS_CPU_ADDR_MIRROR;
} else {
deviceQuery->size = (DRM_XE_QUERY_CONFIG_REV_AND_DEVICE_ID + 1) * sizeof(uint64_t);
}
return 0;
}
}
return -1;
};
EXPECT_TRUE(IoctlHelperXe::queryDeviceIdAndRevision(*drm));
EXPECT_FALSE(drm->isSharedSystemAllocEnabled());
}
TEST_F(IoctlHelperXeTest, whenQueryDeviceIdAndRevisionConfigFlagHasGpuAddrMirrorSetAndPageFaultDebugFlagClearThenSharedSystemAllocEnableFalse) {
MockExecutionEnvironment executionEnvironment{};
std::unique_ptr<Drm> drm{Drm::create(std::make_unique<HwDeviceIdDrm>(0, ""), *executionEnvironment.rootDeviceEnvironments[0])};
DebugManagerStateRestore restore;
debugManager.flags.EnableRecoverablePageFaults.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);
if (deviceQuery->query == DRM_XE_DEVICE_QUERY_CONFIG) {
if (deviceQuery->data) {
struct drm_xe_query_config *config = reinterpret_cast<struct drm_xe_query_config *>(deviceQuery->data);
config->num_params = DRM_XE_QUERY_CONFIG_REV_AND_DEVICE_ID + 1;
config->info[DRM_XE_QUERY_CONFIG_FLAGS] = DRM_XE_QUERY_CONFIG_FLAG_HAS_CPU_ADDR_MIRROR;
} else {
deviceQuery->size = (DRM_XE_QUERY_CONFIG_REV_AND_DEVICE_ID + 1) * sizeof(uint64_t);
}
return 0;
}
}
return -1;
};
EXPECT_TRUE(IoctlHelperXe::queryDeviceIdAndRevision(*drm));
EXPECT_FALSE(drm->isSharedSystemAllocEnabled());
}

View File

@@ -109,7 +109,7 @@ HWTEST_F(ProductHelperTest, givenProductHelperWhenGettingSharedSystemMemCapabili
for (auto enable : {-1, 0, 1}) {
debugManager.flags.EnableSharedSystemUsmSupport.set(enable);
if (enable != 1) {
if (enable == 0) {
EXPECT_EQ(0u, productHelper->getSharedSystemMemCapabilities(&pInHwInfo));
} else {
for (auto pfEnable : {-1, 0, 1}) {
@@ -136,7 +136,7 @@ HWTEST_F(ProductHelperTest, givenProductHelperWhenGettingMemoryCapabilitiesThenC
for (auto capabilityBitmask : {0, 0b0001, 0b0010, 0b0100, 0b1000, 0b1111}) {
debugManager.flags.EnableUsmConcurrentAccessSupport.set(capabilityBitmask);
std::bitset<4> capabilityBitset(capabilityBitmask);
std::bitset<5> capabilityBitset(capabilityBitmask);
auto hostMemCapabilities = productHelper->getHostMemCapabilities(&pInHwInfo);
if (hostMemCapabilities > 0) {
@@ -523,6 +523,10 @@ HWTEST2_F(ProductHelperTest, givenProductHelperWhenAskedGetSharedSystemPatIndexT
EXPECT_EQ(0ull, productHelper->getSharedSystemPatIndex());
}
HWTEST2_F(ProductHelperTest, givenProductHelperWhenAskedUseSharedSystemUsmThenReturnDefaultValue, IsPVC) {
EXPECT_FALSE(productHelper->useSharedSystemUsm());
}
HWTEST_F(ProductHelperTest, givenLockableAllocationWhenGettingIsBlitCopyRequiredForLocalMemoryThenCorrectValuesAreReturned) {
DebugManagerStateRestore restore{};

View File

@@ -69,6 +69,10 @@ BMGTEST_F(BmgProductHelperLinux, givenProductHelperWhenAskedGetSharedSystemPatIn
EXPECT_EQ(0ull, productHelper->getSharedSystemPatIndex());
}
BMGTEST_F(BmgProductHelperLinux, givenProductHelperWhenAskedUseSharedSystemUsmThenReturnCorrectValue) {
EXPECT_FALSE(productHelper->useSharedSystemUsm());
}
BMGTEST_F(BmgProductHelperLinux, WhenGtIsSetupThenGtSystemInfoIsCorrect) {
auto executionEnvironment = std::make_unique<ExecutionEnvironment>();
executionEnvironment->prepareRootDeviceEnvironments(1);

View File

@@ -73,6 +73,10 @@ LNLTEST_F(LnlProductHelperLinux, givenProductHelperWhenAskedGetSharedSystemPatIn
EXPECT_EQ(1ull, productHelper->getSharedSystemPatIndex());
}
LNLTEST_F(LnlProductHelperLinux, givenProductHelperWhenAskedUseSharedSystemUsmThenReturnCorrectValue) {
EXPECT_FALSE(productHelper->useSharedSystemUsm());
}
LNLTEST_F(LnlProductHelperLinux, givenProductHelperWhenAskedIfIsTlbFlushRequiredThenFalseIsReturned) {
EXPECT_FALSE(productHelper->isTlbFlushRequired());
}

View File

@@ -29,6 +29,10 @@ PTLTEST_F(PtlProductHelperLinux, givenProductHelperWhenAskedGetSharedSystemPatIn
EXPECT_EQ(1ull, productHelper->getSharedSystemPatIndex());
}
PTLTEST_F(PtlProductHelperLinux, givenProductHelperWhenAskedUseSharedSystemUsmThenReturnCorrectValue) {
EXPECT_FALSE(productHelper->useSharedSystemUsm());
}
using PtlHwInfoLinux = ::testing::Test;
PTLTEST_F(PtlHwInfoLinux, WhenGtIsSetupThenGtSystemInfoIsCorrect) {