Skip to content

Commit 7411015

Browse files
fix: add infrastructure to limit device usm reuse max memory used
Related-To: NEO-12924 Signed-off-by: Dominik Dabek <[email protected]>
1 parent 81644a4 commit 7411015

File tree

8 files changed

+45
-1
lines changed

8 files changed

+45
-1
lines changed

shared/source/ail/ail_configuration.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ class AILConfiguration {
8282

8383
virtual bool disableBindlessAddressing() = 0;
8484

85+
virtual bool limitAmountOfDeviceMemoryForRecycling() = 0;
86+
8587
protected:
8688
virtual void applyExt(RuntimeCapabilityTable &runtimeCapabilityTable) = 0;
8789
std::string processName;
@@ -96,6 +98,7 @@ extern const std::set<std::string_view> applicationsContextSyncFlag;
9698
extern const std::set<std::string_view> applicationsForceRcsDg2;
9799
extern const std::set<std::string_view> applicationsBufferPoolDisabled;
98100
extern const std::set<std::string_view> applicationsOverfetchDisabled;
101+
extern const std::set<std::string_view> applicationsDeviceUSMRecyclingLimited;
99102

100103
template <PRODUCT_FAMILY product>
101104
class AILConfigurationHw : public AILConfiguration {
@@ -115,6 +118,7 @@ class AILConfigurationHw : public AILConfiguration {
115118
bool forceRcs() override;
116119
bool handleDivergentBarriers() override;
117120
bool disableBindlessAddressing() override;
121+
bool limitAmountOfDeviceMemoryForRecycling() override;
118122

119123
bool shouldForceRcs = false;
120124
bool shouldHandleDivergentBarriers = false;

shared/source/ail/ail_configuration_base.inl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,9 @@ inline void AILConfigurationHw<product>::setDisableBindlessAddressing(bool val)
6161
shouldDisableBindlessAddressing = val;
6262
}
6363

64+
template <PRODUCT_FAMILY product>
65+
inline bool AILConfigurationHw<product>::limitAmountOfDeviceMemoryForRecycling() {
66+
return false;
67+
}
68+
6469
} // namespace NEO

shared/source/ail/ail_configuration_extra.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ const std::set<std::string_view> applicationsBufferPoolDisabled = {};
3636

3737
const std::set<std::string_view> applicationsOverfetchDisabled = {};
3838

39+
const std::set<std::string_view> applicationsDeviceUSMRecyclingLimited = {};
40+
3941
AILConfigurationCreateFunctionType ailConfigurationFactory[IGFX_MAX_PRODUCT];
4042

4143
void AILConfiguration::apply(RuntimeCapabilityTable &runtimeCapabilityTable) {

shared/source/ail/xe2_hpg_core/lnl/ail_configuration_lnl.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ bool AILConfigurationHw<IGFX_LUNARLAKE>::isBufferPoolEnabled() {
1818
return iterator == applicationsBufferPoolDisabled.end();
1919
}
2020

21+
template <>
22+
bool AILConfigurationHw<IGFX_LUNARLAKE>::limitAmountOfDeviceMemoryForRecycling() {
23+
auto iterator = applicationsDeviceUSMRecyclingLimited.find(processName);
24+
return iterator != applicationsDeviceUSMRecyclingLimited.end();
25+
}
26+
2127
template <>
2228
bool AILConfigurationHw<IGFX_LUNARLAKE>::is256BPrefetchDisableRequired() {
2329
auto iterator = applicationsOverfetchDisabled.find(processName);

shared/source/ail/xe_hpg_core/mtl/ail_configuration_mtl.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@ bool AILConfigurationHw<IGFX_METEORLAKE>::isBufferPoolEnabled() {
5858
return iterator == applicationsBufferPoolDisabled.end();
5959
}
6060

61+
template <>
62+
bool AILConfigurationHw<IGFX_METEORLAKE>::limitAmountOfDeviceMemoryForRecycling() {
63+
auto iterator = applicationsDeviceUSMRecyclingLimited.find(processName);
64+
return iterator != applicationsDeviceUSMRecyclingLimited.end();
65+
}
66+
6167
template class AILConfigurationHw<IGFX_METEORLAKE>;
6268

6369
} // namespace NEO

shared/source/memory_manager/unified_memory_manager.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
#include "shared/source/memory_manager/unified_memory_manager.h"
99

10+
#include "shared/source/ail/ail_configuration.h"
1011
#include "shared/source/command_stream/command_stream_receiver.h"
1112
#include "shared/source/device/sub_device.h"
1213
#include "shared/source/execution_environment/execution_environment.h"
@@ -713,7 +714,9 @@ void SVMAllocsManager::freeZeroCopySvmAllocation(SvmAllocationData *svmData) {
713714
void SVMAllocsManager::initUsmDeviceAllocationsCache(Device &device) {
714715
this->usmDeviceAllocationsCache.allocations.reserve(128u);
715716
const auto totalDeviceMemory = device.getGlobalMemorySize(static_cast<uint32_t>(device.getDeviceBitfield().to_ulong()));
716-
auto fractionOfTotalMemoryForRecycling = 0.08;
717+
auto ailConfiguration = device.getAilConfigurationHelper();
718+
const bool limitDeviceMemoryForReuse = ailConfiguration && ailConfiguration->limitAmountOfDeviceMemoryForRecycling();
719+
auto fractionOfTotalMemoryForRecycling = limitDeviceMemoryForReuse ? 0.02 : 0.08;
717720
if (debugManager.flags.ExperimentalEnableDeviceAllocationCache.get() != -1) {
718721
fractionOfTotalMemoryForRecycling = 0.01 * std::min(100, debugManager.flags.ExperimentalEnableDeviceAllocationCache.get());
719722
}

shared/test/common/mocks/mock_ail_configuration.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ class MockAILConfiguration : public AILConfiguration {
3333
return isBufferPoolEnabledReturn;
3434
}
3535

36+
bool limitAmountOfDeviceMemoryForRecyclingReturn = false;
37+
bool limitAmountOfDeviceMemoryForRecycling() override {
38+
return limitAmountOfDeviceMemoryForRecyclingReturn;
39+
}
40+
3641
bool fallbackToLegacyValidationLogic = false;
3742
bool useLegacyValidationLogic() override {
3843
return fallbackToLegacyValidationLogic;

shared/test/unit_test/memory_manager/unified_memory_manager_cache_tests.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "shared/source/helpers/api_specific_config.h"
99
#include "shared/test/common/helpers/debug_manager_state_restore.h"
1010
#include "shared/test/common/helpers/raii_product_helper.h"
11+
#include "shared/test/common/mocks/mock_ail_configuration.h"
1112
#include "shared/test/common/mocks/mock_device.h"
1213
#include "shared/test/common/mocks/mock_graphics_allocation.h"
1314
#include "shared/test/common/mocks/mock_memory_manager.h"
@@ -136,6 +137,8 @@ HWTEST_F(SvmDeviceAllocationCacheTest, givenOclApiSpecificConfigWhenCheckingIfEn
136137
std::unique_ptr<UltDeviceFactory> deviceFactory(new UltDeviceFactory(1, 1));
137138
auto device = deviceFactory->rootDevices[0];
138139
RAIIProductHelperFactory<MockProductHelper> raii(*device->getExecutionEnvironment()->rootDeviceEnvironments[0]);
140+
MockAILConfiguration mockAilConfigurationHelper;
141+
device->mockAilConfigurationHelper = &mockAilConfigurationHelper;
139142
{
140143
raii.mockProductHelper->isDeviceUsmAllocationReuseSupportedResult = false;
141144
auto svmManager = std::make_unique<MockSVMAllocsManager>(device->getMemoryManager(), false);
@@ -152,6 +155,16 @@ HWTEST_F(SvmDeviceAllocationCacheTest, givenOclApiSpecificConfigWhenCheckingIfEn
152155
const auto expectedMaxSize = static_cast<size_t>(0.08 * device->getGlobalMemorySize(static_cast<uint32_t>(device->getDeviceBitfield().to_ullong())));
153156
EXPECT_EQ(expectedMaxSize, svmManager->usmDeviceAllocationsCache.maxSize);
154157
}
158+
{
159+
raii.mockProductHelper->isDeviceUsmAllocationReuseSupportedResult = true;
160+
mockAilConfigurationHelper.limitAmountOfDeviceMemoryForRecyclingReturn = true;
161+
auto svmManager = std::make_unique<MockSVMAllocsManager>(device->getMemoryManager(), false);
162+
EXPECT_FALSE(svmManager->usmDeviceAllocationsCacheEnabled);
163+
svmManager->initUsmAllocationsCaches(*device);
164+
EXPECT_TRUE(svmManager->usmDeviceAllocationsCacheEnabled);
165+
const auto expectedMaxSize = static_cast<size_t>(0.02 * device->getGlobalMemorySize(static_cast<uint32_t>(device->getDeviceBitfield().to_ullong())));
166+
EXPECT_EQ(expectedMaxSize, svmManager->usmDeviceAllocationsCache.maxSize);
167+
}
155168
}
156169

157170
struct SvmDeviceAllocationCacheSimpleTestDataType {

0 commit comments

Comments
 (0)