Make small buffer allocations lockable

Allocations of buffers <= 64KB will be lockable, to
allow copying through locked pointer.

Related-To: NEO-7332

Signed-off-by: Dominik Dabek <dominik.dabek@intel.com>
This commit is contained in:
Dominik Dabek
2022-11-18 14:29:50 +00:00
committed by Compute-Runtime-Automation
parent 3b97ca8709
commit 9b9b0f10ef
6 changed files with 39 additions and 9 deletions

View File

@ -50,6 +50,8 @@ class Context : public BaseObject<_cl_context> {
static constexpr auto startingOffset = chunkAlignment; static constexpr auto startingOffset = chunkAlignment;
static_assert(aggregatedSmallBuffersPoolSize > smallBufferThreshold, "Largest allowed buffer needs to fit in pool"); 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, Buffer *allocateBufferFromPool(const MemoryProperties &memoryProperties,
cl_mem_flags flags, cl_mem_flags flags,
cl_mem_flags_intel flagsIntel, cl_mem_flags_intel flagsIntel,

View File

@ -84,6 +84,12 @@ TEST_F(aggregatedSmallBuffersDisabledTest, givenAggregatedSmallBuffersDisabledWh
using aggregatedSmallBuffersEnabledTest = AggregatedSmallBuffersTestTemplate<1>; 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) { TEST_F(aggregatedSmallBuffersEnabledTest, givenAggregatedSmallBuffersEnabledAndSizeLargerThanThresholdWhenBufferCreateCalledThenDoNotUsePool) {
ASSERT_TRUE(poolAllocator->isAggregatedSmallBuffersEnabled()); ASSERT_TRUE(poolAllocator->isAggregatedSmallBuffersEnabled());
ASSERT_NE(poolAllocator->mainStorage, nullptr); ASSERT_NE(poolAllocator->mainStorage, nullptr);

View File

@ -35,7 +35,7 @@ StorageInfo MemoryManager::createStorageInfoFromProperties(const AllocationPrope
StorageInfo storageInfo{preferredTile, allTilesValue}; StorageInfo storageInfo{preferredTile, allTilesValue};
storageInfo.subDeviceBitfield = properties.subDevicesBitfield; 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); storageInfo.cpuVisibleSegment = GraphicsAllocation::isCpuAccessRequired(properties.allocationType);
AppResourceHelper::copyResourceTagStr(storageInfo.resourceTag, properties.allocationType, AppResourceHelper::copyResourceTagStr(storageInfo.resourceTag, properties.allocationType,

View File

@ -57,6 +57,8 @@ class GraphicsAllocation : public IDNode<GraphicsAllocation> {
GPU GPU
}; };
static constexpr auto largestLockableBufferSize = 64 * KB;
~GraphicsAllocation() override; ~GraphicsAllocation() override;
GraphicsAllocation &operator=(const GraphicsAllocation &) = delete; GraphicsAllocation &operator=(const GraphicsAllocation &) = delete;
GraphicsAllocation(const GraphicsAllocation &) = delete; GraphicsAllocation(const GraphicsAllocation &) = delete;
@ -212,6 +214,10 @@ class GraphicsAllocation : public IDNode<GraphicsAllocation> {
type == AllocationType::DEBUG_MODULE_AREA; type == AllocationType::DEBUG_MODULE_AREA;
} }
static bool isSmallBuffer(AllocationType type, size_t size) {
return type == AllocationType::BUFFER && size <= largestLockableBufferSize;
}
static bool isDebugSurfaceAllocationType(AllocationType type) { static bool isDebugSurfaceAllocationType(AllocationType type) {
return type == AllocationType::DEBUG_CONTEXT_SAVE_AREA || return type == AllocationType::DEBUG_CONTEXT_SAVE_AREA ||
type == AllocationType::DEBUG_SBA_TRACKING_BUFFER; type == AllocationType::DEBUG_SBA_TRACKING_BUFFER;

View File

@ -198,6 +198,18 @@ TEST(GraphicsAllocationTest, whenAllocationTypeIsImageThenAllocationIsNotLockabl
EXPECT_FALSE(GraphicsAllocation::isLockable(AllocationType::IMAGE)); 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) { TEST(GraphicsAllocationTest, givenNumMemoryBanksWhenGettingNumHandlesForKmdSharedAllocationThenReturnCorrectValue) {
DebugManagerStateRestore restore; DebugManagerStateRestore restore;

View File

@ -459,15 +459,19 @@ TEST_F(MultiDeviceStorageInfoTest, givenGraphicsAllocationWithCpuAccessRequiredW
TEST_F(MultiDeviceStorageInfoTest, givenGraphicsAllocationThatIsLockableWhenCreatingStorageInfoThenIsLockableFlagIsEnabled) { TEST_F(MultiDeviceStorageInfoTest, givenGraphicsAllocationThatIsLockableWhenCreatingStorageInfoThenIsLockableFlagIsEnabled) {
auto firstAllocationIdx = static_cast<int>(AllocationType::UNKNOWN); auto firstAllocationIdx = static_cast<int>(AllocationType::UNKNOWN);
auto lastAllocationIdx = static_cast<int>(AllocationType::COUNT); auto lastAllocationIdx = static_cast<int>(AllocationType::COUNT);
std::array<size_t, 2> allocationSizes = {1u, GraphicsAllocation::largestLockableBufferSize + 1};
for (int allocationIdx = firstAllocationIdx; allocationIdx != lastAllocationIdx; allocationIdx++) { for (auto allocationSize : allocationSizes) {
auto allocationType = static_cast<AllocationType>(allocationIdx); for (int allocationIdx = firstAllocationIdx; allocationIdx != lastAllocationIdx; allocationIdx++) {
AllocationProperties properties{mockRootDeviceIndex, false, 1u, allocationType, false, singleTileMask}; auto allocationType = static_cast<AllocationType>(allocationIdx);
auto storageInfo = memoryManager->createStorageInfoFromProperties(properties); AllocationProperties properties{mockRootDeviceIndex, false, allocationSize, allocationType, false, singleTileMask};
if (GraphicsAllocation::isLockable(properties.allocationType)) { auto storageInfo = memoryManager->createStorageInfoFromProperties(properties);
EXPECT_TRUE(storageInfo.isLockable); if (GraphicsAllocation::isLockable(properties.allocationType) ||
} else { GraphicsAllocation::isSmallBuffer(properties.allocationType, allocationSize)) {
EXPECT_FALSE(storageInfo.isLockable); EXPECT_TRUE(storageInfo.isLockable);
} else {
EXPECT_FALSE(storageInfo.isLockable);
}
} }
} }
} }