mirror of
https://github.com/intel/compute-runtime.git
synced 2026-01-06 02:18:05 +08:00
fix: Add path for clCreateBuffer with host unified memory ptr
Related-To: NEO-9612 Signed-off-by: Milczarek, Slawomir <slawomir.milczarek@intel.com>
This commit is contained in:
committed by
Compute-Runtime-Automation
parent
3695e63f9d
commit
87247e6949
@@ -380,13 +380,23 @@ Buffer *Buffer::create(Context *context,
|
||||
if (svmManager) {
|
||||
auto svmData = svmManager->getSVMAlloc(hostPtr);
|
||||
if (svmData) {
|
||||
allocationInfo.memory = svmData->gpuAllocations.getGraphicsAllocation(rootDeviceIndex);
|
||||
allocationInfo.allocationType = allocationInfo.memory->getAllocationType();
|
||||
allocationInfo.isHostPtrSVM = true;
|
||||
allocationInfo.zeroCopyAllowed = allocationInfo.memory->getAllocationType() == AllocationType::SVM_ZERO_COPY;
|
||||
allocationInfo.copyMemoryFromHostPtr = false;
|
||||
allocationInfo.allocateMemory = false;
|
||||
allocationInfo.mapAllocation = svmData->cpuAllocation;
|
||||
if ((svmData->memoryType == InternalMemoryType::HOST_UNIFIED_MEMORY) && memoryManager->isLocalMemorySupported(rootDeviceIndex)) {
|
||||
allocationInfo.memory = nullptr;
|
||||
allocationInfo.allocationType = AllocationType::BUFFER;
|
||||
allocationInfo.isHostPtrSVM = false;
|
||||
allocationInfo.zeroCopyAllowed = false;
|
||||
allocationInfo.copyMemoryFromHostPtr = true;
|
||||
allocationInfo.allocateMemory = true;
|
||||
allocationInfo.mapAllocation = svmData->gpuAllocations.getGraphicsAllocation(rootDeviceIndex);
|
||||
} else {
|
||||
allocationInfo.memory = svmData->gpuAllocations.getGraphicsAllocation(rootDeviceIndex);
|
||||
allocationInfo.allocationType = allocationInfo.memory->getAllocationType();
|
||||
allocationInfo.isHostPtrSVM = true;
|
||||
allocationInfo.zeroCopyAllowed = allocationInfo.memory->getAllocationType() == AllocationType::SVM_ZERO_COPY;
|
||||
allocationInfo.copyMemoryFromHostPtr = false;
|
||||
allocationInfo.allocateMemory = false;
|
||||
allocationInfo.mapAllocation = svmData->cpuAllocation;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1199,6 +1199,32 @@ TEST_P(ValidHostPtr, GivenSvmHostPtrWhenCreatingBufferThenBufferIsCreatedCorrect
|
||||
}
|
||||
}
|
||||
|
||||
TEST_P(ValidHostPtr, GivenUsmHostPtrWhenCreatingBufferThenBufferIsCreatedCorrectly) {
|
||||
const ClDeviceInfo &devInfo = pClDevice->getDeviceInfo();
|
||||
if (devInfo.svmCapabilities != 0) {
|
||||
auto memoryManager = static_cast<MockMemoryManager *>(context->getDevice(0)->getMemoryManager());
|
||||
memoryManager->localMemorySupported[pDevice->getRootDeviceIndex()] = true;
|
||||
|
||||
NEO::SVMAllocsManager::UnifiedMemoryProperties unifiedMemoryProperties(InternalMemoryType::HOST_UNIFIED_MEMORY, 1, context->getRootDeviceIndices(), context->getDeviceBitfields());
|
||||
auto ptr = context->getSVMAllocsManager()->createHostUnifiedMemoryAllocation(MemoryConstants::pageSize64k, unifiedMemoryProperties);
|
||||
|
||||
auto buffer = Buffer::create(context.get(), CL_MEM_READ_WRITE | CL_MEM_USE_HOST_PTR, 64, ptr, retVal);
|
||||
EXPECT_NE(nullptr, buffer);
|
||||
|
||||
auto svmData = context->getSVMAllocsManager()->getSVMAlloc(ptr);
|
||||
ASSERT_NE(nullptr, svmData);
|
||||
|
||||
EXPECT_EQ(AllocationType::BUFFER, buffer->getGraphicsAllocation(pDevice->getRootDeviceIndex())->getAllocationType());
|
||||
|
||||
auto mapAllocation = buffer->getMapAllocation(pDevice->getRootDeviceIndex());
|
||||
ASSERT_NE(nullptr, mapAllocation);
|
||||
EXPECT_EQ(reinterpret_cast<void *>(mapAllocation->getGpuAddress()), ptr);
|
||||
|
||||
delete buffer;
|
||||
context->getSVMAllocsManager()->freeSVMAlloc(ptr);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_P(ValidHostPtr, WhenValidateInputAndCreateBufferThenCorrectBufferIsSet) {
|
||||
auto buffer = BufferFunctions::validateInputAndCreateBuffer(context.get(), nullptr, flags, 0, testBufferSizeInBytes, pHostPtr, retVal);
|
||||
EXPECT_EQ(retVal, CL_SUCCESS);
|
||||
|
||||
Reference in New Issue
Block a user