[4/n] Unified Shared Memory

- Add allocation logic for host allocation.

Change-Id: Ic250b2165a050bbff7dea1b33b904d6d66cf8113
Related-To: NEO-3148
Signed-off-by: Mrozek, Michal <michal.mrozek@intel.com>
This commit is contained in:
Mrozek, Michal
2019-06-17 11:00:27 +02:00
committed by sys_ocldev
parent 22187bc5e8
commit dd0d81672b
3 changed files with 28 additions and 3 deletions

View File

@ -92,16 +92,21 @@ void *SVMAllocsManager::createSVMAlloc(size_t size, const SvmAllocationPropertie
}
}
void *SVMAllocsManager::createUnifiedMemoryAllocation(size_t size, const UnifiedMemoryProperties svmProperties) {
void *SVMAllocsManager::createUnifiedMemoryAllocation(size_t size, const UnifiedMemoryProperties memoryProperties) {
size_t alignedSize = alignUp<size_t>(size, MemoryConstants::pageSize64k);
AllocationProperties unifiedMemoryProperties{true, alignedSize, GraphicsAllocation::AllocationType::BUFFER, false};
AllocationProperties unifiedMemoryProperties{true,
alignedSize,
memoryProperties.memoryType == InternalMemoryType::DEVICE_UNIFIED_MEMORY ? GraphicsAllocation::AllocationType::BUFFER : GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY,
false};
GraphicsAllocation *unifiedMemoryAllocation = memoryManager->allocateGraphicsMemoryWithProperties(unifiedMemoryProperties);
SvmAllocationData allocData;
allocData.gpuAllocation = unifiedMemoryAllocation;
allocData.cpuAllocation = nullptr;
allocData.size = size;
allocData.memoryType = InternalMemoryType::DEVICE_UNIFIED_MEMORY;
allocData.memoryType = memoryProperties.memoryType;
std::unique_lock<SpinLock> lock(mtx);
this->SVMAllocs.insert(allocData);

View File

@ -21,6 +21,7 @@ class MemoryManager;
enum class InternalMemoryType : uint32_t {
SVM = 0,
DEVICE_UNIFIED_MEMORY,
HOST_UNIFIED_MEMORY,
NOT_SPECIFIED
};

View File

@ -160,6 +160,25 @@ TEST_F(SVMMemoryAllocatorTest, whenDeviceAllocationIsCreatedThenItIsStoredWithPr
svmManager->freeSVMAlloc(ptr);
}
TEST_F(SVMMemoryAllocatorTest, whenHostAllocationIsCreatedThenItIsStoredWithProperTypeInAllocationMap) {
SVMAllocsManager::UnifiedMemoryProperties unifiedMemoryProperties;
unifiedMemoryProperties.memoryType = InternalMemoryType::HOST_UNIFIED_MEMORY;
auto allocationSize = 4096u;
auto ptr = svmManager->createUnifiedMemoryAllocation(4096u, unifiedMemoryProperties);
EXPECT_NE(nullptr, ptr);
auto allocation = svmManager->getSVMAlloc(ptr);
EXPECT_EQ(nullptr, allocation->cpuAllocation);
EXPECT_NE(nullptr, allocation->gpuAllocation);
EXPECT_EQ(InternalMemoryType::HOST_UNIFIED_MEMORY, allocation->memoryType);
EXPECT_EQ(allocationSize, allocation->size);
EXPECT_EQ(alignUp(allocationSize, MemoryConstants::pageSize64k), allocation->gpuAllocation->getUnderlyingBufferSize());
EXPECT_EQ(GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY, allocation->gpuAllocation->getAllocationType());
EXPECT_NE(allocation->gpuAllocation->getMemoryPool(), MemoryPool::LocalMemory);
EXPECT_NE(nullptr, allocation->gpuAllocation->getUnderlyingBuffer());
svmManager->freeSVMAlloc(ptr);
}
TEST(SvmAllocationPropertiesTests, givenDifferentMemFlagsWhenGettingSvmAllocationPropertiesThenPropertiesAreCorrectlySet) {
SVMAllocsManager::SvmAllocationProperties allocationProperties = MemObjHelper::getSvmAllocationProperties(0);
EXPECT_FALSE(allocationProperties.coherent);