diff --git a/level_zero/core/source/cmdlist/cmdlist_hw.inl b/level_zero/core/source/cmdlist/cmdlist_hw.inl index 144197c439..1c66b433f7 100644 --- a/level_zero/core/source/cmdlist/cmdlist_hw.inl +++ b/level_zero/core/source/cmdlist/cmdlist_hw.inl @@ -589,7 +589,8 @@ ze_result_t CommandListCoreFamily::appendImageCopyFromMemory(ze_i } builtinKernel->setArgBufferWithAlloc(0u, allocationStruct.alignedAllocationPtr, - allocationStruct.alloc); + allocationStruct.alloc, + nullptr); builtinKernel->setArgRedescribedImage(1u, image->toHandle()); builtinKernel->setArgumentValue(2u, sizeof(size_t), &allocationStruct.offset); @@ -734,7 +735,8 @@ ze_result_t CommandListCoreFamily::appendImageCopyToMemory(void * builtinKernel->setArgRedescribedImage(0u, image->toHandle()); builtinKernel->setArgBufferWithAlloc(1u, allocationStruct.alignedAllocationPtr, - allocationStruct.alloc); + allocationStruct.alloc, + nullptr); uint32_t origin[] = { static_cast(pSrcRegion->originX), @@ -1033,8 +1035,8 @@ ze_result_t CommandListCoreFamily::appendMemoryCopyKernelWithGA(v return ret; } - builtinKernel->setArgBufferWithAlloc(0u, *reinterpret_cast(dstPtr), dstPtrAlloc); - builtinKernel->setArgBufferWithAlloc(1u, *reinterpret_cast(srcPtr), srcPtrAlloc); + builtinKernel->setArgBufferWithAlloc(0u, *reinterpret_cast(dstPtr), dstPtrAlloc, nullptr); + builtinKernel->setArgBufferWithAlloc(1u, *reinterpret_cast(srcPtr), srcPtrAlloc, nullptr); uint64_t elems = size / elementSize; builtinKernel->setArgumentValue(2, sizeof(elems), &elems); @@ -1512,8 +1514,8 @@ ze_result_t CommandListCoreFamily::appendMemoryCopyKernel3d(Align uint32_t srcPitches[2] = {(srcPitch), (srcSlicePitch)}; uint32_t dstPitches[2] = {(dstPitch), (dstSlicePitch)}; - builtinKernel->setArgBufferWithAlloc(0, srcAlignedAllocation->alignedAllocationPtr, srcAlignedAllocation->alloc); - builtinKernel->setArgBufferWithAlloc(1, dstAlignedAllocation->alignedAllocationPtr, dstAlignedAllocation->alloc); + builtinKernel->setArgBufferWithAlloc(0, srcAlignedAllocation->alignedAllocationPtr, srcAlignedAllocation->alloc, nullptr); + builtinKernel->setArgBufferWithAlloc(1, dstAlignedAllocation->alignedAllocationPtr, dstAlignedAllocation->alloc, nullptr); builtinKernel->setArgumentValue(2, sizeof(srcOrigin), &srcOrigin); builtinKernel->setArgumentValue(3, sizeof(dstOrigin), &dstOrigin); builtinKernel->setArgumentValue(4, sizeof(srcPitches), &srcPitches); @@ -1576,8 +1578,8 @@ ze_result_t CommandListCoreFamily::appendMemoryCopyKernel2d(Align uint32_t srcOrigin[2] = {(srcRegion->originX + static_cast(srcOffset)), (srcRegion->originY)}; uint32_t dstOrigin[2] = {(dstRegion->originX + static_cast(dstOffset)), (dstRegion->originY)}; - builtinKernel->setArgBufferWithAlloc(0, srcAlignedAllocation->alignedAllocationPtr, srcAlignedAllocation->alloc); - builtinKernel->setArgBufferWithAlloc(1, dstAlignedAllocation->alignedAllocationPtr, dstAlignedAllocation->alloc); + builtinKernel->setArgBufferWithAlloc(0, srcAlignedAllocation->alignedAllocationPtr, srcAlignedAllocation->alloc, nullptr); + builtinKernel->setArgBufferWithAlloc(1, dstAlignedAllocation->alignedAllocationPtr, dstAlignedAllocation->alloc, nullptr); builtinKernel->setArgumentValue(2, sizeof(srcOrigin), &srcOrigin); builtinKernel->setArgumentValue(3, sizeof(dstOrigin), &dstOrigin); builtinKernel->setArgumentValue(4, sizeof(srcPitch), &srcPitch); @@ -1620,7 +1622,7 @@ ze_result_t CommandListCoreFamily::appendUnalignedFillKernel(bool builtinKernel->setGroupSize(groupSizeX, groupSizeY, groupSizeZ); ze_group_count_t dispatchKernelRemainderArgs{static_cast(unalignedSize / groupSizeX), 1u, 1u}; uint32_t value = *(reinterpret_cast(pattern)); - builtinKernel->setArgBufferWithAlloc(0, dstAllocation.alignedAllocationPtr, dstAllocation.alloc); + builtinKernel->setArgBufferWithAlloc(0, dstAllocation.alignedAllocationPtr, dstAllocation.alloc, nullptr); builtinKernel->setArgumentValue(1, sizeof(dstAllocation.offset), &dstAllocation.offset); builtinKernel->setArgumentValue(2, sizeof(value), &value); @@ -1741,7 +1743,7 @@ ze_result_t CommandListCoreFamily::appendMemoryFill(void *ptr, uint32_t value = 0; memset(&value, *reinterpret_cast(pattern), 4); - builtinKernel->setArgBufferWithAlloc(0, dstAllocation.alignedAllocationPtr, dstAllocation.alloc); + builtinKernel->setArgBufferWithAlloc(0, dstAllocation.alignedAllocationPtr, dstAllocation.alloc, nullptr); builtinKernel->setArgumentValue(1, sizeof(fillArguments.mainOffset), &fillArguments.mainOffset); builtinKernel->setArgumentValue(2, sizeof(value), &value); @@ -1784,9 +1786,9 @@ ze_result_t CommandListCoreFamily::appendMemoryFill(void *ptr, patternAllocOffset += patternSizeToCopy; } while (patternAllocOffset < patternAllocationSize); if (fillArguments.leftRemainingBytes == 0) { - builtinKernel->setArgBufferWithAlloc(0, dstAllocation.alignedAllocationPtr, dstAllocation.alloc); + builtinKernel->setArgBufferWithAlloc(0, dstAllocation.alignedAllocationPtr, dstAllocation.alloc, nullptr); builtinKernel->setArgumentValue(1, sizeof(dstAllocation.offset), &dstAllocation.offset); - builtinKernel->setArgBufferWithAlloc(2, reinterpret_cast(patternGfxAllocPtr), patternGfxAlloc); + builtinKernel->setArgBufferWithAlloc(2, reinterpret_cast(patternGfxAllocPtr), patternGfxAlloc, nullptr); builtinKernel->setArgumentValue(3, sizeof(fillArguments.patternSizeInEls), &fillArguments.patternSizeInEls); ze_group_count_t dispatchKernelArgs{static_cast(fillArguments.groups), 1u, 1u}; @@ -1809,13 +1811,13 @@ ze_result_t CommandListCoreFamily::appendMemoryFill(void *ptr, builtinKernelRemainder->setArgBufferWithAlloc(0, dstAllocation.alignedAllocationPtr, - dstAllocation.alloc); + dstAllocation.alloc, nullptr); builtinKernelRemainder->setArgumentValue(1, sizeof(dstOffsetRemainder), &dstOffsetRemainder); builtinKernelRemainder->setArgBufferWithAlloc(2, reinterpret_cast(patternGfxAllocPtr), - patternGfxAlloc); + patternGfxAlloc, nullptr); builtinKernelRemainder->setArgumentValue(3, sizeof(patternAllocationSize), &patternAllocationSize); res = appendLaunchKernelSplit(builtinKernelRemainder, &dispatchKernelArgs, signalEvent, launchParams); @@ -1840,13 +1842,13 @@ ze_result_t CommandListCoreFamily::appendMemoryFill(void *ptr, builtinKernelRemainder->setArgBufferWithAlloc(0, dstAllocation.alignedAllocationPtr, - dstAllocation.alloc); + dstAllocation.alloc, nullptr); builtinKernelRemainder->setArgumentValue(1, sizeof(dstOffsetRemainder), &dstOffsetRemainder); builtinKernelRemainder->setArgBufferWithAlloc(2, reinterpret_cast(patternGfxAllocPtr) + patternOffsetRemainder, - patternGfxAlloc); + patternGfxAlloc, nullptr); builtinKernelRemainder->setArgumentValue(3, sizeof(patternAllocationSize), &patternAllocationSize); res = appendLaunchKernelSplit(builtinKernelRemainder, &dispatchKernelArgs, signalEvent, launchParams); @@ -1898,7 +1900,7 @@ ze_result_t CommandListCoreFamily::appendBlitFill(void *ptr, if (driverHandle->isRemoteResourceNeeded(ptr, gpuAllocation, allocData, device)) { if (allocData) { uint64_t pbase = allocData->gpuAllocations.getDefaultGraphicsAllocation()->getGpuAddress(); - gpuAllocation = driverHandle->getPeerAllocation(device, allocData, reinterpret_cast(pbase), nullptr); + gpuAllocation = driverHandle->getPeerAllocation(device, allocData, reinterpret_cast(pbase), nullptr, nullptr); } if (gpuAllocation == nullptr) { return ZE_RESULT_ERROR_INVALID_ARGUMENT; @@ -2024,7 +2026,7 @@ inline AlignedAllocationData CommandListCoreFamily::getAlignedAll uint64_t pbase = allocData->gpuAllocations.getDefaultGraphicsAllocation()->getGpuAddress(); uint64_t offset = sourcePtr - pbase; - alloc = driverHandle->getPeerAllocation(device, allocData, reinterpret_cast(pbase), &alignedPtr); + alloc = driverHandle->getPeerAllocation(device, allocData, reinterpret_cast(pbase), &alignedPtr, nullptr); alignedPtr += offset; if (allocData->memoryType == InternalMemoryType::SHARED_UNIFIED_MEMORY) { @@ -2422,7 +2424,7 @@ ze_result_t CommandListCoreFamily::appendQueryKernelTimestamps( auto offsetValPtr = static_cast(pOffsetAllocationStruct.alloc->getGpuAddress()); commandContainer.addToResidencyContainer(pOffsetAllocationStruct.alloc); builtinKernel = device->getBuiltinFunctionsLib()->getFunction(Builtin::QueryKernelTimestampsWithOffsets); - builtinKernel->setArgBufferWithAlloc(2, offsetValPtr, pOffsetAllocationStruct.alloc); + builtinKernel->setArgBufferWithAlloc(2, offsetValPtr, pOffsetAllocationStruct.alloc, nullptr); builtinKernel->setArgumentValue(3u, sizeof(uint32_t), &useOnlyGlobalTimestamps); offsetValPtr += sizeof(size_t); } @@ -2448,8 +2450,8 @@ ze_result_t CommandListCoreFamily::appendQueryKernelTimestamps( auto dstValPtr = static_cast(dstPtrAllocationStruct.alloc->getGpuAddress()); - builtinKernel->setArgBufferWithAlloc(0u, static_cast(timestampsGPUData->getGpuAddress()), timestampsGPUData); - builtinKernel->setArgBufferWithAlloc(1, dstValPtr, dstPtrAllocationStruct.alloc); + builtinKernel->setArgBufferWithAlloc(0u, static_cast(timestampsGPUData->getGpuAddress()), timestampsGPUData, nullptr); + builtinKernel->setArgBufferWithAlloc(1, dstValPtr, dstPtrAllocationStruct.alloc, nullptr); auto dstAllocationType = dstPtrAllocationStruct.alloc->getAllocationType(); CmdListKernelLaunchParams launchParams = {}; diff --git a/level_zero/core/source/context/context_imp.cpp b/level_zero/core/source/context/context_imp.cpp index e0562cd56e..e9e126df44 100644 --- a/level_zero/core/source/context/context_imp.cpp +++ b/level_zero/core/source/context/context_imp.cpp @@ -377,7 +377,14 @@ void ContextImp::freePeerAllocations(const void *ptr, bool blocking, Device *dev auto peerAllocData = &iter->second; auto peerAlloc = peerAllocData->gpuAllocations.getDefaultGraphicsAllocation(); auto peerPtr = reinterpret_cast(peerAlloc->getGpuAddress()); - this->driverHandle->svmAllocsManager->freeSVMAlloc(peerPtr, blocking); + if (peerAllocData->mappedAllocData) { + auto gpuAllocations = peerAllocData->gpuAllocations; + for (const auto &graphicsAllocation : gpuAllocations.getGraphicsAllocations()) { + this->driverHandle->getMemoryManager()->freeGraphicsMemory(graphicsAllocation); + } + } else { + this->driverHandle->svmAllocsManager->freeSVMAlloc(peerPtr, blocking); + } deviceImp->peerAllocations.allocations.erase(iter); } @@ -709,8 +716,8 @@ ze_result_t ContextImp::openIpcMemHandles(ze_device_handle_t hDevice, handles.push_back(static_cast(handle)); } auto neoDevice = Device::fromHandle(hDevice)->getNEODevice()->getRootDevice(); - - *pptr = this->driverHandle->importFdHandles(neoDevice, flags, handles, nullptr); + NEO::SvmAllocationData allocDataInternal(neoDevice->getRootDeviceIndex()); + *pptr = this->driverHandle->importFdHandles(neoDevice, flags, handles, nullptr, nullptr, allocDataInternal); if (nullptr == *pptr) { return ZE_RESULT_ERROR_INVALID_ARGUMENT; } @@ -1056,6 +1063,7 @@ ze_result_t ContextImp::mapVirtualMem(const void *ptr, allocData.size = size; allocData.pageSizeForAlignment = MemoryConstants::pageSize64k; allocData.setAllocId(this->driverHandle->svmAllocsManager->allocationsCounter++); + allocData.memoryType = InternalMemoryType::RESERVED_DEVICE_MEMORY; NEO::MemoryMappedRange *mappedRange = new NEO::MemoryMappedRange; mappedRange->ptr = ptr; mappedRange->size = size; diff --git a/level_zero/core/source/context/context_imp_drm.cpp b/level_zero/core/source/context/context_imp_drm.cpp index 4e07f14902..736adfa5c4 100644 --- a/level_zero/core/source/context/context_imp_drm.cpp +++ b/level_zero/core/source/context/context_imp_drm.cpp @@ -1,10 +1,13 @@ /* - * Copyright (C) 2022 Intel Corporation + * Copyright (C) 2022-2023 Intel Corporation * * SPDX-License-Identifier: MIT * */ +#include "shared/source/device/device.h" +#include "shared/source/memory_manager/unified_memory_manager.h" + #include "level_zero/core/source/context/context_imp.h" #include "level_zero/core/source/device/device.h" #include "level_zero/core/source/driver/driver_handle_imp.h" @@ -19,7 +22,9 @@ bool ContextImp::isShareableMemory(const void *exportDesc, bool exportableMemory } void *ContextImp::getMemHandlePtr(ze_device_handle_t hDevice, uint64_t handle, NEO::AllocationType allocationType, ze_ipc_memory_flags_t flags) { - return this->driverHandle->importFdHandle(Device::fromHandle(hDevice)->getNEODevice(), flags, handle, allocationType, nullptr); + auto neoDevice = Device::fromHandle(hDevice)->getNEODevice(); + NEO::SvmAllocationData allocDataInternal(neoDevice->getRootDeviceIndex()); + return this->driverHandle->importFdHandle(neoDevice, flags, handle, allocationType, nullptr, nullptr, allocDataInternal); } } // namespace L0 diff --git a/level_zero/core/source/context/context_imp_drm_or_wddm.cpp b/level_zero/core/source/context/context_imp_drm_or_wddm.cpp index 431ad81106..ae8917f795 100644 --- a/level_zero/core/source/context/context_imp_drm_or_wddm.cpp +++ b/level_zero/core/source/context/context_imp_drm_or_wddm.cpp @@ -9,6 +9,7 @@ #include "shared/source/execution_environment/root_device_environment.h" #include "shared/source/helpers/driver_model_type.h" #include "shared/source/memory_manager/memory_manager.h" +#include "shared/source/memory_manager/unified_memory_manager.h" #include "shared/source/os_interface/os_interface.h" #include "level_zero/core/source/context/context_imp.h" @@ -47,11 +48,15 @@ void *ContextImp::getMemHandlePtr(ze_device_handle_t hDevice, reinterpret_cast(handle), allocationType); } else if (driverType == NEO::DriverModelType::DRM) { - return this->driverHandle->importFdHandle(Device::fromHandle(hDevice)->getNEODevice(), + auto neoDevice = Device::fromHandle(hDevice)->getNEODevice(); + NEO::SvmAllocationData allocDataInternal(neoDevice->getRootDeviceIndex()); + return this->driverHandle->importFdHandle(neoDevice, flags, handle, allocationType, - nullptr); + nullptr, + nullptr, + allocDataInternal); } else { return nullptr; } diff --git a/level_zero/core/source/driver/driver_handle_imp.cpp b/level_zero/core/source/driver/driver_handle_imp.cpp index 7a4b098c88..5efc13edf1 100644 --- a/level_zero/core/source/driver/driver_handle_imp.cpp +++ b/level_zero/core/source/driver/driver_handle_imp.cpp @@ -476,7 +476,9 @@ void *DriverHandleImp::importFdHandle(NEO::Device *neoDevice, ze_ipc_memory_flags_t flags, uint64_t handle, NEO::AllocationType allocationType, - NEO::GraphicsAllocation **pAlloc) { + void *basePointer, + NEO::GraphicsAllocation **pAlloc, + NEO::SvmAllocationData &mappedPeerAllocData) { NEO::osHandle osHandle = static_cast(handle); NEO::AllocationProperties unifiedMemoryProperties{neoDevice->getRootDeviceIndex(), MemoryConstants::pageSize, @@ -489,29 +491,39 @@ void *DriverHandleImp::importFdHandle(NEO::Device *neoDevice, unifiedMemoryProperties, false, isHostIpcAllocation, - false); + false, + basePointer); if (alloc == nullptr) { return nullptr; } NEO::SvmAllocationData allocData(neoDevice->getRootDeviceIndex()); - allocData.gpuAllocations.addAllocation(alloc); - allocData.cpuAllocation = nullptr; - allocData.size = alloc->getUnderlyingBufferSize(); - allocData.memoryType = + NEO::SvmAllocationData *allocDataTmp = nullptr; + if (basePointer) { + allocDataTmp = &mappedPeerAllocData; + allocDataTmp->mappedAllocData = true; + } else { + allocDataTmp = &allocData; + allocDataTmp->mappedAllocData = false; + } + allocDataTmp->gpuAllocations.addAllocation(alloc); + allocDataTmp->cpuAllocation = nullptr; + allocDataTmp->size = alloc->getUnderlyingBufferSize(); + allocDataTmp->memoryType = isHostIpcAllocation ? InternalMemoryType::HOST_UNIFIED_MEMORY : InternalMemoryType::DEVICE_UNIFIED_MEMORY; - allocData.device = neoDevice; - allocData.isImportedAllocation = true; + allocDataTmp->device = neoDevice; + allocDataTmp->isImportedAllocation = true; if (flags & ZE_DEVICE_MEM_ALLOC_FLAG_BIAS_UNCACHED) { - allocData.allocationFlagsProperty.flags.locallyUncachedResource = 1; + allocDataTmp->allocationFlagsProperty.flags.locallyUncachedResource = 1; } if (flags & ZE_IPC_MEMORY_FLAG_BIAS_UNCACHED) { - allocData.allocationFlagsProperty.flags.locallyUncachedResource = 1; + allocDataTmp->allocationFlagsProperty.flags.locallyUncachedResource = 1; } - this->getSvmAllocsManager()->insertSVMAlloc(allocData); - + if (!basePointer) { + this->getSvmAllocsManager()->insertSVMAlloc(allocData); + } if (pAlloc) { *pAlloc = alloc; } @@ -519,7 +531,7 @@ void *DriverHandleImp::importFdHandle(NEO::Device *neoDevice, return reinterpret_cast(alloc->getGpuAddress()); } -void *DriverHandleImp::importFdHandles(NEO::Device *neoDevice, ze_ipc_memory_flags_t flags, const std::vector &handles, NEO::GraphicsAllocation **pAlloc) { +void *DriverHandleImp::importFdHandles(NEO::Device *neoDevice, ze_ipc_memory_flags_t flags, const std::vector &handles, void *basePtr, NEO::GraphicsAllocation **pAlloc, NEO::SvmAllocationData &mappedPeerAllocData) { NEO::AllocationProperties unifiedMemoryProperties{neoDevice->getRootDeviceIndex(), MemoryConstants::pageSize, NEO::AllocationType::BUFFER, @@ -531,26 +543,39 @@ void *DriverHandleImp::importFdHandles(NEO::Device *neoDevice, ze_ipc_memory_fla unifiedMemoryProperties, false, false, - false); + false, + basePtr); if (alloc == nullptr) { return nullptr; } + NEO::SvmAllocationData *allocDataTmp = nullptr; NEO::SvmAllocationData allocData(neoDevice->getRootDeviceIndex()); - allocData.gpuAllocations.addAllocation(alloc); - allocData.cpuAllocation = nullptr; - allocData.size = alloc->getUnderlyingBufferSize(); - allocData.memoryType = InternalMemoryType::DEVICE_UNIFIED_MEMORY; - allocData.device = neoDevice; + + if (basePtr) { + allocDataTmp = &mappedPeerAllocData; + allocDataTmp->mappedAllocData = true; + } else { + allocDataTmp = &allocData; + allocDataTmp->mappedAllocData = false; + } + + allocDataTmp->gpuAllocations.addAllocation(alloc); + allocDataTmp->cpuAllocation = nullptr; + allocDataTmp->size = alloc->getUnderlyingBufferSize(); + allocDataTmp->memoryType = InternalMemoryType::DEVICE_UNIFIED_MEMORY; + allocDataTmp->device = neoDevice; if (flags & ZE_DEVICE_MEM_ALLOC_FLAG_BIAS_UNCACHED) { - allocData.allocationFlagsProperty.flags.locallyUncachedResource = 1; + allocDataTmp->allocationFlagsProperty.flags.locallyUncachedResource = 1; } if (flags & ZE_IPC_MEMORY_FLAG_BIAS_UNCACHED) { - allocData.allocationFlagsProperty.flags.locallyUncachedResource = 1; + allocDataTmp->allocationFlagsProperty.flags.locallyUncachedResource = 1; } - this->getSvmAllocsManager()->insertSVMAlloc(allocData); + if (!basePtr) { + this->getSvmAllocsManager()->insertSVMAlloc(allocData); + } if (pAlloc) { *pAlloc = alloc; @@ -603,19 +628,21 @@ ze_result_t DriverHandleImp::getPeerImage(Device *device, Image *image, Image ** NEO::GraphicsAllocation *DriverHandleImp::getPeerAllocation(Device *device, NEO::SvmAllocationData *allocData, void *basePtr, - uintptr_t *peerGpuAddress) { + uintptr_t *peerGpuAddress, + NEO::SvmAllocationData **peerAllocData) { DeviceImp *deviceImp = static_cast(device); NEO::GraphicsAllocation *alloc = nullptr; - - NEO::SvmAllocationData *peerAllocData = nullptr; + void *peerMapAddress = basePtr; void *peerPtr = nullptr; + NEO::SvmAllocationData *peerAllocDataInternal = nullptr; + std::unique_lock lock(deviceImp->peerAllocationsMutex); auto iter = deviceImp->peerAllocations.allocations.find(basePtr); if (iter != deviceImp->peerAllocations.allocations.end()) { - peerAllocData = &iter->second; - alloc = peerAllocData->gpuAllocations.getDefaultGraphicsAllocation(); + peerAllocDataInternal = &iter->second; + alloc = peerAllocDataInternal->gpuAllocations.getDefaultGraphicsAllocation(); UNRECOVERABLE_IF(alloc == nullptr); peerPtr = reinterpret_cast(alloc->getGpuAddress()); } else { @@ -624,6 +651,17 @@ NEO::GraphicsAllocation *DriverHandleImp::getPeerAllocation(Device *device, ze_ipc_memory_flags_t flags = {}; uint32_t numHandles = alloc->getNumHandles(); + // Don't attempt to use the peerMapAddress for reserved memory due to the limitations in the address reserved. + if (allocData->memoryType == InternalMemoryType::RESERVED_DEVICE_MEMORY) { + peerMapAddress = nullptr; + } + + uint32_t peerAllocRootDeviceIndex = device->getNEODevice()->getRootDeviceIndex(); + if (numHandles > 1) { + peerAllocRootDeviceIndex = device->getNEODevice()->getRootDevice()->getRootDeviceIndex(); + } + NEO::SvmAllocationData allocDataInternal(peerAllocRootDeviceIndex); + if (numHandles > 1) { UNRECOVERABLE_IF(numHandles == 0); std::vector handles; @@ -636,7 +674,7 @@ NEO::GraphicsAllocation *DriverHandleImp::getPeerAllocation(Device *device, handles.push_back(static_cast(handle)); } auto neoDevice = device->getNEODevice()->getRootDevice(); - peerPtr = this->importFdHandles(neoDevice, flags, handles, &alloc); + peerPtr = this->importFdHandles(neoDevice, flags, handles, peerMapAddress, &alloc, allocDataInternal); } else { uint64_t handle = 0; int ret = alloc->peekInternalHandle(this->getMemoryManager(), handle); @@ -647,15 +685,28 @@ NEO::GraphicsAllocation *DriverHandleImp::getPeerAllocation(Device *device, flags, handle, NEO::AllocationType::BUFFER, - &alloc); + peerMapAddress, + &alloc, + allocDataInternal); } if (peerPtr == nullptr) { return nullptr; } - peerAllocData = this->getSvmAllocsManager()->getSVMAlloc(peerPtr); - deviceImp->peerAllocations.allocations.insert(std::make_pair(basePtr, *peerAllocData)); + peerAllocDataInternal = &allocDataInternal; + if (peerMapAddress == nullptr) { + peerAllocDataInternal = this->getSvmAllocsManager()->getSVMAlloc(peerPtr); + } + deviceImp->peerAllocations.allocations.insert(std::make_pair(basePtr, *peerAllocDataInternal)); + // Point to the new peer Alloc Data after it is recreated in the peer allocations map + if (peerMapAddress) { + peerAllocDataInternal = &deviceImp->peerAllocations.allocations.at(basePtr); + } + } + + if (peerAllocData) { + *peerAllocData = peerAllocDataInternal; } if (peerGpuAddress) { diff --git a/level_zero/core/source/driver/driver_handle_imp.h b/level_zero/core/source/driver/driver_handle_imp.h index 87d04da503..82b9347474 100644 --- a/level_zero/core/source/driver/driver_handle_imp.h +++ b/level_zero/core/source/driver/driver_handle_imp.h @@ -43,8 +43,8 @@ struct DriverHandleImp : public DriverHandle { NEO::MemoryManager *getMemoryManager() override; void setMemoryManager(NEO::MemoryManager *memoryManager) override; - MOCKABLE_VIRTUAL void *importFdHandle(NEO::Device *neoDevice, ze_ipc_memory_flags_t flags, uint64_t handle, NEO::AllocationType allocationType, NEO::GraphicsAllocation **pAlloc); - MOCKABLE_VIRTUAL void *importFdHandles(NEO::Device *neoDevice, ze_ipc_memory_flags_t flags, const std::vector &handles, NEO::GraphicsAllocation **pAlloc); + MOCKABLE_VIRTUAL void *importFdHandle(NEO::Device *neoDevice, ze_ipc_memory_flags_t flags, uint64_t handle, NEO::AllocationType allocationType, void *basePointer, NEO::GraphicsAllocation **pAlloc, NEO::SvmAllocationData &mappedPeerAllocData); + MOCKABLE_VIRTUAL void *importFdHandles(NEO::Device *neoDevice, ze_ipc_memory_flags_t flags, const std::vector &handles, void *basePointer, NEO::GraphicsAllocation **pAlloc, NEO::SvmAllocationData &mappedPeerAllocData); MOCKABLE_VIRTUAL void *importNTHandle(ze_device_handle_t hDevice, void *handle, NEO::AllocationType allocationType); ze_result_t checkMemoryAccessFromDevice(Device *device, const void *ptr) override; NEO::SVMAllocsManager *getSvmAllocsManager() override; @@ -75,7 +75,8 @@ struct DriverHandleImp : public DriverHandle { NEO::GraphicsAllocation *getPeerAllocation(Device *device, NEO::SvmAllocationData *allocData, void *basePtr, - uintptr_t *peerGpuAddress); + uintptr_t *peerGpuAddress, + NEO::SvmAllocationData **peerAllocData); void initializeVertexes(); ze_result_t fabricVertexGetExp(uint32_t *pCount, ze_fabric_vertex_handle_t *phDevices) override; void createHostPointerManager(); diff --git a/level_zero/core/source/event/event.cpp b/level_zero/core/source/event/event.cpp index b9916e1e80..41a3834332 100644 --- a/level_zero/core/source/event/event.cpp +++ b/level_zero/core/source/event/event.cpp @@ -289,7 +289,8 @@ ze_result_t EventPool::openEventPoolIpcHandle(const ze_ipc_event_pool_handle_t & unifiedMemoryProperties, false, eventPool->isHostVisibleEventPoolAllocation, - false); + false, + nullptr); if (alloc == nullptr) { return ZE_RESULT_ERROR_OUT_OF_DEVICE_MEMORY; diff --git a/level_zero/core/source/image/image_hw.inl b/level_zero/core/source/image/image_hw.inl index 175b8e7a7d..ea8b0ebae9 100644 --- a/level_zero/core/source/image/image_hw.inl +++ b/level_zero/core/source/image/image_hw.inl @@ -82,7 +82,7 @@ ze_result_t ImageCoreFamily::initialize(Device *device, const ze_ } if (lookupTable.sharedHandleType.isDMABUFHandle) { NEO::AllocationProperties properties(device->getRootDeviceIndex(), true, imgInfo, NEO::AllocationType::SHARED_IMAGE, device->getNEODevice()->getDeviceBitfield()); - allocation = device->getNEODevice()->getMemoryManager()->createGraphicsAllocationFromSharedHandle(lookupTable.sharedHandleType.fd, properties, false, false, true); + allocation = device->getNEODevice()->getMemoryManager()->createGraphicsAllocationFromSharedHandle(lookupTable.sharedHandleType.fd, properties, false, false, true, nullptr); device->getNEODevice()->getMemoryManager()->closeSharedHandle(allocation); } else if (lookupTable.sharedHandleType.isNTHandle) { auto verifyResult = device->getNEODevice()->getMemoryManager()->verifyHandle(NEO::toOsHandle(lookupTable.sharedHandleType.ntHnadle), device->getNEODevice()->getRootDeviceIndex(), true); diff --git a/level_zero/core/source/kernel/kernel.h b/level_zero/core/source/kernel/kernel.h index d93895e076..8f5059b8f2 100644 --- a/level_zero/core/source/kernel/kernel.h +++ b/level_zero/core/source/kernel/kernel.h @@ -10,6 +10,7 @@ #include "shared/source/kernel/dispatch_kernel_encoder_interface.h" #include "shared/source/kernel/kernel_descriptor.h" #include "shared/source/memory_manager/graphics_allocation.h" +#include "shared/source/memory_manager/unified_memory_manager.h" #include "shared/source/unified_memory/unified_memory.h" #include @@ -114,7 +115,7 @@ struct Kernel : _ze_kernel_handle_t, virtual NEO::DispatchKernelEncoderI { virtual ze_result_t setArgumentValue(uint32_t argIndex, size_t argSize, const void *pArgValue) = 0; virtual void setGroupCount(uint32_t groupCountX, uint32_t groupCountY, uint32_t groupCountZ) = 0; - virtual ze_result_t setArgBufferWithAlloc(uint32_t argIndex, uintptr_t argVal, NEO::GraphicsAllocation *allocation) = 0; + virtual ze_result_t setArgBufferWithAlloc(uint32_t argIndex, uintptr_t argVal, NEO::GraphicsAllocation *allocation, NEO::SvmAllocationData *peerAllocData) = 0; virtual ze_result_t setArgRedescribedImage(uint32_t argIndex, ze_image_handle_t argVal) = 0; virtual ze_result_t setGroupSize(uint32_t groupSizeX, uint32_t groupSizeY, uint32_t groupSizeZ) = 0; diff --git a/level_zero/core/source/kernel/kernel_imp.cpp b/level_zero/core/source/kernel/kernel_imp.cpp index 2689596207..b2e9d2c403 100644 --- a/level_zero/core/source/kernel/kernel_imp.cpp +++ b/level_zero/core/source/kernel/kernel_imp.cpp @@ -526,7 +526,7 @@ ze_result_t KernelImp::setArgRedescribedImage(uint32_t argIndex, ze_image_handle return ZE_RESULT_SUCCESS; } -ze_result_t KernelImp::setArgBufferWithAlloc(uint32_t argIndex, uintptr_t argVal, NEO::GraphicsAllocation *allocation) { +ze_result_t KernelImp::setArgBufferWithAlloc(uint32_t argIndex, uintptr_t argVal, NEO::GraphicsAllocation *allocation, NEO::SvmAllocationData *peerAllocData) { const auto &arg = kernelImmData->getDescriptor().payloadMappings.explicitArgs[argIndex].as(); const auto val = argVal; @@ -534,8 +534,12 @@ ze_result_t KernelImp::setArgBufferWithAlloc(uint32_t argIndex, uintptr_t argVal if (NEO::isValidOffset(arg.bindful) || NEO::isValidOffset(arg.bindless)) { setBufferSurfaceState(argIndex, reinterpret_cast(val), allocation); } - - auto allocData = this->module->getDevice()->getDriverHandle()->getSvmAllocsManager()->getSVMAlloc(reinterpret_cast(allocation->getGpuAddress())); + NEO::SvmAllocationData *allocData = nullptr; + if (peerAllocData) { + allocData = peerAllocData; + } else { + allocData = this->module->getDevice()->getDriverHandle()->getSvmAllocsManager()->getSVMAlloc(reinterpret_cast(allocation->getGpuAddress())); + } if (allocData) { bool argWasUncacheable = isArgUncached[argIndex]; bool argIsUncacheable = allocData->allocationFlagsProperty.flags.locallyUncachedResource; @@ -546,7 +550,6 @@ ze_result_t KernelImp::setArgBufferWithAlloc(uint32_t argIndex, uintptr_t argVal } this->setKernelArgUncached(argIndex, argIsUncacheable); } - residencyContainer[argIndex] = allocation; return ZE_RESULT_SUCCESS; @@ -633,6 +636,7 @@ ze_result_t KernelImp::setArgBuffer(uint32_t argIndex, size_t argSize, const voi if (allocData == nullptr) { allocData = svmAllocsManager->getSVMAlloc(requestedAddress); } + NEO::SvmAllocationData *peerAllocData = nullptr; if (driverHandle->isRemoteResourceNeeded(requestedAddress, alloc, allocData, device)) { if (allocData == nullptr) { return ZE_RESULT_ERROR_INVALID_ARGUMENT; @@ -640,18 +644,16 @@ ze_result_t KernelImp::setArgBuffer(uint32_t argIndex, size_t argSize, const voi uint64_t pbase = allocData->gpuAllocations.getDefaultGraphicsAllocation()->getGpuAddress(); uint64_t offset = (uint64_t)requestedAddress - pbase; - - alloc = driverHandle->getPeerAllocation(device, allocData, reinterpret_cast(pbase), &gpuAddress); + alloc = driverHandle->getPeerAllocation(device, allocData, reinterpret_cast(pbase), &gpuAddress, &peerAllocData); if (alloc == nullptr) { return ZE_RESULT_ERROR_INVALID_ARGUMENT; } gpuAddress += offset; } - const uint32_t allocId = allocData ? allocData->getAllocId() : 0u; kernelArgInfos[argIndex] = KernelArgInfo{requestedAddress, allocId, allocationsCounter, false}; - return setArgBufferWithAlloc(argIndex, gpuAddress, alloc); + return setArgBufferWithAlloc(argIndex, gpuAddress, alloc, peerAllocData); } ze_result_t KernelImp::setArgImage(uint32_t argIndex, size_t argSize, const void *argVal) { diff --git a/level_zero/core/source/kernel/kernel_imp.h b/level_zero/core/source/kernel/kernel_imp.h index 6a6752c90a..1a9b2bf38c 100644 --- a/level_zero/core/source/kernel/kernel_imp.h +++ b/level_zero/core/source/kernel/kernel_imp.h @@ -9,6 +9,7 @@ #include "shared/source/command_stream/thread_arbitration_policy.h" #include "shared/source/kernel/dispatch_kernel_encoder_interface.h" +#include "shared/source/memory_manager/unified_memory_manager.h" #include "shared/source/unified_memory/unified_memory.h" #include "level_zero/core/source/kernel/kernel.h" @@ -77,7 +78,7 @@ struct KernelImp : Kernel { ze_result_t setArgRedescribedImage(uint32_t argIndex, ze_image_handle_t argVal) override; - ze_result_t setArgBufferWithAlloc(uint32_t argIndex, uintptr_t argVal, NEO::GraphicsAllocation *allocation) override; + ze_result_t setArgBufferWithAlloc(uint32_t argIndex, uintptr_t argVal, NEO::GraphicsAllocation *allocation, NEO::SvmAllocationData *peerAllocData) override; ze_result_t setArgImage(uint32_t argIndex, size_t argSize, const void *argVal); diff --git a/level_zero/core/test/unit_tests/fixtures/device_fixture.h b/level_zero/core/test/unit_tests/fixtures/device_fixture.h index cf040e63e0..c5cac7e697 100644 --- a/level_zero/core/test/unit_tests/fixtures/device_fixture.h +++ b/level_zero/core/test/unit_tests/fixtures/device_fixture.h @@ -52,7 +52,7 @@ struct DeviceFixture { }; struct DriverHandleGetMemHandlePtrMock : public L0::DriverHandleImp { - void *importFdHandle(NEO::Device *neoDevice, ze_ipc_memory_flags_t flags, uint64_t handle, NEO::AllocationType allocationType, NEO::GraphicsAllocation **pAloc) override { + void *importFdHandle(NEO::Device *neoDevice, ze_ipc_memory_flags_t flags, uint64_t handle, NEO::AllocationType allocationType, void *basePointer, NEO::GraphicsAllocation **pAloc, NEO::SvmAllocationData &mappedPeerAllocData) override { if (failHandleLookup) { return nullptr; } diff --git a/level_zero/core/test/unit_tests/fixtures/memory_ipc_fixture.h b/level_zero/core/test/unit_tests/fixtures/memory_ipc_fixture.h index d887fa6166..3c639df02f 100644 --- a/level_zero/core/test/unit_tests/fixtures/memory_ipc_fixture.h +++ b/level_zero/core/test/unit_tests/fixtures/memory_ipc_fixture.h @@ -25,7 +25,7 @@ namespace L0 { namespace ult { struct DriverHandleGetFdMock : public L0::DriverHandleImp { - void *importFdHandle(NEO::Device *neoDevice, ze_ipc_memory_flags_t flags, uint64_t handle, NEO::AllocationType allocationType, NEO::GraphicsAllocation **pAloc) override { + void *importFdHandle(NEO::Device *neoDevice, ze_ipc_memory_flags_t flags, uint64_t handle, NEO::AllocationType allocationType, void *basePointer, NEO::GraphicsAllocation **pAloc, NEO::SvmAllocationData &mappedPeerAllocData) override { this->allocationTypeRequested = allocationType; if (mockFd == allocationMap.second) { return allocationMap.first; @@ -144,7 +144,7 @@ struct DriverHandleGetMemHandleMock : public L0::DriverHandleImp { } return nullptr; } - void *importFdHandle(NEO::Device *neoDevice, ze_ipc_memory_flags_t flags, uint64_t handle, NEO::AllocationType allocationType, NEO::GraphicsAllocation **pAloc) override { + void *importFdHandle(NEO::Device *neoDevice, ze_ipc_memory_flags_t flags, uint64_t handle, NEO::AllocationType allocationType, void *basePointer, NEO::GraphicsAllocation **pAloc, NEO::SvmAllocationData &mappedPeerAllocData) override { if (mockFd == allocationFdMap.second) { return allocationFdMap.first; } @@ -346,7 +346,7 @@ struct MemoryExportImportWinHandleTest : public ::testing::Test { }; struct DriverHandleGetIpcHandleMock : public DriverHandleImp { - void *importFdHandle(NEO::Device *neoDevice, ze_ipc_memory_flags_t flags, uint64_t handle, NEO::AllocationType allocationType, NEO::GraphicsAllocation **pAlloc) override { + void *importFdHandle(NEO::Device *neoDevice, ze_ipc_memory_flags_t flags, uint64_t handle, NEO::AllocationType allocationType, void *basePointer, NEO::GraphicsAllocation **pAlloc, NEO::SvmAllocationData &mappedPeerAllocData) override { EXPECT_EQ(handle, static_cast(mockFd)); if (mockFd == allocationMap.second) { return allocationMap.first; @@ -396,8 +396,8 @@ struct ContextGetIpcHandleMock : public L0::ContextImp { class MemoryManagerIpcMock : public NEO::MemoryManager { public: MemoryManagerIpcMock(NEO::ExecutionEnvironment &executionEnvironment) : NEO::MemoryManager(executionEnvironment) {} - NEO::GraphicsAllocation *createGraphicsAllocationFromMultipleSharedHandles(const std::vector &handles, AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation) override { return nullptr; } - NEO::GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation) override { return nullptr; } + NEO::GraphicsAllocation *createGraphicsAllocationFromMultipleSharedHandles(const std::vector &handles, AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation, void *mapPointer) override { return nullptr; } + NEO::GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation, void *mapPointer) override { return nullptr; } void addAllocationToHostPtrManager(NEO::GraphicsAllocation *memory) override{}; void removeAllocationFromHostPtrManager(NEO::GraphicsAllocation *memory) override{}; NEO::GraphicsAllocation *createGraphicsAllocationFromNTHandle(void *handle, uint32_t rootDeviceIndex, AllocationType allocType) override { return nullptr; }; @@ -489,7 +489,7 @@ class MemoryManagerOpenIpcMock : public MemoryManagerIpcMock { return alloc; } - NEO::GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation) override { + NEO::GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation, void *mapPointer) override { if (failOnCreateGraphicsAllocationFromSharedHandle) { return nullptr; } @@ -507,7 +507,7 @@ class MemoryManagerOpenIpcMock : public MemoryManagerIpcMock { alloc->setGpuBaseAddress(0xabcd); return alloc; } - NEO::GraphicsAllocation *createGraphicsAllocationFromMultipleSharedHandles(const std::vector &handles, AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation) override { + NEO::GraphicsAllocation *createGraphicsAllocationFromMultipleSharedHandles(const std::vector &handles, AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation, void *mapPointer) override { if (failOnCreateGraphicsAllocationFromSharedHandle) { return nullptr; } @@ -617,7 +617,7 @@ class MemoryManagerIpcImplicitScalingMock : public NEO::MemoryManager { public: MemoryManagerIpcImplicitScalingMock(NEO::ExecutionEnvironment &executionEnvironment) : NEO::MemoryManager(executionEnvironment) {} - NEO::GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation) override { return nullptr; } + NEO::GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation, void *mapPointer) override { return nullptr; } void addAllocationToHostPtrManager(NEO::GraphicsAllocation *memory) override{}; void removeAllocationFromHostPtrManager(NEO::GraphicsAllocation *memory) override{}; NEO::GraphicsAllocation *createGraphicsAllocationFromNTHandle(void *handle, uint32_t rootDeviceIndex, AllocationType allocType) override { return nullptr; }; @@ -682,7 +682,7 @@ class MemoryManagerIpcImplicitScalingMock : public NEO::MemoryManager { return alloc; } - NEO::GraphicsAllocation *createGraphicsAllocationFromMultipleSharedHandles(const std::vector &handles, AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation) override { + NEO::GraphicsAllocation *createGraphicsAllocationFromMultipleSharedHandles(const std::vector &handles, AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation, void *mapPointer) override { if (failOnCreateGraphicsAllocationFromSharedHandle) { return nullptr; } diff --git a/level_zero/core/test/unit_tests/mocks/mock_kernel.h b/level_zero/core/test/unit_tests/mocks/mock_kernel.h index 5931683e09..811d54c90c 100644 --- a/level_zero/core/test/unit_tests/mocks/mock_kernel.h +++ b/level_zero/core/test/unit_tests/mocks/mock_kernel.h @@ -118,7 +118,7 @@ struct Mock<::L0::Kernel> : public WhiteBox<::L0::Kernel> { void setBufferSurfaceState(uint32_t argIndex, void *address, NEO::GraphicsAllocation *alloc) override {} void evaluateIfRequiresGenerationOfLocalIdsByRuntime(const NEO::KernelDescriptor &kernelDescriptor) override {} - ze_result_t setArgBufferWithAlloc(uint32_t argIndex, uintptr_t argVal, NEO::GraphicsAllocation *allocation) override { + ze_result_t setArgBufferWithAlloc(uint32_t argIndex, uintptr_t argVal, NEO::GraphicsAllocation *allocation, NEO::SvmAllocationData *peerAllocData) override { return ZE_RESULT_SUCCESS; } diff --git a/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_5.cpp b/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_5.cpp index b4d56d5a29..1876a98aa7 100644 --- a/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_5.cpp +++ b/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_5.cpp @@ -461,7 +461,7 @@ HWTEST2_F(AppendQueryKernelTimestamps, givenEventWhenAppendQueryIsCalledThenSetA this->kernelImmData = &mockKernelImmutableData; } - ze_result_t setArgBufferWithAlloc(uint32_t argIndex, uintptr_t argVal, NEO::GraphicsAllocation *allocation) override { + ze_result_t setArgBufferWithAlloc(uint32_t argIndex, uintptr_t argVal, NEO::GraphicsAllocation *allocation, NEO::SvmAllocationData *peerAllocData) override { if (argIndex == 0) { index0Allocation = allocation; } diff --git a/level_zero/core/test/unit_tests/sources/context/test_context.cpp b/level_zero/core/test/unit_tests/sources/context/test_context.cpp index b4042d4ecf..d70740be3d 100644 --- a/level_zero/core/test/unit_tests/sources/context/test_context.cpp +++ b/level_zero/core/test/unit_tests/sources/context/test_context.cpp @@ -167,7 +167,7 @@ TEST_F(MultiDeviceContextTests, uintptr_t peerGpuAddress = 0u; auto allocData = driverHandle->getSvmAllocsManager()->getSVMAlloc(ptr); EXPECT_NE(allocData, nullptr); - auto peerAlloc = driverHandle->getPeerAllocation(driverHandle->devices[1], allocData, ptr, &peerGpuAddress); + auto peerAlloc = driverHandle->getPeerAllocation(driverHandle->devices[1], allocData, ptr, &peerGpuAddress, nullptr); EXPECT_NE(peerAlloc, nullptr); DeviceImp *deviceImp1 = static_cast(driverHandle->devices[1]); @@ -1318,8 +1318,8 @@ TEST_F(ContextTest, whenCallingVirtualMemoryReservationWithInvalidArgumentsThenF class ReserveMemoryManagerMock : public NEO::MemoryManager { public: ReserveMemoryManagerMock(NEO::ExecutionEnvironment &executionEnvironment) : NEO::MemoryManager(executionEnvironment) {} - NEO::GraphicsAllocation *createGraphicsAllocationFromMultipleSharedHandles(const std::vector &handles, AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation) override { return nullptr; } - NEO::GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation) override { return nullptr; } + NEO::GraphicsAllocation *createGraphicsAllocationFromMultipleSharedHandles(const std::vector &handles, AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation, void *mapPointer) override { return nullptr; } + NEO::GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation, void *mapPointer) override { return nullptr; } void addAllocationToHostPtrManager(NEO::GraphicsAllocation *memory) override{}; void removeAllocationFromHostPtrManager(NEO::GraphicsAllocation *memory) override{}; NEO::GraphicsAllocation *createGraphicsAllocationFromNTHandle(void *handle, uint32_t rootDeviceIndex, AllocationType allocType) override { return nullptr; }; diff --git a/level_zero/core/test/unit_tests/sources/driver/test_driver.cpp b/level_zero/core/test/unit_tests/sources/driver/test_driver.cpp index 5a61a553b7..83ee4314d3 100644 --- a/level_zero/core/test/unit_tests/sources/driver/test_driver.cpp +++ b/level_zero/core/test/unit_tests/sources/driver/test_driver.cpp @@ -262,7 +262,7 @@ HWTEST_F(ImportNTHandle, whenCallingCreateGraphicsAllocationFromMultipleSharedHa device->getNEODevice()->getDeviceBitfield()}; bool requireSpecificBitness{}; bool isHostIpcAllocation{}; - auto ptr = execEnv->memoryManager->createGraphicsAllocationFromMultipleSharedHandles(handles, properties, requireSpecificBitness, isHostIpcAllocation, true); + auto ptr = execEnv->memoryManager->createGraphicsAllocationFromMultipleSharedHandles(handles, properties, requireSpecificBitness, isHostIpcAllocation, true, nullptr); EXPECT_EQ(nullptr, ptr); } diff --git a/level_zero/core/test/unit_tests/sources/event/test_event.cpp b/level_zero/core/test/unit_tests/sources/event/test_event.cpp index f6246cd83c..1a15bfce97 100644 --- a/level_zero/core/test/unit_tests/sources/event/test_event.cpp +++ b/level_zero/core/test/unit_tests/sources/event/test_event.cpp @@ -61,8 +61,8 @@ class MemoryManagerEventPoolFailMock : public NEO::MemoryManager { void *createMultiGraphicsAllocationInSystemMemoryPool(RootDeviceIndicesContainer &rootDeviceIndices, AllocationProperties &properties, NEO::MultiGraphicsAllocation &multiGraphicsAllocation) override { return nullptr; }; - GraphicsAllocation *createGraphicsAllocationFromMultipleSharedHandles(const std::vector &handles, AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation) override { return nullptr; } - NEO::GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation) override { return nullptr; } + GraphicsAllocation *createGraphicsAllocationFromMultipleSharedHandles(const std::vector &handles, AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation, void *mapPointer) override { return nullptr; } + NEO::GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation, void *mapPointer) override { return nullptr; } void addAllocationToHostPtrManager(NEO::GraphicsAllocation *memory) override{}; void removeAllocationFromHostPtrManager(NEO::GraphicsAllocation *memory) override{}; NEO::GraphicsAllocation *createGraphicsAllocationFromNTHandle(void *handle, uint32_t rootDeviceIndex, AllocationType allocType) override { return nullptr; }; @@ -321,9 +321,9 @@ class MemoryManagerEventPoolIpcMock : public NEO::MockMemoryManager { multiGraphicsAllocation.addAllocation(alloc); return reinterpret_cast(alloc->getUnderlyingBuffer()); } - GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation) override { + GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation, void *mapPointer) override { if (callParentCreateGraphicsAllocationFromSharedHandle) { - return NEO::MockMemoryManager::createGraphicsAllocationFromSharedHandle(handle, properties, requireSpecificBitness, isHostIpcAllocation, reuseSharedAllocation); + return NEO::MockMemoryManager::createGraphicsAllocationFromSharedHandle(handle, properties, requireSpecificBitness, isHostIpcAllocation, reuseSharedAllocation, mapPointer); } alloc = new EventPoolIpcMockGraphicsAllocation(&buffer, sizeof(buffer)); alloc->isShareableHostMemory = true; @@ -898,7 +898,7 @@ class MultiDeviceEventPoolOpenIpcHandleMemoryManager : public FailMemoryManager public: MultiDeviceEventPoolOpenIpcHandleMemoryManager(NEO::ExecutionEnvironment &executionEnvironment) : FailMemoryManager(executionEnvironment) {} - GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation) override { + GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation, void *mapPointer) override { return &mockAllocation0; } diff --git a/level_zero/core/test/unit_tests/sources/kernel/test_kernel.cpp b/level_zero/core/test/unit_tests/sources/kernel/test_kernel.cpp index 9a2158b322..7ecfa4a6e7 100644 --- a/level_zero/core/test/unit_tests/sources/kernel/test_kernel.cpp +++ b/level_zero/core/test/unit_tests/sources/kernel/test_kernel.cpp @@ -166,9 +166,9 @@ TEST(KernelArgTest, givenKernelWhenSetArgUnknownCalledThenSuccessRteurned) { struct MockKernelWithCallTracking : Mock<::L0::Kernel> { using ::L0::KernelImp::kernelArgInfos; - ze_result_t setArgBufferWithAlloc(uint32_t argIndex, uintptr_t argVal, NEO::GraphicsAllocation *allocation) override { + ze_result_t setArgBufferWithAlloc(uint32_t argIndex, uintptr_t argVal, NEO::GraphicsAllocation *allocation, NEO::SvmAllocationData *peerAllocData) override { ++setArgBufferWithAllocCalled; - return KernelImp::setArgBufferWithAlloc(argIndex, argVal, allocation); + return KernelImp::setArgBufferWithAlloc(argIndex, argVal, allocation, peerAllocData); } size_t setArgBufferWithAllocCalled = 0u; @@ -2126,8 +2126,8 @@ struct MyMockKernel : public Mock { void setBufferSurfaceState(uint32_t argIndex, void *address, NEO::GraphicsAllocation *alloc) override { setSurfaceStateCalled = true; } - ze_result_t setArgBufferWithAlloc(uint32_t argIndex, uintptr_t argVal, NEO::GraphicsAllocation *allocation) override { - return KernelImp::setArgBufferWithAlloc(argIndex, argVal, allocation); + ze_result_t setArgBufferWithAlloc(uint32_t argIndex, uintptr_t argVal, NEO::GraphicsAllocation *allocation, NEO::SvmAllocationData *peerAllocData) override { + return KernelImp::setArgBufferWithAlloc(argIndex, argVal, allocation, peerAllocData); } bool setSurfaceStateCalled = false; }; @@ -2146,7 +2146,7 @@ TEST_F(KernelImpPatchBindlessTest, GivenValidBindlessOffsetWhenSetArgBufferWithA NEO::MockGraphicsAllocation alloc; - mockKernel.setArgBufferWithAlloc(0, 0x1234, &alloc); + mockKernel.setArgBufferWithAlloc(0, 0x1234, &alloc, nullptr); EXPECT_TRUE(mockKernel.setSurfaceStateCalled); } @@ -2165,7 +2165,7 @@ TEST_F(KernelImpPatchBindlessTest, GivenValidBindfulOffsetWhenSetArgBufferWithAl NEO::MockGraphicsAllocation alloc; - mockKernel.setArgBufferWithAlloc(0, 0x1234, &alloc); + mockKernel.setArgBufferWithAlloc(0, 0x1234, &alloc, nullptr); EXPECT_TRUE(mockKernel.setSurfaceStateCalled); } @@ -2184,7 +2184,7 @@ TEST_F(KernelImpPatchBindlessTest, GivenUndefiedBidfulAndBindlesstOffsetWhenSetA NEO::MockGraphicsAllocation alloc; - mockKernel.setArgBufferWithAlloc(0, 0x1234, &alloc); + mockKernel.setArgBufferWithAlloc(0, 0x1234, &alloc, nullptr); EXPECT_FALSE(mockKernel.setSurfaceStateCalled); } @@ -2205,7 +2205,7 @@ TEST_F(KernelBindlessUncachedMemoryTests, givenBindlessKernelAndAllocDataNoTfoun NEO::MockGraphicsAllocation alloc; - mockKernel.setArgBufferWithAlloc(0, 0x1234, &alloc); + mockKernel.setArgBufferWithAlloc(0, 0x1234, &alloc, nullptr); EXPECT_FALSE(mockKernel.getKernelRequiresUncachedMocs()); } @@ -2235,7 +2235,7 @@ TEST_F(KernelBindlessUncachedMemoryTests, auto alloc = device->getDriverHandle()->getSvmAllocsManager()->getSVMAllocs()->get(devicePtr)->gpuAllocations.getGraphicsAllocation(device->getRootDeviceIndex()); EXPECT_NE(nullptr, alloc); - mockKernel.setArgBufferWithAlloc(0, 0x1234, alloc); + mockKernel.setArgBufferWithAlloc(0, 0x1234, alloc, nullptr); EXPECT_FALSE(mockKernel.getKernelRequiresUncachedMocs()); context->freeMem(devicePtr); } @@ -2253,7 +2253,7 @@ TEST_F(KernelBindlessUncachedMemoryTests, auto alloc = device->getDriverHandle()->getSvmAllocsManager()->getSVMAllocs()->get(devicePtr)->gpuAllocations.getGraphicsAllocation(device->getRootDeviceIndex()); EXPECT_NE(nullptr, alloc); - mockKernel.setArgBufferWithAlloc(0, 0x1234, alloc); + mockKernel.setArgBufferWithAlloc(0, 0x1234, alloc, nullptr); EXPECT_FALSE(mockKernel.getKernelRequiresUncachedMocs()); context->freeMem(devicePtr); } @@ -2286,7 +2286,7 @@ TEST_F(KernelBindlessUncachedMemoryTests, auto alloc = device->getDriverHandle()->getSvmAllocsManager()->getSVMAllocs()->get(devicePtr)->gpuAllocations.getGraphicsAllocation(device->getRootDeviceIndex()); EXPECT_NE(nullptr, alloc); - mockKernel.setArgBufferWithAlloc(0, 0x1234, alloc); + mockKernel.setArgBufferWithAlloc(0, 0x1234, alloc, nullptr); EXPECT_TRUE(mockKernel.getKernelRequiresUncachedMocs()); context->freeMem(devicePtr); } @@ -2305,7 +2305,7 @@ TEST_F(KernelBindlessUncachedMemoryTests, auto alloc = device->getDriverHandle()->getSvmAllocsManager()->getSVMAllocs()->get(devicePtr)->gpuAllocations.getGraphicsAllocation(device->getRootDeviceIndex()); EXPECT_NE(nullptr, alloc); - mockKernel.setArgBufferWithAlloc(0, 0x1234, alloc); + mockKernel.setArgBufferWithAlloc(0, 0x1234, alloc, nullptr); EXPECT_TRUE(mockKernel.getKernelRequiresUncachedMocs()); context->freeMem(devicePtr); } @@ -2338,7 +2338,7 @@ TEST_F(KernelBindlessUncachedMemoryTests, auto alloc = device->getDriverHandle()->getSvmAllocsManager()->getSVMAllocs()->get(devicePtr)->gpuAllocations.getGraphicsAllocation(device->getRootDeviceIndex()); EXPECT_NE(nullptr, alloc); - mockKernel.setArgBufferWithAlloc(0, 0x1234, alloc); + mockKernel.setArgBufferWithAlloc(0, 0x1234, alloc, nullptr); EXPECT_TRUE(mockKernel.getKernelRequiresUncachedMocs()); context->freeMem(devicePtr); } @@ -2356,7 +2356,7 @@ TEST_F(KernelBindlessUncachedMemoryTests, auto alloc = device->getDriverHandle()->getSvmAllocsManager()->getSVMAllocs()->get(devicePtr)->gpuAllocations.getGraphicsAllocation(device->getRootDeviceIndex()); EXPECT_NE(nullptr, alloc); - mockKernel.setArgBufferWithAlloc(0, 0x1234, alloc); + mockKernel.setArgBufferWithAlloc(0, 0x1234, alloc, nullptr); EXPECT_FALSE(mockKernel.getKernelRequiresUncachedMocs()); context->freeMem(devicePtr); } @@ -2388,7 +2388,7 @@ TEST_F(KernelBindlessUncachedMemoryTests, auto alloc = device->getDriverHandle()->getSvmAllocsManager()->getSVMAllocs()->get(ptr)->gpuAllocations.getGraphicsAllocation(device->getRootDeviceIndex()); EXPECT_NE(nullptr, alloc); - mockKernel.setArgBufferWithAlloc(0, 0x1234, alloc); + mockKernel.setArgBufferWithAlloc(0, 0x1234, alloc, nullptr); EXPECT_TRUE(mockKernel.getKernelRequiresUncachedMocs()); context->freeMem(ptr); } @@ -2405,7 +2405,7 @@ TEST_F(KernelBindlessUncachedMemoryTests, auto alloc = device->getDriverHandle()->getSvmAllocsManager()->getSVMAllocs()->get(ptr)->gpuAllocations.getGraphicsAllocation(device->getRootDeviceIndex()); EXPECT_NE(nullptr, alloc); - mockKernel.setArgBufferWithAlloc(0, 0x1234, alloc); + mockKernel.setArgBufferWithAlloc(0, 0x1234, alloc, nullptr); EXPECT_FALSE(mockKernel.getKernelRequiresUncachedMocs()); context->freeMem(ptr); } diff --git a/level_zero/core/test/unit_tests/sources/memory/linux/test_memory_linux.cpp b/level_zero/core/test/unit_tests/sources/memory/linux/test_memory_linux.cpp index 98c81e7741..2ccd0e20b5 100644 --- a/level_zero/core/test/unit_tests/sources/memory/linux/test_memory_linux.cpp +++ b/level_zero/core/test/unit_tests/sources/memory/linux/test_memory_linux.cpp @@ -60,7 +60,7 @@ class MemoryManagerIpcImplicitScalingObtainFdMock : public NEO::DrmMemoryManager public: MemoryManagerIpcImplicitScalingObtainFdMock(NEO::ExecutionEnvironment &executionEnvironment) : NEO::DrmMemoryManager(gemCloseWorkerMode::gemCloseWorkerInactive, false, false, executionEnvironment) {} - NEO::GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation) override { return nullptr; } + NEO::GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation, void *mapPointer) override { return nullptr; } void addAllocationToHostPtrManager(NEO::GraphicsAllocation *memory) override{}; void removeAllocationFromHostPtrManager(NEO::GraphicsAllocation *memory) override{}; NEO::GraphicsAllocation *createGraphicsAllocationFromNTHandle(void *handle, uint32_t rootDeviceIndex, AllocationType allocType) override { return nullptr; }; @@ -113,7 +113,8 @@ class MemoryManagerIpcImplicitScalingObtainFdMock : public NEO::DrmMemoryManager AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, - bool reuseSharedAllocation) override { + bool reuseSharedAllocation, + void *mapPointer) override { if (failOnCreateGraphicsAllocationFromSharedHandle) { return nullptr; } @@ -400,7 +401,7 @@ TEST_F(MemoryExportImportObtainFdTest, auto allocData = context->getDriverHandle()->getSvmAllocsManager()->getSVMAlloc(ptr); EXPECT_NE(allocData, nullptr); currMemoryManager->failOnObtainFdFromHandle = false; - auto peerAlloc = driverHandle->getPeerAllocation(device1, allocData, ptr, &peerGpuAddress); + auto peerAlloc = driverHandle->getPeerAllocation(device1, allocData, ptr, &peerGpuAddress, nullptr); EXPECT_NE(peerAlloc, nullptr); result = context->freeMem(ptr); @@ -426,7 +427,7 @@ TEST_F(MemoryExportImportObtainFdTest, auto allocData = context->getDriverHandle()->getSvmAllocsManager()->getSVMAlloc(ptr); EXPECT_NE(allocData, nullptr); currMemoryManager->failOnObtainFdFromHandle = true; - auto peerAlloc = driverHandle->getPeerAllocation(device1, allocData, ptr, &peerGpuAddress); + auto peerAlloc = driverHandle->getPeerAllocation(device1, allocData, ptr, &peerGpuAddress, nullptr); EXPECT_EQ(peerAlloc, nullptr); result = context->freeMem(ptr); @@ -468,7 +469,7 @@ class MemoryManagerIpcObtainFdMock : public NEO::DrmMemoryManager { public: MemoryManagerIpcObtainFdMock(NEO::ExecutionEnvironment &executionEnvironment) : NEO::DrmMemoryManager(gemCloseWorkerMode::gemCloseWorkerInactive, false, false, executionEnvironment) {} - NEO::GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation) override { return nullptr; } + NEO::GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation, void *mapPointer) override { return nullptr; } void addAllocationToHostPtrManager(NEO::GraphicsAllocation *memory) override{}; void removeAllocationFromHostPtrManager(NEO::GraphicsAllocation *memory) override{}; NEO::GraphicsAllocation *createGraphicsAllocationFromNTHandle(void *handle, uint32_t rootDeviceIndex, AllocationType allocType) override { return nullptr; }; @@ -521,7 +522,8 @@ class MemoryManagerIpcObtainFdMock : public NEO::DrmMemoryManager { AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, - bool reuseSharedAllocation) override { + bool reuseSharedAllocation, + void *mapPointer) override { if (failOnCreateGraphicsAllocationFromSharedHandle) { return nullptr; } @@ -562,7 +564,7 @@ class MemoryManagerIpcObtainFdMock : public NEO::DrmMemoryManager { }; struct DriverHandleObtaindFdMock : public L0::DriverHandleImp { - void *importFdHandle(NEO::Device *neoDevice, ze_ipc_memory_flags_t flags, uint64_t handle, NEO::AllocationType allocationType, NEO::GraphicsAllocation **pAloc) override { + void *importFdHandle(NEO::Device *neoDevice, ze_ipc_memory_flags_t flags, uint64_t handle, NEO::AllocationType allocationType, void *basePointer, NEO::GraphicsAllocation **pAloc, NEO::SvmAllocationData &mappedPeerAllocData) override { DeviceBitfield deviceBitfield{0x0}; AllocationProperties properties(0, MemoryConstants::pageSize, AllocationType::BUFFER, @@ -657,7 +659,7 @@ TEST_F(MemoryObtainFdTest, auto allocData = context->getDriverHandle()->getSvmAllocsManager()->getSVMAlloc(ptr); EXPECT_NE(allocData, nullptr); currMemoryManager->failOnObtainFdFromHandle = true; - auto peerAlloc = driverHandle->getPeerAllocation(device1, allocData, ptr, &peerGpuAddress); + auto peerAlloc = driverHandle->getPeerAllocation(device1, allocData, ptr, &peerGpuAddress, nullptr); EXPECT_EQ(peerAlloc, nullptr); result = context->freeMem(ptr); diff --git a/level_zero/core/test/unit_tests/sources/memory/test_memory.cpp b/level_zero/core/test/unit_tests/sources/memory/test_memory.cpp index 1c9660fde8..771f21e766 100644 --- a/level_zero/core/test/unit_tests/sources/memory/test_memory.cpp +++ b/level_zero/core/test/unit_tests/sources/memory/test_memory.cpp @@ -292,7 +292,8 @@ TEST_F(MemoryExportImportImplicitScalingTest, void *ipcPtr; NEO::GraphicsAllocation *ipcAlloc = nullptr; DriverHandleImp *driverHandleImp = static_cast(context->getDriverHandle()); - ipcPtr = driverHandleImp->importFdHandles(device->getNEODevice(), flags, handles, &ipcAlloc); + NEO::SvmAllocationData allocDataInternal(device->getNEODevice()->getRootDeviceIndex()); + ipcPtr = driverHandleImp->importFdHandles(device->getNEODevice(), flags, handles, nullptr, &ipcAlloc, allocDataInternal); EXPECT_NE(ipcPtr, nullptr); EXPECT_NE(ipcAlloc, nullptr); @@ -342,7 +343,8 @@ TEST_F(MemoryExportImportImplicitScalingTest, void *ipcPtr; NEO::GraphicsAllocation *ipcAlloc = nullptr; DriverHandleImp *driverHandleImp = static_cast(context->getDriverHandle()); - ipcPtr = driverHandleImp->importFdHandles(device->getNEODevice(), flags, handles, &ipcAlloc); + NEO::SvmAllocationData allocDataInternal(device->getNEODevice()->getRootDeviceIndex()); + ipcPtr = driverHandleImp->importFdHandles(device->getNEODevice(), flags, handles, nullptr, &ipcAlloc, allocDataInternal); EXPECT_NE(ipcPtr, nullptr); EXPECT_NE(ipcAlloc, nullptr); @@ -417,7 +419,8 @@ TEST_F(MemoryExportImportImplicitScalingTest, ze_ipc_memory_flags_t flags = {}; NEO::GraphicsAllocation *ipcAlloc = nullptr; DriverHandleImp *driverHandleImp = static_cast(context->getDriverHandle()); - void *ipcPtr = driverHandleImp->importFdHandle(device->getNEODevice(), flags, handle, NEO::AllocationType::BUFFER, &ipcAlloc); + NEO::SvmAllocationData allocDataInternal(device->getNEODevice()->getRootDeviceIndex()); + void *ipcPtr = driverHandleImp->importFdHandle(device->getNEODevice(), flags, handle, NEO::AllocationType::BUFFER, nullptr, &ipcAlloc, allocDataInternal); EXPECT_EQ(ipcPtr, nullptr); result = context->freeMem(ptr); @@ -2314,7 +2317,7 @@ TEST_F(ContextMemoryTests, givenMultipleSubDevicesWhenAllocatingThenUseCorrectGl } struct DriverHandleFailGetFdMock : public L0::DriverHandleImp { - void *importFdHandle(NEO::Device *neoDevicee, ze_ipc_memory_flags_t flags, uint64_t handle, NEO::AllocationType allocationType, NEO::GraphicsAllocation **pAloc) override { + void *importFdHandle(NEO::Device *neoDevicee, ze_ipc_memory_flags_t flags, uint64_t handle, NEO::AllocationType allocationType, void *basePointer, NEO::GraphicsAllocation **pAloc, NEO::SvmAllocationData &mappedPeerAllocData) override { importFdHandleCalledTimes++; if (mockFd == allocationMap.second) { return allocationMap.first; @@ -3118,7 +3121,7 @@ TEST_F(MultipleDevicePeerAllocationFailTest, EXPECT_NE(allocData, nullptr); DriverHandleFailGetFdMock *driverHandleFailGetFdMock = static_cast(context->getDriverHandle()); - auto peerAlloc = driverHandle->getPeerAllocation(device1, allocData, ptr, &peerGpuAddress); + auto peerAlloc = driverHandle->getPeerAllocation(device1, allocData, ptr, &peerGpuAddress, nullptr); EXPECT_GT(driverHandleFailGetFdMock->importFdHandleCalledTimes, 0u); EXPECT_EQ(peerAlloc, nullptr); @@ -3784,7 +3787,7 @@ TEST_F(MultipleDevicePeerAllocationTest, uintptr_t peerGpuAddress = 0u; auto allocData = context->getDriverHandle()->getSvmAllocsManager()->getSVMAlloc(ptr); EXPECT_NE(allocData, nullptr); - auto peerAlloc = driverHandle->getPeerAllocation(device1, allocData, ptr, &peerGpuAddress); + auto peerAlloc = driverHandle->getPeerAllocation(device1, allocData, ptr, &peerGpuAddress, nullptr); EXPECT_EQ(peerAlloc, nullptr); result = context->freeMem(ptr); @@ -3809,13 +3812,40 @@ TEST_F(MultipleDevicePeerAllocationTest, uintptr_t peerGpuAddress = 0u; auto allocData = context->getDriverHandle()->getSvmAllocsManager()->getSVMAlloc(ptr); EXPECT_NE(allocData, nullptr); - auto peerAlloc = driverHandle->getPeerAllocation(device1, allocData, ptr, &peerGpuAddress); + auto peerAlloc = driverHandle->getPeerAllocation(device1, allocData, ptr, &peerGpuAddress, nullptr); EXPECT_NE(peerAlloc, nullptr); result = context->freeMem(ptr); ASSERT_EQ(result, ZE_RESULT_SUCCESS); } +TEST_F(MultipleDevicePeerAllocationTest, + whenPeerAllocationForDeviceAllocationIsRequestedWithPeerAllocDataThenPeerAllocDataIsReturned) { + L0::Device *device0 = driverHandle->devices[0]; + L0::Device *device1 = driverHandle->devices[1]; + + size_t size = 1024; + size_t alignment = 1u; + void *ptr = nullptr; + ze_device_mem_alloc_desc_t deviceDesc = {}; + ze_result_t result = context->allocDeviceMem(device0->toHandle(), + &deviceDesc, + size, alignment, &ptr); + EXPECT_EQ(ZE_RESULT_SUCCESS, result); + EXPECT_NE(nullptr, ptr); + + uintptr_t peerGpuAddress = 0u; + auto allocData = context->getDriverHandle()->getSvmAllocsManager()->getSVMAlloc(ptr); + EXPECT_NE(allocData, nullptr); + NEO::SvmAllocationData *peerAllocData; + auto peerAlloc = driverHandle->getPeerAllocation(device1, allocData, ptr, &peerGpuAddress, &peerAllocData); + EXPECT_NE(peerAlloc, nullptr); + EXPECT_NE(peerAllocData, nullptr); + + result = context->freeMem(ptr); + ASSERT_EQ(result, ZE_RESULT_SUCCESS); +} + TEST_F(MultipleDevicePeerAllocationTest, whenPeerAllocationForDeviceAllocationIsRequestedThenPeerAllocationIsAddedToDeviceMapAndRemovedWhenAllocationIsFreed) { L0::Device *device0 = driverHandle->devices[0]; @@ -3834,7 +3864,7 @@ TEST_F(MultipleDevicePeerAllocationTest, uintptr_t peerGpuAddress = 0u; auto allocData = context->getDriverHandle()->getSvmAllocsManager()->getSVMAlloc(ptr); EXPECT_NE(allocData, nullptr); - auto peerAlloc = driverHandle->getPeerAllocation(device1, allocData, ptr, &peerGpuAddress); + auto peerAlloc = driverHandle->getPeerAllocation(device1, allocData, ptr, &peerGpuAddress, nullptr); EXPECT_NE(peerAlloc, nullptr); DeviceImp *deviceImp1 = static_cast(device1); @@ -3874,7 +3904,7 @@ TEST_F(MultipleDevicePeerAllocationTest, DeviceImp *deviceImp1 = static_cast(device1); EXPECT_EQ(0u, deviceImp1->peerAllocations.allocations.size()); - auto peerAlloc = driverHandle->getPeerAllocation(device1, allocData, ptr, &peerGpuAddress); + auto peerAlloc = driverHandle->getPeerAllocation(device1, allocData, ptr, &peerGpuAddress, nullptr); EXPECT_NE(peerAlloc, nullptr); EXPECT_EQ(1u, deviceImp1->peerAllocations.allocations.size()); @@ -3884,7 +3914,7 @@ TEST_F(MultipleDevicePeerAllocationTest, } uintptr_t peerGpuAddress2 = 0u; - peerAlloc = driverHandle->getPeerAllocation(device1, allocData, ptr, &peerGpuAddress2); + peerAlloc = driverHandle->getPeerAllocation(device1, allocData, ptr, &peerGpuAddress2, nullptr); EXPECT_NE(peerAlloc, nullptr); EXPECT_EQ(1u, deviceImp1->peerAllocations.allocations.size()); EXPECT_EQ(peerGpuAddress, peerGpuAddress2); @@ -3916,7 +3946,7 @@ TEST_F(MultipleDevicePeerAllocationTest, auto allocData = context->getDriverHandle()->getSvmAllocsManager()->getSVMAlloc(ptr); EXPECT_NE(allocData, nullptr); - auto peerAlloc = driverHandle->getPeerAllocation(device1, allocData, ptr, nullptr); + auto peerAlloc = driverHandle->getPeerAllocation(device1, allocData, ptr, nullptr, nullptr); EXPECT_NE(peerAlloc, nullptr); result = context->freeMem(ptr); @@ -3942,11 +3972,11 @@ TEST_F(MultipleDevicePeerAllocationTest, EXPECT_NE(allocData, nullptr); uintptr_t peerGpuAddress0 = 0u; - auto peerAlloc0 = driverHandle->getPeerAllocation(device1, allocData, ptr, &peerGpuAddress0); + auto peerAlloc0 = driverHandle->getPeerAllocation(device1, allocData, ptr, &peerGpuAddress0, nullptr); EXPECT_NE(peerAlloc0, nullptr); uintptr_t peerGpuAddress1 = 0u; - auto peerAlloc1 = driverHandle->getPeerAllocation(device1, allocData, ptr, &peerGpuAddress1); + auto peerAlloc1 = driverHandle->getPeerAllocation(device1, allocData, ptr, &peerGpuAddress1, nullptr); EXPECT_NE(peerAlloc1, nullptr); EXPECT_EQ(peerAlloc0, peerAlloc1); @@ -4681,7 +4711,8 @@ TEST_F(ImportFdUncachedTests, givenCallToImportFdHandleWithUncachedFlagsThenLocallyUncachedResourceIsSet) { ze_ipc_memory_flags_t flags = ZE_DEVICE_MEM_ALLOC_FLAG_BIAS_UNCACHED; uint64_t handle = 1; - void *ptr = driverHandle->importFdHandle(device->getNEODevice(), flags, handle, NEO::AllocationType::BUFFER, nullptr); + NEO::SvmAllocationData allocDataInternal(device->getNEODevice()->getRootDeviceIndex()); + void *ptr = driverHandle->importFdHandle(device->getNEODevice(), flags, handle, NEO::AllocationType::BUFFER, nullptr, nullptr, allocDataInternal); EXPECT_NE(nullptr, ptr); auto allocData = driverHandle->svmAllocsManager->getSVMAlloc(ptr); @@ -4694,7 +4725,8 @@ TEST_F(ImportFdUncachedTests, givenCallToImportFdHandleWithUncachedIpcFlagsThenLocallyUncachedResourceIsSet) { ze_ipc_memory_flags_t flags = ZE_IPC_MEMORY_FLAG_BIAS_UNCACHED; uint64_t handle = 1; - void *ptr = driverHandle->importFdHandle(device->getNEODevice(), flags, handle, NEO::AllocationType::BUFFER, nullptr); + NEO::SvmAllocationData allocDataInternal(device->getNEODevice()->getRootDeviceIndex()); + void *ptr = driverHandle->importFdHandle(device->getNEODevice(), flags, handle, NEO::AllocationType::BUFFER, nullptr, nullptr, allocDataInternal); EXPECT_NE(nullptr, ptr); auto allocData = driverHandle->svmAllocsManager->getSVMAlloc(ptr); @@ -4707,7 +4739,8 @@ TEST_F(ImportFdUncachedTests, givenCallToImportFdHandleWithBothUncachedFlagsThenLocallyUncachedResourceIsSet) { ze_ipc_memory_flags_t flags = ZE_DEVICE_MEM_ALLOC_FLAG_BIAS_UNCACHED | ZE_IPC_MEMORY_FLAG_BIAS_UNCACHED; uint64_t handle = 1; - void *ptr = driverHandle->importFdHandle(device->getNEODevice(), flags, handle, NEO::AllocationType::BUFFER, nullptr); + NEO::SvmAllocationData allocDataInternal(device->getNEODevice()->getRootDeviceIndex()); + void *ptr = driverHandle->importFdHandle(device->getNEODevice(), flags, handle, NEO::AllocationType::BUFFER, nullptr, nullptr, allocDataInternal); EXPECT_NE(nullptr, ptr); auto allocData = driverHandle->svmAllocsManager->getSVMAlloc(ptr); @@ -4720,7 +4753,8 @@ TEST_F(ImportFdUncachedTests, givenCallToImportFdHandleWithoutUncachedFlagsThenLocallyUncachedResourceIsNotSet) { ze_ipc_memory_flags_t flags = {}; uint64_t handle = 1; - void *ptr = driverHandle->importFdHandle(device->getNEODevice(), flags, handle, NEO::AllocationType::BUFFER, nullptr); + NEO::SvmAllocationData allocDataInternal(device->getNEODevice()->getRootDeviceIndex()); + void *ptr = driverHandle->importFdHandle(device->getNEODevice(), flags, handle, NEO::AllocationType::BUFFER, nullptr, nullptr, allocDataInternal); EXPECT_NE(nullptr, ptr); auto allocData = driverHandle->svmAllocsManager->getSVMAlloc(ptr); @@ -4733,7 +4767,8 @@ TEST_F(ImportFdUncachedTests, givenCallToImportFdHandleWithHostBufferMemoryAllocationTypeThenHostUnifiedMemoryIsSet) { ze_ipc_memory_flags_t flags = {}; uint64_t handle = 1; - void *ptr = driverHandle->importFdHandle(device->getNEODevice(), flags, handle, NEO::AllocationType::BUFFER_HOST_MEMORY, nullptr); + NEO::SvmAllocationData allocDataInternal(device->getNEODevice()->getRootDeviceIndex()); + void *ptr = driverHandle->importFdHandle(device->getNEODevice(), flags, handle, NEO::AllocationType::BUFFER_HOST_MEMORY, nullptr, nullptr, allocDataInternal); EXPECT_NE(nullptr, ptr); auto allocData = driverHandle->svmAllocsManager->getSVMAlloc(ptr); @@ -4747,7 +4782,8 @@ TEST_F(ImportFdUncachedTests, givenCallToImportFdHandleWithBufferMemoryAllocationTypeThenDeviceUnifiedMemoryIsSet) { ze_ipc_memory_flags_t flags = {}; uint64_t handle = 1; - void *ptr = driverHandle->importFdHandle(device->getNEODevice(), flags, handle, NEO::AllocationType::BUFFER, nullptr); + NEO::SvmAllocationData allocDataInternal(device->getNEODevice()->getRootDeviceIndex()); + void *ptr = driverHandle->importFdHandle(device->getNEODevice(), flags, handle, NEO::AllocationType::BUFFER, nullptr, nullptr, allocDataInternal); EXPECT_NE(nullptr, ptr); auto allocData = driverHandle->svmAllocsManager->getSVMAlloc(ptr); @@ -5029,12 +5065,12 @@ class MockSharedHandleMemoryManager : public MockMemoryManager { public: using MockMemoryManager::MockMemoryManager; - GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation) override { + GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation, void *mapPointer) override { if (failOnCreateGraphicsAllocationFromSharedHandle) { return nullptr; } - return MockMemoryManager::createGraphicsAllocationFromSharedHandle(handle, properties, requireSpecificBitness, isHostIpcAllocation, reuseSharedAllocation); + return MockMemoryManager::createGraphicsAllocationFromSharedHandle(handle, properties, requireSpecificBitness, isHostIpcAllocation, reuseSharedAllocation, mapPointer); } GraphicsAllocation *allocateGraphicsMemoryWithProperties(const AllocationProperties &properties) override { diff --git a/level_zero/core/test/unit_tests/sources/module/test_module.cpp b/level_zero/core/test/unit_tests/sources/module/test_module.cpp index 0d2cbb30cc..96559bd033 100644 --- a/level_zero/core/test/unit_tests/sources/module/test_module.cpp +++ b/level_zero/core/test/unit_tests/sources/module/test_module.cpp @@ -403,7 +403,7 @@ HWTEST2_F(ModuleUncachedBufferTest, EXPECT_NE(nullptr, gpuAlloc); uint32_t argIndex = 0u; - kernelImp->setArgBufferWithAlloc(argIndex, reinterpret_cast(devicePtr), gpuAlloc); + kernelImp->setArgBufferWithAlloc(argIndex, reinterpret_cast(devicePtr), gpuAlloc, nullptr); EXPECT_FALSE(kernelImp->getKernelRequiresUncachedMocs()); Kernel::fromHandle(kernelHandle)->destroy(); @@ -439,7 +439,7 @@ HWTEST2_F(ModuleUncachedBufferTest, uint32_t argIndex = 0u; kernelImp->setKernelArgUncached(argIndex, true); kernelImp->kernelRequiresUncachedMocsCount++; - kernelImp->setArgBufferWithAlloc(argIndex, reinterpret_cast(devicePtr), gpuAlloc); + kernelImp->setArgBufferWithAlloc(argIndex, reinterpret_cast(devicePtr), gpuAlloc, nullptr); EXPECT_FALSE(kernelImp->getKernelRequiresUncachedMocs()); Kernel::fromHandle(kernelHandle)->destroy(); @@ -474,7 +474,7 @@ HWTEST2_F(ModuleUncachedBufferTest, EXPECT_NE(nullptr, gpuAlloc); uint32_t argIndex = 0u; - kernelImp->setArgBufferWithAlloc(argIndex, reinterpret_cast(devicePtr), gpuAlloc); + kernelImp->setArgBufferWithAlloc(argIndex, reinterpret_cast(devicePtr), gpuAlloc, nullptr); EXPECT_TRUE(kernelImp->getKernelRequiresUncachedMocs()); Kernel::fromHandle(kernelHandle)->destroy(); @@ -512,7 +512,7 @@ HWTEST2_F(ModuleUncachedBufferTest, uint32_t argIndex = 0u; kernelImp->setKernelArgUncached(argIndex, true); kernelImp->kernelRequiresUncachedMocsCount++; - kernelImp->setArgBufferWithAlloc(argIndex, reinterpret_cast(devicePtr), gpuAlloc); + kernelImp->setArgBufferWithAlloc(argIndex, reinterpret_cast(devicePtr), gpuAlloc, nullptr); EXPECT_TRUE(kernelImp->getKernelRequiresUncachedMocs()); auto argInfo = kernelImp->getImmutableData()->getDescriptor().payloadMappings.explicitArgs[argIndex].as(); diff --git a/opencl/source/sharings/d3d/d3d_buffer.h b/opencl/source/sharings/d3d/d3d_buffer.h index ebf5e1631d..d6c2929aa0 100644 --- a/opencl/source/sharings/d3d/d3d_buffer.h +++ b/opencl/source/sharings/d3d/d3d_buffer.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2022 Intel Corporation + * Copyright (C) 2018-2023 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -46,7 +46,7 @@ class D3DBuffer : public D3DSharing { AllocationType::SHARED_BUFFER, false, // isMultiStorageAllocation context->getDeviceBitfieldForAllocation(context->getDevice(0)->getRootDeviceIndex())}; - auto alloc = context->getMemoryManager()->createGraphicsAllocationFromSharedHandle(toOsHandle(sharedHandle), properties, true, false, true); + auto alloc = context->getMemoryManager()->createGraphicsAllocationFromSharedHandle(toOsHandle(sharedHandle), properties, true, false, true, nullptr); auto d3dBufferObj = new D3DBuffer(context, d3dBuffer, bufferStaging, sharedResource); diff --git a/opencl/source/sharings/d3d/d3d_surface.cpp b/opencl/source/sharings/d3d/d3d_surface.cpp index 0892183d85..dca32e0c6c 100644 --- a/opencl/source/sharings/d3d/d3d_surface.cpp +++ b/opencl/source/sharings/d3d/d3d_surface.cpp @@ -90,7 +90,7 @@ Image *D3DSurface::create(Context *context, cl_dx9_surface_info_khr *surfaceInfo false, // isMultiStorageAllocation context->getDeviceBitfieldForAllocation(rootDeviceIndex)); alloc = context->getMemoryManager()->createGraphicsAllocationFromSharedHandle(toOsHandle(surfaceInfo->shared_handle), allocProperties, - false, false, true); + false, false, true, nullptr); updateImgInfoAndDesc(alloc->getDefaultGmm(), imgInfo, imagePlane, 0u); } else { lockable = !(surfaceDesc.Usage & D3DResourceFlags::USAGE_RENDERTARGET) || imagePlane != ImagePlane::NO_PLANE; diff --git a/opencl/source/sharings/d3d/d3d_texture.cpp b/opencl/source/sharings/d3d/d3d_texture.cpp index 310569b1d1..b8ed1712b4 100644 --- a/opencl/source/sharings/d3d/d3d_texture.cpp +++ b/opencl/source/sharings/d3d/d3d_texture.cpp @@ -94,7 +94,7 @@ Image *D3DTexture::create2d(Context *context, D3DTexture2d *d3dTexture, cl_ false, // isMultiStorageAllocation context->getDeviceBitfieldForAllocation(rootDeviceIndex)); if (memoryManager->verifyHandle(toOsHandle(sharedHandle), rootDeviceIndex, false)) { - alloc = memoryManager->createGraphicsAllocationFromSharedHandle(toOsHandle(sharedHandle), allocProperties, false, false, true); + alloc = memoryManager->createGraphicsAllocationFromSharedHandle(toOsHandle(sharedHandle), allocProperties, false, false, true, nullptr); } else { err.set(CL_INVALID_D3D11_RESOURCE_KHR); return nullptr; @@ -188,7 +188,7 @@ Image *D3DTexture::create3d(Context *context, D3DTexture3d *d3dTexture, cl_ false, // isMultiStorageAllocation context->getDeviceBitfieldForAllocation(rootDeviceIndex)); if (memoryManager->verifyHandle(toOsHandle(sharedHandle), rootDeviceIndex, false)) { - alloc = memoryManager->createGraphicsAllocationFromSharedHandle(toOsHandle(sharedHandle), allocProperties, false, false, true); + alloc = memoryManager->createGraphicsAllocationFromSharedHandle(toOsHandle(sharedHandle), allocProperties, false, false, true, nullptr); } else { err.set(CL_INVALID_D3D11_RESOURCE_KHR); return nullptr; diff --git a/opencl/source/sharings/gl/linux/gl_buffer_linux.cpp b/opencl/source/sharings/gl/linux/gl_buffer_linux.cpp index 6f97087100..c2ba73a7b3 100644 --- a/opencl/source/sharings/gl/linux/gl_buffer_linux.cpp +++ b/opencl/source/sharings/gl/linux/gl_buffer_linux.cpp @@ -153,7 +153,7 @@ GraphicsAllocation *GlBuffer::createGraphicsAllocation(Context *context, unsigne context->getDeviceBitfieldForAllocation(context->getDevice(0)->getRootDeviceIndex())}; // couldn't find allocation for reuse - create new graphicsAllocation = - context->getMemoryManager()->createGraphicsAllocationFromSharedHandle(bufferInfo.globalShareHandle, properties, true, false, false); + context->getMemoryManager()->createGraphicsAllocationFromSharedHandle(bufferInfo.globalShareHandle, properties, true, false, false, nullptr); } if (!graphicsAllocation) { diff --git a/opencl/source/sharings/gl/linux/gl_texture_linux.cpp b/opencl/source/sharings/gl/linux/gl_texture_linux.cpp index a9ade4f4b3..3c7e3f0c76 100644 --- a/opencl/source/sharings/gl/linux/gl_texture_linux.cpp +++ b/opencl/source/sharings/gl/linux/gl_texture_linux.cpp @@ -105,7 +105,7 @@ Image *GlTexture::createSharedGlTexture(Context *context, cl_mem_flags flags, cl imgInfo, AllocationType::SHARED_IMAGE, context->getDeviceBitfieldForAllocation(context->getDevice(0)->getRootDeviceIndex())); - auto alloc = memoryManager->createGraphicsAllocationFromSharedHandle(texInfo.globalShareHandle, allocProperties, false, false, false); + auto alloc = memoryManager->createGraphicsAllocationFromSharedHandle(texInfo.globalShareHandle, allocProperties, false, false, false, nullptr); if (alloc == nullptr) { errorCode.set(CL_INVALID_GL_OBJECT); diff --git a/opencl/source/sharings/gl/windows/gl_buffer_windows.cpp b/opencl/source/sharings/gl/windows/gl_buffer_windows.cpp index c705a46baf..3566649cea 100644 --- a/opencl/source/sharings/gl/windows/gl_buffer_windows.cpp +++ b/opencl/source/sharings/gl/windows/gl_buffer_windows.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2022 Intel Corporation + * Copyright (C) 2020-2023 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -153,7 +153,7 @@ GraphicsAllocation *GlBuffer::createGraphicsAllocation(Context *context, unsigne context->getDeviceBitfieldForAllocation(context->getDevice(0)->getRootDeviceIndex())}; // couldn't find allocation for reuse - create new graphicsAllocation = - context->getMemoryManager()->createGraphicsAllocationFromSharedHandle(bufferInfo.globalShareHandle, properties, true, false, true); + context->getMemoryManager()->createGraphicsAllocationFromSharedHandle(bufferInfo.globalShareHandle, properties, true, false, true, nullptr); } if (!graphicsAllocation) { diff --git a/opencl/source/sharings/gl/windows/gl_texture_windows.cpp b/opencl/source/sharings/gl/windows/gl_texture_windows.cpp index 9f7150ebc2..5182ea8098 100644 --- a/opencl/source/sharings/gl/windows/gl_texture_windows.cpp +++ b/opencl/source/sharings/gl/windows/gl_texture_windows.cpp @@ -59,7 +59,7 @@ Image *GlTexture::createSharedGlTexture(Context *context, cl_mem_flags flags, cl AllocationType::SHARED_IMAGE, false, // isMultiStorageAllocation context->getDeviceBitfieldForAllocation(context->getDevice(0)->getRootDeviceIndex())); - auto alloc = memoryManager->createGraphicsAllocationFromSharedHandle(texInfo.globalShareHandle, allocProperties, false, false, true); + auto alloc = memoryManager->createGraphicsAllocationFromSharedHandle(texInfo.globalShareHandle, allocProperties, false, false, true, nullptr); if (alloc == nullptr) { errorCode.set(CL_INVALID_GL_OBJECT); @@ -128,7 +128,7 @@ Image *GlTexture::createSharedGlTexture(Context *context, cl_mem_flags flags, cl GraphicsAllocation *mcsAlloc = nullptr; if (texInfo.globalShareHandleMCS) { AllocationProperties allocProperties(context->getDevice(0)->getRootDeviceIndex(), 0, AllocationType::MCS, context->getDeviceBitfieldForAllocation(context->getDevice(0)->getRootDeviceIndex())); - mcsAlloc = memoryManager->createGraphicsAllocationFromSharedHandle(texInfo.globalShareHandleMCS, allocProperties, false, false, true); + mcsAlloc = memoryManager->createGraphicsAllocationFromSharedHandle(texInfo.globalShareHandleMCS, allocProperties, false, false, true, nullptr); if (texInfo.pGmmResInfoMCS) { DEBUG_BREAK_IF(mcsAlloc->getDefaultGmm() != nullptr); mcsAlloc->setDefaultGmm(new Gmm(gmmHelper, texInfo.pGmmResInfoMCS)); diff --git a/opencl/source/sharings/unified/unified_sharing.cpp b/opencl/source/sharings/unified/unified_sharing.cpp index 9ba819a515..62844484e3 100644 --- a/opencl/source/sharings/unified/unified_sharing.cpp +++ b/opencl/source/sharings/unified/unified_sharing.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019-2022 Intel Corporation + * Copyright (C) 2019-2023 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -47,7 +47,7 @@ GraphicsAllocation *UnifiedSharing::createGraphicsAllocation(Context *context, U allocationType, false, // isMultiStorageAllocation context->getDeviceBitfieldForAllocation(context->getDevice(0)->getRootDeviceIndex())}; - return memoryManager->createGraphicsAllocationFromSharedHandle(toOsHandle(description.handle), properties, false, false, true); + return memoryManager->createGraphicsAllocationFromSharedHandle(toOsHandle(description.handle), properties, false, false, true, nullptr); } default: return nullptr; diff --git a/opencl/source/sharings/va/va_surface.cpp b/opencl/source/sharings/va/va_surface.cpp index c47a9ddd45..e303ba857f 100644 --- a/opencl/source/sharings/va/va_surface.cpp +++ b/opencl/source/sharings/va/va_surface.cpp @@ -202,7 +202,7 @@ Image *VASurface::createSharedVaSurface(Context *context, VASharingFunctions *sh sharedSurfaceInfo.imgInfo, AllocationType::SHARED_IMAGE, context->getDeviceBitfieldForAllocation(context->getDevice(0)->getRootDeviceIndex())); - auto alloc = memoryManager->createGraphicsAllocationFromSharedHandle(sharedSurfaceInfo.sharedHandle, properties, false, false, true); + auto alloc = memoryManager->createGraphicsAllocationFromSharedHandle(sharedSurfaceInfo.sharedHandle, properties, false, false, true, nullptr); memoryManager->closeSharedHandle(alloc); diff --git a/opencl/test/unit_test/d3d_sharing/d3d9_tests.cpp b/opencl/test/unit_test/d3d_sharing/d3d9_tests.cpp index 33431fddf7..5eed90f0db 100644 --- a/opencl/test/unit_test/d3d_sharing/d3d9_tests.cpp +++ b/opencl/test/unit_test/d3d_sharing/d3d9_tests.cpp @@ -33,8 +33,8 @@ IDXGIAdapter *MockD3DSharingFunctions::getDxgiDescAdapterR class MockMM : public OsAgnosticMemoryManager { public: MockMM(const ExecutionEnvironment &executionEnvironment) : OsAgnosticMemoryManager(const_cast(executionEnvironment)){}; - GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation) override { - auto alloc = OsAgnosticMemoryManager::createGraphicsAllocationFromSharedHandle(handle, properties, requireSpecificBitness, isHostIpcAllocation, reuseSharedAllocation); + GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation, void *mapPointer) override { + auto alloc = OsAgnosticMemoryManager::createGraphicsAllocationFromSharedHandle(handle, properties, requireSpecificBitness, isHostIpcAllocation, reuseSharedAllocation, mapPointer); alloc->setDefaultGmm(forceGmm); gmmOwnershipPassed = true; return alloc; @@ -42,7 +42,7 @@ class MockMM : public OsAgnosticMemoryManager { GraphicsAllocation *allocateGraphicsMemoryForImage(const AllocationData &allocationData) override { auto gmm = std::make_unique(executionEnvironment.rootDeviceEnvironments[allocationData.rootDeviceIndex]->getGmmHelper(), *allocationData.imgInfo, StorageInfo{}, false); AllocationProperties properties(allocationData.rootDeviceIndex, nullptr, false, AllocationType::SHARED_IMAGE, false, {}); - auto alloc = OsAgnosticMemoryManager::createGraphicsAllocationFromSharedHandle(1, properties, false, false, true); + auto alloc = OsAgnosticMemoryManager::createGraphicsAllocationFromSharedHandle(1, properties, false, false, true, nullptr); alloc->setDefaultGmm(forceGmm); gmmOwnershipPassed = true; return alloc; diff --git a/opencl/test/unit_test/fixtures/d3d_test_fixture.h b/opencl/test/unit_test/fixtures/d3d_test_fixture.h index e05a303daf..63aaeade56 100644 --- a/opencl/test/unit_test/fixtures/d3d_test_fixture.h +++ b/opencl/test/unit_test/fixtures/d3d_test_fixture.h @@ -50,11 +50,11 @@ class D3DTests : public PlatformFixture, public ::testing::Test { public: using OsAgnosticMemoryManager::OsAgnosticMemoryManager; bool failAlloc = false; - GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation) override { + GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation, void *mapPointer) override { if (failAlloc) { return nullptr; } - auto alloc = OsAgnosticMemoryManager::createGraphicsAllocationFromSharedHandle(handle, properties, requireSpecificBitness, isHostIpcAllocation, reuseSharedAllocation); + auto alloc = OsAgnosticMemoryManager::createGraphicsAllocationFromSharedHandle(handle, properties, requireSpecificBitness, isHostIpcAllocation, reuseSharedAllocation, mapPointer); alloc->setDefaultGmm(forceGmm); gmmOwnershipPassed = true; return alloc; @@ -64,7 +64,7 @@ class D3DTests : public PlatformFixture, public ::testing::Test { return nullptr; } AllocationProperties properties(rootDeviceIndex, true, 0, AllocationType::INTERNAL_HOST_MEMORY, false, false, 0); - auto alloc = OsAgnosticMemoryManager::createGraphicsAllocationFromSharedHandle(toOsHandle(handle), properties, false, false, true); + auto alloc = OsAgnosticMemoryManager::createGraphicsAllocationFromSharedHandle(toOsHandle(handle), properties, false, false, true, nullptr); alloc->setDefaultGmm(forceGmm); gmmOwnershipPassed = true; return alloc; diff --git a/opencl/test/unit_test/memory_manager/memory_manager_tests.cpp b/opencl/test/unit_test/memory_manager/memory_manager_tests.cpp index 8f72900ac2..79d7b6f237 100644 --- a/opencl/test/unit_test/memory_manager/memory_manager_tests.cpp +++ b/opencl/test/unit_test/memory_manager/memory_manager_tests.cpp @@ -1114,7 +1114,7 @@ TEST(OsAgnosticMemoryManager, givenDefaultMemoryManagerWhenCreateGraphicsAllocat osHandle handle = 1; auto size = 4096u; AllocationProperties properties(mockRootDeviceIndex, false, size, AllocationType::SHARED_BUFFER, false, mockDeviceBitfield); - auto sharedAllocation = memoryManager.createGraphicsAllocationFromSharedHandle(handle, properties, false, false, true); + auto sharedAllocation = memoryManager.createGraphicsAllocationFromSharedHandle(handle, properties, false, false, true, nullptr); EXPECT_NE(nullptr, sharedAllocation); EXPECT_FALSE(sharedAllocation->isCoherent()); EXPECT_NE(nullptr, sharedAllocation->getUnderlyingBuffer()); @@ -1124,6 +1124,23 @@ TEST(OsAgnosticMemoryManager, givenDefaultMemoryManagerWhenCreateGraphicsAllocat memoryManager.freeGraphicsMemory(sharedAllocation); } +TEST(OsAgnosticMemoryManager, givenDefaultMemoryManagerWhenCreateGraphicsAllocationFromSharedObjectIsCalledWithAMappedPointerThenGraphicsAllocationIsReturnedWithTheSameAddress) { + MockExecutionEnvironment executionEnvironment(defaultHwInfo.get()); + MemoryManagerCreate memoryManager(false, false, executionEnvironment); + osHandle handle = 1; + auto size = 4096u; + void *mapPointer = reinterpret_cast(0x1234); + AllocationProperties properties(mockRootDeviceIndex, false, size, AllocationType::SHARED_BUFFER, false, mockDeviceBitfield); + auto sharedAllocation = memoryManager.createGraphicsAllocationFromSharedHandle(handle, properties, false, false, true, mapPointer); + EXPECT_NE(nullptr, sharedAllocation); + EXPECT_FALSE(sharedAllocation->isCoherent()); + EXPECT_EQ(mapPointer, sharedAllocation->getUnderlyingBuffer()); + EXPECT_EQ(size, sharedAllocation->getUnderlyingBufferSize()); + EXPECT_EQ(MemoryPool::SystemCpuInaccessible, sharedAllocation->getMemoryPool()); + + memoryManager.freeGraphicsMemory(sharedAllocation); +} + TEST(OsAgnosticMemoryManager, givenDefaultMemoryManagerWhenCreateGraphicsAllocationFromSharedObjectIsCalledAndRootDeviceIndexIsSpecifiedThenGraphicsAllocationIsReturnedWithCorrectRootDeviceIndex) { MockExecutionEnvironment executionEnvironment(defaultHwInfo.get()); MemoryManagerCreate memoryManager(false, false, executionEnvironment); @@ -1133,7 +1150,7 @@ TEST(OsAgnosticMemoryManager, givenDefaultMemoryManagerWhenCreateGraphicsAllocat EXPECT_EQ(properties.subDevicesBitfield, mockDeviceBitfield); EXPECT_EQ(properties.rootDeviceIndex, 0u); - auto sharedAllocation = memoryManager.createGraphicsAllocationFromSharedHandle(handle, properties, false, false, true); + auto sharedAllocation = memoryManager.createGraphicsAllocationFromSharedHandle(handle, properties, false, false, true, nullptr); EXPECT_NE(nullptr, sharedAllocation); EXPECT_EQ(0u, sharedAllocation->getRootDeviceIndex()); EXPECT_FALSE(sharedAllocation->isCoherent()); @@ -1150,7 +1167,7 @@ TEST(OsAgnosticMemoryManager, givenDefaultMemoryManagerWhenCreateGraphicsAllocat osHandle handle = 1; auto size = 4096u; AllocationProperties properties(mockRootDeviceIndex, false, size, AllocationType::SHARED_BUFFER, false, mockDeviceBitfield); - auto sharedAllocation = memoryManager.createGraphicsAllocationFromSharedHandle(handle, properties, true, false, true); + auto sharedAllocation = memoryManager.createGraphicsAllocationFromSharedHandle(handle, properties, true, false, true, nullptr); EXPECT_NE(nullptr, sharedAllocation); EXPECT_TRUE(sharedAllocation->is32BitAllocation()); EXPECT_FALSE(sharedAllocation->isCoherent()); diff --git a/opencl/test/unit_test/mt_tests/os_interface/linux/drm_memory_manager_mt_tests.cpp b/opencl/test/unit_test/mt_tests/os_interface/linux/drm_memory_manager_mt_tests.cpp index 916d0b0459..8f94730ffe 100644 --- a/opencl/test/unit_test/mt_tests/os_interface/linux/drm_memory_manager_mt_tests.cpp +++ b/opencl/test/unit_test/mt_tests/os_interface/linux/drm_memory_manager_mt_tests.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2022 Intel Corporation + * Copyright (C) 2018-2023 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -55,7 +55,7 @@ TEST(DrmMemoryManagerTest, givenDrmMemoryManagerWhenSharedAllocationIsCreatedFro auto createFunction = [&]() { size_t indexFree = index++; AllocationProperties properties(0, false, MemoryConstants::pageSize, AllocationType::SHARED_BUFFER, false, {}); - createdAllocations[indexFree] = memoryManager->createGraphicsAllocationFromSharedHandle(handle, properties, false, false, true); + createdAllocations[indexFree] = memoryManager->createGraphicsAllocationFromSharedHandle(handle, properties, false, false, true, nullptr); EXPECT_NE(nullptr, createdAllocations[indexFree]); EXPECT_GE(1u, memoryManager->peekSharedBosSize()); allocateCount++; @@ -126,7 +126,7 @@ TEST(DrmMemoryManagerTest, givenMultipleThreadsWhenSharedAllocationIsCreatedThen auto createFunction = [&]() { size_t indexFree = index++; AllocationProperties properties(0, false, MemoryConstants::pageSize, AllocationType::SHARED_BUFFER, false, {}); - createdAllocations[indexFree] = memoryManager->createGraphicsAllocationFromSharedHandle(handle, properties, false, false, true); + createdAllocations[indexFree] = memoryManager->createGraphicsAllocationFromSharedHandle(handle, properties, false, false, true, nullptr); EXPECT_NE(nullptr, createdAllocations[indexFree]); std::this_thread::yield(); diff --git a/opencl/test/unit_test/os_interface/linux/cl_drm_memory_manager_tests.cpp b/opencl/test/unit_test/os_interface/linux/cl_drm_memory_manager_tests.cpp index cb4be7f3bc..d4dbcd3601 100644 --- a/opencl/test/unit_test/os_interface/linux/cl_drm_memory_manager_tests.cpp +++ b/opencl/test/unit_test/os_interface/linux/cl_drm_memory_manager_tests.cpp @@ -773,7 +773,7 @@ TEST_F(ClDrmMemoryManagerTest, givenOsHandleWithNonTiledObjectWhenCreateFromShar AllocationProperties properties(rootDeviceIndex, false, imgInfo, AllocationType::SHARED_IMAGE, context.getDevice(0)->getDeviceBitfield()); - auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(handle, properties, false, false, true); + auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(handle, properties, false, false, true, nullptr); ASSERT_NE(nullptr, graphicsAllocation); EXPECT_EQ(boHandle, mock->getTilingHandleIn); EXPECT_EQ(AllocationType::SHARED_IMAGE, graphicsAllocation->getAllocationType()); @@ -816,7 +816,7 @@ TEST_F(ClDrmMemoryManagerTest, givenOsHandleWithTileYObjectWhenCreateFromSharedH AllocationProperties properties(rootDeviceIndex, false, imgInfo, AllocationType::SHARED_IMAGE, context.getDevice(0)->getDeviceBitfield()); - auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(handle, properties, false, false, true); + auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(handle, properties, false, false, true, nullptr); ASSERT_NE(nullptr, graphicsAllocation); EXPECT_EQ(boHandle, mock->getTilingHandleIn); EXPECT_EQ(AllocationType::SHARED_IMAGE, graphicsAllocation->getAllocationType()); @@ -858,7 +858,7 @@ TEST_F(ClDrmMemoryManagerTest, givenDrmMemoryManagerWhenCreateFromSharedHandleFa AllocationProperties properties(rootDeviceIndex, false, imgInfo, AllocationType::SHARED_IMAGE, context.getDevice(0)->getDeviceBitfield()); - auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(handle, properties, false, false, true); + auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(handle, properties, false, false, true, nullptr); ASSERT_NE(nullptr, graphicsAllocation); EXPECT_EQ(boHandle, mock->getTilingHandleIn); EXPECT_EQ(AllocationType::SHARED_IMAGE, graphicsAllocation->getAllocationType()); diff --git a/opencl/test/unit_test/os_interface/windows/wddm_memory_manager_tests.cpp b/opencl/test/unit_test/os_interface/windows/wddm_memory_manager_tests.cpp index 7b91664856..dc892c7c2e 100644 --- a/opencl/test/unit_test/os_interface/windows/wddm_memory_manager_tests.cpp +++ b/opencl/test/unit_test/os_interface/windows/wddm_memory_manager_tests.cpp @@ -353,7 +353,7 @@ TEST_F(WddmMemoryManagerSimpleTest, givenMemoryManagerWhenCreateAllocationFromHa gdi->getOpenResourceArgOut().pOpenAllocationInfo = &allocationInfo; AllocationProperties properties(0, false, 0, AllocationType::SHARED_BUFFER, false, false, 0); - auto allocation = memoryManager->createGraphicsAllocationFromSharedHandle(osHandle, properties, false, false, true); + auto allocation = memoryManager->createGraphicsAllocationFromSharedHandle(osHandle, properties, false, false, true, nullptr); EXPECT_NE(nullptr, allocation); EXPECT_EQ(MemoryPool::SystemCpuInaccessible, allocation->getMemoryPool()); memoryManager->freeGraphicsMemory(allocation); @@ -374,7 +374,7 @@ TEST_F(WddmMemoryManagerSimpleTest, givenSharedHandleWhenCreateGraphicsAllocatio AllocationProperties properties(0, false, 0, AllocationType::SHARED_BUFFER, false, false, 0); std::vector handles{handle}; - auto allocation = memoryManager->createGraphicsAllocationFromMultipleSharedHandles(handles, properties, false, false, true); + auto allocation = memoryManager->createGraphicsAllocationFromMultipleSharedHandles(handles, properties, false, false, true, nullptr); EXPECT_EQ(nullptr, allocation); } @@ -397,7 +397,7 @@ TEST_F(WddmMemoryManagerSimpleTest, givenAllocationPropertiesWhenCreateAllocatio AllocationProperties *propertiesArray[2] = {&propertiesBuffer, &propertiesImage}; for (auto properties : propertiesArray) { - auto allocation = memoryManager->createGraphicsAllocationFromSharedHandle(osHandle, *properties, false, false, true); + auto allocation = memoryManager->createGraphicsAllocationFromSharedHandle(osHandle, *properties, false, false, true, nullptr); EXPECT_NE(nullptr, allocation); EXPECT_EQ(properties->allocationType, allocation->getAllocationType()); memoryManager->freeGraphicsMemory(allocation); @@ -422,7 +422,7 @@ TEST_F(WddmMemoryManagerSimpleTest, whenCreateAllocationFromHandleAndMapCallFail AllocationProperties properties(0, false, 0, AllocationType::SHARED_BUFFER, false, false, 0); - auto allocation = memoryManager->createGraphicsAllocationFromSharedHandle(osHandle, properties, false, false, true); + auto allocation = memoryManager->createGraphicsAllocationFromSharedHandle(osHandle, properties, false, false, true, nullptr); EXPECT_EQ(nullptr, allocation); EXPECT_EQ(1u, memoryManager->freeGraphicsMemoryImplCalled); } @@ -725,7 +725,7 @@ TEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerWhenCreateFromSharedHandleIs AllocationProperties properties(0, false, 4096u, AllocationType::SHARED_BUFFER, false, false, mockDeviceBitfield); - auto *gpuAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(osHandle, properties, false, false, true); + auto *gpuAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(osHandle, properties, false, false, true, nullptr); auto wddmAlloc = static_cast(gpuAllocation); ASSERT_NE(nullptr, gpuAllocation); EXPECT_EQ(RESOURCE_HANDLE, wddmAlloc->resourceHandle); @@ -747,7 +747,7 @@ TEST_F(WddmMemoryManagerSimpleTest, whenAllocationCreatedFromSharedHandleIsDestr AllocationProperties properties(0, false, 0, AllocationType::SHARED_BUFFER, false, false, 0); - auto allocation = memoryManager->createGraphicsAllocationFromSharedHandle(1, properties, false, false, true); + auto allocation = memoryManager->createGraphicsAllocationFromSharedHandle(1, properties, false, false, true, nullptr); EXPECT_NE(nullptr, allocation); memoryManager->setDeferredDeleter(nullptr); @@ -831,7 +831,7 @@ TEST_F(WddmMemoryManagerTest, GivenForce32bitAddressingAndRequireSpecificBitness AllocationProperties properties(0, false, 4096u, AllocationType::SHARED_BUFFER, false, false, 0); - auto *gpuAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(osHandle, properties, true, false, true); + auto *gpuAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(osHandle, properties, true, false, true, nullptr); ASSERT_NE(nullptr, gpuAllocation); if constexpr (is64bit) { EXPECT_TRUE(gpuAllocation->is32BitAllocation()); @@ -855,7 +855,7 @@ TEST_F(WddmMemoryManagerTest, GivenForce32bitAddressingAndNotRequiredSpecificBit memoryManager->setForce32BitAllocations(true); AllocationProperties properties(0, false, 4096u, AllocationType::SHARED_BUFFER, false, false, 0); - auto *gpuAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(osHandle, properties, false, false, true); + auto *gpuAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(osHandle, properties, false, false, true, nullptr); ASSERT_NE(nullptr, gpuAllocation); EXPECT_FALSE(gpuAllocation->is32BitAllocation()); @@ -875,7 +875,7 @@ TEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerWhenFreeAllocFromSharedHandl setSizesFcn(gmm->gmmResourceInfo.get(), 1u, 1024u, 1u); AllocationProperties properties(0, false, 4096u, AllocationType::SHARED_BUFFER, false, false, 0); - auto gpuAllocation = (WddmAllocation *)memoryManager->createGraphicsAllocationFromSharedHandle(osHandle, properties, false, false, true); + auto gpuAllocation = (WddmAllocation *)memoryManager->createGraphicsAllocationFromSharedHandle(osHandle, properties, false, false, true, nullptr); EXPECT_NE(nullptr, gpuAllocation); auto expectedDestroyHandle = gpuAllocation->resourceHandle; EXPECT_NE(0u, expectedDestroyHandle); @@ -910,7 +910,7 @@ TEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerSizeZeroWhenCreateFromShared setSizesFcn(gmm->gmmResourceInfo.get(), 1u, 1024u, 1u); AllocationProperties properties(0, false, size, AllocationType::SHARED_BUFFER, false, false, 0); - auto *gpuAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(osHandle, properties, false, false, true); + auto *gpuAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(osHandle, properties, false, false, true, nullptr); ASSERT_NE(nullptr, gpuAllocation); EXPECT_EQ(size, gpuAllocation->getUnderlyingBufferSize()); memoryManager->freeGraphicsMemory(gpuAllocation); @@ -1021,7 +1021,7 @@ TEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerWhenCreateFromSharedHandleFa wddm->failOpenSharedHandle = true; AllocationProperties properties(0, false, size, AllocationType::SHARED_BUFFER, false, false, 0); - auto *gpuAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(osHandle, properties, false, false, true); + auto *gpuAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(osHandle, properties, false, false, true, nullptr); EXPECT_EQ(nullptr, gpuAllocation); } diff --git a/opencl/test/unit_test/sharings/gl/linux/gl_create_from_texture_tests.cpp b/opencl/test/unit_test/sharings/gl/linux/gl_create_from_texture_tests.cpp index a94b2c553b..55d00f0af9 100644 --- a/opencl/test/unit_test/sharings/gl/linux/gl_create_from_texture_tests.cpp +++ b/opencl/test/unit_test/sharings/gl/linux/gl_create_from_texture_tests.cpp @@ -32,8 +32,8 @@ class CreateFromGlTexture : public ::testing::Test { mockExecutionEnvironment.reset(&executionEnvironment); executionEnvironment.rootDeviceEnvironments[0]->initGmm(); } - GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation) override { - auto alloc = OsAgnosticMemoryManager::createGraphicsAllocationFromSharedHandle(handle, properties, requireSpecificBitness, isHostIpcAllocation, reuseSharedAllocation); + GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation, void *mapPointer) override { + auto alloc = OsAgnosticMemoryManager::createGraphicsAllocationFromSharedHandle(handle, properties, requireSpecificBitness, isHostIpcAllocation, reuseSharedAllocation, mapPointer); if (handle == CreateFromGlTexture::mcsHandle) { alloc->setDefaultGmm(forceMcsGmm); } else { diff --git a/opencl/test/unit_test/sharings/gl/linux/gl_texture_tests.cpp b/opencl/test/unit_test/sharings/gl/linux/gl_texture_tests.cpp index 33c5f2f4f2..59cec7ad65 100644 --- a/opencl/test/unit_test/sharings/gl/linux/gl_texture_tests.cpp +++ b/opencl/test/unit_test/sharings/gl/linux/gl_texture_tests.cpp @@ -29,8 +29,8 @@ class GlSharingTextureTests : public ::testing::Test { class TempMM : public MockMemoryManager { public: using MockMemoryManager::MockMemoryManager; - GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation) override { - auto alloc = OsAgnosticMemoryManager::createGraphicsAllocationFromSharedHandle(handle, properties, requireSpecificBitness, isHostIpcAllocation, reuseSharedAllocation); + GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation, void *mapPointer) override { + auto alloc = OsAgnosticMemoryManager::createGraphicsAllocationFromSharedHandle(handle, properties, requireSpecificBitness, isHostIpcAllocation, reuseSharedAllocation, mapPointer); if (useForcedGmm) { if (alloc->getDefaultGmm()) { delete alloc->getDefaultGmm(); @@ -120,7 +120,7 @@ TEST_F(GlSharingTextureTests, givenMockGlWhen2dGlTextureIsCreatedThenMemObjectHa class FailingMemoryManager : public MockMemoryManager { public: - GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation) override { + GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation, void *mapPointer) override { return nullptr; } }; diff --git a/opencl/test/unit_test/sharings/gl/windows/gl_create_from_texture_tests.cpp b/opencl/test/unit_test/sharings/gl/windows/gl_create_from_texture_tests.cpp index fe63124116..d57b05ea28 100644 --- a/opencl/test/unit_test/sharings/gl/windows/gl_create_from_texture_tests.cpp +++ b/opencl/test/unit_test/sharings/gl/windows/gl_create_from_texture_tests.cpp @@ -31,8 +31,8 @@ class CreateFromGlTexture : public ::testing::Test { TempMM() : OsAgnosticMemoryManager(*(new MockExecutionEnvironment(defaultHwInfo.get()))) { mockExecutionEnvironment.reset(&executionEnvironment); } - GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation) override { - auto alloc = OsAgnosticMemoryManager::createGraphicsAllocationFromSharedHandle(handle, properties, requireSpecificBitness, isHostIpcAllocation, reuseSharedAllocation); + GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation, void *mapPointer) override { + auto alloc = OsAgnosticMemoryManager::createGraphicsAllocationFromSharedHandle(handle, properties, requireSpecificBitness, isHostIpcAllocation, reuseSharedAllocation, mapPointer); if (handle == CreateFromGlTexture::mcsHandle) { alloc->setDefaultGmm(forceMcsGmm); } else { diff --git a/opencl/test/unit_test/sharings/gl/windows/gl_reused_buffers_tests.cpp b/opencl/test/unit_test/sharings/gl/windows/gl_reused_buffers_tests.cpp index 04c17c6536..3af17609e0 100644 --- a/opencl/test/unit_test/sharings/gl/windows/gl_reused_buffers_tests.cpp +++ b/opencl/test/unit_test/sharings/gl/windows/gl_reused_buffers_tests.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2022 Intel Corporation + * Copyright (C) 2018-2023 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -40,7 +40,7 @@ struct GlReusedBufferTests : public ::testing::Test { class FailingMemoryManager : public MockMemoryManager { public: - GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation) override { + GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation, void *mapPointer) override { return nullptr; } }; diff --git a/opencl/test/unit_test/sharings/gl/windows/gl_sharing_tests.cpp b/opencl/test/unit_test/sharings/gl/windows/gl_sharing_tests.cpp index 29a08ec662..cb0361bb5d 100644 --- a/opencl/test/unit_test/sharings/gl/windows/gl_sharing_tests.cpp +++ b/opencl/test/unit_test/sharings/gl/windows/gl_sharing_tests.cpp @@ -97,7 +97,7 @@ TEST_F(glSharingTests, givenMockGlWhenGlBufferIsCreatedThenMemObjectHasGlHandler class FailingMemoryManager : public MockMemoryManager { public: - GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation) override { + GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation, void *mapPointer) override { return nullptr; } }; diff --git a/opencl/test/unit_test/sharings/gl/windows/gl_texture_tests.cpp b/opencl/test/unit_test/sharings/gl/windows/gl_texture_tests.cpp index e5e5458a46..6fb1c287dc 100644 --- a/opencl/test/unit_test/sharings/gl/windows/gl_texture_tests.cpp +++ b/opencl/test/unit_test/sharings/gl/windows/gl_texture_tests.cpp @@ -29,8 +29,8 @@ class GlSharingTextureTests : public ::testing::Test { class TempMM : public MockMemoryManager { public: using MockMemoryManager::MockMemoryManager; - GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation) override { - auto alloc = OsAgnosticMemoryManager::createGraphicsAllocationFromSharedHandle(handle, properties, requireSpecificBitness, isHostIpcAllocation, reuseSharedAllocation); + GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation, void *mapPointer) override { + auto alloc = OsAgnosticMemoryManager::createGraphicsAllocationFromSharedHandle(handle, properties, requireSpecificBitness, isHostIpcAllocation, reuseSharedAllocation, mapPointer); if (useForcedGmm) { alloc->setDefaultGmm(forceGmm.get()); } @@ -116,7 +116,7 @@ TEST_F(GlSharingTextureTests, givenMockGlWhen1dGlTextureIsCreatedThenMemObjectHa class FailingMemoryManager : public MockMemoryManager { public: - GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation) override { + GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation, void *mapPointer) override { return nullptr; } }; diff --git a/opencl/test/unit_test/sharings/unified/unified_sharing_tests.cpp b/opencl/test/unit_test/sharings/unified/unified_sharing_tests.cpp index a89a6e1873..7f54e62068 100644 --- a/opencl/test/unit_test/sharings/unified/unified_sharing_tests.cpp +++ b/opencl/test/unit_test/sharings/unified/unified_sharing_tests.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019-2022 Intel Corporation + * Copyright (C) 2019-2023 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -169,7 +169,7 @@ struct UnifiedSharingCreateAllocationTests : UnifiedSharingTestsWithMemoryManage this->handle = toOsHandle(handle); return nullptr; } - GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation) override { + GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation, void *mapPointer) override { this->createFromSharedHandleCalled = true; this->handle = handle; this->properties = std::make_unique(properties); diff --git a/shared/source/memory_manager/memory_manager.h b/shared/source/memory_manager/memory_manager.h index 13242c7b48..b1fb74e606 100644 --- a/shared/source/memory_manager/memory_manager.h +++ b/shared/source/memory_manager/memory_manager.h @@ -118,8 +118,8 @@ class MemoryManager { virtual bool verifyHandle(osHandle handle, uint32_t rootDeviceIndex, bool) { return true; } virtual bool isNTHandle(osHandle handle, uint32_t rootDeviceIndex) { return false; } - virtual GraphicsAllocation *createGraphicsAllocationFromMultipleSharedHandles(const std::vector &handles, AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation) = 0; - virtual GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation) = 0; + virtual GraphicsAllocation *createGraphicsAllocationFromMultipleSharedHandles(const std::vector &handles, AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation, void *mapPointer) = 0; + virtual GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation, void *mapPointer) = 0; virtual void closeSharedHandle(GraphicsAllocation *graphicsAllocation){}; virtual void closeInternalHandle(uint64_t &handle, uint32_t handleId, GraphicsAllocation *graphicsAllocation){}; virtual GraphicsAllocation *createGraphicsAllocationFromNTHandle(void *handle, uint32_t rootDeviceIndex, AllocationType allocType) = 0; diff --git a/shared/source/memory_manager/os_agnostic_memory_manager.cpp b/shared/source/memory_manager/os_agnostic_memory_manager.cpp index 0e4f57ee13..a9ae4e856f 100644 --- a/shared/source/memory_manager/os_agnostic_memory_manager.cpp +++ b/shared/source/memory_manager/os_agnostic_memory_manager.cpp @@ -238,12 +238,16 @@ GraphicsAllocation *OsAgnosticMemoryManager::allocate32BitGraphicsMemoryImpl(con return memoryAllocation; } -GraphicsAllocation *OsAgnosticMemoryManager::createGraphicsAllocationFromMultipleSharedHandles(const std::vector &handles, AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation) { +GraphicsAllocation *OsAgnosticMemoryManager::createGraphicsAllocationFromMultipleSharedHandles(const std::vector &handles, AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation, void *mapPointer) { return nullptr; } -GraphicsAllocation *OsAgnosticMemoryManager::createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation) { - auto graphicsAllocation = createMemoryAllocation(properties.allocationType, nullptr, reinterpret_cast(1), 1, +GraphicsAllocation *OsAgnosticMemoryManager::createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation, void *mapPointer) { + void *gpuPtr = reinterpret_cast(1); + if (mapPointer) { + gpuPtr = mapPointer; + } + auto graphicsAllocation = createMemoryAllocation(properties.allocationType, nullptr, gpuPtr, 1, 4096u, static_cast(handle), MemoryPool::SystemCpuInaccessible, properties.rootDeviceIndex, false, false, requireSpecificBitness); graphicsAllocation->setSharedHandle(handle); diff --git a/shared/source/memory_manager/os_agnostic_memory_manager.h b/shared/source/memory_manager/os_agnostic_memory_manager.h index 0ac1c1c88d..f8821e504d 100644 --- a/shared/source/memory_manager/os_agnostic_memory_manager.h +++ b/shared/source/memory_manager/os_agnostic_memory_manager.h @@ -23,8 +23,8 @@ class OsAgnosticMemoryManager : public MemoryManager { OsAgnosticMemoryManager(bool aubUsage, ExecutionEnvironment &executionEnvironment); void initialize(bool aubUsage); ~OsAgnosticMemoryManager() override; - GraphicsAllocation *createGraphicsAllocationFromMultipleSharedHandles(const std::vector &handles, AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation) override; - GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation) override; + GraphicsAllocation *createGraphicsAllocationFromMultipleSharedHandles(const std::vector &handles, AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation, void *mapPointer) override; + GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation, void *mapPointer) override; GraphicsAllocation *createGraphicsAllocationFromNTHandle(void *handle, uint32_t rootDeviceIndex, AllocationType allocType) override { return nullptr; } void addAllocationToHostPtrManager(GraphicsAllocation *gfxAllocation) override; diff --git a/shared/source/memory_manager/unified_memory_manager.cpp b/shared/source/memory_manager/unified_memory_manager.cpp index 0d53a41bc8..9b4eda68e4 100644 --- a/shared/source/memory_manager/unified_memory_manager.cpp +++ b/shared/source/memory_manager/unified_memory_manager.cpp @@ -434,7 +434,6 @@ bool SVMAllocsManager::freeSVMAlloc(void *ptr, bool blocking) { if (svmDeferFreeAllocs.allocations.size() > 0) { this->freeSVMAllocDeferImpl(); } - SvmAllocationData *svmData = getSVMAlloc(ptr); if (svmData) { if (InternalMemoryType::DEVICE_UNIFIED_MEMORY == svmData->memoryType && diff --git a/shared/source/memory_manager/unified_memory_manager.h b/shared/source/memory_manager/unified_memory_manager.h index 14808f6a1d..4fa7a9b360 100644 --- a/shared/source/memory_manager/unified_memory_manager.h +++ b/shared/source/memory_manager/unified_memory_manager.h @@ -42,6 +42,7 @@ struct SvmAllocationData { this->gpuAllocations.addAllocation(allocation); } } + this->mappedAllocData = svmAllocData.mappedAllocData; } SvmAllocationData &operator=(const SvmAllocationData &) = delete; GraphicsAllocation *cpuAllocation = nullptr; @@ -55,6 +56,7 @@ struct SvmAllocationData { void setAllocId(uint32_t id) { allocId = id; } + bool mappedAllocData = false; uint32_t getAllocId() { return allocId; diff --git a/shared/source/os_interface/linux/drm_memory_manager.cpp b/shared/source/os_interface/linux/drm_memory_manager.cpp index 82896ee742..581b1cda0d 100644 --- a/shared/source/os_interface/linux/drm_memory_manager.cpp +++ b/shared/source/os_interface/linux/drm_memory_manager.cpp @@ -775,10 +775,12 @@ GraphicsAllocation *DrmMemoryManager::createGraphicsAllocationFromMultipleShared AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, - bool reuseSharedAllocation) { + bool reuseSharedAllocation, + void *mapPointer) { BufferObjects bos; std::vector sizes; size_t totalSize = 0; + uint64_t gpuRange = 0; std::unique_lock lock(mtx); @@ -828,10 +830,14 @@ GraphicsAllocation *DrmMemoryManager::createGraphicsAllocationFromMultipleShared sizes.push_back(bo->peekSize()); } - auto gfxPartition = getGfxPartition(properties.rootDeviceIndex); - auto prefer57bitAddressing = (gfxPartition->getHeapLimit(HeapIndex::HEAP_EXTENDED) > 0); - auto heapIndex = prefer57bitAddressing ? HeapIndex::HEAP_EXTENDED : HeapIndex::HEAP_STANDARD2MB; - auto gpuRange = acquireGpuRange(totalSize, properties.rootDeviceIndex, heapIndex); + if (mapPointer) { + gpuRange = reinterpret_cast(mapPointer); + } else { + auto gfxPartition = getGfxPartition(properties.rootDeviceIndex); + auto prefer57bitAddressing = (gfxPartition->getHeapLimit(HeapIndex::HEAP_EXTENDED) > 0); + auto heapIndex = prefer57bitAddressing ? HeapIndex::HEAP_EXTENDED : HeapIndex::HEAP_STANDARD2MB; + gpuRange = acquireGpuRange(totalSize, properties.rootDeviceIndex, heapIndex); + } if (reuseSharedAllocation) { lock.unlock(); @@ -928,7 +934,8 @@ GraphicsAllocation *DrmMemoryManager::createGraphicsAllocationFromSharedHandle(o const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, - bool reuseSharedAllocation) { + bool reuseSharedAllocation, + void *mapPointer) { if (isHostIpcAllocation) { return createUSMHostAllocationFromSharedHandle(handle, properties, false, reuseSharedAllocation); } @@ -936,6 +943,7 @@ GraphicsAllocation *DrmMemoryManager::createGraphicsAllocationFromSharedHandle(o std::unique_lock lock(mtx); PrimeHandle openFd{}; + uint64_t gpuRange = 0; openFd.fileDescriptor = handle; auto &drm = this->getDrm(properties.rootDeviceIndex); @@ -986,8 +994,12 @@ GraphicsAllocation *DrmMemoryManager::createGraphicsAllocationFromSharedHandle(o return HeapIndex::HEAP_STANDARD; }; - auto heapIndex = getHeapIndex(); - auto gpuRange = acquireGpuRange(size, properties.rootDeviceIndex, heapIndex); + if (mapPointer) { + gpuRange = reinterpret_cast(mapPointer); + } else { + auto heapIndex = getHeapIndex(); + gpuRange = acquireGpuRange(size, properties.rootDeviceIndex, heapIndex); + } bo->setAddress(gpuRange); bo->setUnmapSize(size); diff --git a/shared/source/os_interface/linux/drm_memory_manager.h b/shared/source/os_interface/linux/drm_memory_manager.h index 07c8010e28..ced5055799 100644 --- a/shared/source/os_interface/linux/drm_memory_manager.h +++ b/shared/source/os_interface/linux/drm_memory_manager.h @@ -38,8 +38,8 @@ class DrmMemoryManager : public MemoryManager { void freeGraphicsMemoryImpl(GraphicsAllocation *gfxAllocation, bool isImportedAllocation) override; void handleFenceCompletion(GraphicsAllocation *allocation) override; GraphicsAllocation *createGraphicsAllocationFromExistingStorage(AllocationProperties &properties, void *ptr, MultiGraphicsAllocation &multiGraphicsAllocation) override; - GraphicsAllocation *createGraphicsAllocationFromMultipleSharedHandles(const std::vector &handles, AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation) override; - GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation) override; + GraphicsAllocation *createGraphicsAllocationFromMultipleSharedHandles(const std::vector &handles, AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation, void *mapPointer) override; + GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation, void *mapPointer) override; void closeSharedHandle(GraphicsAllocation *gfxAllocation) override; void closeInternalHandle(uint64_t &handle, uint32_t handleId, GraphicsAllocation *graphicsAllocation) override; diff --git a/shared/source/os_interface/windows/wddm_memory_manager.cpp b/shared/source/os_interface/windows/wddm_memory_manager.cpp index cf8ddebb84..a15d0a8236 100644 --- a/shared/source/os_interface/windows/wddm_memory_manager.cpp +++ b/shared/source/os_interface/windows/wddm_memory_manager.cpp @@ -504,7 +504,7 @@ bool WddmMemoryManager::isNTHandle(osHandle handle, uint32_t rootDeviceIndex) { return status; } -GraphicsAllocation *WddmMemoryManager::createAllocationFromHandle(osHandle handle, bool requireSpecificBitness, bool ntHandle, AllocationType allocationType, uint32_t rootDeviceIndex) { +GraphicsAllocation *WddmMemoryManager::createAllocationFromHandle(osHandle handle, bool requireSpecificBitness, bool ntHandle, AllocationType allocationType, uint32_t rootDeviceIndex, void *mapPointer) { auto allocation = std::make_unique(rootDeviceIndex, allocationType, nullptr, 0, handle, MemoryPool::SystemCpuInaccessible, maxOsContextCount, 0llu); bool status = ntHandle ? getWddm(rootDeviceIndex).openNTHandle(reinterpret_cast(static_cast(handle)), allocation.get()) @@ -518,18 +518,22 @@ GraphicsAllocation *WddmMemoryManager::createAllocationFromHandle(osHandle handl size_t size = allocation->getDefaultGmm()->gmmResourceInfo->getSizeAllocation(); allocation->setSize(size); - if (is32bit) { - void *ptr = nullptr; - if (!getWddm(rootDeviceIndex).reserveValidAddressRange(size, ptr)) { - return nullptr; + if (mapPointer == nullptr) { + if (is32bit) { + void *ptr = nullptr; + if (!getWddm(rootDeviceIndex).reserveValidAddressRange(size, ptr)) { + return nullptr; + } + allocation->setReservedAddressRange(ptr, size); + } else if (requireSpecificBitness && this->force32bitAllocations) { + allocation->set32BitAllocation(true); + auto gmmHelper = getGmmHelper(allocation->getRootDeviceIndex()); + allocation->setGpuBaseAddress(gmmHelper->canonize(getExternalHeapBaseAddress(allocation->getRootDeviceIndex(), false))); } - allocation->setReservedAddressRange(ptr, size); - } else if (requireSpecificBitness && this->force32bitAllocations) { - allocation->set32BitAllocation(true); - auto gmmHelper = getGmmHelper(allocation->getRootDeviceIndex()); - allocation->setGpuBaseAddress(gmmHelper->canonize(getExternalHeapBaseAddress(allocation->getRootDeviceIndex(), false))); + status = mapGpuVirtualAddress(allocation.get(), allocation->getReservedAddressPtr()); + } else { + status = mapPhysicalToVirtualMemory(allocation.get(), reinterpret_cast(mapPointer), size); } - status = mapGpuVirtualAddress(allocation.get(), allocation->getReservedAddressPtr()); DEBUG_BREAK_IF(!status); if (!status) { freeGraphicsMemoryImpl(allocation.release()); @@ -540,16 +544,16 @@ GraphicsAllocation *WddmMemoryManager::createAllocationFromHandle(osHandle handl return allocation.release(); } -GraphicsAllocation *WddmMemoryManager::createGraphicsAllocationFromMultipleSharedHandles(const std::vector &handles, AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation) { +GraphicsAllocation *WddmMemoryManager::createGraphicsAllocationFromMultipleSharedHandles(const std::vector &handles, AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation, void *mapPointer) { return nullptr; } -GraphicsAllocation *WddmMemoryManager::createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation) { - return createAllocationFromHandle(handle, requireSpecificBitness, false, properties.allocationType, properties.rootDeviceIndex); +GraphicsAllocation *WddmMemoryManager::createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation, void *mapPointer) { + return createAllocationFromHandle(handle, requireSpecificBitness, false, properties.allocationType, properties.rootDeviceIndex, mapPointer); } GraphicsAllocation *WddmMemoryManager::createGraphicsAllocationFromNTHandle(void *handle, uint32_t rootDeviceIndex, AllocationType allocType) { - return createAllocationFromHandle(toOsHandle(handle), false, true, allocType, rootDeviceIndex); + return createAllocationFromHandle(toOsHandle(handle), false, true, allocType, rootDeviceIndex, nullptr); } void WddmMemoryManager::addAllocationToHostPtrManager(GraphicsAllocation *gfxAllocation) { diff --git a/shared/source/os_interface/windows/wddm_memory_manager.h b/shared/source/os_interface/windows/wddm_memory_manager.h index 0f4055ba50..cb83555a1f 100644 --- a/shared/source/os_interface/windows/wddm_memory_manager.h +++ b/shared/source/os_interface/windows/wddm_memory_manager.h @@ -40,8 +40,8 @@ class WddmMemoryManager : public MemoryManager { void freeGraphicsMemoryImpl(GraphicsAllocation *gfxAllocation, bool isImportedAllocation) override; void handleFenceCompletion(GraphicsAllocation *allocation) override; - GraphicsAllocation *createGraphicsAllocationFromMultipleSharedHandles(const std::vector &handles, AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation) override; - GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation) override; + GraphicsAllocation *createGraphicsAllocationFromMultipleSharedHandles(const std::vector &handles, AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation, void *mapPointer) override; + GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation, void *mapPointer) override; GraphicsAllocation *createGraphicsAllocationFromNTHandle(void *handle, uint32_t rootDeviceIndex, AllocationType allocType) override; void addAllocationToHostPtrManager(GraphicsAllocation *memory) override; @@ -106,7 +106,7 @@ class WddmMemoryManager : public MemoryManager { MOCKABLE_VIRTUAL size_t getHugeGfxMemoryChunkSize(GfxMemoryAllocationMethod allocationMethod) const; MOCKABLE_VIRTUAL GraphicsAllocation *allocateHugeGraphicsMemory(const AllocationData &allocationData, bool sharedVirtualAddress); - GraphicsAllocation *createAllocationFromHandle(osHandle handle, bool requireSpecificBitness, bool ntHandle, AllocationType allocationType, uint32_t rootDeviceIndex); + GraphicsAllocation *createAllocationFromHandle(osHandle handle, bool requireSpecificBitness, bool ntHandle, AllocationType allocationType, uint32_t rootDeviceIndex, void *mapPointer); static bool validateAllocation(WddmAllocation *alloc); MOCKABLE_VIRTUAL bool createWddmAllocation(WddmAllocation *allocation, void *requiredGpuPtr); MOCKABLE_VIRTUAL bool mapGpuVirtualAddress(WddmAllocation *graphicsAllocation, const void *requiredGpuPtr); diff --git a/shared/source/unified_memory/unified_memory.h b/shared/source/unified_memory/unified_memory.h index 96357f5bd8..f30cef5ebb 100644 --- a/shared/source/unified_memory/unified_memory.h +++ b/shared/source/unified_memory/unified_memory.h @@ -14,7 +14,8 @@ enum InternalMemoryType : uint32_t { SVM = 0b1, DEVICE_UNIFIED_MEMORY = 0b10, HOST_UNIFIED_MEMORY = 0b100, - SHARED_UNIFIED_MEMORY = 0b1000 + SHARED_UNIFIED_MEMORY = 0b1000, + RESERVED_DEVICE_MEMORY = 0b10000 }; enum class InternalIpcMemoryType : uint32_t { diff --git a/shared/test/common/mocks/mock_memory_manager.cpp b/shared/test/common/mocks/mock_memory_manager.cpp index 4078a21d4c..ecc0be615a 100644 --- a/shared/test/common/mocks/mock_memory_manager.cpp +++ b/shared/test/common/mocks/mock_memory_manager.cpp @@ -218,9 +218,9 @@ GraphicsAllocation *MockMemoryManager::createGraphicsAllocationFromExistingStora return allocation; } -GraphicsAllocation *MockMemoryManager::createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation) { +GraphicsAllocation *MockMemoryManager::createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation, void *mapPointer) { if (handle != invalidSharedHandle) { - auto allocation = OsAgnosticMemoryManager::createGraphicsAllocationFromSharedHandle(handle, properties, requireSpecificBitness, isHostIpcAllocation, reuseSharedAllocation); + auto allocation = OsAgnosticMemoryManager::createGraphicsAllocationFromSharedHandle(handle, properties, requireSpecificBitness, isHostIpcAllocation, reuseSharedAllocation, mapPointer); this->capturedSharedHandle = handle; return allocation; } else { diff --git a/shared/test/common/mocks/mock_memory_manager.h b/shared/test/common/mocks/mock_memory_manager.h index 3e151154c7..81b710a34d 100644 --- a/shared/test/common/mocks/mock_memory_manager.h +++ b/shared/test/common/mocks/mock_memory_manager.h @@ -79,7 +79,7 @@ class MockMemoryManager : public MemoryManagerCreate { GraphicsAllocation *allocateGraphicsMemoryWithProperties(const AllocationProperties &properties) override; GraphicsAllocation *allocateGraphicsMemoryWithProperties(const AllocationProperties &properties, const void *ptr) override; GraphicsAllocation *createGraphicsAllocationFromExistingStorage(AllocationProperties &properties, void *ptr, MultiGraphicsAllocation &multiGraphicsAllocation) override; - GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation) override; + GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation, void *mapPointer) override; GraphicsAllocation *createGraphicsAllocationFromNTHandle(void *handle, uint32_t rootDeviceIndex, AllocationType allocType) override; void *allocateSystemMemory(size_t size, size_t alignment) override; @@ -315,11 +315,11 @@ class FailMemoryManager : public MockMemoryManager { return nullptr; } - GraphicsAllocation *createGraphicsAllocationFromMultipleSharedHandles(const std::vector &handles, AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation) override { + GraphicsAllocation *createGraphicsAllocationFromMultipleSharedHandles(const std::vector &handles, AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation, void *mapPointer) override { return nullptr; } - GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation) override { + GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation, void *mapPointer) override { return nullptr; } GraphicsAllocation *createGraphicsAllocationFromNTHandle(void *handle, uint32_t rootDeviceIndex, AllocationType allocType) override { diff --git a/shared/test/unit_test/command_stream/compute_mode_tests.h b/shared/test/unit_test/command_stream/compute_mode_tests.h index 55c03f9fe8..2c4b6232b7 100644 --- a/shared/test/unit_test/command_stream/compute_mode_tests.h +++ b/shared/test/unit_test/command_stream/compute_mode_tests.h @@ -86,7 +86,7 @@ struct ComputeModeRequirements : public ::testing::Test { device->resetCommandStreamReceiver(csr); AllocationProperties properties(device->getRootDeviceIndex(), false, MemoryConstants::pageSize, AllocationType::SHARED_BUFFER, false, {}); - alloc = device->getMemoryManager()->createGraphicsAllocationFromSharedHandle(static_cast(123), properties, false, false, true); + alloc = device->getMemoryManager()->createGraphicsAllocationFromSharedHandle(static_cast(123), properties, false, false, true, nullptr); } void TearDown() override { diff --git a/shared/test/unit_test/device/neo_device_tests.cpp b/shared/test/unit_test/device/neo_device_tests.cpp index aa9ba96fa2..30e4f2fba1 100644 --- a/shared/test/unit_test/device/neo_device_tests.cpp +++ b/shared/test/unit_test/device/neo_device_tests.cpp @@ -457,8 +457,8 @@ TEST_F(DeviceGetCapsTest, givenFlagEnabled64kbPagesWhenCallConstructorMemoryMana MockMemoryManager(ExecutionEnvironment &executionEnvironment) : MemoryManager(executionEnvironment) {} void addAllocationToHostPtrManager(GraphicsAllocation *memory) override{}; void removeAllocationFromHostPtrManager(GraphicsAllocation *memory) override{}; - GraphicsAllocation *createGraphicsAllocationFromMultipleSharedHandles(const std::vector &handles, AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation) override { return nullptr; } - GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation) override { return nullptr; }; + GraphicsAllocation *createGraphicsAllocationFromMultipleSharedHandles(const std::vector &handles, AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation, void *mapPointer) override { return nullptr; } + GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation, void *mapPointer) override { return nullptr; }; GraphicsAllocation *createGraphicsAllocationFromNTHandle(void *handle, uint32_t rootDeviceIndex, AllocationType allocType) override { return nullptr; }; AllocationStatus populateOsHandles(OsHandleStorage &handleStorage, uint32_t rootDeviceIndex) override { return AllocationStatus::Success; }; void cleanOsHandles(OsHandleStorage &handleStorage, uint32_t rootDeviceIndex) override{}; diff --git a/shared/test/unit_test/gen12lp/coherency_tests_gen12lp.inl b/shared/test/unit_test/gen12lp/coherency_tests_gen12lp.inl index ccff5ad8b2..d82d7713d4 100644 --- a/shared/test/unit_test/gen12lp/coherency_tests_gen12lp.inl +++ b/shared/test/unit_test/gen12lp/coherency_tests_gen12lp.inl @@ -48,7 +48,7 @@ struct Gen12LpCoherencyRequirements : public ::testing::Test { device->resetCommandStreamReceiver(csr); AllocationProperties properties(device->getRootDeviceIndex(), false, MemoryConstants::pageSize, AllocationType::SHARED_BUFFER, false, {}); - alloc = device->getMemoryManager()->createGraphicsAllocationFromSharedHandle(static_cast(123), properties, false, false, true); + alloc = device->getMemoryManager()->createGraphicsAllocationFromSharedHandle(static_cast(123), properties, false, false, true, nullptr); } void TearDown() override { diff --git a/shared/test/unit_test/memory_manager/memory_manager_multi_device_tests.cpp b/shared/test/unit_test/memory_manager/memory_manager_multi_device_tests.cpp index c958abcc8f..e721bfb496 100644 --- a/shared/test/unit_test/memory_manager/memory_manager_multi_device_tests.cpp +++ b/shared/test/unit_test/memory_manager/memory_manager_multi_device_tests.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019-2022 Intel Corporation + * Copyright (C) 2019-2023 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -45,12 +45,12 @@ TEST_P(MemoryManagerMultiDeviceTest, givenRootDeviceIndexSpecifiedWhenAllocateGr EXPECT_EQ(rootDeviceIndex, gfxAllocation->getRootDeviceIndex()); memoryManager->freeGraphicsMemory(gfxAllocation); - gfxAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(static_cast(0u), properties, false, false, true); + gfxAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(static_cast(0u), properties, false, false, true, nullptr); ASSERT_NE(gfxAllocation, nullptr); EXPECT_EQ(rootDeviceIndex, gfxAllocation->getRootDeviceIndex()); memoryManager->freeGraphicsMemory(gfxAllocation); - gfxAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(static_cast(0u), properties, true, false, true); + gfxAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(static_cast(0u), properties, true, false, true, nullptr); ASSERT_NE(gfxAllocation, nullptr); EXPECT_EQ(rootDeviceIndex, gfxAllocation->getRootDeviceIndex()); memoryManager->freeGraphicsMemory(gfxAllocation); diff --git a/shared/test/unit_test/memory_manager/memory_manager_tests.cpp b/shared/test/unit_test/memory_manager/memory_manager_tests.cpp index e7675fb614..800aeaa517 100644 --- a/shared/test/unit_test/memory_manager/memory_manager_tests.cpp +++ b/shared/test/unit_test/memory_manager/memory_manager_tests.cpp @@ -232,3 +232,62 @@ TEST(OsAgnosticMemoryManager, givenOsAgnosticMemoryManagerWhenGpuAddressReservat EXPECT_NE(static_cast(addressRange.address), 0x1234); EXPECT_NE(static_cast(addressRange.size), 0); } + +TEST(OsAgnosticMemoryManager, whenCallingCreateGraphicsAllocationFromMultipleSharedHandlesWithBasePointerFromOsAgnosticMemoryManagerThenNullptrIsReturned) { + MockExecutionEnvironment executionEnvironment; + OsAgnosticMemoryManager memoryManager(executionEnvironment); + uint32_t mockRootDeviceIndex = 0u; + DeviceBitfield mockDeviceBitfield(0b1); + + std::vector handles{6, 7}; + AllocationProperties properties = {mockRootDeviceIndex, + true, + MemoryConstants::pageSize, + AllocationType::BUFFER, + false, + mockDeviceBitfield}; + bool requireSpecificBitness{}; + bool isHostIpcAllocation{}; + uint64_t basePointer = 0x1234; + auto ptr = memoryManager.createGraphicsAllocationFromMultipleSharedHandles(handles, properties, requireSpecificBitness, isHostIpcAllocation, true, reinterpret_cast(basePointer)); + EXPECT_EQ(nullptr, ptr); +} + +TEST(OsAgnosticMemoryManager, whenCallingCreateGraphicsAllocationFromSharedHandleWithNullBasePointerFromOsAgnosticMemoryManagerThenBasicPointerReturned) { + uint32_t mockRootDeviceIndex = 0u; + DeviceBitfield mockDeviceBitfield(0b1); + MockExecutionEnvironment executionEnvironment(defaultHwInfo.get()); + MemoryManagerCreate memoryManager(false, false, executionEnvironment); + osHandle handle = 1; + auto size = 4096u; + AllocationProperties properties(mockRootDeviceIndex, false, size, AllocationType::SHARED_BUFFER, false, mockDeviceBitfield); + auto sharedAllocation = memoryManager.createGraphicsAllocationFromSharedHandle(handle, properties, false, false, true, nullptr); + EXPECT_NE(nullptr, sharedAllocation); + EXPECT_EQ(reinterpret_cast(1u), sharedAllocation->getUnderlyingBuffer()); + EXPECT_FALSE(sharedAllocation->isCoherent()); + EXPECT_NE(nullptr, sharedAllocation->getUnderlyingBuffer()); + EXPECT_EQ(size, sharedAllocation->getUnderlyingBufferSize()); + EXPECT_EQ(MemoryPool::SystemCpuInaccessible, sharedAllocation->getMemoryPool()); + + memoryManager.freeGraphicsMemory(sharedAllocation); +} + +TEST(OsAgnosticMemoryManager, whenCallingCreateGraphicsAllocationFromSharedHandleWithBasePointerFromOsAgnosticMemoryManagerThenBasePointerReturned) { + uint32_t mockRootDeviceIndex = 0u; + DeviceBitfield mockDeviceBitfield(0b1); + MockExecutionEnvironment executionEnvironment(defaultHwInfo.get()); + MemoryManagerCreate memoryManager(false, false, executionEnvironment); + osHandle handle = 1; + auto size = 4096u; + uint64_t basePointer = 0x1234; + AllocationProperties properties(mockRootDeviceIndex, false, size, AllocationType::SHARED_BUFFER, false, mockDeviceBitfield); + auto sharedAllocation = memoryManager.createGraphicsAllocationFromSharedHandle(handle, properties, false, false, true, reinterpret_cast(basePointer)); + EXPECT_NE(nullptr, sharedAllocation); + EXPECT_EQ(reinterpret_cast(0x1234), sharedAllocation->getUnderlyingBuffer()); + EXPECT_FALSE(sharedAllocation->isCoherent()); + EXPECT_NE(nullptr, sharedAllocation->getUnderlyingBuffer()); + EXPECT_EQ(size, sharedAllocation->getUnderlyingBufferSize()); + EXPECT_EQ(MemoryPool::SystemCpuInaccessible, sharedAllocation->getMemoryPool()); + + memoryManager.freeGraphicsMemory(sharedAllocation); +} \ No newline at end of file diff --git a/shared/test/unit_test/os_interface/linux/drm_memory_manager_localmem_prelim_tests.cpp b/shared/test/unit_test/os_interface/linux/drm_memory_manager_localmem_prelim_tests.cpp index 6766838b58..74379b75d8 100644 --- a/shared/test/unit_test/os_interface/linux/drm_memory_manager_localmem_prelim_tests.cpp +++ b/shared/test/unit_test/os_interface/linux/drm_memory_manager_localmem_prelim_tests.cpp @@ -2037,7 +2037,7 @@ TEST_F(DrmMemoryManagerTestPrelim, whenSettingNumHandlesThenTheyAreRetrievedCorr size_t size = 65536u * 2; AllocationProperties properties(rootDeviceIndex, true, size, AllocationType::BUFFER_HOST_MEMORY, false, device->getDeviceBitfield()); - auto graphicsAllocation = memoryManager->createGraphicsAllocationFromMultipleSharedHandles(handles, properties, false, false, true); + auto graphicsAllocation = memoryManager->createGraphicsAllocationFromMultipleSharedHandles(handles, properties, false, false, true, nullptr); ASSERT_NE(nullptr, graphicsAllocation); uint32_t numHandlesExpected = 8; @@ -2060,10 +2060,10 @@ TEST_F(DrmMemoryManagerTestPrelim, whenCreatingAllocationFromMultipleSharedHandl memoryManager->failOnfindAndReferenceSharedBufferObject = false; - auto graphicsAllocationFromReferencedHandle = memoryManager->createGraphicsAllocationFromMultipleSharedHandles(handles, properties, false, false, true); + auto graphicsAllocationFromReferencedHandle = memoryManager->createGraphicsAllocationFromMultipleSharedHandles(handles, properties, false, false, true, nullptr); ASSERT_NE(nullptr, graphicsAllocationFromReferencedHandle); - auto graphicsAllocationFromReferencedHandle2 = memoryManager->createGraphicsAllocationFromMultipleSharedHandles(handles, properties, false, false, true); + auto graphicsAllocationFromReferencedHandle2 = memoryManager->createGraphicsAllocationFromMultipleSharedHandles(handles, properties, false, false, true, nullptr); ASSERT_NE(nullptr, graphicsAllocationFromReferencedHandle2); DrmAllocation *drmAllocationFromReferencedHandle = static_cast(graphicsAllocationFromReferencedHandle); @@ -2082,6 +2082,40 @@ TEST_F(DrmMemoryManagerTestPrelim, whenCreatingAllocationFromMultipleSharedHandl memoryManager->freeGraphicsMemory(graphicsAllocationFromReferencedHandle); } +TEST_F(DrmMemoryManagerTestPrelim, whenCreatingAllocationFromMultipleSharedHandlesWithSharingResourcesWithBasePointerThenUnderlyingPointerIsTheSame) { + mock->ioctlExpected.primeFdToHandle = 4; + mock->ioctlExpected.gemWait = 2; + mock->ioctlExpected.gemClose = 2; + + std::vector handles{6, 7}; + size_t size = 65536u * 2; + AllocationProperties properties(rootDeviceIndex, true, size, AllocationType::BUFFER_HOST_MEMORY, false, device->getDeviceBitfield()); + + memoryManager->failOnfindAndReferenceSharedBufferObject = false; + + auto graphicsAllocationFromReferencedHandle = memoryManager->createGraphicsAllocationFromMultipleSharedHandles(handles, properties, false, false, true, nullptr); + ASSERT_NE(nullptr, graphicsAllocationFromReferencedHandle); + + auto graphicsAllocationFromReferencedHandle2 = memoryManager->createGraphicsAllocationFromMultipleSharedHandles(handles, properties, false, false, true, reinterpret_cast(graphicsAllocationFromReferencedHandle->getGpuAddress())); + ASSERT_NE(nullptr, graphicsAllocationFromReferencedHandle2); + + DrmAllocation *drmAllocationFromReferencedHandle = static_cast(graphicsAllocationFromReferencedHandle); + auto boFromReferencedHandle = drmAllocationFromReferencedHandle->getBO(); + EXPECT_EQ(boFromReferencedHandle->peekHandle(), (int)this->mock->outputHandle); + EXPECT_NE(0llu, boFromReferencedHandle->peekAddress()); + + DrmAllocation *drmAllocationFromReferencedHandle2 = static_cast(graphicsAllocationFromReferencedHandle2); + auto boFromReferencedHandle2 = drmAllocationFromReferencedHandle2->getBO(); + EXPECT_EQ(boFromReferencedHandle2->peekHandle(), (int)this->mock->outputHandle); + EXPECT_NE(0llu, boFromReferencedHandle2->peekAddress()); + + EXPECT_EQ(boFromReferencedHandle->peekAddress(), boFromReferencedHandle2->peekAddress()); + + EXPECT_EQ(graphicsAllocationFromReferencedHandle->getGpuAddress(), graphicsAllocationFromReferencedHandle2->getGpuAddress()); + memoryManager->freeGraphicsMemory(graphicsAllocationFromReferencedHandle2); + memoryManager->freeGraphicsMemory(graphicsAllocationFromReferencedHandle); +} + TEST_F(DrmMemoryManagerTestPrelim, whenCreatingAllocationFromMultipleSharedHandlesWithNoSharingResourcesThenDifferentAllocationsAreReturned) { mock->ioctlExpected.primeFdToHandle = 4; mock->ioctlExpected.gemWait = 2; @@ -2093,10 +2127,10 @@ TEST_F(DrmMemoryManagerTestPrelim, whenCreatingAllocationFromMultipleSharedHandl memoryManager->failOnfindAndReferenceSharedBufferObject = false; - auto graphicsAllocationFromReferencedHandle = memoryManager->createGraphicsAllocationFromMultipleSharedHandles(handles, properties, false, false, false); + auto graphicsAllocationFromReferencedHandle = memoryManager->createGraphicsAllocationFromMultipleSharedHandles(handles, properties, false, false, false, nullptr); ASSERT_NE(nullptr, graphicsAllocationFromReferencedHandle); - auto graphicsAllocationFromReferencedHandle2 = memoryManager->createGraphicsAllocationFromMultipleSharedHandles(handles, properties, false, false, false); + auto graphicsAllocationFromReferencedHandle2 = memoryManager->createGraphicsAllocationFromMultipleSharedHandles(handles, properties, false, false, false, nullptr); ASSERT_NE(nullptr, graphicsAllocationFromReferencedHandle2); DrmAllocation *drmAllocationFromReferencedHandle = static_cast(graphicsAllocationFromReferencedHandle); @@ -2125,7 +2159,7 @@ TEST_F(DrmMemoryManagerTestPrelim, whenCreatingAllocationFromMultipleSharedHandl AllocationProperties properties(rootDeviceIndex, true, size, AllocationType::BUFFER_HOST_MEMORY, false, device->getDeviceBitfield()); memoryManager->failOnfindAndReferenceSharedBufferObject = false; - auto graphicsAllocation = memoryManager->createGraphicsAllocationFromMultipleSharedHandles(handles, properties, false, false, true); + auto graphicsAllocation = memoryManager->createGraphicsAllocationFromMultipleSharedHandles(handles, properties, false, false, true, nullptr); ASSERT_NE(nullptr, graphicsAllocation); DrmAllocation *drmAllocation = static_cast(graphicsAllocation); @@ -2133,7 +2167,7 @@ TEST_F(DrmMemoryManagerTestPrelim, whenCreatingAllocationFromMultipleSharedHandl EXPECT_EQ(bo->peekHandle(), (int)this->mock->outputHandle); EXPECT_NE(0llu, bo->peekAddress()); - auto graphicsAllocationFromReferencedHandle = memoryManager->createGraphicsAllocationFromMultipleSharedHandles(handles, properties, false, false, true); + auto graphicsAllocationFromReferencedHandle = memoryManager->createGraphicsAllocationFromMultipleSharedHandles(handles, properties, false, false, true, nullptr); ASSERT_NE(nullptr, graphicsAllocationFromReferencedHandle); DrmAllocation *drmAllocationFromReferencedHandle = static_cast(graphicsAllocationFromReferencedHandle); @@ -2155,7 +2189,7 @@ TEST_F(DrmMemoryManagerTestPrelim, whenCreatingAllocationFromMultipleSharedHandl AllocationProperties properties(rootDeviceIndex, true, size, AllocationType::BUFFER_HOST_MEMORY, false, device->getDeviceBitfield()); memoryManager->failOnfindAndReferenceSharedBufferObject = false; - auto graphicsAllocation = memoryManager->createGraphicsAllocationFromMultipleSharedHandles(handles, properties, false, false, true); + auto graphicsAllocation = memoryManager->createGraphicsAllocationFromMultipleSharedHandles(handles, properties, false, false, true, nullptr); ASSERT_NE(nullptr, graphicsAllocation); const bool prefer57bitAddressing = memoryManager->getGfxPartition(rootDeviceIndex)->getHeapLimit(HeapIndex::HEAP_EXTENDED) > 0; @@ -2187,7 +2221,7 @@ TEST_F(DrmMemoryManagerTestPrelim, whenCreatingAllocationFromMultipleSharedHandl AllocationProperties properties(rootDeviceIndex, true, size, AllocationType::BUFFER_HOST_MEMORY, false, device->getDeviceBitfield()); memoryManager->failOnfindAndReferenceSharedBufferObject = false; - auto graphicsAllocation = memoryManager->createGraphicsAllocationFromMultipleSharedHandles(handles, properties, false, false, true); + auto graphicsAllocation = memoryManager->createGraphicsAllocationFromMultipleSharedHandles(handles, properties, false, false, true, nullptr); EXPECT_EQ(nullptr, graphicsAllocation); } @@ -2200,7 +2234,7 @@ TEST_F(DrmMemoryManagerTestPrelim, whenCreatingAllocationFromMultipleSharedHandl size_t size = 65536u * 2; AllocationProperties properties(rootDeviceIndex, true, size, AllocationType::BUFFER_HOST_MEMORY, false, device->getDeviceBitfield()); - auto graphicsAllocation = memoryManager->createGraphicsAllocationFromMultipleSharedHandles(handles, properties, false, false, true); + auto graphicsAllocation = memoryManager->createGraphicsAllocationFromMultipleSharedHandles(handles, properties, false, false, true, nullptr); ASSERT_NE(nullptr, graphicsAllocation); DrmAllocation *drmAllocation = static_cast(graphicsAllocation); @@ -2253,7 +2287,7 @@ TEST_F(DrmMemoryManagerTestPrelim, givenDrmMemoryManagerAndOsHandleWhenCreateIsC size_t size = 4096u; AllocationProperties properties(rootDeviceIndex, false, size, AllocationType::BUFFER_HOST_MEMORY, false, {}); - auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(handle, properties, false, true, true); + auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(handle, properties, false, true, true, nullptr); ASSERT_NE(nullptr, graphicsAllocation); EXPECT_NE(nullptr, graphicsAllocation->getUnderlyingBuffer()); @@ -2285,7 +2319,7 @@ TEST_F(DrmMemoryManagerTestPrelim, AllocationProperties properties(rootDeviceIndex, false, size, AllocationType::BUFFER_HOST_MEMORY, false, {}); testing::internal::CaptureStdout(); - auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(handle, properties, false, true, true); + auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(handle, properties, false, true, true, nullptr); ASSERT_NE(nullptr, graphicsAllocation); EXPECT_NE(nullptr, graphicsAllocation->getUnderlyingBuffer()); @@ -2325,7 +2359,7 @@ TEST_F(DrmMemoryManagerTestPrelim, givenDrmMemoryManagerAndOsHandleWhenCreateIsC size_t size = 4096u; AllocationProperties properties(rootDeviceIndex, false, size, AllocationType::BUFFER_HOST_MEMORY, false, {}); - auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(handle, properties, false, true, true); + auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(handle, properties, false, true, true, nullptr); ASSERT_NE(nullptr, graphicsAllocation); EXPECT_NE(nullptr, graphicsAllocation->getUnderlyingBuffer()); @@ -2354,7 +2388,7 @@ TEST_F(DrmMemoryManagerTestPrelim, givenDrmMemoryManagerAndOsHandleWhenCreateIsC size_t size = 4096u; AllocationProperties properties(rootDeviceIndex, false, size, AllocationType::BUFFER_HOST_MEMORY, false, {}); - auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(handle, properties, false, true, true); + auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(handle, properties, false, true, true, nullptr); ASSERT_NE(nullptr, graphicsAllocation); EXPECT_NE(nullptr, graphicsAllocation->getUnderlyingBuffer()); @@ -2369,7 +2403,7 @@ TEST_F(DrmMemoryManagerTestPrelim, givenDrmMemoryManagerAndOsHandleWhenCreateIsC EXPECT_EQ(1u, bo->getRefCount()); EXPECT_EQ(size, bo->peekSize()); - auto graphicsAllocation2 = memoryManager->createGraphicsAllocationFromSharedHandle(handle, properties, false, true, true); + auto graphicsAllocation2 = memoryManager->createGraphicsAllocationFromSharedHandle(handle, properties, false, true, true, nullptr); ASSERT_NE(nullptr, graphicsAllocation2); EXPECT_NE(nullptr, graphicsAllocation2->getUnderlyingBuffer()); @@ -2396,7 +2430,7 @@ TEST_F(DrmMemoryManagerTestPrelim, givenDrmMemoryManagerAndOsHandleWhenCreateIsC mock->returnIoctlExtraErrorValue = true; mock->failOnMmapOffset = true; - auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(handle, properties, false, true, true); + auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(handle, properties, false, true, true, nullptr); EXPECT_EQ(nullptr, graphicsAllocation); memoryManager->freeGraphicsMemory(graphicsAllocation); @@ -2414,7 +2448,7 @@ TEST_F(DrmMemoryManagerTestPrelim, givenDrmMemoryManagerAndUseMmapObjectSetToFal AllocationProperties properties(rootDeviceIndex, false, size, AllocationType::BUFFER_HOST_MEMORY, false, {}); properties.useMmapObject = false; - auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(handle, properties, false, true, true); + auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(handle, properties, false, true, true, nullptr); EXPECT_EQ(static_cast(handle), static_cast(graphicsAllocation)->getBO()->peekHandle()); memoryManager->freeGraphicsMemory(graphicsAllocation); @@ -2433,7 +2467,7 @@ TEST_F(DrmMemoryManagerTestPrelim, givenDrmMemoryManagerWithoutMemoryInfoThenDrm size_t size = 4096u; AllocationProperties properties(rootDeviceIndex, false, size, AllocationType::BUFFER_HOST_MEMORY, false, {}); - auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(handle, properties, false, true, true); + auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(handle, properties, false, true, true, nullptr); EXPECT_EQ(static_cast(handle), static_cast(graphicsAllocation)->getBO()->peekHandle()); memoryManager->freeGraphicsMemory(graphicsAllocation); @@ -2451,7 +2485,7 @@ TEST_F(DrmMemoryManagerTestPrelim, MmapFailWhenUSMHostAllocationFromSharedHandle return MAP_FAILED; }; - auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(handle, properties, false, true, true); + auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(handle, properties, false, true, true, nullptr); ASSERT_EQ(nullptr, graphicsAllocation); } diff --git a/shared/test/unit_test/os_interface/linux/drm_memory_manager_localmem_upstream_tests.cpp b/shared/test/unit_test/os_interface/linux/drm_memory_manager_localmem_upstream_tests.cpp index bde1b52375..a5c3fbffd9 100644 --- a/shared/test/unit_test/os_interface/linux/drm_memory_manager_localmem_upstream_tests.cpp +++ b/shared/test/unit_test/os_interface/linux/drm_memory_manager_localmem_upstream_tests.cpp @@ -232,7 +232,7 @@ TEST_F(DrmMemoryManagerUsmSharedHandleTest, givenDrmMemoryManagerAndOsHandleWhen size_t size = 4096u; AllocationProperties properties(rootDeviceIndex, false, size, AllocationType::BUFFER_HOST_MEMORY, false, {}); - auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(handle, properties, false, true, true); + auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(handle, properties, false, true, true, nullptr); ASSERT_NE(nullptr, graphicsAllocation); EXPECT_EQ(this->mock->inputFd, (int)handle); diff --git a/shared/test/unit_test/os_interface/linux/drm_memory_manager_tests.cpp b/shared/test/unit_test/os_interface/linux/drm_memory_manager_tests.cpp index e62ae9aa6e..241c570740 100644 --- a/shared/test/unit_test/os_interface/linux/drm_memory_manager_tests.cpp +++ b/shared/test/unit_test/os_interface/linux/drm_memory_manager_tests.cpp @@ -61,14 +61,14 @@ TEST_P(MemoryManagerMultiDeviceSharedHandleTest, whenCreatingAllocationFromShare uint32_t handle0 = 0; uint32_t rootDeviceIndex0 = 0; AllocationProperties properties0{rootDeviceIndex0, true, MemoryConstants::pageSize, AllocationType::BUFFER, false, false, mockDeviceBitfield}; - auto gfxAllocation0 = memoryManager->createGraphicsAllocationFromSharedHandle(handle0, properties0, false, false, true); + auto gfxAllocation0 = memoryManager->createGraphicsAllocationFromSharedHandle(handle0, properties0, false, false, true, nullptr); ASSERT_NE(gfxAllocation0, nullptr); EXPECT_EQ(rootDeviceIndex0, gfxAllocation0->getRootDeviceIndex()); uint32_t handle1 = 0; uint32_t rootDeviceIndex1 = 0; AllocationProperties properties1{rootDeviceIndex1, true, MemoryConstants::pageSize, AllocationType::BUFFER, false, false, mockDeviceBitfield}; - auto gfxAllocation1 = memoryManager->createGraphicsAllocationFromSharedHandle(handle1, properties1, false, false, true); + auto gfxAllocation1 = memoryManager->createGraphicsAllocationFromSharedHandle(handle1, properties1, false, false, true, nullptr); ASSERT_NE(gfxAllocation1, nullptr); EXPECT_EQ(rootDeviceIndex1, gfxAllocation1->getRootDeviceIndex()); @@ -85,14 +85,14 @@ TEST_P(MemoryManagerMultiDeviceSharedHandleTest, whenCreatingAllocationFromShare uint32_t handle0 = 0; uint32_t rootDeviceIndex0 = 0; AllocationProperties properties0{rootDeviceIndex0, true, MemoryConstants::pageSize, AllocationType::BUFFER, false, false, mockDeviceBitfield}; - auto gfxAllocation0 = memoryManager->createGraphicsAllocationFromSharedHandle(handle0, properties0, false, false, true); + auto gfxAllocation0 = memoryManager->createGraphicsAllocationFromSharedHandle(handle0, properties0, false, false, true, nullptr); ASSERT_NE(gfxAllocation0, nullptr); EXPECT_EQ(rootDeviceIndex0, gfxAllocation0->getRootDeviceIndex()); uint32_t handle1 = 0; uint32_t rootDeviceIndex1 = 1; AllocationProperties properties1{rootDeviceIndex1, true, MemoryConstants::pageSize, AllocationType::BUFFER, false, false, mockDeviceBitfield}; - auto gfxAllocation1 = memoryManager->createGraphicsAllocationFromSharedHandle(handle1, properties1, false, false, true); + auto gfxAllocation1 = memoryManager->createGraphicsAllocationFromSharedHandle(handle1, properties1, false, false, true, nullptr); ASSERT_NE(gfxAllocation1, nullptr); EXPECT_EQ(rootDeviceIndex1, gfxAllocation1->getRootDeviceIndex()); @@ -105,18 +105,43 @@ TEST_P(MemoryManagerMultiDeviceSharedHandleTest, whenCreatingAllocationFromShare memoryManager->freeGraphicsMemory(gfxAllocation1); } +TEST_P(MemoryManagerMultiDeviceSharedHandleTest, whenCreatingAllocationFromSharedHandleWithSameHandleAndDifferentRootDeviceWithBasePointerOnSecondDeviceThenSamePointerIsUsed) { + uint32_t handle0 = 0; + uint32_t rootDeviceIndex0 = 0; + AllocationProperties properties0{rootDeviceIndex0, true, MemoryConstants::pageSize, AllocationType::BUFFER, false, false, mockDeviceBitfield}; + auto gfxAllocation0 = memoryManager->createGraphicsAllocationFromSharedHandle(handle0, properties0, false, false, true, nullptr); + ASSERT_NE(gfxAllocation0, nullptr); + EXPECT_EQ(rootDeviceIndex0, gfxAllocation0->getRootDeviceIndex()); + + uint32_t handle1 = 0; + uint32_t rootDeviceIndex1 = 1; + AllocationProperties properties1{rootDeviceIndex1, true, MemoryConstants::pageSize, AllocationType::BUFFER, false, false, mockDeviceBitfield}; + auto gfxAllocation1 = memoryManager->createGraphicsAllocationFromSharedHandle(handle1, properties1, false, false, true, reinterpret_cast(gfxAllocation0->getUnderlyingBuffer())); + ASSERT_NE(gfxAllocation1, nullptr); + EXPECT_EQ(rootDeviceIndex1, gfxAllocation1->getRootDeviceIndex()); + + DrmAllocation *drmAllocation0 = static_cast(gfxAllocation0); + DrmAllocation *drmAllocation1 = static_cast(gfxAllocation1); + + EXPECT_NE(drmAllocation0->getBO(), drmAllocation1->getBO()); + EXPECT_EQ(gfxAllocation0->getUnderlyingBuffer(), gfxAllocation1->getUnderlyingBuffer()); + + memoryManager->freeGraphicsMemory(gfxAllocation0); + memoryManager->freeGraphicsMemory(gfxAllocation1); +} + TEST_P(MemoryManagerMultiDeviceSharedHandleTest, whenCreatingAllocationFromSharedHandleWithDifferentHandleAndSameRootDeviceThenDifferentBOIsUsed) { uint32_t handle0 = 0; uint32_t rootDeviceIndex0 = 0; AllocationProperties properties0{rootDeviceIndex0, true, MemoryConstants::pageSize, AllocationType::BUFFER, false, false, mockDeviceBitfield}; - auto gfxAllocation0 = memoryManager->createGraphicsAllocationFromSharedHandle(handle0, properties0, false, false, true); + auto gfxAllocation0 = memoryManager->createGraphicsAllocationFromSharedHandle(handle0, properties0, false, false, true, nullptr); ASSERT_NE(gfxAllocation0, nullptr); EXPECT_EQ(rootDeviceIndex0, gfxAllocation0->getRootDeviceIndex()); uint32_t handle1 = 1; uint32_t rootDeviceIndex1 = 0; AllocationProperties properties1{rootDeviceIndex1, true, MemoryConstants::pageSize, AllocationType::BUFFER, false, false, mockDeviceBitfield}; - auto gfxAllocation1 = memoryManager->createGraphicsAllocationFromSharedHandle(handle1, properties1, false, false, true); + auto gfxAllocation1 = memoryManager->createGraphicsAllocationFromSharedHandle(handle1, properties1, false, false, true, nullptr); ASSERT_NE(gfxAllocation1, nullptr); EXPECT_EQ(rootDeviceIndex1, gfxAllocation1->getRootDeviceIndex()); @@ -133,14 +158,14 @@ TEST_P(MemoryManagerMultiDeviceSharedHandleTest, whenCreatingAllocationFromShare uint32_t handle0 = 0; uint32_t rootDeviceIndex0 = 0; AllocationProperties properties0{rootDeviceIndex0, true, MemoryConstants::pageSize, AllocationType::BUFFER, false, false, mockDeviceBitfield}; - auto gfxAllocation0 = memoryManager->createGraphicsAllocationFromSharedHandle(handle0, properties0, false, false, true); + auto gfxAllocation0 = memoryManager->createGraphicsAllocationFromSharedHandle(handle0, properties0, false, false, true, nullptr); ASSERT_NE(gfxAllocation0, nullptr); EXPECT_EQ(rootDeviceIndex0, gfxAllocation0->getRootDeviceIndex()); uint32_t handle1 = 1; uint32_t rootDeviceIndex1 = 1; AllocationProperties properties1{rootDeviceIndex1, true, MemoryConstants::pageSize, AllocationType::BUFFER, false, false, mockDeviceBitfield}; - auto gfxAllocation1 = memoryManager->createGraphicsAllocationFromSharedHandle(handle1, properties1, false, false, true); + auto gfxAllocation1 = memoryManager->createGraphicsAllocationFromSharedHandle(handle1, properties1, false, false, true, nullptr); ASSERT_NE(gfxAllocation1, nullptr); EXPECT_EQ(rootDeviceIndex1, gfxAllocation1->getRootDeviceIndex()); @@ -915,7 +940,7 @@ TEST_F(DrmMemoryManagerTest, GivenAllocationWhenClosingSharedHandleThenSucceeds) size_t size = 4096u; AllocationProperties properties(rootDeviceIndex, false, size, AllocationType::SHARED_BUFFER, false, {}); - auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(handle, properties, false, false, true); + auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(handle, properties, false, false, true, nullptr); EXPECT_EQ(handle, graphicsAllocation->peekSharedHandle()); memoryManager->closeSharedHandle(graphicsAllocation); @@ -936,7 +961,7 @@ TEST_F(DrmMemoryManagerTest, GivenAllocationWhenClosingInternalHandleThenSucceed size_t size = 4096u; AllocationProperties properties(rootDeviceIndex, false, size, AllocationType::SHARED_BUFFER, false, {}); - auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(handle, properties, false, false, true); + auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(handle, properties, false, false, true, nullptr); EXPECT_EQ(0, graphicsAllocation->createInternalHandle(this->memoryManager, 0u, handleVal)); memoryManager->closeInternalHandle(handleVal, 0u, graphicsAllocation); @@ -1020,7 +1045,7 @@ TEST_F(DrmMemoryManagerTest, GivenDeviceSharedAllocationWhichRequiresHostMapThen this->mock->queryEngineInfo(); AllocationProperties properties(rootDeviceIndex, false, size, AllocationType::GPU_TIMESTAMP_DEVICE_BUFFER, false, {}); - auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(handle, properties, false, true, false); + auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(handle, properties, false, true, false, nullptr); DrmAllocation *drmAlloc = (DrmAllocation *)graphicsAllocation; EXPECT_TRUE(isAligned(drmAlloc->getMmapPtr())); @@ -1792,7 +1817,7 @@ TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerAndOsHandleWhenCreateIsCalledT size_t size = 4096u; AllocationProperties properties(rootDeviceIndex, false, size, AllocationType::SHARED_BUFFER, false, {}); - auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(handle, properties, false, false, true); + auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(handle, properties, false, false, true, nullptr); ASSERT_NE(nullptr, graphicsAllocation); EXPECT_NE(nullptr, graphicsAllocation->getUnderlyingBuffer()); @@ -1822,7 +1847,7 @@ TEST_F(DrmMemoryManagerWithLocalMemoryTest, givenDrmMemoryManagerWithLocalMemory size_t size = 4096u; AllocationProperties properties(rootDeviceIndex, false, size, AllocationType::SHARED_BUFFER, false, {}); - auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(handle, properties, false, false, true); + auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(handle, properties, false, false, true, nullptr); ASSERT_NE(nullptr, graphicsAllocation); EXPECT_NE(nullptr, graphicsAllocation->getUnderlyingBuffer()); @@ -1863,7 +1888,7 @@ TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerAndOsHandleWhenCreateIsCalledA AllocationProperties properties(rootDeviceIndex, false, size, AllocationType::SHARED_BUFFER, false, false, 0u); ASSERT_TRUE(properties.subDevicesBitfield.none()); - auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(handle, properties, false, false, true); + auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(handle, properties, false, false, true, nullptr); ASSERT_NE(nullptr, graphicsAllocation); EXPECT_EQ(rootDeviceIndex, graphicsAllocation->getRootDeviceIndex()); @@ -1890,7 +1915,7 @@ TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerAndOsHandleWhenAllocationFails InjectedFunction method = [this, &handle](size_t failureIndex) { AllocationProperties properties(rootDeviceIndex, false, MemoryConstants::pageSize, AllocationType::SHARED_BUFFER, false, mockDeviceBitfield); - auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(handle, properties, false, false, true); + auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(handle, properties, false, false, true, nullptr); if (MemoryManagement::nonfailingAllocation == failureIndex) { EXPECT_NE(nullptr, graphicsAllocation); memoryManager->freeGraphicsMemory(graphicsAllocation); @@ -1924,7 +1949,7 @@ TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerAndThreeOsHandlesWhenReuseCrea AllocationProperties properties(rootDeviceIndex, false, MemoryConstants::pageSize, AllocationType::SHARED_BUFFER, false, mockDeviceBitfield); - graphicsAllocations[i] = memoryManager->createGraphicsAllocationFromSharedHandle(handles[i], properties, false, false, true); + graphicsAllocations[i] = memoryManager->createGraphicsAllocationFromSharedHandle(handles[i], properties, false, false, true, nullptr); // Clang-tidy false positive WA if (graphicsAllocations[i] == nullptr) { ASSERT_FALSE(true); @@ -1965,7 +1990,7 @@ TEST_F(DrmMemoryManagerTest, given32BitAddressingWhenBufferFromSharedHandleAndBi AllocationProperties properties(rootDeviceIndex, false, MemoryConstants::pageSize, AllocationType::SHARED_BUFFER, false, mockDeviceBitfield); - auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(handle, properties, true, false, true); + auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(handle, properties, true, false, true, nullptr); auto drmAllocation = static_cast(graphicsAllocation); EXPECT_TRUE(graphicsAllocation->is32BitAllocation()); EXPECT_EQ(1, lseekCalledCount); @@ -1983,7 +2008,7 @@ TEST_F(DrmMemoryManagerTest, given32BitAddressingWhenBufferFromSharedHandleIsCre osHandle handle = 1u; this->mock->outputHandle = 2u; AllocationProperties properties(rootDeviceIndex, false, MemoryConstants::pageSize, AllocationType::SHARED_BUFFER, false, mockDeviceBitfield); - auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(handle, properties, false, false, true); + auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(handle, properties, false, false, true, nullptr); auto drmAllocation = static_cast(graphicsAllocation); EXPECT_FALSE(graphicsAllocation->is32BitAllocation()); @@ -2003,7 +2028,7 @@ TEST_F(DrmMemoryManagerTest, givenLimitedRangeAllocatorWhenBufferFromSharedHandl osHandle handle = 1u; this->mock->outputHandle = 2u; AllocationProperties properties(rootDeviceIndex, false, MemoryConstants::pageSize, AllocationType::SHARED_BUFFER, false, mockDeviceBitfield); - auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(handle, properties, false, false, true); + auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(handle, properties, false, false, true, nullptr); EXPECT_FALSE(graphicsAllocation->is32BitAllocation()); auto drmAllocation = static_cast(graphicsAllocation); @@ -2021,7 +2046,7 @@ TEST_F(DrmMemoryManagerTest, givenNon32BitAddressingWhenBufferFromSharedHandleIs osHandle handle = 1u; this->mock->outputHandle = 2u; AllocationProperties properties(rootDeviceIndex, false, MemoryConstants::pageSize, AllocationType::SHARED_BUFFER, false, mockDeviceBitfield); - auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(handle, properties, true, false, true); + auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(handle, properties, true, false, true, nullptr); auto drmAllocation = static_cast(graphicsAllocation); EXPECT_FALSE(graphicsAllocation->is32BitAllocation()); EXPECT_EQ(1, lseekCalledCount); @@ -2037,7 +2062,7 @@ TEST_F(DrmMemoryManagerTest, givenSharedHandleWhenAllocationIsCreatedAndIoctlPri osHandle handle = 1u; this->mock->outputHandle = 2u; AllocationProperties properties(rootDeviceIndex, false, MemoryConstants::pageSize, AllocationType::SHARED_BUFFER, false, mockDeviceBitfield); - auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(handle, properties, false, false, true); + auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(handle, properties, false, false, true, nullptr); EXPECT_EQ(nullptr, graphicsAllocation); memoryManager->freeGraphicsMemory(graphicsAllocation); } @@ -2050,8 +2075,8 @@ TEST_F(DrmMemoryManagerTest, givenTwoGraphicsAllocationsThatShareTheSameBufferOb osHandle sharedHandle = 1u; AllocationProperties properties(rootDeviceIndex, false, MemoryConstants::pageSize, AllocationType::SHARED_BUFFER, false, mockDeviceBitfield); - auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(sharedHandle, properties, false, false, true); - auto graphicsAllocation2 = memoryManager->createGraphicsAllocationFromSharedHandle(sharedHandle, properties, false, false, true); + auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(sharedHandle, properties, false, false, true, nullptr); + auto graphicsAllocation2 = memoryManager->createGraphicsAllocationFromSharedHandle(sharedHandle, properties, false, false, true, nullptr); auto currentResidentSize = testedCsr->getResidencyAllocations().size(); testedCsr->makeResident(*graphicsAllocation); @@ -2076,9 +2101,9 @@ TEST_F(DrmMemoryManagerTest, givenTwoGraphicsAllocationsThatDoesnShareTheSameBuf osHandle sharedHandle = 1u; AllocationProperties properties(rootDeviceIndex, false, MemoryConstants::pageSize, AllocationType::SHARED_BUFFER, false, {}); - auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(sharedHandle, properties, false, false, true); + auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(sharedHandle, properties, false, false, true, nullptr); mock->outputHandle++; - auto graphicsAllocation2 = memoryManager->createGraphicsAllocationFromSharedHandle(sharedHandle, properties, false, false, true); + auto graphicsAllocation2 = memoryManager->createGraphicsAllocationFromSharedHandle(sharedHandle, properties, false, false, true, nullptr); auto currentResidentSize = testedCsr->getResidencyAllocations().size(); testedCsr->makeResident(*graphicsAllocation); @@ -2341,7 +2366,7 @@ TEST_F(DrmMemoryManagerTest, givenSharedAllocationWithSmallerThenRealSizeWhenCre osHandle sharedHandle = 1u; AllocationProperties properties(rootDeviceIndex, false, MemoryConstants::pageSize, AllocationType::SHARED_BUFFER, false, {}); - auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(sharedHandle, properties, false, false, true); + auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(sharedHandle, properties, false, false, true, nullptr); EXPECT_NE(nullptr, graphicsAllocation->getUnderlyingBuffer()); EXPECT_EQ(realSize, graphicsAllocation->getUnderlyingBufferSize()); @@ -2709,7 +2734,7 @@ TEST_F(DrmMemoryManagerBasic, givenMemoryManagerWhenCreateAllocationFromHandleIs executionEnvironment)); auto osHandle = 1u; AllocationProperties properties(rootDeviceIndex, false, MemoryConstants::pageSize, AllocationType::SHARED_BUFFER, false, {}); - auto allocation = memoryManager->createGraphicsAllocationFromSharedHandle(osHandle, properties, false, false, true); + auto allocation = memoryManager->createGraphicsAllocationFromSharedHandle(osHandle, properties, false, false, true, nullptr); EXPECT_NE(nullptr, allocation); EXPECT_EQ(MemoryPool::SystemCpuInaccessible, allocation->getMemoryPool()); memoryManager->freeGraphicsMemory(allocation); @@ -3585,10 +3610,10 @@ TEST(DrmMemoryManagerFreeGraphicsMemoryUnreferenceTest, osHandle handle = 1u; AllocationProperties properties(rootDeviceIndex, false, MemoryConstants::pageSize, AllocationType::SHARED_BUFFER, false, {}); - auto allocation = memoryManger.createGraphicsAllocationFromSharedHandle(handle, properties, false, false, false); + auto allocation = memoryManger.createGraphicsAllocationFromSharedHandle(handle, properties, false, false, false, nullptr); ASSERT_NE(nullptr, allocation); - auto allocation2 = memoryManger.createGraphicsAllocationFromSharedHandle(handle, properties, false, false, false); + auto allocation2 = memoryManger.createGraphicsAllocationFromSharedHandle(handle, properties, false, false, false, nullptr); ASSERT_NE(nullptr, allocation2); EXPECT_NE(allocation->getGpuAddress(), allocation2->getGpuAddress()); @@ -3615,7 +3640,7 @@ TEST(DrmMemoryManagerFreeGraphicsMemoryUnreferenceTest, AllocationProperties properties(rootDeviceIndex, false, MemoryConstants::pageSize, AllocationType::SHARED_BUFFER, false, {}); testing::internal::CaptureStdout(); - auto allocation = memoryManger.createGraphicsAllocationFromSharedHandle(handle, properties, false, false, false); + auto allocation = memoryManger.createGraphicsAllocationFromSharedHandle(handle, properties, false, false, false, nullptr); ASSERT_NE(nullptr, allocation); std::stringstream expectedOutput; @@ -3645,10 +3670,10 @@ TEST(DrmMemoryManagerFreeGraphicsMemoryUnreferenceTest, osHandle handle = 1u; AllocationProperties properties(rootDeviceIndex, false, MemoryConstants::pageSize, AllocationType::SHARED_BUFFER, false, {}); - auto allocation = memoryManger.createGraphicsAllocationFromSharedHandle(handle, properties, false, false, true); + auto allocation = memoryManger.createGraphicsAllocationFromSharedHandle(handle, properties, false, false, true, nullptr); ASSERT_NE(nullptr, allocation); - auto allocation2 = memoryManger.createGraphicsAllocationFromSharedHandle(handle, properties, false, false, true); + auto allocation2 = memoryManger.createGraphicsAllocationFromSharedHandle(handle, properties, false, false, true, nullptr); ASSERT_NE(nullptr, allocation2); EXPECT_EQ(allocation->getGpuAddress(), allocation2->getGpuAddress()); @@ -3669,7 +3694,7 @@ TEST(DrmMemoryManagerFreeGraphicsMemoryUnreferenceTest, givenDrmMemoryManagerAnd osHandle handle = 1u; AllocationProperties properties(rootDeviceIndex, false, MemoryConstants::pageSize, AllocationType::SHARED_BUFFER, false, {}); - auto allocation = memoryManger.createGraphicsAllocationFromSharedHandle(handle, properties, false, false, true); + auto allocation = memoryManger.createGraphicsAllocationFromSharedHandle(handle, properties, false, false, true, nullptr); ASSERT_NE(nullptr, allocation); memoryManger.freeGraphicsMemory(allocation); diff --git a/shared/test/unit_test/os_interface/windows/wddm20_tests.cpp b/shared/test/unit_test/os_interface/windows/wddm20_tests.cpp index d16bac6082..7e56c4b7d5 100644 --- a/shared/test/unit_test/os_interface/windows/wddm20_tests.cpp +++ b/shared/test/unit_test/os_interface/windows/wddm20_tests.cpp @@ -501,7 +501,7 @@ TEST_F(Wddm20WithMockGdiDllTests, givenSharedHandleWhenCreateGraphicsAllocationF MemoryManagerCreate mm(false, false, *executionEnvironment); AllocationProperties properties(0, false, 4096u, AllocationType::SHARED_BUFFER, false, {}); - auto graphicsAllocation = mm.createGraphicsAllocationFromSharedHandle(ALLOCATION_HANDLE, properties, false, false, true); + auto graphicsAllocation = mm.createGraphicsAllocationFromSharedHandle(ALLOCATION_HANDLE, properties, false, false, true, nullptr); auto wddmAllocation = (WddmAllocation *)graphicsAllocation; ASSERT_NE(nullptr, wddmAllocation); @@ -529,6 +529,48 @@ TEST_F(Wddm20WithMockGdiDllTests, givenSharedHandleWhenCreateGraphicsAllocationF EXPECT_EQ(1u, destroyWithResourceHandleCalled); } +TEST_F(Wddm20WithMockGdiDllTests, givenSharedHandleWhenCreateGraphicsAllocationFromSharedHandleIsCalledWithMapPointerThenGraphicsAllocationWithSharedPropertiesIsCreated) { + void *pSysMem = (void *)0x1000; + + size_t sizeAlignedTo64Kb = 64 * KB; + void *reservedAddress; + EXPECT_TRUE(wddm->reserveValidAddressRange(sizeAlignedTo64Kb, reservedAddress)); + + std::unique_ptr gmm(new Gmm(getGmmHelper(), pSysMem, sizeAlignedTo64Kb, 0, GMM_RESOURCE_USAGE_OCL_BUFFER, false, {}, true)); + auto status = setSizesFcn(gmm->gmmResourceInfo.get(), 1u, 1024u, 1u); + EXPECT_EQ(0u, static_cast(status)); + + MemoryManagerCreate mm(false, false, *executionEnvironment); + AllocationProperties properties(0, false, sizeAlignedTo64Kb, AllocationType::SHARED_BUFFER, false, {}); + + auto graphicsAllocation = mm.createGraphicsAllocationFromSharedHandle(ALLOCATION_HANDLE, properties, false, false, true, reservedAddress); + auto wddmAllocation = (WddmAllocation *)graphicsAllocation; + ASSERT_NE(nullptr, wddmAllocation); + + EXPECT_EQ(ALLOCATION_HANDLE, wddmAllocation->peekSharedHandle()); + EXPECT_EQ(RESOURCE_HANDLE, wddmAllocation->resourceHandle); + EXPECT_NE(0u, wddmAllocation->getDefaultHandle()); + EXPECT_EQ(ALLOCATION_HANDLE, wddmAllocation->getDefaultHandle()); + EXPECT_EQ(reservedAddress, reinterpret_cast(wddmAllocation->getGpuAddress())); + EXPECT_EQ(sizeAlignedTo64Kb, wddmAllocation->getUnderlyingBufferSize()); + EXPECT_EQ(nullptr, wddmAllocation->getAlignedCpuPtr()); + EXPECT_NE(nullptr, wddmAllocation->getDefaultGmm()); + + EXPECT_EQ(sizeAlignedTo64Kb, wddmAllocation->getDefaultGmm()->gmmResourceInfo->getSizeAllocation()); + mm.freeGraphicsMemory(graphicsAllocation); + wddm->releaseReservedAddress(nullptr); + auto destroyWithResourceHandleCalled = 0u; + D3DKMT_DESTROYALLOCATION2 *ptrToDestroyAlloc2 = nullptr; + + status = getSizesFcn(destroyWithResourceHandleCalled, ptrToDestroyAlloc2); + + EXPECT_EQ(0u, ptrToDestroyAlloc2->Flags.SynchronousDestroy); + EXPECT_EQ(1u, ptrToDestroyAlloc2->Flags.AssumeNotInUse); + + EXPECT_EQ(0u, static_cast(status)); + EXPECT_EQ(1u, destroyWithResourceHandleCalled); +} + TEST_F(Wddm20WithMockGdiDllTests, givenSharedHandleWhenCreateGraphicsAllocationFromMultipleSharedHandlesIsCalledThenNullptrIsReturned) { void *pSysMem = (void *)0x1000; std::unique_ptr gmm(new Gmm(getGmmHelper(), pSysMem, 4096u, 0, GMM_RESOURCE_USAGE_OCL_BUFFER, false, {}, true)); @@ -539,7 +581,7 @@ TEST_F(Wddm20WithMockGdiDllTests, givenSharedHandleWhenCreateGraphicsAllocationF AllocationProperties properties(0, false, 4096u, AllocationType::SHARED_BUFFER, false, {}); std::vector handles{ALLOCATION_HANDLE}; - auto graphicsAllocation = mm.createGraphicsAllocationFromMultipleSharedHandles(handles, properties, false, false, true); + auto graphicsAllocation = mm.createGraphicsAllocationFromMultipleSharedHandles(handles, properties, false, false, true, nullptr); ASSERT_EQ(nullptr, graphicsAllocation); } @@ -552,7 +594,7 @@ TEST_F(Wddm20WithMockGdiDllTests, givenSharedHandleWhenCreateGraphicsAllocationF MemoryManagerCreate mm(false, false, *executionEnvironment); AllocationProperties properties(0, false, 4096, AllocationType::SHARED_BUFFER, false, {}); - auto graphicsAllocation = mm.createGraphicsAllocationFromSharedHandle(ALLOCATION_HANDLE, properties, false, false, true); + auto graphicsAllocation = mm.createGraphicsAllocationFromSharedHandle(ALLOCATION_HANDLE, properties, false, false, true, nullptr); auto wddmAllocation = (WddmAllocation *)graphicsAllocation; ASSERT_NE(nullptr, wddmAllocation);