performance(ocl): enable device usm alloc reuse

Enabling on MTL+
Limited to use max 2% of global device memory.

Related-To: NEO-6893, NEO-11463

Signed-off-by: Dominik Dabek <dominik.dabek@intel.com>
This commit is contained in:
Dominik Dabek
2024-05-17 11:54:37 +00:00
committed by Compute-Runtime-Automation
parent 95b7929d97
commit a236171f0d
16 changed files with 86 additions and 11 deletions

View File

@@ -39,7 +39,8 @@ TEST(ApiSpecificConfigL0Tests, WhenGettingRegistryPathThenL0RegistryPathIsReturn
EXPECT_STREQ(L0::registryPath, ApiSpecificConfig::getRegistryPath());
}
TEST(ApiSpecificConfigL0Tests, WhenCheckingIfDeviceAllocationCacheIsEnabledThenReturnFalse) {
TEST(ApiSpecificConfigL0Tests, WhenCheckingIfHostDeviceAllocationCacheIsEnabledThenReturnFalse) {
EXPECT_FALSE(ApiSpecificConfig::isHostAllocationCacheEnabled());
EXPECT_FALSE(ApiSpecificConfig::isDeviceAllocationCacheEnabled());
}

View File

@@ -33,7 +33,7 @@ bool ApiSpecificConfig::getBindlessMode(const ReleaseHelper *releaseHelper) {
}
bool ApiSpecificConfig::isDeviceAllocationCacheEnabled() {
return false;
return true;
}
bool ApiSpecificConfig::isHostAllocationCacheEnabled() {

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2018-2023 Intel Corporation
* Copyright (C) 2018-2024 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -821,6 +821,7 @@ TEST_F(GTPinContextDestroyTest, whenCallingConxtextDestructorThenGTPinIsNotified
if (mockContext->svmAllocsManager) {
mockContext->getDeviceMemAllocPool().cleanup();
mockContext->getHostMemAllocPool().cleanup();
mockContext->svmAllocsManager->trimUSMDeviceAllocCache();
delete mockContext->svmAllocsManager;
}
mockContext->svmAllocsManager = new MockSVMAllocManager();

View File

@@ -41,8 +41,9 @@ TEST(ApiSpecificConfigOclTests, WhenGettingRegistryPathThenOclRegistryPathIsRetu
EXPECT_STREQ(oclRegPath, ApiSpecificConfig::getRegistryPath());
}
TEST(ApiSpecificConfigOclTests, WhenCheckingIfDeviceAllocationCacheIsEnabledThenReturnFalse) {
EXPECT_FALSE(ApiSpecificConfig::isDeviceAllocationCacheEnabled());
TEST(ApiSpecificConfigOclTests, WhenCheckingIfHostOrDeviceAllocationCacheIsEnabledThenReturnCorrectValue) {
EXPECT_FALSE(ApiSpecificConfig::isHostAllocationCacheEnabled());
EXPECT_TRUE(ApiSpecificConfig::isDeviceAllocationCacheEnabled());
}
TEST(ApiSpecificConfigOclTests, givenEnableStatelessCompressionWhenProvidingSvmGpuAllocationThenPreferCompressedBuffer) {

View File

@@ -698,7 +698,7 @@ void SVMAllocsManager::initUsmHostAllocationsCache() {
}
void SVMAllocsManager::initUsmAllocationsCaches(Device &device) {
this->usmDeviceAllocationsCacheEnabled = NEO::ApiSpecificConfig::isDeviceAllocationCacheEnabled();
this->usmDeviceAllocationsCacheEnabled = NEO::ApiSpecificConfig::isDeviceAllocationCacheEnabled() && device.getProductHelper().isDeviceUsmAllocationReuseSupported();
if (debugManager.flags.ExperimentalEnableDeviceAllocationCache.get() != -1) {
this->usmDeviceAllocationsCacheEnabled = !!debugManager.flags.ExperimentalEnableDeviceAllocationCache.get();
}

View File

@@ -172,6 +172,7 @@ class ProductHelper {
virtual bool isMidThreadPreemptionDisallowedForRayTracingKernels() const = 0;
virtual bool isBufferPoolAllocatorSupported() const = 0;
virtual bool isUsmPoolAllocatorSupported() const = 0;
virtual bool isDeviceUsmAllocationReuseSupported() const = 0;
virtual bool useLocalPreferredForCacheableBuffers() const = 0;
virtual bool useGemCreateExtInAllocateMemoryByKMD() const = 0;
virtual bool isTlbFlushRequired() const = 0;

View File

@@ -103,6 +103,11 @@ bool ProductHelperHw<gfxProduct>::isUsmPoolAllocatorSupported() const {
return false;
}
template <PRODUCT_FAMILY gfxProduct>
bool ProductHelperHw<gfxProduct>::isDeviceUsmAllocationReuseSupported() const {
return false;
}
template <PRODUCT_FAMILY gfxProduct>
bool ProductHelperHw<gfxProduct>::useLocalPreferredForCacheableBuffers() const {
return false;

View File

@@ -118,6 +118,7 @@ class ProductHelperHw : public ProductHelper {
bool isMidThreadPreemptionDisallowedForRayTracingKernels() const override;
bool isBufferPoolAllocatorSupported() const override;
bool isUsmPoolAllocatorSupported() const override;
bool isDeviceUsmAllocationReuseSupported() const override;
bool useLocalPreferredForCacheableBuffers() const override;
bool useGemCreateExtInAllocateMemoryByKMD() const override;
bool isTlbFlushRequired() const override;

View File

@@ -46,4 +46,9 @@ bool ProductHelperHw<gfxProduct>::isDeviceToHostCopySignalingFenceRequired() con
return true;
}
template <>
bool ProductHelperHw<gfxProduct>::isDeviceUsmAllocationReuseSupported() const {
return false;
}
} // namespace NEO

View File

@@ -256,4 +256,9 @@ void ProductHelperHw<gfxProduct>::adjustNumberOfCcs(HardwareInfo &hwInfo) const
hwInfo.gtSystemInfo.CCSInfo.NumberOfCCSEnabled = 1;
}
template <>
bool ProductHelperHw<gfxProduct>::isDeviceUsmAllocationReuseSupported() const {
return false;
}
} // namespace NEO

View File

@@ -108,4 +108,9 @@ bool ProductHelperHw<gfxProduct>::isNewCoherencyModelSupported() const {
return true;
}
template <>
bool ProductHelperHw<gfxProduct>::isDeviceUsmAllocationReuseSupported() const {
return true;
}
} // namespace NEO

View File

@@ -412,6 +412,11 @@ bool ProductHelperHw<gfxProduct>::isUsmPoolAllocatorSupported() const {
return false;
}
template <PRODUCT_FAMILY gfxProduct>
bool ProductHelperHw<gfxProduct>::isDeviceUsmAllocationReuseSupported() const {
return false;
}
template <PRODUCT_FAMILY gfxProduct>
bool ProductHelperHw<gfxProduct>::useLocalPreferredForCacheableBuffers() const {
return false;

View File

@@ -20,5 +20,6 @@ struct MockProductHelper : ProductHelperHw<IGFX_UNKNOWN> {
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));
ADDMETHOD_CONST_NOBASE(isDeviceUsmAllocationReuseSupported, bool, false, ());
};
} // namespace NEO

View File

@@ -40,7 +40,11 @@ bool ApiSpecificConfig::getBindlessMode(const ReleaseHelper *) {
}
bool ApiSpecificConfig::isDeviceAllocationCacheEnabled() {
return false;
if (apiTypeForUlts == ApiSpecificConfig::L0) {
return false;
} else {
return true;
}
}
bool ApiSpecificConfig::isHostAllocationCacheEnabled() {

View File

@@ -5,17 +5,22 @@
*
*/
#include "shared/source/helpers/api_specific_config.h"
#include "shared/test/common/helpers/debug_manager_state_restore.h"
#include "shared/test/common/helpers/raii_product_helper.h"
#include "shared/test/common/mocks/mock_device.h"
#include "shared/test/common/mocks/mock_graphics_allocation.h"
#include "shared/test/common/mocks/mock_memory_manager.h"
#include "shared/test/common/mocks/mock_product_helper.h"
#include "shared/test/common/mocks/mock_svm_manager.h"
#include "shared/test/common/mocks/ult_device_factory.h"
#include "shared/test/common/test_macros/hw_test.h"
#include "shared/test/common/test_macros/test.h"
#include "gtest/gtest.h"
namespace NEO {
using namespace NEO;
extern ApiSpecificConfig::ApiType apiTypeForUlts;
TEST(SortedVectorBasedAllocationTrackerTests, givenSortedVectorBasedAllocationTrackerWhenInsertRemoveAndGetThenStoreDataProperly) {
SvmAllocationData data(1u);
@@ -99,16 +104,38 @@ struct SvmAllocationCacheTestFixture {
using SvmDeviceAllocationCacheTest = Test<SvmAllocationCacheTestFixture>;
TEST_F(SvmDeviceAllocationCacheTest, givenAllocationCacheDefaultWhenCheckingIfEnabledThenItIsDisabled) {
TEST_F(SvmDeviceAllocationCacheTest, givenAllocationCacheDisabledWhenCheckingIfEnabledThenItIsDisabled) {
DebugManagerStateRestore restorer;
std::unique_ptr<UltDeviceFactory> deviceFactory(new UltDeviceFactory(1, 1));
auto device = deviceFactory->rootDevices[0];
auto svmManager = std::make_unique<MockSVMAllocsManager>(device->getMemoryManager(), false);
ASSERT_EQ(debugManager.flags.ExperimentalEnableDeviceAllocationCache.get(), -1);
debugManager.flags.ExperimentalEnableDeviceAllocationCache.set(0);
EXPECT_FALSE(svmManager->usmDeviceAllocationsCacheEnabled);
svmManager->initUsmAllocationsCaches(*device);
EXPECT_FALSE(svmManager->usmDeviceAllocationsCacheEnabled);
}
HWTEST_F(SvmDeviceAllocationCacheTest, givenOclApiSpecificConfigWhenCheckingIfEnabledItIsEnabledIfProductHelperMethodReturnsTrue) {
VariableBackup<ApiSpecificConfig::ApiType> backup(&apiTypeForUlts, ApiSpecificConfig::OCL);
std::unique_ptr<UltDeviceFactory> deviceFactory(new UltDeviceFactory(1, 1));
auto device = deviceFactory->rootDevices[0];
RAIIProductHelperFactory<MockProductHelper> raii(*device->getExecutionEnvironment()->rootDeviceEnvironments[0]);
{
raii.mockProductHelper->isDeviceUsmAllocationReuseSupportedResult = false;
auto svmManager = std::make_unique<MockSVMAllocsManager>(device->getMemoryManager(), false);
EXPECT_FALSE(svmManager->usmDeviceAllocationsCacheEnabled);
svmManager->initUsmAllocationsCaches(*device);
EXPECT_FALSE(svmManager->usmDeviceAllocationsCacheEnabled);
}
{
raii.mockProductHelper->isDeviceUsmAllocationReuseSupportedResult = true;
auto svmManager = std::make_unique<MockSVMAllocsManager>(device->getMemoryManager(), false);
EXPECT_FALSE(svmManager->usmDeviceAllocationsCacheEnabled);
svmManager->initUsmAllocationsCaches(*device);
EXPECT_TRUE(svmManager->usmDeviceAllocationsCacheEnabled);
}
}
struct SvmDeviceAllocationCacheSimpleTestDataType {
size_t allocationSize;
void *allocation;
@@ -889,4 +916,5 @@ TEST_F(SvmHostAllocationCacheTest, givenHostOutOfMemoryWhenAllocatingThenCacheIs
svmManager->trimUSMHostAllocCache();
ASSERT_EQ(svmManager->usmHostAllocationsCache.allocations.size(), 0u);
}
}
} // namespace NEO

View File

@@ -828,6 +828,18 @@ HWTEST2_F(ProductHelperTest, givenProductHelperWhenCheckingIsUsmPoolAllocatorSup
EXPECT_TRUE(productHelper->isUsmPoolAllocatorSupported());
}
HWTEST2_F(ProductHelperTest, givenProductHelperWhenCheckingIsDeviceUsmAllocationReuseSupportedThenCorrectValueIsReturned, IsAtMostDg2) {
EXPECT_FALSE(productHelper->isDeviceUsmAllocationReuseSupported());
}
HWTEST2_F(ProductHelperTest, givenProductHelperWhenCheckingIsDeviceUsmAllocationReuseSupportedThenCorrectValueIsReturned, IsXeHpcCore) {
EXPECT_FALSE(productHelper->isDeviceUsmAllocationReuseSupported());
}
HWTEST2_F(ProductHelperTest, givenProductHelperWhenCheckingIsDeviceUsmAllocationReuseSupportedThenCorrectValueIsReturned, IsAtLeastMtl) {
EXPECT_TRUE(productHelper->isDeviceUsmAllocationReuseSupported());
}
HWTEST_F(ProductHelperTest, givenProductHelperWhenCheckingIsUnlockingLockedPtrNecessaryThenReturnFalse) {
EXPECT_FALSE(productHelper->isUnlockingLockedPtrNecessary(pInHwInfo));
}