diff --git a/opencl/source/context/context.h b/opencl/source/context/context.h index 942b5d3401..88ae4010eb 100644 --- a/opencl/source/context/context.h +++ b/opencl/source/context/context.h @@ -50,6 +50,8 @@ class Context : public BaseObject<_cl_context> { static constexpr auto startingOffset = chunkAlignment; static_assert(aggregatedSmallBuffersPoolSize > smallBufferThreshold, "Largest allowed buffer needs to fit in pool"); + static_assert(aggregatedSmallBuffersPoolSize <= GraphicsAllocation::largestLockableBufferSize, "Pool buffer should be lockable"); + Buffer *allocateBufferFromPool(const MemoryProperties &memoryProperties, cl_mem_flags flags, cl_mem_flags_intel flagsIntel, diff --git a/opencl/test/unit_test/mem_obj/buffer_pool_alloc_tests.cpp b/opencl/test/unit_test/mem_obj/buffer_pool_alloc_tests.cpp index 0ebed29e04..dee6eb0161 100644 --- a/opencl/test/unit_test/mem_obj/buffer_pool_alloc_tests.cpp +++ b/opencl/test/unit_test/mem_obj/buffer_pool_alloc_tests.cpp @@ -84,6 +84,12 @@ TEST_F(aggregatedSmallBuffersDisabledTest, givenAggregatedSmallBuffersDisabledWh using aggregatedSmallBuffersEnabledTest = AggregatedSmallBuffersTestTemplate<1>; +TEST_F(aggregatedSmallBuffersEnabledTest, givenAggregatedSmallBuffersEnabledWhenCheckingMainStorageAllocationStorageInfoThenItIsLockable) { + ASSERT_TRUE(poolAllocator->isAggregatedSmallBuffersEnabled()); + ASSERT_NE(poolAllocator->mainStorage, nullptr); + EXPECT_TRUE(poolAllocator->mainStorage->getGraphicsAllocation(mockRootDeviceIndex)->isAllocationLockable()); +} + TEST_F(aggregatedSmallBuffersEnabledTest, givenAggregatedSmallBuffersEnabledAndSizeLargerThanThresholdWhenBufferCreateCalledThenDoNotUsePool) { ASSERT_TRUE(poolAllocator->isAggregatedSmallBuffersEnabled()); ASSERT_NE(poolAllocator->mainStorage, nullptr); diff --git a/shared/source/memory_manager/definitions/storage_info.cpp b/shared/source/memory_manager/definitions/storage_info.cpp index 29f2555563..3e85d5dea0 100644 --- a/shared/source/memory_manager/definitions/storage_info.cpp +++ b/shared/source/memory_manager/definitions/storage_info.cpp @@ -35,7 +35,7 @@ StorageInfo MemoryManager::createStorageInfoFromProperties(const AllocationPrope StorageInfo storageInfo{preferredTile, allTilesValue}; storageInfo.subDeviceBitfield = properties.subDevicesBitfield; - storageInfo.isLockable = GraphicsAllocation::isLockable(properties.allocationType); + storageInfo.isLockable = GraphicsAllocation::isLockable(properties.allocationType) || GraphicsAllocation::isSmallBuffer(properties.allocationType, properties.size); storageInfo.cpuVisibleSegment = GraphicsAllocation::isCpuAccessRequired(properties.allocationType); AppResourceHelper::copyResourceTagStr(storageInfo.resourceTag, properties.allocationType, diff --git a/shared/source/memory_manager/graphics_allocation.h b/shared/source/memory_manager/graphics_allocation.h index ab5d84e30f..a7e3560750 100644 --- a/shared/source/memory_manager/graphics_allocation.h +++ b/shared/source/memory_manager/graphics_allocation.h @@ -57,6 +57,8 @@ class GraphicsAllocation : public IDNode { GPU }; + static constexpr auto largestLockableBufferSize = 64 * KB; + ~GraphicsAllocation() override; GraphicsAllocation &operator=(const GraphicsAllocation &) = delete; GraphicsAllocation(const GraphicsAllocation &) = delete; @@ -212,6 +214,10 @@ class GraphicsAllocation : public IDNode { type == AllocationType::DEBUG_MODULE_AREA; } + static bool isSmallBuffer(AllocationType type, size_t size) { + return type == AllocationType::BUFFER && size <= largestLockableBufferSize; + } + static bool isDebugSurfaceAllocationType(AllocationType type) { return type == AllocationType::DEBUG_CONTEXT_SAVE_AREA || type == AllocationType::DEBUG_SBA_TRACKING_BUFFER; diff --git a/shared/test/unit_test/memory_manager/graphics_allocation_tests.cpp b/shared/test/unit_test/memory_manager/graphics_allocation_tests.cpp index 297f52c284..5128f00d9e 100644 --- a/shared/test/unit_test/memory_manager/graphics_allocation_tests.cpp +++ b/shared/test/unit_test/memory_manager/graphics_allocation_tests.cpp @@ -198,6 +198,18 @@ TEST(GraphicsAllocationTest, whenAllocationTypeIsImageThenAllocationIsNotLockabl EXPECT_FALSE(GraphicsAllocation::isLockable(AllocationType::IMAGE)); } +TEST(GraphicsAllocationTest, whenAllocationTypeIsNotBufferThenAllocationIsNotSmallBuffer) { + EXPECT_FALSE(GraphicsAllocation::isSmallBuffer(AllocationType::IMAGE, GraphicsAllocation::largestLockableBufferSize)); +} + +TEST(GraphicsAllocationTest, whenAllocationSizeIsAboveThresholdThenAllocationIsNotSmallBuffer) { + EXPECT_FALSE(GraphicsAllocation::isSmallBuffer(AllocationType::BUFFER, GraphicsAllocation::largestLockableBufferSize + 1)); +} + +TEST(GraphicsAllocationTest, whenAllocationTypeIsBufferAndSizeIsAtMostThresholdThenAllocationIsSmallBuffer) { + EXPECT_TRUE(GraphicsAllocation::isSmallBuffer(AllocationType::BUFFER, GraphicsAllocation::largestLockableBufferSize)); +} + TEST(GraphicsAllocationTest, givenNumMemoryBanksWhenGettingNumHandlesForKmdSharedAllocationThenReturnCorrectValue) { DebugManagerStateRestore restore; diff --git a/shared/test/unit_test/memory_manager/storage_info_tests.cpp b/shared/test/unit_test/memory_manager/storage_info_tests.cpp index 9d7c3b7855..2f54d5fad6 100644 --- a/shared/test/unit_test/memory_manager/storage_info_tests.cpp +++ b/shared/test/unit_test/memory_manager/storage_info_tests.cpp @@ -459,15 +459,19 @@ TEST_F(MultiDeviceStorageInfoTest, givenGraphicsAllocationWithCpuAccessRequiredW TEST_F(MultiDeviceStorageInfoTest, givenGraphicsAllocationThatIsLockableWhenCreatingStorageInfoThenIsLockableFlagIsEnabled) { auto firstAllocationIdx = static_cast(AllocationType::UNKNOWN); auto lastAllocationIdx = static_cast(AllocationType::COUNT); + std::array allocationSizes = {1u, GraphicsAllocation::largestLockableBufferSize + 1}; - for (int allocationIdx = firstAllocationIdx; allocationIdx != lastAllocationIdx; allocationIdx++) { - auto allocationType = static_cast(allocationIdx); - AllocationProperties properties{mockRootDeviceIndex, false, 1u, allocationType, false, singleTileMask}; - auto storageInfo = memoryManager->createStorageInfoFromProperties(properties); - if (GraphicsAllocation::isLockable(properties.allocationType)) { - EXPECT_TRUE(storageInfo.isLockable); - } else { - EXPECT_FALSE(storageInfo.isLockable); + for (auto allocationSize : allocationSizes) { + for (int allocationIdx = firstAllocationIdx; allocationIdx != lastAllocationIdx; allocationIdx++) { + auto allocationType = static_cast(allocationIdx); + AllocationProperties properties{mockRootDeviceIndex, false, allocationSize, allocationType, false, singleTileMask}; + auto storageInfo = memoryManager->createStorageInfoFromProperties(properties); + if (GraphicsAllocation::isLockable(properties.allocationType) || + GraphicsAllocation::isSmallBuffer(properties.allocationType, allocationSize)) { + EXPECT_TRUE(storageInfo.isLockable); + } else { + EXPECT_FALSE(storageInfo.isLockable); + } } } }