refactor: host usm recycle

Signed-off-by: Dominik Dabek <dominik.dabek@intel.com>
This commit is contained in:
Dominik Dabek
2024-07-23 14:40:05 +00:00
committed by Compute-Runtime-Automation
parent e65451e582
commit 9b3ccf73b7
13 changed files with 81 additions and 13 deletions

View File

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

View File

@@ -22,5 +22,6 @@ struct MockProductHelper : ProductHelperHw<IGFX_UNKNOWN> {
ADDMETHOD_CONST_NOBASE(supportReadOnlyAllocations, bool, false, ());
ADDMETHOD_CONST_NOBASE(isBlitCopyRequiredForLocalMemory, bool, true, (const RootDeviceEnvironment &rootDeviceEnvironment, const GraphicsAllocation &allocation));
ADDMETHOD_CONST_NOBASE(isDeviceUsmAllocationReuseSupported, bool, false, ());
ADDMETHOD_CONST_NOBASE(isHostUsmAllocationReuseSupported, bool, false, ());
};
} // namespace NEO

View File

@@ -48,7 +48,11 @@ bool ApiSpecificConfig::isDeviceAllocationCacheEnabled() {
}
bool ApiSpecificConfig::isHostAllocationCacheEnabled() {
return false;
if (apiTypeForUlts == ApiSpecificConfig::L0) {
return false;
} else {
return true;
}
}
bool ApiSpecificConfig::isDeviceUsmPoolingEnabled() {

View File

@@ -552,31 +552,51 @@ TEST_F(SvmDeviceAllocationCacheTest, givenAllocationWithIsInternalAllocationSetW
using SvmHostAllocationCacheTest = Test<SvmAllocationCacheTestFixture>;
TEST_F(SvmHostAllocationCacheTest, givenAllocationCacheDefaultWhenCheckingIfEnabledThenItIsDisabled) {
TEST_F(SvmHostAllocationCacheTest, givenAllocationCacheDisabledWhenCheckingIfEnabledThenItIsDisabled) {
DebugManagerStateRestore restorer;
std::unique_ptr<UltDeviceFactory> deviceFactory(new UltDeviceFactory(1, 1));
RootDeviceIndicesContainer rootDeviceIndices = {mockRootDeviceIndex};
std::map<uint32_t, DeviceBitfield> deviceBitfields{{mockRootDeviceIndex, mockDeviceBitfield}};
auto device = deviceFactory->rootDevices[0];
auto svmManager = std::make_unique<MockSVMAllocsManager>(device->getMemoryManager(), false);
ASSERT_EQ(debugManager.flags.ExperimentalEnableHostAllocationCache.get(), -1);
debugManager.flags.ExperimentalEnableHostAllocationCache.set(0);
EXPECT_FALSE(svmManager->usmHostAllocationsCacheEnabled);
svmManager->initUsmAllocationsCaches(*device);
EXPECT_FALSE(svmManager->usmHostAllocationsCacheEnabled);
RootDeviceIndicesContainer rootDeviceIndices = {mockRootDeviceIndex};
std::map<uint32_t, DeviceBitfield> deviceBitfields{{mockRootDeviceIndex, mockDeviceBitfield}};
SVMAllocsManager::UnifiedMemoryProperties unifiedMemoryProperties(InternalMemoryType::hostUnifiedMemory, 1, rootDeviceIndices, deviceBitfields);
auto allocation = svmManager->createHostUnifiedMemoryAllocation(1u, unifiedMemoryProperties);
EXPECT_NE(nullptr, allocation);
EXPECT_EQ(0u, svmManager->usmHostAllocationsCache.allocations.size());
EXPECT_TRUE(svmManager->freeSVMAlloc(allocation));
EXPECT_NE(allocation, nullptr);
svmManager->freeSVMAlloc(allocation);
EXPECT_EQ(0u, svmManager->usmHostAllocationsCache.allocations.size());
allocation = svmManager->createHostUnifiedMemoryAllocation(1u, unifiedMemoryProperties);
EXPECT_NE(nullptr, allocation);
EXPECT_NE(allocation, nullptr);
svmManager->freeSVMAllocDefer(allocation);
EXPECT_EQ(0u, svmManager->usmHostAllocationsCache.allocations.size());
}
EXPECT_TRUE(svmManager->freeSVMAllocDefer(allocation));
EXPECT_EQ(0u, svmManager->usmHostAllocationsCache.allocations.size());
HWTEST_F(SvmHostAllocationCacheTest, 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->isHostUsmAllocationReuseSupportedResult = false;
auto svmManager = std::make_unique<MockSVMAllocsManager>(device->getMemoryManager(), false);
EXPECT_FALSE(svmManager->usmHostAllocationsCacheEnabled);
svmManager->initUsmAllocationsCaches(*device);
EXPECT_FALSE(svmManager->usmHostAllocationsCacheEnabled);
}
{
raii.mockProductHelper->isHostUsmAllocationReuseSupportedResult = true;
auto svmManager = std::make_unique<MockSVMAllocsManager>(device->getMemoryManager(), false);
EXPECT_FALSE(svmManager->usmHostAllocationsCacheEnabled);
svmManager->initUsmAllocationsCaches(*device);
EXPECT_TRUE(svmManager->usmHostAllocationsCacheEnabled);
const auto expectedMaxSize = static_cast<size_t>(0.02 * svmManager->memoryManager->getSystemSharedMemory(0u));
EXPECT_EQ(expectedMaxSize, svmManager->usmHostAllocationsCache.maxSize);
}
}
struct SvmHostAllocationCacheSimpleTestDataType {

View File

@@ -844,6 +844,18 @@ HWTEST2_F(ProductHelperTest, givenProductHelperWhenCheckingIsDeviceUsmAllocation
EXPECT_TRUE(productHelper->isDeviceUsmAllocationReuseSupported());
}
HWTEST2_F(ProductHelperTest, givenProductHelperWhenCheckingIsHostUsmAllocationReuseSupportedThenCorrectValueIsReturned, IsAtMostDg2) {
EXPECT_FALSE(productHelper->isHostUsmAllocationReuseSupported());
}
HWTEST2_F(ProductHelperTest, givenProductHelperWhenCheckingIsHostUsmAllocationReuseSupportedThenCorrectValueIsReturned, IsXeHpcCore) {
EXPECT_FALSE(productHelper->isHostUsmAllocationReuseSupported());
}
HWTEST2_F(ProductHelperTest, givenProductHelperWhenCheckingIsHostUsmAllocationReuseSupportedThenCorrectValueIsReturned, IsAtLeastMtl) {
EXPECT_TRUE(productHelper->isHostUsmAllocationReuseSupported());
}
HWTEST_F(ProductHelperTest, givenProductHelperWhenCheckingIsUnlockingLockedPtrNecessaryThenReturnFalse) {
EXPECT_FALSE(productHelper->isUnlockingLockedPtrNecessary(pInHwInfo));
}