Skip to content

Commit 0607118

Browse files
Correct allocating memory for multi root device buffers
use dedicated method for creating allocation from existing storage Related-To: NEO-3691 Signed-off-by: Mateusz Jablonski <[email protected]>
1 parent 1762701 commit 0607118

File tree

4 files changed

+29
-1
lines changed

4 files changed

+29
-1
lines changed

opencl/source/mem_obj/buffer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ Buffer *Buffer::create(Context *context,
275275
allocationInfo[rootDeviceIndex].allocateMemory, size, allocationInfo[rootDeviceIndex].allocationType, context->areMultiStorageAllocationsPreferred(),
276276
*hwInfo, context->getDeviceBitfieldForAllocation(rootDeviceIndex));
277277
allocProperties.flags.crossRootDeviceAccess = context->getRootDeviceIndices().size() > 1;
278-
allocationInfo[rootDeviceIndex].memory = memoryManager->allocateGraphicsMemoryWithProperties(allocProperties, ptr);
278+
allocationInfo[rootDeviceIndex].memory = memoryManager->createGraphicsAllocationFromExistingStorage(allocProperties, ptr, multiGraphicsAllocation);
279279
} else {
280280
AllocationProperties allocProperties = MemoryPropertiesHelper::getAllocationProperties(rootDeviceIndex, memoryProperties,
281281
allocationInfo[rootDeviceIndex].allocateMemory, size, allocationInfo[rootDeviceIndex].allocationType, context->areMultiStorageAllocationsPreferred(),

opencl/test/unit_test/mem_obj/buffer_tests.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1943,6 +1943,24 @@ TEST_F(MultiRootDeviceBufferTest, WhenBufferIsCreatedThenBufferMultiGraphicsAllo
19431943
EXPECT_TRUE(MemoryPool::isSystemMemoryPool(buffer1->getMultiGraphicsAllocation().getGraphicsAllocation(2u)->getMemoryPool()));
19441944
}
19451945

1946+
TEST(MultiRootDeviceBufferTest2, WhenBufferIsCreatedThenSecondAndSubsequentAllocationsAreCreatedFromExisitingStorage) {
1947+
cl_int retVal = 0;
1948+
MockDefaultContext context;
1949+
auto memoryManager = static_cast<MockMemoryManager *>(context.getMemoryManager());
1950+
memoryManager->createGraphicsAllocationFromExistingStorageCalled = 0u;
1951+
memoryManager->allocationsFromExistingStorage.clear();
1952+
std::unique_ptr<Buffer> buffer(Buffer::create(&context, 0, MemoryConstants::pageSize, nullptr, retVal));
1953+
1954+
EXPECT_EQ(3u, context.getRootDeviceIndices().size());
1955+
EXPECT_NE(nullptr, buffer->getMultiGraphicsAllocation().getGraphicsAllocation(0u));
1956+
EXPECT_NE(nullptr, buffer->getMultiGraphicsAllocation().getGraphicsAllocation(1u));
1957+
EXPECT_NE(nullptr, buffer->getMultiGraphicsAllocation().getGraphicsAllocation(2u));
1958+
1959+
EXPECT_EQ(2u, memoryManager->createGraphicsAllocationFromExistingStorageCalled);
1960+
EXPECT_EQ(memoryManager->allocationsFromExistingStorage[0], buffer->getMultiGraphicsAllocation().getGraphicsAllocation(1u));
1961+
EXPECT_EQ(memoryManager->allocationsFromExistingStorage[1], buffer->getMultiGraphicsAllocation().getGraphicsAllocation(2u));
1962+
}
1963+
19461964
TEST_F(MultiRootDeviceBufferTest, givenBufferWhenGetSurfaceSizeCalledWithoutAlignSizeForAuxTranslationThenCorrectValueReturned) {
19471965
cl_int retVal = 0;
19481966
cl_mem_flags flags = CL_MEM_READ_WRITE;

opencl/test/unit_test/mocks/mock_memory_manager.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,13 @@ GraphicsAllocation *MockMemoryManager::allocate32BitGraphicsMemoryImpl(const All
137137
return OsAgnosticMemoryManager::allocate32BitGraphicsMemoryImpl(allocationData, useLocalMemory);
138138
}
139139

140+
GraphicsAllocation *MockMemoryManager::createGraphicsAllocationFromExistingStorage(AllocationProperties &properties, void *ptr, MultiGraphicsAllocation &multiGraphicsAllocation) {
141+
auto allocation = OsAgnosticMemoryManager::createGraphicsAllocationFromExistingStorage(properties, ptr, multiGraphicsAllocation);
142+
createGraphicsAllocationFromExistingStorageCalled++;
143+
allocationsFromExistingStorage.push_back(allocation);
144+
return allocation;
145+
}
146+
140147
FailMemoryManager::FailMemoryManager(int32_t failedAllocationsCount, ExecutionEnvironment &executionEnvironment) : MockMemoryManager(executionEnvironment) {
141148
this->failedAllocationsCount = failedAllocationsCount;
142149
}

opencl/test/unit_test/mocks/mock_memory_manager.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ class MockMemoryManager : public MemoryManagerCreate<OsAgnosticMemoryManager> {
7878
GraphicsAllocation *allocateGraphicsMemoryWithAlignment(const AllocationData &allocationData) override;
7979
GraphicsAllocation *allocateGraphicsMemoryWithProperties(const AllocationProperties &properties) override;
8080
GraphicsAllocation *allocateGraphicsMemoryWithProperties(const AllocationProperties &properties, const void *ptr) override;
81+
GraphicsAllocation *createGraphicsAllocationFromExistingStorage(AllocationProperties &properties, void *ptr, MultiGraphicsAllocation &multiGraphicsAllocation) override;
8182

8283
void *allocateSystemMemory(size_t size, size_t alignment) override;
8384

@@ -137,6 +138,8 @@ class MockMemoryManager : public MemoryManagerCreate<OsAgnosticMemoryManager> {
137138
uint32_t freeGraphicsMemoryCalled = 0u;
138139
uint32_t unlockResourceCalled = 0u;
139140
uint32_t lockResourceCalled = 0u;
141+
uint32_t createGraphicsAllocationFromExistingStorageCalled = 0u;
142+
std::vector<GraphicsAllocation *> allocationsFromExistingStorage{};
140143
AllocationData alignAllocationData;
141144
uint32_t successAllocatedGraphicsMemoryIndex = 0u;
142145
uint32_t maxSuccessAllocatedGraphicsMemoryIndex = std::numeric_limits<uint32_t>::max();

0 commit comments

Comments
 (0)