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 <mateusz.hoppe@intel.com>
This commit is contained in:
Hoppe, Mateusz
2019-05-08 14:48:26 +02:00
committed by sys_ocldev
parent eefb2bb488
commit 97245a2ca6
3 changed files with 29 additions and 6 deletions

View File

@@ -212,12 +212,11 @@ class MemoryManager {
return nullptr;
}
uint64_t gpuAddress = reinterpret_cast<uint64_t>(allocationData.hostPtr);
allocation = new GraphicsAllocation(allocationData.type,
cpuAllocation,
gpuAddress,
gpuAddress,
allocationData.size, MemoryPool::LocalMemory, false);
allocation->setDriverAllocatedCpuPtr(cpuAllocation);
allocation = constructGraphicsAllocation(allocationData.type,
cpuAllocation,
gpuAddress,
allocationData.size, MemoryPool::LocalMemory, false);
allocation->setGpuBaseAddress(gpuAddress);
} else {
allocation = allocateGraphicsMemory(allocationData);
}
@@ -236,6 +235,10 @@ class MemoryManager {
GraphicsAllocation *allocateGraphicsMemoryForImageFromHostPtr(const AllocationData &allocationData);
MOCKABLE_VIRTUAL GraphicsAllocation *allocateGraphicsMemoryForImage(const AllocationData &allocationData);
virtual GraphicsAllocation *allocateGraphicsMemoryForImageImpl(const AllocationData &allocationData, std::unique_ptr<Gmm> gmm) = 0;
virtual GraphicsAllocation *constructGraphicsAllocation(GraphicsAllocation::AllocationType allocationType, void *cpuPtrIn, uint64_t gpuAddress,
size_t sizeIn, MemoryPool::Type pool, bool multiOsContextCapable) {
return nullptr;
}
virtual void *lockResourceImpl(GraphicsAllocation &graphicsAllocation) = 0;
virtual void unlockResourceImpl(GraphicsAllocation &graphicsAllocation) = 0;

View File

@@ -80,6 +80,10 @@ class OsAgnosticMemoryManager : public MemoryManager {
void unlockResourceImpl(GraphicsAllocation &graphicsAllocation) override {}
GraphicsAllocation *allocate32BitGraphicsMemoryImpl(const AllocationData &allocationData) override;
GraphicsAllocation *allocateGraphicsMemoryInDevicePool(const AllocationData &allocationData, AllocationStatus &status) override;
GraphicsAllocation *constructGraphicsAllocation(GraphicsAllocation::AllocationType allocationType, void *cpuPtrIn, uint64_t gpuAddress,
size_t sizeIn, MemoryPool::Type pool, bool multiOsContextCapable) override {
return new MemoryAllocation(allocationType, cpuPtrIn, cpuPtrIn, gpuAddress, sizeIn, counter++, pool, multiOsContextCapable, false, false);
}
private:
unsigned long long counter = 0;

View File

@@ -1676,6 +1676,22 @@ TEST(MemoryManagerTest, givenAllocationTypesThatMayNeedL3FlushWhenCallingGetAllo
}
}
TEST(MemoryManagerTest, givenSpecializedMemoryManagerWhenCallingConstructGraphicsAllocationThenNullptrIsReturned) {
struct MemoryManagerConstructAllocation : public MockMemoryManager {
GraphicsAllocation *constructGraphicsAllocation(GraphicsAllocation::AllocationType allocationType, void *cpuPtrIn, uint64_t gpuAddress,
size_t sizeIn, MemoryPool::Type pool, bool multiOsContextCapable) override {
return MemoryManager::constructGraphicsAllocation(allocationType, cpuPtrIn, gpuAddress,
sizeIn, pool, multiOsContextCapable);
}
MemoryManagerConstructAllocation(ExecutionEnvironment &executionEnvironment) : MockMemoryManager(false, executionEnvironment) {}
};
MockExecutionEnvironment executionEnvironment(*platformDevices);
MemoryManagerConstructAllocation memoryManager(executionEnvironment);
auto allocation = memoryManager.constructGraphicsAllocation(GraphicsAllocation::AllocationType::UNKNOWN, nullptr, 0, 0, MemoryPool::MemoryNull, false);
EXPECT_EQ(nullptr, allocation);
}
TEST(HeapSelectorTest, given32bitInternalAllocationWhenSelectingHeapThenInternalHeapIsUsed) {
GraphicsAllocation allocation{GraphicsAllocation::AllocationType::KERNEL_ISA, nullptr, 0, 0, 0, MemoryPool::MemoryNull, false};
allocation.set32BitAllocation(true);