Add support for external hostptr in shared allocations

Signed-off-by: Lukasz Jobczyk <lukasz.jobczyk@intel.com>
This commit is contained in:
Lukasz Jobczyk
2022-10-27 14:25:07 +00:00
committed by Compute-Runtime-Automation
parent 4d6bb9a807
commit ff500e0de6
4 changed files with 14 additions and 14 deletions

View File

@@ -480,24 +480,28 @@ void *SVMAllocsManager::createUnifiedAllocationWithDeviceStorage(size_t size, co
auto rootDeviceIndex = unifiedMemoryProperties.device
? unifiedMemoryProperties.device->getRootDeviceIndex()
: *unifiedMemoryProperties.rootDeviceIndices.begin();
auto externalPtr = reinterpret_cast<void *>(unifiedMemoryProperties.allocationFlags.hostptr);
bool useExternalHostPtrForCpu = externalPtr != nullptr;
size_t alignedSizeCpu = alignUp<size_t>(size, MemoryConstants::pageSize2Mb);
size_t pageSizeForAlignment = MemoryConstants::pageSize64k;
size_t alignedSizeGpu = alignUp<size_t>(size, pageSizeForAlignment);
DeviceBitfield subDevices = unifiedMemoryProperties.subdeviceBitfields.at(rootDeviceIndex);
AllocationProperties cpuProperties{rootDeviceIndex,
true, // allocateMemory
!useExternalHostPtrForCpu, // allocateMemory
alignedSizeCpu, AllocationType::SVM_CPU,
false, // isMultiStorageAllocation
subDevices};
cpuProperties.alignment = MemoryConstants::pageSize2Mb;
cpuProperties.flags.isUSMHostAllocation = useExternalHostPtrForCpu;
auto cacheRegion = MemoryPropertiesHelper::getCacheRegion(unifiedMemoryProperties.allocationFlags);
MemoryPropertiesHelper::fillCachePolicyInProperties(cpuProperties, false, svmProperties.readOnly, false, cacheRegion);
GraphicsAllocation *allocationCpu = memoryManager->allocateGraphicsMemoryWithProperties(cpuProperties);
GraphicsAllocation *allocationCpu = memoryManager->allocateGraphicsMemoryWithProperties(cpuProperties, externalPtr);
if (!allocationCpu) {
return nullptr;
}
setUnifiedAllocationProperties(allocationCpu, svmProperties);
void *svmPtr = allocationCpu->getUnderlyingBuffer();
UNRECOVERABLE_IF(useExternalHostPtrForCpu && (externalPtr != svmPtr));
bool multiStorageAllocation = (subDevices.count() > 1) && multiOsContextSupport;
if ((subDevices.count() > 1) && !multiOsContextSupport) {