Skip to content

Commit 97245a2

Browse files
Refactor MemoryManager::allocateGraphicsMemoryInDevicePool
- create MemoryAllocation for OsAgnosticMemoryManager so that freeGraphicsMemory is freeing correct object type - other memory managers do not go this path Change-Id: If2ada9b77bb4a41d09f82b79502594e0eda9f11b Signed-off-by: Hoppe, Mateusz <[email protected]>
1 parent eefb2bb commit 97245a2

File tree

3 files changed

+29
-6
lines changed

3 files changed

+29
-6
lines changed

runtime/memory_manager/memory_manager.h

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -212,12 +212,11 @@ class MemoryManager {
212212
return nullptr;
213213
}
214214
uint64_t gpuAddress = reinterpret_cast<uint64_t>(allocationData.hostPtr);
215-
allocation = new GraphicsAllocation(allocationData.type,
216-
cpuAllocation,
217-
gpuAddress,
218-
gpuAddress,
219-
allocationData.size, MemoryPool::LocalMemory, false);
220-
allocation->setDriverAllocatedCpuPtr(cpuAllocation);
215+
allocation = constructGraphicsAllocation(allocationData.type,
216+
cpuAllocation,
217+
gpuAddress,
218+
allocationData.size, MemoryPool::LocalMemory, false);
219+
allocation->setGpuBaseAddress(gpuAddress);
221220
} else {
222221
allocation = allocateGraphicsMemory(allocationData);
223222
}
@@ -236,6 +235,10 @@ class MemoryManager {
236235
GraphicsAllocation *allocateGraphicsMemoryForImageFromHostPtr(const AllocationData &allocationData);
237236
MOCKABLE_VIRTUAL GraphicsAllocation *allocateGraphicsMemoryForImage(const AllocationData &allocationData);
238237
virtual GraphicsAllocation *allocateGraphicsMemoryForImageImpl(const AllocationData &allocationData, std::unique_ptr<Gmm> gmm) = 0;
238+
virtual GraphicsAllocation *constructGraphicsAllocation(GraphicsAllocation::AllocationType allocationType, void *cpuPtrIn, uint64_t gpuAddress,
239+
size_t sizeIn, MemoryPool::Type pool, bool multiOsContextCapable) {
240+
return nullptr;
241+
}
239242

240243
virtual void *lockResourceImpl(GraphicsAllocation &graphicsAllocation) = 0;
241244
virtual void unlockResourceImpl(GraphicsAllocation &graphicsAllocation) = 0;

runtime/memory_manager/os_agnostic_memory_manager.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ class OsAgnosticMemoryManager : public MemoryManager {
8080
void unlockResourceImpl(GraphicsAllocation &graphicsAllocation) override {}
8181
GraphicsAllocation *allocate32BitGraphicsMemoryImpl(const AllocationData &allocationData) override;
8282
GraphicsAllocation *allocateGraphicsMemoryInDevicePool(const AllocationData &allocationData, AllocationStatus &status) override;
83+
GraphicsAllocation *constructGraphicsAllocation(GraphicsAllocation::AllocationType allocationType, void *cpuPtrIn, uint64_t gpuAddress,
84+
size_t sizeIn, MemoryPool::Type pool, bool multiOsContextCapable) override {
85+
return new MemoryAllocation(allocationType, cpuPtrIn, cpuPtrIn, gpuAddress, sizeIn, counter++, pool, multiOsContextCapable, false, false);
86+
}
8387

8488
private:
8589
unsigned long long counter = 0;

unit_tests/memory_manager/memory_manager_tests.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1676,6 +1676,22 @@ TEST(MemoryManagerTest, givenAllocationTypesThatMayNeedL3FlushWhenCallingGetAllo
16761676
}
16771677
}
16781678

1679+
TEST(MemoryManagerTest, givenSpecializedMemoryManagerWhenCallingConstructGraphicsAllocationThenNullptrIsReturned) {
1680+
struct MemoryManagerConstructAllocation : public MockMemoryManager {
1681+
GraphicsAllocation *constructGraphicsAllocation(GraphicsAllocation::AllocationType allocationType, void *cpuPtrIn, uint64_t gpuAddress,
1682+
size_t sizeIn, MemoryPool::Type pool, bool multiOsContextCapable) override {
1683+
return MemoryManager::constructGraphicsAllocation(allocationType, cpuPtrIn, gpuAddress,
1684+
sizeIn, pool, multiOsContextCapable);
1685+
}
1686+
MemoryManagerConstructAllocation(ExecutionEnvironment &executionEnvironment) : MockMemoryManager(false, executionEnvironment) {}
1687+
};
1688+
1689+
MockExecutionEnvironment executionEnvironment(*platformDevices);
1690+
MemoryManagerConstructAllocation memoryManager(executionEnvironment);
1691+
auto allocation = memoryManager.constructGraphicsAllocation(GraphicsAllocation::AllocationType::UNKNOWN, nullptr, 0, 0, MemoryPool::MemoryNull, false);
1692+
EXPECT_EQ(nullptr, allocation);
1693+
}
1694+
16791695
TEST(HeapSelectorTest, given32bitInternalAllocationWhenSelectingHeapThenInternalHeapIsUsed) {
16801696
GraphicsAllocation allocation{GraphicsAllocation::AllocationType::KERNEL_ISA, nullptr, 0, 0, 0, MemoryPool::MemoryNull, false};
16811697
allocation.set32BitAllocation(true);

0 commit comments

Comments
 (0)