performance: add override cacheable to gmm

add attribute to override cacheable attribute to gmm constructor

enable this override for command buffers on mtl

change command buffers back to allocation by kmd

this keeps the quicker allocation which is needed to keep enqueue times
low

Related-To: NEO-8152

Signed-off-by: Dominik Dabek <dominik.dabek@intel.com>
This commit is contained in:
Dominik Dabek
2023-11-15 15:04:20 +00:00
committed by Compute-Runtime-Automation
parent bcc9c367a2
commit 8f06f3f50a
16 changed files with 78 additions and 33 deletions

View File

@@ -39,8 +39,12 @@ Gmm::Gmm(GmmHelper *gmmHelper, const void *alignedPtr, size_t alignedSize, size_
resourceParams.Usage = gmmResourceUsage;
resourceParams.Flags.Info.Linear = 1;
this->preferNoCpuAccess = CacheSettingsHelper::preferNoCpuAccess(gmmResourceUsage, gmmHelper->getRootDeviceEnvironment());
resourceParams.Flags.Info.Cacheable = !this->preferNoCpuAccess && !CacheSettingsHelper::isUncachedType(gmmResourceUsage);
bool cacheable = !this->preferNoCpuAccess && !CacheSettingsHelper::isUncachedType(gmmResourceUsage);
gmmRequirements.overriderCacheable.doOverride(cacheable);
resourceParams.Flags.Info.Cacheable = cacheable;
resourceParams.Flags.Gpu.Texture = 1;
if (alignedPtr) {

View File

@@ -19,9 +19,22 @@ struct StorageInfo;
class GmmResourceInfo;
class GmmHelper;
template <typename OverriddenType>
struct Overrider {
bool enableOverride{false};
OverriddenType value;
void doOverride(OverriddenType &variable) const {
if (enableOverride) {
variable = value;
}
}
};
struct GmmRequirements {
bool preferCompressed;
bool allowLargePages;
Overrider<bool> overriderCacheable;
};
class Gmm {

View File

@@ -20,6 +20,7 @@ enum class ProductFamily : uint32_t;
namespace NEO {
struct AllocationData;
class CommandStreamReceiver;
class Device;
enum class LocalMemoryAccessMode;
@@ -168,6 +169,7 @@ class ProductHelper {
virtual uint32_t getCommandBuffersPreallocatedPerCommandQueue() const = 0;
virtual bool isPlatformDpasSupported() const = 0;
virtual bool isPlatformDp4aSupported() const = 0;
virtual bool overrideAllocationCacheable(const AllocationData &allocationData) const = 0;
virtual bool getFrontEndPropertyScratchSizeSupport() const = 0;
virtual bool getFrontEndPropertyPrivateScratchSizeSupport() const = 0;

View File

@@ -176,6 +176,11 @@ bool ProductHelperHw<gfxProduct>::isPlatformDp4aSupported() const {
return false;
}
template <PRODUCT_FAMILY gfxProduct>
bool ProductHelperHw<gfxProduct>::overrideAllocationCacheable(const AllocationData &allocationData) const {
return false;
}
template <PRODUCT_FAMILY gfxProduct>
bool ProductHelperHw<gfxProduct>::isAdditionalStateBaseAddressWARequired(const HardwareInfo &hwInfo) const {
return false;

View File

@@ -122,6 +122,7 @@ class ProductHelperHw : public ProductHelper {
uint32_t getCommandBuffersPreallocatedPerCommandQueue() const override;
bool isPlatformDpasSupported() const override;
bool isPlatformDp4aSupported() const override;
bool overrideAllocationCacheable(const AllocationData &allocationData) const override;
bool getFrontEndPropertyScratchSizeSupport() const override;
bool getFrontEndPropertyPrivateScratchSizeSupport() const override;

View File

@@ -111,7 +111,6 @@ bool WddmMemoryManager::mapPhysicalToVirtualMemory(GraphicsAllocation *physicalA
}
GraphicsAllocation *WddmMemoryManager::allocatePhysicalDeviceMemory(const AllocationData &allocationData, AllocationStatus &status) {
auto &productHelper = executionEnvironment.rootDeviceEnvironments[allocationData.rootDeviceIndex]->getHelper<ProductHelper>();
StorageInfo systemMemoryStorageInfo = {};
systemMemoryStorageInfo.isLockable = allocationData.storageInfo.isLockable;
@@ -215,6 +214,10 @@ GraphicsAllocation *WddmMemoryManager::allocateGraphicsMemoryUsingKmdAndMapItToC
GmmRequirements gmmRequirements{};
gmmRequirements.allowLargePages = allowLargePages;
gmmRequirements.preferCompressed = allocationData.flags.preferCompressed;
if (productHelper.overrideAllocationCacheable(allocationData)) {
gmmRequirements.overriderCacheable.enableOverride = true;
gmmRequirements.overriderCacheable.value = true;
}
auto gmm = new Gmm(executionEnvironment.rootDeviceEnvironments[allocationData.rootDeviceIndex]->getGmmHelper(), nullptr,
sizeAligned, 0u,

View File

@@ -21,8 +21,6 @@ std::optional<GfxMemoryAllocationMethod> ReleaseHelperHw<release>::getPreferredA
case AllocationType::TAG_BUFFER:
case AllocationType::TIMESTAMP_PACKET_TAG_BUFFER:
return {};
case AllocationType::COMMAND_BUFFER:
return GfxMemoryAllocationMethod::UseUmdSystemPtr;
default:
return GfxMemoryAllocationMethod::AllocateByKmd;
}

View File

@@ -7,6 +7,7 @@
#include "shared/source/command_stream/command_stream_receiver.h"
#include "shared/source/helpers/gfx_core_helper.h"
#include "shared/source/memory_manager/allocation_properties.h"
#include "shared/source/memory_manager/allocation_type.h"
#include "shared/source/os_interface/product_helper.h"
#include "shared/source/os_interface/product_helper.inl"
@@ -91,6 +92,11 @@ bool ProductHelperHw<gfxProduct>::isPlatformDp4aSupported() const {
return true;
}
template <>
bool ProductHelperHw<gfxProduct>::overrideAllocationCacheable(const AllocationData &allocationData) const {
return allocationData.type == AllocationType::COMMAND_BUFFER;
}
template <>
uint32_t ProductHelperHw<gfxProduct>::getCommandBuffersPreallocatedPerCommandQueue() const {
return 2u;

View File

@@ -16,6 +16,7 @@ struct MockProductHelper : ProductHelperHw<IGFX_UNKNOWN> {
MockProductHelper() = default;
ADDMETHOD_CONST_NOBASE(is48bResourceNeededForRayTracing, bool, true, ());
ADDMETHOD_CONST_NOBASE(overrideAllocationCacheable, bool, false, (const AllocationData &allocationData));
ADDMETHOD_NOBASE(configureHwInfoWddm, int, 0, (const HardwareInfo *inHwInfo, HardwareInfo *outHwInfo, const RootDeviceEnvironment &rootDeviceEnvironment));
};
} // namespace NEO

View File

@@ -119,6 +119,12 @@ HWTEST_F(GmmTests, givenVariousResourceUsageTypeWhenCreateGmmThenFlagCacheableIs
auto gmm = std::make_unique<Gmm>(getGmmHelper(), nullptr, 0, 0, uncacheableResourceUsageType, storageInfo, gmmRequirements);
EXPECT_FALSE(gmm->resourceParams.Flags.Info.Cacheable);
}
{
gmmRequirements.overriderCacheable.enableOverride = true;
gmmRequirements.overriderCacheable.value = true;
auto gmm = std::make_unique<Gmm>(getGmmHelper(), nullptr, 0, 0, GMM_RESOURCE_USAGE_OCL_BUFFER, storageInfo, gmmRequirements);
EXPECT_TRUE(gmm->resourceParams.Flags.Info.Cacheable);
}
}
} // namespace NEO

View File

@@ -28,6 +28,7 @@
#include "shared/test/common/mocks/mock_gmm_page_table_mngr.h"
#include "shared/test/common/mocks/mock_memory_manager.h"
#include "shared/test/common/mocks/mock_os_context.h"
#include "shared/test/common/mocks/mock_product_helper.h"
#include "shared/test/common/mocks/windows/mock_wddm_allocation.h"
#include "shared/test/common/os_interface/windows/mock_wddm_memory_manager.h"
#include "shared/test/common/os_interface/windows/wddm_fixture.h"
@@ -141,6 +142,23 @@ TEST_F(WddmMemoryManagerTests, GivenNotCompressedAndNotLockableAllocationTypeWhe
memoryManager->freeGraphicsMemory(graphicsAllocation);
}
TEST_F(WddmMemoryManagerTests, GivenOverrideAllocationCacheableWhenAllocateUsingKmdAndMapToCpuVaThenOverrideAllocationCacheable) {
NEO::AllocationData allocData = {};
allocData.type = NEO::AllocationType::COMMAND_BUFFER;
auto mockProductHelper = std::make_unique<MockProductHelper>();
mockProductHelper->overrideAllocationCacheableResult = true;
executionEnvironment->rootDeviceEnvironments[0]->productHelper.reset(mockProductHelper.release());
memoryManager->callBaseAllocateGraphicsMemoryUsingKmdAndMapItToCpuVA = true;
auto graphicsAllocation = memoryManager->allocateGraphicsMemoryUsingKmdAndMapItToCpuVA(allocData, false);
ASSERT_NE(nullptr, graphicsAllocation);
EXPECT_TRUE(graphicsAllocation->getDefaultGmm()->resourceParams.Flags.Info.Cacheable);
memoryManager->freeGraphicsMemory(graphicsAllocation);
}
TEST_F(WddmMemoryManagerTests, GivenCompressedAndNotLockableAllocationTypeWhenAllocateUsingKmdAndMapToCpuVaThenSetResourceNotLockable) {
NEO::AllocationData allocData = {};
allocData.type = NEO::AllocationType::BUFFER;

View File

@@ -66,8 +66,8 @@ TEST_F(ReleaseHelper1270Tests, whenGettingMediaFrequencyTileIndexThenOneIsReturn
whenGettingMediaFrequencyTileIndexThenOneIsReturned();
}
TEST_F(ReleaseHelper1270Tests, whenCheckPreferredAllocationMethodThenAllocateByKmdIsReturnedExceptTagBufferAndTimestapPacketTagBuffer) {
whenCheckPreferredAllocationMethodThenAllocateByKmdIsReturnedExceptTagBufferAndTimestampPacketTagBufferAndCommandBuffer();
TEST_F(ReleaseHelper1270Tests, whenCheckPreferredAllocationMethodThenAllocateByKmdIsReturnedExceptTagBufferAndTimestampPacketTagBuffer) {
whenCheckPreferredAllocationMethodThenAllocateByKmdIsReturnedExceptTagBufferAndTimestampPacketTagBuffer();
}
TEST_F(ReleaseHelper1270Tests, whenGettingSupportedNumGrfsThenCorrectValuesAreReturned) {

View File

@@ -67,8 +67,8 @@ TEST_F(ReleaseHelper1271Tests, whenGettingMediaFrequencyTileIndexThenOneIsReturn
whenGettingMediaFrequencyTileIndexThenOneIsReturned();
}
TEST_F(ReleaseHelper1271Tests, whenCheckPreferredAllocationMethodThenAllocateByKmdIsReturnedExceptTagBufferAndTimestapPacketTagBuffer) {
whenCheckPreferredAllocationMethodThenAllocateByKmdIsReturnedExceptTagBufferAndTimestampPacketTagBufferAndCommandBuffer();
TEST_F(ReleaseHelper1271Tests, whenCheckPreferredAllocationMethodThenAllocateByKmdIsReturnedExceptTagBufferAndTimestampPacketTagBuffer) {
whenCheckPreferredAllocationMethodThenAllocateByKmdIsReturnedExceptTagBufferAndTimestampPacketTagBuffer();
}
TEST_F(ReleaseHelper1271Tests, whenGettingSupportedNumGrfsThenCorrectValuesAreReturned) {

View File

@@ -68,7 +68,7 @@ void ReleaseHelperTestsBase::whenGettingMediaFrequencyTileIndexThenOneIsReturned
}
}
void ReleaseHelperTestsBase::whenCheckPreferredAllocationMethodThenAllocateByKmdIsReturnedExceptTagBufferAndTimestapPacketTagBuffer() {
void ReleaseHelperTestsBase::whenCheckPreferredAllocationMethodThenAllocateByKmdIsReturnedExceptTagBufferAndTimestampPacketTagBuffer() {
for (auto &revision : getRevisions()) {
ipVersion.revision = revision;
releaseHelper = ReleaseHelper::create(ipVersion);
@@ -87,28 +87,6 @@ void ReleaseHelperTestsBase::whenCheckPreferredAllocationMethodThenAllocateByKmd
}
}
void ReleaseHelperTestsBase::whenCheckPreferredAllocationMethodThenAllocateByKmdIsReturnedExceptTagBufferAndTimestampPacketTagBufferAndCommandBuffer() {
for (auto &revision : getRevisions()) {
ipVersion.revision = revision;
releaseHelper = ReleaseHelper::create(ipVersion);
ASSERT_NE(nullptr, releaseHelper);
for (auto i = 0; i < static_cast<int>(AllocationType::COUNT); i++) {
auto allocationType = static_cast<AllocationType>(i);
auto preferredAllocationMethod = releaseHelper->getPreferredAllocationMethod(allocationType);
if (allocationType == AllocationType::TAG_BUFFER ||
allocationType == AllocationType::TIMESTAMP_PACKET_TAG_BUFFER) {
EXPECT_FALSE(preferredAllocationMethod.has_value());
} else if (allocationType == AllocationType::COMMAND_BUFFER) {
EXPECT_TRUE(preferredAllocationMethod.has_value());
EXPECT_EQ(GfxMemoryAllocationMethod::UseUmdSystemPtr, preferredAllocationMethod.value());
} else {
EXPECT_TRUE(preferredAllocationMethod.has_value());
EXPECT_EQ(GfxMemoryAllocationMethod::AllocateByKmd, preferredAllocationMethod.value());
}
}
}
}
void ReleaseHelperTestsBase::whenShouldAdjustCalledThenTrueReturned() {
for (auto &revision : getRevisions()) {
ipVersion.revision = revision;

View File

@@ -25,8 +25,7 @@ struct ReleaseHelperTestsBase : public ::testing::Test {
void whenGettingPreferredAllocationMethodThenNoPreferenceIsReturned();
void whenGettingMaxPreferredSlmSizeThenSizeIsNotModified();
void whenGettingMediaFrequencyTileIndexThenOneIsReturned();
void whenCheckPreferredAllocationMethodThenAllocateByKmdIsReturnedExceptTagBufferAndTimestapPacketTagBuffer();
void whenCheckPreferredAllocationMethodThenAllocateByKmdIsReturnedExceptTagBufferAndTimestampPacketTagBufferAndCommandBuffer();
void whenCheckPreferredAllocationMethodThenAllocateByKmdIsReturnedExceptTagBufferAndTimestampPacketTagBuffer();
void whenShouldAdjustCalledThenTrueReturned();
void whenShouldAdjustCalledThenFalseReturned();
void whenGettingSupportedNumGrfsThenValues128And256Returned();

View File

@@ -5,6 +5,8 @@
*
*/
#include "shared/source/memory_manager/allocation_properties.h"
#include "shared/source/memory_manager/allocation_type.h"
#include "shared/source/os_interface/product_helper.h"
#include "shared/source/xe_hpg_core/hw_cmds_mtl.h"
#include "shared/test/common/test_macros/header/per_product_test_definitions.h"
@@ -18,3 +20,12 @@ using MtlProductHelper = ProductHelperTest;
MTLTEST_F(MtlProductHelper, givenProductHelperWhenCheckDirectSubmissionSupportedThenTrueIsReturned) {
EXPECT_TRUE(productHelper->isDirectSubmissionSupported(releaseHelper));
}
MTLTEST_F(MtlProductHelper, givenProductHelperWhenCheckOverrideAllocationCacheableThenTrueIsReturnedForCommandBuffer) {
AllocationData allocationData{};
allocationData.type = AllocationType::COMMAND_BUFFER;
EXPECT_TRUE(productHelper->overrideAllocationCacheable(allocationData));
allocationData.type = AllocationType::BUFFER;
EXPECT_FALSE(productHelper->overrideAllocationCacheable(allocationData));
}