fix: correct usages of ULLS-related resources

Related-To: NEO-14360

Current gmm usage type of these resources is causing
them to be cached, which is incorrect.

Signed-off-by: Szymon Morek <szymon.morek@intel.com>
This commit is contained in:
Szymon Morek
2025-05-07 09:35:03 +00:00
committed by Compute-Runtime-Automation
parent 7167f45199
commit 6ae43123f6
20 changed files with 85 additions and 50 deletions

View File

@@ -13,9 +13,9 @@
#include "shared/source/helpers/gfx_core_helper.h"
#include "shared/source/helpers/hw_info.h"
#include "shared/source/memory_manager/allocation_type.h"
#include "shared/source/memory_manager/graphics_allocation.h"
#include "shared/source/os_interface/product_helper.h"
#include "shared/source/release_helper/release_helper.h"
namespace NEO {
GMM_RESOURCE_USAGE_TYPE_ENUM CacheSettingsHelper::getGmmUsageType(AllocationType allocationType, bool forceUncached, const ProductHelper &productHelper, const HardwareInfo *hwInfo) {
@@ -60,7 +60,9 @@ GMM_RESOURCE_USAGE_TYPE_ENUM CacheSettingsHelper::getDefaultUsageTypeWithCaching
}
if (hwInfo->capabilityTable.isIntegratedDevice) {
if (AllocationType::semaphoreBuffer == allocationType || (AllocationType::ringBuffer == allocationType && productHelper.allowSharedResourcesInCoherentMemory())) {
if (productHelper.isResourceUncachedForCS(allocationType)) {
return GMM_RESOURCE_USAGE_OCL_BUFFER_CSR_UC;
} else if (AllocationType::semaphoreBuffer == allocationType) {
return GMM_RESOURCE_USAGE_OCL_SYSTEM_MEMORY_BUFFER;
}
}

View File

@@ -259,6 +259,12 @@ class GraphicsAllocation : public IDNode<GraphicsAllocation>, NEO::NonCopyableAn
type == AllocationType::profilingTagBuffer;
}
static bool isAccessedFromCommandStreamer(AllocationType allocationType) {
return allocationType == AllocationType::commandBuffer ||
allocationType == AllocationType::ringBuffer ||
allocationType == AllocationType::semaphoreBuffer;
}
static uint32_t getNumHandlesForKmdSharedAllocation(uint32_t numBanks);
void *getReservedAddressPtr() const {

View File

@@ -2058,7 +2058,7 @@ inline std::unique_ptr<Gmm> DrmMemoryManager::makeGmmIfSingleHandle(const Alloca
gmmRequirements.allowLargePages = true;
gmmRequirements.preferCompressed = allocationData.flags.preferCompressed;
if (productHelper.overrideAllocationCacheable(allocationData)) {
if (productHelper.overrideAllocationCpuCacheable(allocationData)) {
gmmRequirements.overriderCacheable.enableOverride = true;
gmmRequirements.overriderCacheable.value = true;
}

View File

@@ -197,7 +197,7 @@ class ProductHelper {
virtual uint32_t getMaxNumSamplers() const = 0;
virtual uint32_t getCommandBuffersPreallocatedPerCommandQueue() const = 0;
virtual uint32_t getInternalHeapsPreallocated() const = 0;
virtual bool overrideAllocationCacheable(const AllocationData &allocationData) const = 0;
virtual bool overrideAllocationCpuCacheable(const AllocationData &allocationData) const = 0;
virtual bool is2MBLocalMemAlignmentEnabled() const = 0;
virtual bool isPostImageWriteFlushRequired() const = 0;
@@ -246,7 +246,7 @@ class ProductHelper {
virtual std::optional<GfxMemoryAllocationMethod> getPreferredAllocationMethod(AllocationType allocationType) const = 0;
virtual bool isCachingOnCpuAvailable() const = 0;
virtual bool isNewCoherencyModelSupported() const = 0;
virtual bool allowSharedResourcesInCoherentMemory() const = 0;
virtual bool isResourceUncachedForCS(AllocationType allocationType) const = 0;
virtual bool deferMOCSToPatIndex() const = 0;
virtual const std::vector<uint32_t> getSupportedLocalDispatchSizes(const HardwareInfo &hwInfo) const = 0;
virtual uint32_t getMaxLocalRegionSize(const HardwareInfo &hwInfo) const = 0;

View File

@@ -217,7 +217,7 @@ uint64_t ProductHelperHw<gfxProduct>::getDeviceMemoryMaxBandWidthInBytesPerSecon
}
template <PRODUCT_FAMILY gfxProduct>
bool ProductHelperHw<gfxProduct>::overrideAllocationCacheable(const AllocationData &allocationData) const {
bool ProductHelperHw<gfxProduct>::overrideAllocationCpuCacheable(const AllocationData &allocationData) const {
return false;
}

View File

@@ -46,7 +46,7 @@ bool ProductHelperHw<gfxProduct>::isCompressionForbidden(const HardwareInfo &hwI
}
template <PRODUCT_FAMILY gfxProduct>
bool ProductHelperHw<gfxProduct>::allowSharedResourcesInCoherentMemory() const {
bool ProductHelperHw<gfxProduct>::isResourceUncachedForCS(AllocationType allocationType) const {
return false;
}

View File

@@ -137,7 +137,7 @@ class ProductHelperHw : public ProductHelper {
uint32_t getMaxNumSamplers() const override;
uint32_t getCommandBuffersPreallocatedPerCommandQueue() const override;
uint32_t getInternalHeapsPreallocated() const override;
bool overrideAllocationCacheable(const AllocationData &allocationData) const override;
bool overrideAllocationCpuCacheable(const AllocationData &allocationData) const override;
bool is2MBLocalMemAlignmentEnabled() const override;
bool isPostImageWriteFlushRequired() const override;
@@ -184,7 +184,7 @@ class ProductHelperHw : public ProductHelper {
std::optional<GfxMemoryAllocationMethod> getPreferredAllocationMethod(AllocationType allocationType) const override;
bool isCachingOnCpuAvailable() const override;
bool isNewCoherencyModelSupported() const override;
bool allowSharedResourcesInCoherentMemory() const override;
bool isResourceUncachedForCS(AllocationType allocationType) const override;
bool deferMOCSToPatIndex() const override;
bool supportReadOnlyAllocations() const override;
const std::vector<uint32_t> getSupportedLocalDispatchSizes(const HardwareInfo &hwInfo) const override;

View File

@@ -6,7 +6,6 @@
*/
#include "shared/source/os_interface/product_helper_hw.h"
namespace NEO {
template <PRODUCT_FAMILY gfxProduct>
@@ -50,8 +49,8 @@ bool ProductHelperHw<gfxProduct>::isCompressionForbidden(const HardwareInfo &hwI
}
template <PRODUCT_FAMILY gfxProduct>
bool ProductHelperHw<gfxProduct>::allowSharedResourcesInCoherentMemory() const {
return true;
bool ProductHelperHw<gfxProduct>::isResourceUncachedForCS(AllocationType allocationType) const {
return GraphicsAllocation::isAccessedFromCommandStreamer(allocationType);
}
} // namespace NEO

View File

@@ -237,7 +237,7 @@ GraphicsAllocation *WddmMemoryManager::allocateGraphicsMemoryUsingKmdAndMapItToC
GmmRequirements gmmRequirements{};
gmmRequirements.allowLargePages = allowLargePages;
gmmRequirements.preferCompressed = allocationData.flags.preferCompressed;
if (productHelper.overrideAllocationCacheable(allocationData)) {
if (productHelper.overrideAllocationCpuCacheable(allocationData)) {
gmmRequirements.overriderCacheable.enableOverride = true;
gmmRequirements.overriderCacheable.value = true;
}
@@ -467,7 +467,7 @@ GraphicsAllocation *WddmMemoryManager::allocateGraphicsMemoryForNonSvmHostPtr(co
GmmRequirements gmmRequirements{};
gmmRequirements.allowLargePages = true;
gmmRequirements.preferCompressed = false;
if (productHelper.overrideAllocationCacheable(allocationData)) {
if (productHelper.overrideAllocationCpuCacheable(allocationData)) {
gmmRequirements.overriderCacheable.enableOverride = true;
gmmRequirements.overriderCacheable.value = true;
}

View File

@@ -14,8 +14,8 @@
namespace NEO {
template <>
bool ProductHelperHw<gfxProduct>::overrideAllocationCacheable(const AllocationData &allocationData) const {
return allocationData.type == AllocationType::commandBuffer || this->overrideCacheableForDcFlushMitigation(allocationData.type);
bool ProductHelperHw<gfxProduct>::overrideAllocationCpuCacheable(const AllocationData &allocationData) const {
return GraphicsAllocation::isAccessedFromCommandStreamer(allocationData.type) || this->overrideCacheableForDcFlushMitigation(allocationData.type);
}
template <>

View File

@@ -10,8 +10,8 @@
namespace NEO {
template <>
bool ProductHelperHw<gfxProduct>::overrideAllocationCacheable(const AllocationData &allocationData) const {
return allocationData.type == AllocationType::commandBuffer || this->overrideCacheableForDcFlushMitigation(allocationData.type);
bool ProductHelperHw<gfxProduct>::overrideAllocationCpuCacheable(const AllocationData &allocationData) const {
return GraphicsAllocation::isAccessedFromCommandStreamer(allocationData.type) || this->overrideCacheableForDcFlushMitigation(allocationData.type);
}
template <>

View File

@@ -51,7 +51,7 @@ bool ProductHelperHw<gfxProduct>::isResolveDependenciesByPipeControlsSupported(c
}
template <>
bool ProductHelperHw<gfxProduct>::overrideAllocationCacheable(const AllocationData &allocationData) const {
bool ProductHelperHw<gfxProduct>::overrideAllocationCpuCacheable(const AllocationData &allocationData) const {
return allocationData.type == AllocationType::commandBuffer;
}

View File

@@ -509,7 +509,7 @@ template <>
void ProductHelperHw<IGFX_UNKNOWN>::setRenderCompressedFlags(HardwareInfo &hwInfo) const {}
template <>
bool ProductHelperHw<IGFX_UNKNOWN>::allowSharedResourcesInCoherentMemory() const {
bool ProductHelperHw<IGFX_UNKNOWN>::isResourceUncachedForCS(AllocationType allocationType) const {
return false;
}

View File

@@ -17,7 +17,7 @@ struct MockProductHelper : ProductHelperHw<IGFX_UNKNOWN> {
MockProductHelper() = default;
ADDMETHOD_CONST_NOBASE(is48bResourceNeededForRayTracing, bool, true, ());
ADDMETHOD_CONST_NOBASE(overrideAllocationCacheable, bool, false, (const AllocationData &allocationData));
ADDMETHOD_CONST_NOBASE(overrideAllocationCpuCacheable, bool, false, (const AllocationData &allocationData));
ADDMETHOD_NOBASE(configureHwInfoWddm, int, 0, (const HardwareInfo *inHwInfo, HardwareInfo *outHwInfo, const RootDeviceEnvironment &rootDeviceEnvironment));
ADDMETHOD_CONST_NOBASE(supportReadOnlyAllocations, bool, false, ());
ADDMETHOD_CONST_NOBASE(isBlitCopyRequiredForLocalMemory, bool, true, (const RootDeviceEnvironment &rootDeviceEnvironment, const GraphicsAllocation &allocation));

View File

@@ -766,19 +766,23 @@ TEST(GmmTest, givenAllocationTypeWhenGettingUsageTypeThenReturnCorrectValue) {
case AllocationType::fillPattern:
case AllocationType::internalHostMemory:
case AllocationType::mapAllocation:
case AllocationType::semaphoreBuffer:
case AllocationType::svmCpu:
case AllocationType::svmZeroCopy:
case AllocationType::tagBuffer:
expectedUsage = forceUncached ? uncachedGmmUsageType : GMM_RESOURCE_USAGE_OCL_SYSTEM_MEMORY_BUFFER;
break;
case AllocationType::semaphoreBuffer:
case AllocationType::ringBuffer:
case AllocationType::commandBuffer:
if (forceUncached) {
expectedUsage = uncachedGmmUsageType;
break;
}
if (productHelper.allowSharedResourcesInCoherentMemory()) {
if (productHelper.isResourceUncachedForCS(allocationType)) {
expectedUsage = GMM_RESOURCE_USAGE_OCL_BUFFER_CSR_UC;
break;
} else if (allocationType == AllocationType::semaphoreBuffer) {
expectedUsage = GMM_RESOURCE_USAGE_OCL_SYSTEM_MEMORY_BUFFER;
break;
}
@@ -904,11 +908,15 @@ TEST(GmmTest, givenAllocationTypeAndMitigatedDcFlushWhenGettingUsageTypeThenRetu
expectedUsage = GMM_RESOURCE_USAGE_OCL_IMAGE;
break;
case AllocationType::fillPattern:
case AllocationType::semaphoreBuffer:
expectedUsage = GMM_RESOURCE_USAGE_OCL_SYSTEM_MEMORY_BUFFER;
break;
case AllocationType::semaphoreBuffer:
case AllocationType::ringBuffer:
if (productHelper.allowSharedResourcesInCoherentMemory()) {
case AllocationType::commandBuffer:
if (productHelper.isResourceUncachedForCS(allocationType)) {
expectedUsage = GMM_RESOURCE_USAGE_OCL_BUFFER_CSR_UC;
break;
} else if (allocationType == AllocationType::semaphoreBuffer) {
expectedUsage = GMM_RESOURCE_USAGE_OCL_SYSTEM_MEMORY_BUFFER;
break;
}
@@ -934,14 +942,18 @@ TEST(GmmTest, givenAllocationTypeAndMitigatedDcFlushWhenGettingUsageTypeThenRetu
case AllocationType::fillPattern:
case AllocationType::internalHostMemory:
case AllocationType::mapAllocation:
case AllocationType::semaphoreBuffer:
case AllocationType::svmCpu:
case AllocationType::svmZeroCopy:
case AllocationType::tagBuffer:
expectedUsage = GMM_RESOURCE_USAGE_OCL_SYSTEM_MEMORY_BUFFER;
break;
case AllocationType::semaphoreBuffer:
case AllocationType::ringBuffer:
if (productHelper.allowSharedResourcesInCoherentMemory()) {
case AllocationType::commandBuffer:
if (productHelper.isResourceUncachedForCS(allocationType)) {
expectedUsage = GMM_RESOURCE_USAGE_OCL_BUFFER_CSR_UC;
break;
} else if (allocationType == AllocationType::semaphoreBuffer) {
expectedUsage = GMM_RESOURCE_USAGE_OCL_SYSTEM_MEMORY_BUFFER;
break;
}

View File

@@ -1181,10 +1181,22 @@ HWTEST_F(ProductHelperTest, givenProductHelperWhenCallingUseAdditionalBlitProper
EXPECT_FALSE(productHelper->useAdditionalBlitProperties());
}
HWTEST2_F(ProductHelperTest, givenProductHelperWhenCallingAllowSharedResourcesInCoherentMemoryThenFalseReturned, IsBeforeXe2HpgCore) {
EXPECT_FALSE(productHelper->allowSharedResourcesInCoherentMemory());
HWTEST2_F(ProductHelperTest, givenProductHelperWhenCallingIsResourceUncachedForCSThenFalseReturned, IsBeforeXe2HpgCore) {
for (uint32_t i = 0; i < static_cast<uint32_t>(AllocationType::count); i++) {
auto allocationType = static_cast<AllocationType>(i);
EXPECT_FALSE(productHelper->isResourceUncachedForCS(allocationType));
}
}
HWTEST2_F(ProductHelperTest, givenProductHelperWhenCallingAllowSharedResourcesInCoherentMemoryThenTrueReturned, IsAtLeastXe2HpgCore) {
EXPECT_TRUE(productHelper->allowSharedResourcesInCoherentMemory());
HWTEST2_F(ProductHelperTest, givenProductHelperWhenCallingIsResourceUncachedForCSThenTrueReturned, IsAtLeastXe2HpgCore) {
for (uint32_t i = 0; i < static_cast<uint32_t>(AllocationType::count); i++) {
auto allocationType = static_cast<AllocationType>(i);
if (allocationType == AllocationType::commandBuffer ||
allocationType == AllocationType::ringBuffer ||
allocationType == AllocationType::semaphoreBuffer) {
EXPECT_TRUE(productHelper->isResourceUncachedForCS(allocationType));
} else {
EXPECT_FALSE(productHelper->isResourceUncachedForCS(allocationType));
}
}
}

View File

@@ -142,11 +142,11 @@ TEST_F(WddmMemoryManagerTests, GivenNotCompressedAndNotLockableAllocationTypeWhe
memoryManager->freeGraphicsMemory(graphicsAllocation);
}
TEST_F(WddmMemoryManagerTests, GivenOverrideAllocationCacheableWhenAllocateUsingKmdAndMapToCpuVaThenOverrideAllocationCacheable) {
TEST_F(WddmMemoryManagerTests, GivenoverrideAllocationCpuCacheableWhenAllocateUsingKmdAndMapToCpuVaThenoverrideAllocationCpuCacheable) {
NEO::AllocationData allocData = {};
allocData.type = NEO::AllocationType::commandBuffer;
auto mockProductHelper = std::make_unique<MockProductHelper>();
mockProductHelper->overrideAllocationCacheableResult = true;
mockProductHelper->overrideAllocationCpuCacheableResult = true;
executionEnvironment->rootDeviceEnvironments[0]->productHelper.reset(mockProductHelper.release());
memoryManager->callBaseAllocateGraphicsMemoryUsingKmdAndMapItToCpuVA = true;

View File

@@ -108,13 +108,13 @@ LNLTEST_F(LnlProductHelper, givenProductHelperWhenCallIsCachingOnCpuAvailableThe
EXPECT_FALSE(productHelper->isCachingOnCpuAvailable());
}
LNLTEST_F(LnlProductHelper, givenProductHelperWhenCheckOverrideAllocationCacheableThenTrueIsReturnedForCommandBuffer) {
LNLTEST_F(LnlProductHelper, givenProductHelperWhenCheckoverrideAllocationCpuCacheableThenTrueIsReturnedForCommandBuffer) {
AllocationData allocationData{};
allocationData.type = AllocationType::commandBuffer;
EXPECT_TRUE(productHelper->overrideAllocationCacheable(allocationData));
EXPECT_TRUE(productHelper->overrideAllocationCpuCacheable(allocationData));
allocationData.type = AllocationType::buffer;
EXPECT_FALSE(productHelper->overrideAllocationCacheable(allocationData));
EXPECT_FALSE(productHelper->overrideAllocationCpuCacheable(allocationData));
}
LNLTEST_F(LnlProductHelper, givenExternalHostPtrWhenMitigateDcFlushThenOverrideCacheable) {
@@ -123,7 +123,7 @@ LNLTEST_F(LnlProductHelper, givenExternalHostPtrWhenMitigateDcFlushThenOverrideC
AllocationData allocationData{};
allocationData.type = AllocationType::externalHostPtr;
EXPECT_FALSE(productHelper->overrideAllocationCacheable(allocationData));
EXPECT_FALSE(productHelper->overrideAllocationCpuCacheable(allocationData));
debugManager.flags.AllowDcFlush.set(0);
@@ -132,7 +132,9 @@ LNLTEST_F(LnlProductHelper, givenExternalHostPtrWhenMitigateDcFlushThenOverrideC
allocationData.type = allocationType;
switch (allocationData.type) {
case AllocationType::commandBuffer:
EXPECT_TRUE(productHelper->overrideAllocationCacheable(allocationData));
case AllocationType::ringBuffer:
case AllocationType::semaphoreBuffer:
EXPECT_TRUE(productHelper->overrideAllocationCpuCacheable(allocationData));
break;
case AllocationType::externalHostPtr:
case AllocationType::bufferHostMemory:
@@ -141,11 +143,11 @@ LNLTEST_F(LnlProductHelper, givenExternalHostPtrWhenMitigateDcFlushThenOverrideC
case AllocationType::svmZeroCopy:
case AllocationType::internalHostMemory:
case AllocationType::printfSurface:
EXPECT_TRUE(productHelper->overrideAllocationCacheable(allocationData));
EXPECT_TRUE(productHelper->overrideAllocationCpuCacheable(allocationData));
EXPECT_TRUE(productHelper->overrideCacheableForDcFlushMitigation(allocationData.type));
break;
default:
EXPECT_FALSE(productHelper->overrideAllocationCacheable(allocationData));
EXPECT_FALSE(productHelper->overrideAllocationCpuCacheable(allocationData));
EXPECT_FALSE(productHelper->overrideCacheableForDcFlushMitigation(allocationData.type));
break;
}

View File

@@ -46,13 +46,13 @@ PTLTEST_F(PtlProductHelper, givenProductHelperWhenCheckDirectSubmissionSupported
EXPECT_TRUE(productHelper->isDirectSubmissionSupported(releaseHelper));
}
PTLTEST_F(PtlProductHelper, givenProductHelperWhenCheckOverrideAllocationCacheableThenTrueIsReturnedForCommandBuffer) {
PTLTEST_F(PtlProductHelper, givenProductHelperWhenCheckoverrideAllocationCpuCacheableThenTrueIsReturnedForCommandBuffer) {
AllocationData allocationData{};
allocationData.type = AllocationType::commandBuffer;
EXPECT_TRUE(productHelper->overrideAllocationCacheable(allocationData));
EXPECT_TRUE(productHelper->overrideAllocationCpuCacheable(allocationData));
allocationData.type = AllocationType::buffer;
EXPECT_FALSE(productHelper->overrideAllocationCacheable(allocationData));
EXPECT_FALSE(productHelper->overrideAllocationCpuCacheable(allocationData));
}
PTLTEST_F(PtlProductHelper, givenExternalHostPtrWhenMitigateDcFlushThenOverrideCacheable) {
@@ -61,7 +61,7 @@ PTLTEST_F(PtlProductHelper, givenExternalHostPtrWhenMitigateDcFlushThenOverrideC
AllocationData allocationData{};
allocationData.type = AllocationType::externalHostPtr;
EXPECT_FALSE(productHelper->overrideAllocationCacheable(allocationData));
EXPECT_FALSE(productHelper->overrideAllocationCpuCacheable(allocationData));
debugManager.flags.AllowDcFlush.set(0);
@@ -70,7 +70,9 @@ PTLTEST_F(PtlProductHelper, givenExternalHostPtrWhenMitigateDcFlushThenOverrideC
allocationData.type = allocationType;
switch (allocationData.type) {
case AllocationType::commandBuffer:
EXPECT_TRUE(productHelper->overrideAllocationCacheable(allocationData));
case AllocationType::ringBuffer:
case AllocationType::semaphoreBuffer:
EXPECT_TRUE(productHelper->overrideAllocationCpuCacheable(allocationData));
break;
case AllocationType::externalHostPtr:
case AllocationType::bufferHostMemory:
@@ -79,11 +81,11 @@ PTLTEST_F(PtlProductHelper, givenExternalHostPtrWhenMitigateDcFlushThenOverrideC
case AllocationType::svmZeroCopy:
case AllocationType::internalHostMemory:
case AllocationType::printfSurface:
EXPECT_TRUE(productHelper->overrideAllocationCacheable(allocationData));
EXPECT_TRUE(productHelper->overrideAllocationCpuCacheable(allocationData));
EXPECT_TRUE(productHelper->overrideCacheableForDcFlushMitigation(allocationData.type));
break;
default:
EXPECT_FALSE(productHelper->overrideAllocationCacheable(allocationData));
EXPECT_FALSE(productHelper->overrideAllocationCpuCacheable(allocationData));
EXPECT_FALSE(productHelper->overrideCacheableForDcFlushMitigation(allocationData.type));
break;
}

View File

@@ -72,11 +72,11 @@ MTLTEST_F(MtlProductHelper, givenMtlWithoutHwIpVersionInHwInfoWhenGettingIpVersi
EXPECT_EQ(compilerProductHelper->getDefaultHwIpVersion(), compilerProductHelper->getHwIpVersion(hwInfo));
}
MTLTEST_F(MtlProductHelper, givenProductHelperWhenCheckOverrideAllocationCacheableThenTrueIsReturnedForCommandBuffer) {
MTLTEST_F(MtlProductHelper, givenProductHelperWhenCheckoverrideAllocationCpuCacheableThenTrueIsReturnedForCommandBuffer) {
AllocationData allocationData{};
allocationData.type = AllocationType::commandBuffer;
EXPECT_TRUE(productHelper->overrideAllocationCacheable(allocationData));
EXPECT_TRUE(productHelper->overrideAllocationCpuCacheable(allocationData));
allocationData.type = AllocationType::buffer;
EXPECT_FALSE(productHelper->overrideAllocationCacheable(allocationData));
EXPECT_FALSE(productHelper->overrideAllocationCpuCacheable(allocationData));
}