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

@@ -277,18 +277,13 @@ ze_result_t ContextImp::allocSharedMem(ze_device_handle_t hDevice,
unifiedMemoryProperties.allocationFlags.flags.resource48Bit = 1;
}
void *usmPtr = nullptr;
if (hostDesc->flags & ZEX_HOST_MEM_ALLOC_FLAG_USE_HOST_PTR) {
unifiedMemoryProperties.allocationFlags.hostptr = reinterpret_cast<uintptr_t>(*ptr);
usmPtr = this->driverHandle->svmAllocsManager->createHostUnifiedMemoryAllocation(size,
unifiedMemoryProperties);
} else {
usmPtr =
this->driverHandle->svmAllocsManager->createSharedUnifiedMemoryAllocation(size,
unifiedMemoryProperties,
static_cast<void *>(neoDevice->getSpecializedDevice<L0::Device>()));
}
auto usmPtr = this->driverHandle->svmAllocsManager->createSharedUnifiedMemoryAllocation(size,
unifiedMemoryProperties,
static_cast<void *>(neoDevice->getSpecializedDevice<L0::Device>()));
if (usmPtr == nullptr) {
return ZE_RESULT_ERROR_OUT_OF_DEVICE_MEMORY;
}

View File

@@ -868,7 +868,7 @@ struct ZexHostPointerTests : public ::testing::Test {
std::unique_ptr<ContextZexPointerMock> context;
};
TEST_F(ZexHostPointerTests, whenAllocatingSharedMemoryWithUseHostPtrFlagThenCreateHostUSMAlloc) {
TEST_F(ZexHostPointerTests, whenAllocatingSharedMemoryWithUseHostPtrFlagThenCreateSharedUSMAlloc) {
size_t size = 10;
size_t alignment = 1u;
void *ptr = reinterpret_cast<void *>(0x1234);
@@ -887,8 +887,8 @@ TEST_F(ZexHostPointerTests, whenAllocatingSharedMemoryWithUseHostPtrFlagThenCrea
uint32_t curAllocCounterShared = currSvmAllocsManager->sharedUnifiedMemoryAllocationTimes;
uint32_t curAllocCounterHost = currSvmAllocsManager->hostUnifiedMemoryAllocationTimes;
EXPECT_EQ(curAllocCounterShared, prevAllocCounterShared);
EXPECT_EQ(curAllocCounterHost, prevAllocCounterHost + 1);
EXPECT_EQ(curAllocCounterShared, prevAllocCounterShared + 1);
EXPECT_EQ(curAllocCounterHost, prevAllocCounterHost);
result = context->freeMem(ptr);
EXPECT_EQ(ZE_RESULT_SUCCESS, result);

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) {

View File

@@ -400,7 +400,8 @@ GraphicsAllocation *DrmMemoryManager::allocateUSMHostGraphicsMemory(const Alloca
// if limitedRangeAlloction is enabled, memory allocation for bo in the limited Range heap is required
uint64_t gpuAddress = 0;
if (isLimitedRange(allocationData.rootDeviceIndex)) {
auto svmCpuAllocation = allocationData.type == AllocationType::SVM_CPU;
if (isLimitedRange(allocationData.rootDeviceIndex) || svmCpuAllocation) {
gpuAddress = acquireGpuRange(cSize, allocationData.rootDeviceIndex, HeapIndex::HEAP_STANDARD);
if (!gpuAddress) {
return nullptr;