refactor: prepare CLOS logic for extension

Prepare cache setup and reservation logic to be extended w.r.t other
cache-levels.

Conceptually this change is like adding a switch-statement, in several
places, in which existing code makes a single (and only) case. This is
caused by splitting larger development to ease the review. Further cases
will be added in following steps. Such approach sometimes creates code
which may seem redundant but it is meant to simplify plugging following
extensions in an easy way.

Related-To: NEO-12837
Signed-off-by: Maciej Bielski <maciej.bielski@intel.com>
This commit is contained in:
Maciej Bielski
2025-02-13 17:01:04 +00:00
committed by Compute-Runtime-Automation
parent 9f3a95b7d6
commit 6924a48ca6
29 changed files with 256 additions and 114 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2022-2024 Intel Corporation
* Copyright (C) 2022-2025 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -26,7 +26,7 @@ TEST(DrmCacheInfoTest, givenCacheRegionsExistsWhenCallingSetUpCacheInfoThenCache
drm.setupCacheInfo(*defaultHwInfo.get());
auto cacheInfo = drm.getL3CacheInfo();
auto cacheInfo = drm.getCacheInfo();
EXPECT_NE(nullptr, cacheInfo);
if (productHelper.getNumCacheRegions() == 0) {
@@ -56,8 +56,8 @@ TEST(DrmCacheInfoTest, givenDebugFlagSetWhenCallingSetUpCacheInfoThenCacheInfoIs
DrmQueryMock drm(*executionEnvironment->rootDeviceEnvironments[0]);
drm.setupCacheInfo(*defaultHwInfo.get());
EXPECT_NE(nullptr, drm.getL3CacheInfo());
auto cacheInfo = drm.getL3CacheInfo();
EXPECT_NE(nullptr, drm.getCacheInfo());
auto cacheInfo = drm.getCacheInfo();
EXPECT_EQ(0u, cacheInfo->getMaxReservationCacheSize());
EXPECT_EQ(0u, cacheInfo->getMaxReservationNumCacheRegions());
@@ -68,7 +68,11 @@ TEST(DrmCacheInfoTest, givenCacheInfoCreatedWhenGetCacheRegionSucceedsToReserveC
auto executionEnvironment = std::make_unique<MockExecutionEnvironment>();
DrmQueryMock drm(*executionEnvironment->rootDeviceEnvironments[0]);
CacheInfo cacheInfo(*drm.getIoctlHelper(), 32 * MemoryConstants::kiloByte, 2, 32);
CacheReservationParameters l3CacheParameters{};
l3CacheParameters.maxSize = 32 * MemoryConstants::kiloByte;
l3CacheParameters.maxNumRegions = 2;
l3CacheParameters.maxNumWays = 32;
CacheInfo cacheInfo(*drm.getIoctlHelper(), l3CacheParameters);
size_t cacheReservationSize = cacheInfo.getMaxReservationCacheSize();
EXPECT_TRUE(cacheInfo.getCacheRegion(cacheReservationSize, CacheRegion::region1));
@@ -80,7 +84,11 @@ TEST(DrmCacheInfoTest, givenCacheInfoCreatedWhenGetCacheRegionFailsToReserveCach
auto executionEnvironment = std::make_unique<MockExecutionEnvironment>();
DrmQueryMock drm(*executionEnvironment->rootDeviceEnvironments[0]);
CacheInfo cacheInfo(*drm.getIoctlHelper(), 32 * MemoryConstants::kiloByte, 2, 32);
CacheReservationParameters l3CacheParameters{};
l3CacheParameters.maxSize = 32 * MemoryConstants::kiloByte;
l3CacheParameters.maxNumRegions = 2;
l3CacheParameters.maxNumWays = 32;
CacheInfo cacheInfo(*drm.getIoctlHelper(), l3CacheParameters);
size_t cacheReservationSize = cacheInfo.getMaxReservationCacheSize();
drm.context.closIndex = 0xFFFF;
@@ -93,7 +101,11 @@ TEST(DrmCacheInfoTest, givenCacheInfoWithReservedCacheRegionWhenGetCacheRegionIs
auto executionEnvironment = std::make_unique<MockExecutionEnvironment>();
DrmQueryMock drm(*executionEnvironment->rootDeviceEnvironments[0]);
CacheInfo cacheInfo(*drm.getIoctlHelper(), 32 * MemoryConstants::kiloByte, 2, 32);
CacheReservationParameters l3CacheParameters{};
l3CacheParameters.maxSize = 32 * MemoryConstants::kiloByte;
l3CacheParameters.maxNumRegions = 2;
l3CacheParameters.maxNumWays = 32;
CacheInfo cacheInfo(*drm.getIoctlHelper(), l3CacheParameters);
size_t cacheReservationSize = cacheInfo.getMaxReservationCacheSize();
EXPECT_EQ(CacheRegion::region1, cacheInfo.reserveCacheRegion(cacheReservationSize));
@@ -107,7 +119,11 @@ TEST(DrmCacheInfoTest, givenCacheInfoCreatedWhenGetCacheRegionIsCalledForReserva
auto executionEnvironment = std::make_unique<MockExecutionEnvironment>();
DrmQueryMock drm(*executionEnvironment->rootDeviceEnvironments[0]);
CacheInfo cacheInfo(*drm.getIoctlHelper(), 32 * MemoryConstants::kiloByte, 2, 32);
CacheReservationParameters l3CacheParameters{};
l3CacheParameters.maxSize = 32 * MemoryConstants::kiloByte;
l3CacheParameters.maxNumRegions = 2;
l3CacheParameters.maxNumWays = 32;
CacheInfo cacheInfo(*drm.getIoctlHelper(), l3CacheParameters);
size_t regionSize = cacheInfo.getMaxReservationCacheSize() / cacheInfo.getMaxReservationNumCacheRegions();
EXPECT_TRUE(cacheInfo.getCacheRegion(regionSize, CacheRegion::region1));
@@ -126,7 +142,11 @@ TEST(DrmCacheInfoTest, givenCacheInfoWhenSpecificNumCacheWaysIsRequestedThenRese
auto executionEnvironment = std::make_unique<MockExecutionEnvironment>();
DrmQueryMock drm(*executionEnvironment->rootDeviceEnvironments[0]);
MockCacheInfo cacheInfo(*drm.getIoctlHelper(), 32 * MemoryConstants::kiloByte, 2, maxNumCacheWays);
CacheReservationParameters l3CacheParameters{};
l3CacheParameters.maxSize = 32 * MemoryConstants::kiloByte;
l3CacheParameters.maxNumRegions = 2;
l3CacheParameters.maxNumWays = maxNumCacheWays;
MockCacheInfo cacheInfo(*drm.getIoctlHelper(), l3CacheParameters);
size_t maxReservationCacheSize = cacheInfo.getMaxReservationCacheSize();
EXPECT_EQ(CacheRegion::region1, cacheInfo.reserveCacheRegion(maxReservationCacheSize));
@@ -144,7 +164,11 @@ TEST(DrmCacheInfoTest, givenCacheInfoWhenNumCacheWaysIsExceededThenDontReserveCa
auto executionEnvironment = std::make_unique<MockExecutionEnvironment>();
DrmQueryMock drm(*executionEnvironment->rootDeviceEnvironments[0]);
MockCacheInfo cacheInfo(*drm.getIoctlHelper(), 32 * MemoryConstants::kiloByte, 2, maxNumCacheWays);
CacheReservationParameters l3CacheParameters{};
l3CacheParameters.maxSize = 32 * MemoryConstants::kiloByte;
l3CacheParameters.maxNumRegions = 2;
l3CacheParameters.maxNumWays = maxNumCacheWays;
MockCacheInfo cacheInfo(*drm.getIoctlHelper(), l3CacheParameters);
size_t maxReservationCacheSize = cacheInfo.getMaxReservationCacheSize();
EXPECT_EQ(CacheRegion::region1, cacheInfo.reserveCacheRegion(maxReservationCacheSize));
@@ -155,10 +179,15 @@ TEST(DrmCacheInfoTest, givenCacheInfoWhenNumCacheWaysIsExceededThenDontReserveCa
}
TEST(DrmCacheInfoTest, givenCacheInfoCreatedWhenFreeCacheRegionIsCalledForNonReservedRegionThenItFails) {
constexpr uint16_t maxNumCacheWays = 32;
auto executionEnvironment = std::make_unique<MockExecutionEnvironment>();
DrmQueryMock drm(*executionEnvironment->rootDeviceEnvironments[0]);
MockCacheInfo cacheInfo(*drm.getIoctlHelper(), 32 * MemoryConstants::kiloByte, 2, 32);
CacheReservationParameters l3CacheParameters{};
l3CacheParameters.maxSize = 32 * MemoryConstants::kiloByte;
l3CacheParameters.maxNumRegions = 2;
l3CacheParameters.maxNumWays = maxNumCacheWays;
MockCacheInfo cacheInfo(*drm.getIoctlHelper(), l3CacheParameters);
cacheInfo.reservedCacheRegionsSize[toUnderlying(CacheRegion::region1)] = MemoryConstants::kiloByte;
EXPECT_EQ(CacheRegion::none, cacheInfo.freeCacheRegion(CacheRegion::region1));

View File

@@ -4944,7 +4944,11 @@ TEST_F(DrmAllocationTests, givenDrmAllocationWhenDefaultCacheInfoIsAvailableThen
TEST_F(DrmAllocationTests, givenDrmAllocationWhenCacheRegionIsNotSetThenReturnFalse) {
const uint32_t rootDeviceIndex = 0u;
DrmMock drm(*executionEnvironment->rootDeviceEnvironments[rootDeviceIndex]);
drm.l3CacheInfo.reset(new MockCacheInfo(*drm.getIoctlHelper(), 32 * MemoryConstants::kiloByte, 2, 32));
CacheReservationParameters l3CacheParameters{};
l3CacheParameters.maxSize = 32 * MemoryConstants::kiloByte;
l3CacheParameters.maxNumRegions = 2;
l3CacheParameters.maxNumWays = 32;
drm.cacheInfo.reset(new MockCacheInfo(*drm.getIoctlHelper(), l3CacheParameters));
MockDrmAllocation allocation(rootDeviceIndex, AllocationType::buffer, MemoryPool::localMemory);
@@ -4955,7 +4959,12 @@ TEST_F(DrmAllocationTests, givenDrmAllocationWhenCacheRegionIsSetSuccessfullyThe
const uint32_t rootDeviceIndex = 0u;
DrmMock drm(*executionEnvironment->rootDeviceEnvironments[rootDeviceIndex]);
drm.queryAndSetVmBindPatIndexProgrammingSupport();
drm.l3CacheInfo.reset(new MockCacheInfo(*drm.getIoctlHelper(), 32 * MemoryConstants::kiloByte, 2, 32));
CacheReservationParameters l3CacheParameters{};
l3CacheParameters.maxSize = 32 * MemoryConstants::kiloByte;
l3CacheParameters.maxNumRegions = 2;
l3CacheParameters.maxNumWays = 32;
drm.cacheInfo.reset(new MockCacheInfo(*drm.getIoctlHelper(), l3CacheParameters));
MockDrmAllocation allocation(rootDeviceIndex, AllocationType::buffer, MemoryPool::localMemory);
auto &productHelper = executionEnvironment->rootDeviceEnvironments[0]->getHelper<ProductHelper>();
@@ -4972,7 +4981,12 @@ TEST_F(DrmAllocationTests, givenDrmAllocationWhenCacheRegionIsSetSuccessfullyThe
const uint32_t rootDeviceIndex = 0u;
DrmMock drm(*executionEnvironment->rootDeviceEnvironments[rootDeviceIndex]);
drm.queryAndSetVmBindPatIndexProgrammingSupport();
drm.l3CacheInfo.reset(new MockCacheInfo(*drm.getIoctlHelper(), 32 * MemoryConstants::kiloByte, 2, 32));
CacheReservationParameters l3CacheParameters{};
l3CacheParameters.maxSize = 32 * MemoryConstants::kiloByte;
l3CacheParameters.maxNumRegions = 2;
l3CacheParameters.maxNumWays = 32;
drm.cacheInfo.reset(new MockCacheInfo(*drm.getIoctlHelper(), l3CacheParameters));
MockBufferObject bo(rootDeviceIndex, &drm, 3, 0, 0, 1);
MockDrmAllocation allocation(rootDeviceIndex, AllocationType::buffer, MemoryPool::localMemory);
@@ -5128,7 +5142,12 @@ TEST_F(DrmMemoryManagerTest, givenDrmAllocationWithHostPtrWhenItIsCreatedWithCac
}
mock->ioctlExpected.total = -1;
auto drm = static_cast<DrmMockCustom *>(executionEnvironment->rootDeviceEnvironments[rootDeviceIndex]->osInterface->getDriverModel()->as<Drm>());
drm->l3CacheInfo.reset(new MockCacheInfo(*drm->getIoctlHelper(), 32 * MemoryConstants::kiloByte, 2, 32));
CacheReservationParameters l3CacheParameters{};
l3CacheParameters.maxSize = 32 * MemoryConstants::kiloByte;
l3CacheParameters.maxNumRegions = 2;
l3CacheParameters.maxNumWays = 32;
drm->cacheInfo.reset(new MockCacheInfo(*drm->getIoctlHelper(), l3CacheParameters));
auto ptr = reinterpret_cast<void *>(0x1000);
auto size = MemoryConstants::pageSize;
@@ -6264,7 +6283,7 @@ TEST_F(DrmMemoryManagerWithLocalMemoryAndExplicitExpectationsTest, givenUAllocat
allocData.cacheRegion = 0xFFFF;
auto &drm = static_cast<DrmMockCustom &>(memoryManager->getDrm(0));
drm.l3CacheInfo.reset(nullptr);
drm.cacheInfo.reset(nullptr);
auto allocation = memoryManager->allocatePhysicalLocalDeviceMemory(allocData, status);
EXPECT_EQ(nullptr, allocation);

View File

@@ -1294,7 +1294,11 @@ TEST_F(DrmMemoryOperationsHandlerBindTest, givenClosEnabledAndAllocationToBeCach
auto osContext = memoryManager->createAndRegisterOsContext(csr.get(), EngineDescriptorHelper::getDefaultDescriptor());
csr->setupContext(*osContext);
mock->l3CacheInfo.reset(new CacheInfo(*mock->getIoctlHelper(), 64 * MemoryConstants::kiloByte, 2, 32));
CacheReservationParameters l3CacheParameters{};
l3CacheParameters.maxSize = 64 * MemoryConstants::kiloByte;
l3CacheParameters.maxNumRegions = 2;
l3CacheParameters.maxNumWays = 32;
mock->cacheInfo.reset(new CacheInfo(*mock->getIoctlHelper(), l3CacheParameters));
auto &productHelper = executionEnvironment->rootDeviceEnvironments[0]->getHelper<ProductHelper>();