Add MultiGraphicsAllocation to USM

Related-To: NEO-4672
Change-Id: I53ea4bea73ae6d52840146f63bc561bb90f9fe62
Signed-off-by: Mateusz Jablonski <mateusz.jablonski@intel.com>
This commit is contained in:
Mateusz Jablonski
2020-06-29 12:47:13 +02:00
committed by sys_ocldev
parent 5bc511b77d
commit 93c1e1b976
33 changed files with 306 additions and 237 deletions

View File

@@ -1108,15 +1108,16 @@ ze_result_t CommandListCoreFamily<gfxCoreFamily>::appendBlitFill(void *ptr,
size_t patternSize,
size_t size,
ze_event_handle_t hEvent) {
auto neoDevice = device->getNEODevice();
if (useMemCopyToBlitFill(patternSize)) {
NEO::AllocationProperties properties = {device->getNEODevice()->getRootDeviceIndex(),
NEO::AllocationProperties properties = {neoDevice->getRootDeviceIndex(),
false,
size,
NEO::GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY,
false,
device->getNEODevice()->getDeviceBitfield()};
neoDevice->getDeviceBitfield()};
properties.flags.allocateMemory = 1;
auto internalAlloc = device->getNEODevice()->getMemoryManager()->allocateGraphicsMemoryWithProperties(properties);
auto internalAlloc = neoDevice->getMemoryManager()->allocateGraphicsMemoryWithProperties(properties);
size_t offset = 0;
for (uint32_t i = 0; i < size / patternSize; i++) {
memcpy_s(ptrOffset(internalAlloc->getUnderlyingBuffer(), offset), (internalAlloc->getUnderlyingBufferSize() - offset), pattern, patternSize);
@@ -1133,10 +1134,14 @@ ze_result_t CommandListCoreFamily<gfxCoreFamily>::appendBlitFill(void *ptr,
if (dstAllocFound == false) {
return ZE_RESULT_ERROR_INVALID_ARGUMENT;
}
commandContainer.addToResidencyContainer(allocData->gpuAllocation);
auto gpuAllocation = allocData->gpuAllocations.getGraphicsAllocation(device->getRootDeviceIndex());
commandContainer.addToResidencyContainer(gpuAllocation);
uint32_t patternToCommand[4] = {};
memcpy_s(&patternToCommand, sizeof(patternToCommand), pattern, patternSize);
NEO::BlitCommandsHelper<GfxFamily>::dispatchBlitMemoryColorFill(allocData->gpuAllocation, patternToCommand, patternSize, *commandContainer.getCommandStream(), size, *device->getNEODevice()->getExecutionEnvironment()->rootDeviceEnvironments[device->getRootDeviceIndex()]);
NEO::BlitCommandsHelper<GfxFamily>::dispatchBlitMemoryColorFill(gpuAllocation, patternToCommand, patternSize,
*commandContainer.getCommandStream(),
size,
*neoDevice->getExecutionEnvironment()->rootDeviceEnvironments[device->getRootDeviceIndex()]);
appendSignalEventPostWalker(hEvent);
}
return ZE_RESULT_SUCCESS;
@@ -1214,7 +1219,7 @@ inline AlignedAllocationData CommandListCoreFamily<gfxCoreFamily>::getAlignedAll
alignedPtr = static_cast<uintptr_t>(alignDown(alloc->getGpuAddress(), NEO::EncodeSurfaceState<GfxFamily>::getSurfaceBaseAddressAlignment()));
hostPointerNeedsFlush = true;
} else {
alloc = allocData->gpuAllocation;
alloc = allocData->gpuAllocations.getGraphicsAllocation(device->getRootDeviceIndex());
alignedPtr = reinterpret_cast<uintptr_t>(buffer) - offset;
@@ -1381,7 +1386,7 @@ ze_result_t CommandListCoreFamily<gfxCoreFamily>::prepareIndirectParams(const ze
using GfxFamily = typename NEO::GfxFamilyMapper<gfxCoreFamily>::GfxFamily;
auto allocData = device->getDriverHandle()->getSvmAllocsManager()->getSVMAlloc(pThreadGroupDimensions);
if (allocData) {
auto alloc = allocData->gpuAllocation;
auto alloc = allocData->gpuAllocations.getGraphicsAllocation(device->getRootDeviceIndex());
commandContainer.addToResidencyContainer(alloc);
NEO::EncodeSetMMIO<GfxFamily>::encodeMEM(commandContainer, GPUGPU_DISPATCHDIMX,

View File

@@ -184,7 +184,7 @@ ze_result_t DeviceImp::evictMemory(void *ptr, size_t size) {
return ZE_RESULT_ERROR_INVALID_ARGUMENT;
}
NEO::MemoryOperationsHandler *memoryOperationsIface = neoDevice->getRootDeviceEnvironment().memoryOperationsInterface.get();
auto success = memoryOperationsIface->evict(*alloc->gpuAllocation);
auto success = memoryOperationsIface->evict(*alloc->gpuAllocations.getGraphicsAllocation(getRootDeviceIndex()));
return changeMemoryOperationStatusToL0ResultType(success);
}
@@ -402,7 +402,8 @@ ze_result_t DeviceImp::makeMemoryResident(void *ptr, size_t size) {
return ZE_RESULT_ERROR_INVALID_ARGUMENT;
}
NEO::MemoryOperationsHandler *memoryOperationsIface = neoDevice->getRootDeviceEnvironment().memoryOperationsInterface.get();
auto success = memoryOperationsIface->makeResident(ArrayRef<NEO::GraphicsAllocation *>(&alloc->gpuAllocation, 1));
auto gpuAllocation = alloc->gpuAllocations.getGraphicsAllocation(getRootDeviceIndex());
auto success = memoryOperationsIface->makeResident(ArrayRef<NEO::GraphicsAllocation *>(&gpuAllocation, 1));
return changeMemoryOperationStatusToL0ResultType(success);
}
@@ -693,13 +694,13 @@ NEO::GraphicsAllocation *DeviceImp::allocateManagedMemoryFromHostPtr(void *buffe
bool allocFound = false;
std::vector<NEO::SvmAllocationData *> allocDataArray = driverHandle->findAllocationsWithinRange(buffer, size, &allocFound);
if (allocFound) {
return allocDataArray[0]->gpuAllocation;
return allocDataArray[0]->gpuAllocations.getGraphicsAllocation(getRootDeviceIndex());
}
if (!allocDataArray.empty()) {
UNRECOVERABLE_IF(commandList == nullptr);
for (auto allocData : allocDataArray) {
allocation = allocData->gpuAllocation;
allocation = allocData->gpuAllocations.getGraphicsAllocation(getRootDeviceIndex());
char *allocAddress = reinterpret_cast<char *>(allocation->getGpuAddress());
size_t allocSize = allocData->size;
@@ -734,8 +735,8 @@ NEO::GraphicsAllocation *DeviceImp::allocateManagedMemoryFromHostPtr(void *buffe
return allocation;
}
NEO::SvmAllocationData allocData;
allocData.gpuAllocation = allocation;
NEO::SvmAllocationData allocData(getRootDeviceIndex());
allocData.gpuAllocations.addAllocation(allocation);
allocData.cpuAllocation = nullptr;
allocData.size = size;
allocData.memoryType = InternalMemoryType::NOT_SPECIFIED;

View File

@@ -91,7 +91,7 @@ ze_result_t DriverHandleImp::getMemAllocProperties(const void *ptr,
auto alloc = svmAllocsManager->getSVMAlloc(ptr);
if (alloc) {
pMemAllocProperties->type = parseUSMType(alloc->memoryType);
pMemAllocProperties->id = alloc->gpuAllocation->getGpuAddress();
pMemAllocProperties->id = alloc->gpuAllocations.getDefaultGraphicsAllocation()->getGpuAddress();
if (phDevice != nullptr) {
if (alloc->device == nullptr) {
@@ -234,7 +234,7 @@ bool DriverHandleImp::findAllocationDataForRange(const void *buffer,
// Return true if the whole range requested is covered by the same allocation
if (beginAllocData && endAllocData &&
(beginAllocData->gpuAllocation == endAllocData->gpuAllocation)) {
(beginAllocData->gpuAllocations.getDefaultGraphicsAllocation() == endAllocData->gpuAllocations.getDefaultGraphicsAllocation())) {
return true;
}
return false;
@@ -256,7 +256,7 @@ std::vector<NEO::SvmAllocationData *> DriverHandleImp::findAllocationsWithinRang
// Add the allocation that matches the end address range if there was no beginning allocation
// or the beginning allocation does not match the ending allocation
if (endAllocData) {
if ((beginAllocData && (beginAllocData->gpuAllocation != endAllocData->gpuAllocation)) ||
if ((beginAllocData && (beginAllocData->gpuAllocations.getDefaultGraphicsAllocation() != endAllocData->gpuAllocations.getDefaultGraphicsAllocation())) ||
!beginAllocData) {
allocDataArray.push_back(endAllocData);
}
@@ -264,7 +264,7 @@ std::vector<NEO::SvmAllocationData *> DriverHandleImp::findAllocationsWithinRang
// Return true if the whole range requested is covered by the same allocation
if (beginAllocData && endAllocData &&
(beginAllocData->gpuAllocation == endAllocData->gpuAllocation)) {
(beginAllocData->gpuAllocations.getDefaultGraphicsAllocation() == endAllocData->gpuAllocations.getDefaultGraphicsAllocation())) {
*allocationRangeCovered = true;
} else {
*allocationRangeCovered = false;

View File

@@ -490,7 +490,7 @@ ze_result_t KernelImp::setArgBuffer(uint32_t argIndex, size_t argSize, const voi
if (nullptr == svmAllocsManager->getSVMAlloc(requestedAddress)) {
return ZE_RESULT_ERROR_INVALID_ARGUMENT;
}
NEO::GraphicsAllocation *alloc = svmAllocsManager->getSVMAlloc(requestedAddress)->gpuAllocation;
NEO::GraphicsAllocation *alloc = svmAllocsManager->getSVMAlloc(requestedAddress)->gpuAllocations.getDefaultGraphicsAllocation();
auto gpuAddress = reinterpret_cast<uintptr_t>(requestedAddress);
return setArgBufferWithAlloc(argIndex, gpuAddress, alloc);
}

View File

@@ -21,7 +21,7 @@ void PageFaultManager::transferToCpu(void *ptr, size_t size, void *device) {
auto ret =
deviceImp->pageFaultCommandList->appendPageFaultCopy(allocData->cpuAllocation,
allocData->gpuAllocation,
allocData->gpuAllocations.getGraphicsAllocation(deviceImp->getRootDeviceIndex()),
allocData->size, true);
UNRECOVERABLE_IF(ret);
}
@@ -32,7 +32,7 @@ void PageFaultManager::transferToGpu(void *ptr, void *device) {
UNRECOVERABLE_IF(allocData == nullptr);
auto ret =
deviceImp->pageFaultCommandList->appendPageFaultCopy(allocData->gpuAllocation,
deviceImp->pageFaultCommandList->appendPageFaultCopy(allocData->gpuAllocations.getGraphicsAllocation(deviceImp->getRootDeviceIndex()),
allocData->cpuAllocation,
allocData->size, false);
UNRECOVERABLE_IF(ret);

View File

@@ -16,7 +16,7 @@ namespace L0 {
ze_result_t DriverHandleImp::getIpcMemHandle(const void *ptr, ze_ipc_mem_handle_t *pIpcHandle) {
NEO::SvmAllocationData *allocData = svmAllocsManager->getSVMAlloc(ptr);
if (allocData) {
uint64_t handle = allocData->gpuAllocation->peekInternalHandle(this->getMemoryManager());
uint64_t handle = allocData->gpuAllocations.getDefaultGraphicsAllocation()->peekInternalHandle(this->getMemoryManager());
memcpy_s(reinterpret_cast<void *>(pIpcHandle->data),
sizeof(ze_ipc_mem_handle_t),
&handle,
@@ -29,12 +29,13 @@ ze_result_t DriverHandleImp::getIpcMemHandle(const void *ptr, ze_ipc_mem_handle_
ze_result_t DriverHandleImp::openIpcMemHandle(ze_device_handle_t hDevice, ze_ipc_mem_handle_t pIpcHandle,
ze_ipc_memory_flag_t flags, void **ptr) {
auto neoDevice = Device::fromHandle(hDevice)->getNEODevice();
uint64_t handle = *(pIpcHandle.data);
NEO::osHandle osHandle = static_cast<NEO::osHandle>(handle);
NEO::AllocationProperties unifiedMemoryProperties{Device::fromHandle(hDevice)->getNEODevice()->getRootDeviceIndex(),
NEO::AllocationProperties unifiedMemoryProperties{neoDevice->getRootDeviceIndex(),
MemoryConstants::pageSize,
NEO::GraphicsAllocation::AllocationType::BUFFER};
unifiedMemoryProperties.subDevicesBitfield = Device::fromHandle(hDevice)->getNEODevice()->getDeviceBitfield();
unifiedMemoryProperties.subDevicesBitfield = neoDevice->getDeviceBitfield();
NEO::GraphicsAllocation *alloc =
this->getMemoryManager()->createGraphicsAllocationFromSharedHandle(osHandle,
unifiedMemoryProperties,
@@ -43,12 +44,12 @@ ze_result_t DriverHandleImp::openIpcMemHandle(ze_device_handle_t hDevice, ze_ipc
return ZE_RESULT_ERROR_INVALID_ARGUMENT;
}
NEO::SvmAllocationData allocData;
allocData.gpuAllocation = alloc;
NEO::SvmAllocationData allocData(neoDevice->getRootDeviceIndex());
allocData.gpuAllocations.addAllocation(alloc);
allocData.cpuAllocation = nullptr;
allocData.size = alloc->getUnderlyingBufferSize();
allocData.memoryType = InternalMemoryType::DEVICE_UNIFIED_MEMORY;
allocData.device = Device::fromHandle(hDevice)->getNEODevice();
allocData.device = neoDevice;
this->getSvmAllocsManager()->insertSVMAlloc(allocData);
@@ -71,20 +72,18 @@ ze_result_t DriverHandleImp::checkMemoryAccessFromDevice(Device *device, const v
allocation->memoryType == InternalMemoryType::SHARED_UNIFIED_MEMORY)
return ZE_RESULT_SUCCESS;
if (allocation->gpuAllocation->getRootDeviceIndex() == device->getRootDeviceIndex())
if (allocation->gpuAllocations.getGraphicsAllocation(device->getRootDeviceIndex()) != nullptr) {
return ZE_RESULT_SUCCESS;
}
ze_bool_t p2pCapable = true;
device->canAccessPeer(devices[allocation->gpuAllocation->getRootDeviceIndex()], &p2pCapable);
return p2pCapable ? ZE_RESULT_SUCCESS : ZE_RESULT_ERROR_INVALID_ARGUMENT;
return ZE_RESULT_ERROR_INVALID_ARGUMENT;
}
ze_result_t DriverHandleImp::getMemAddressRange(const void *ptr, void **pBase, size_t *pSize) {
NEO::SvmAllocationData *allocData = svmAllocsManager->getSVMAlloc(ptr);
if (allocData) {
NEO::GraphicsAllocation *alloc;
alloc = allocData->gpuAllocation;
alloc = allocData->gpuAllocations.getDefaultGraphicsAllocation();
if (pBase) {
uint64_t *allocBase = reinterpret_cast<uint64_t *>(pBase);
*allocBase = alloc->getGpuAddress();

View File

@@ -362,17 +362,18 @@ class MockDriverHandle : public L0::DriverHandleImp {
bool findAllocationDataForRange(const void *buffer,
size_t size,
NEO::SvmAllocationData **allocData) override {
mockAllocation.reset(new NEO::MockGraphicsAllocation(0, NEO::GraphicsAllocation::AllocationType::INTERNAL_HOST_MEMORY,
mockAllocation.reset(new NEO::MockGraphicsAllocation(rootDeviceIndex, NEO::GraphicsAllocation::AllocationType::INTERNAL_HOST_MEMORY,
reinterpret_cast<void *>(0x1234), 0x1000, 0, sizeof(uint32_t),
MemoryPool::System4KBPages));
data.gpuAllocation = mockAllocation.get();
data.gpuAllocations.addAllocation(mockAllocation.get());
if (allocData) {
*allocData = &data;
}
return true;
}
const uint32_t rootDeviceIndex = 0u;
std::unique_ptr<NEO::GraphicsAllocation> mockAllocation;
NEO::SvmAllocationData data = {};
NEO::SvmAllocationData data{rootDeviceIndex};
};
HWTEST2_F(CommandListCreate, givenCommandListWhenMemoryCopyRegionCalledThenAppendMemoryCopyWithappendMemoryCopyWithBliterCalled, Platforms) {

View File

@@ -312,7 +312,7 @@ HWTEST_F(CommandQueueIndirectAllocations, givenCommandQueueWhenExecutingCommandL
auto result = device->getDriverHandle()->allocDeviceMem(device->toHandle(), ZE_DEVICE_MEM_ALLOC_FLAG_DEFAULT, 16384u, 4096u, &deviceAlloc);
ASSERT_EQ(ZE_RESULT_SUCCESS, result);
auto gpuAlloc = device->getDriverHandle()->getSvmAllocsManager()->getSVMAllocs()->get(deviceAlloc)->gpuAllocation;
auto gpuAlloc = device->getDriverHandle()->getSvmAllocsManager()->getSVMAllocs()->get(deviceAlloc)->gpuAllocations.getGraphicsAllocation(device->getRootDeviceIndex());
ASSERT_NE(nullptr, gpuAlloc);
createKernel();

View File

@@ -3708,7 +3708,7 @@ cl_int clGetMemAllocInfoINTEL(
if (!unifiedMemoryAllocation) {
return changeGetInfoStatusToCLResultType(info.set<void *>(nullptr));
}
return changeGetInfoStatusToCLResultType(info.set<uint64_t>(unifiedMemoryAllocation->gpuAllocation->getGpuAddress()));
return changeGetInfoStatusToCLResultType(info.set<uint64_t>(unifiedMemoryAllocation->gpuAllocations.getDefaultGraphicsAllocation()->getGpuAddress()));
}
case CL_MEM_ALLOC_SIZE_INTEL: {
if (!unifiedMemoryAllocation) {
@@ -4545,7 +4545,7 @@ cl_int CL_API_CALL clSetKernelArgSVMPointer(cl_kernel kernel,
return retVal;
}
} else {
pSvmAlloc = svmData->gpuAllocation;
pSvmAlloc = svmData->gpuAllocations.getGraphicsAllocation(pKernel->getDevice().getRootDeviceIndex());
}
}
@@ -4612,7 +4612,7 @@ cl_int CL_API_CALL clSetKernelExecInfo(cl_kernel kernel,
TRACING_EXIT(clSetKernelExecInfo, &retVal);
return retVal;
}
GraphicsAllocation *svmAlloc = svmData->gpuAllocation;
GraphicsAllocation *svmAlloc = svmData->gpuAllocations.getGraphicsAllocation(pKernel->getDevice().getRootDeviceIndex());
if (paramName == CL_KERNEL_EXEC_INFO_SVM_PTRS) {
pKernel->setSvmKernelExecInfo(svmAlloc);

View File

@@ -37,6 +37,7 @@ cl_int CommandQueueHw<GfxFamily>::enqueueReadBuffer(
notifyEnqueueReadBuffer(buffer, !!blockingRead);
}
auto rootDeviceIndex = getDevice().getRootDeviceIndex();
const cl_command_type cmdType = CL_COMMAND_READ_BUFFER;
bool isMemTransferNeeded = buffer->isMemObjZeroCopy() ? buffer->checkIfMemoryTransferIsRequired(offset, 0, ptr, cmdType) : true;
bool isCpuCopyAllowed = bufferCpuCopyAllowed(buffer, cmdType, blockingRead, size, ptr,
@@ -46,11 +47,11 @@ cl_int CommandQueueHw<GfxFamily>::enqueueReadBuffer(
if (!mapAllocation && this->getContext().getSVMAllocsManager()) {
auto svmEntry = this->getContext().getSVMAllocsManager()->getSVMAlloc(ptr);
if (svmEntry) {
if ((svmEntry->gpuAllocation->getGpuAddress() + svmEntry->size) < (castToUint64(ptr) + size)) {
if ((svmEntry->gpuAllocations.getGraphicsAllocation(rootDeviceIndex)->getGpuAddress() + svmEntry->size) < (castToUint64(ptr) + size)) {
return CL_INVALID_OPERATION;
}
mapAllocation = svmEntry->cpuAllocation ? svmEntry->cpuAllocation : svmEntry->gpuAllocation;
mapAllocation = svmEntry->cpuAllocation ? svmEntry->cpuAllocation : svmEntry->gpuAllocations.getGraphicsAllocation(rootDeviceIndex);
if (isCpuCopyAllowed) {
if (svmEntry->memoryType == DEVICE_UNIFIED_MEMORY) {
isCpuCopyAllowed = false;

View File

@@ -77,7 +77,7 @@ cl_int CommandQueueHw<GfxFamily>::enqueueSVMMap(cl_bool blockingMap,
}
bool blocking = blockingMap == CL_TRUE;
if (svmData->gpuAllocation->getAllocationType() == GraphicsAllocation::AllocationType::SVM_ZERO_COPY) {
if (svmData->gpuAllocations.getAllocationType() == GraphicsAllocation::AllocationType::SVM_ZERO_COPY) {
NullSurface s;
Surface *surfaces[] = {&s};
if (context->isProvidingPerformanceHints()) {
@@ -111,8 +111,10 @@ cl_int CommandQueueHw<GfxFamily>::enqueueSVMMap(cl_bool blockingMap,
this->getDevice());
BuiltInOwnershipWrapper builtInLock(builder, this->context);
auto gpuAllocation = svmData->gpuAllocations.getGraphicsAllocation(getDevice().getRootDeviceIndex());
GeneralSurface dstSurface(svmData->cpuAllocation);
GeneralSurface srcSurface(svmData->gpuAllocation);
GeneralSurface srcSurface(gpuAllocation);
Surface *surfaces[] = {&dstSurface, &srcSurface};
void *svmBasePtr = svmData->cpuAllocation->getUnderlyingBuffer();
@@ -122,8 +124,8 @@ cl_int CommandQueueHw<GfxFamily>::enqueueSVMMap(cl_bool blockingMap,
dc.dstPtr = reinterpret_cast<void *>(svmData->cpuAllocation->getGpuAddressToPatch());
dc.dstSvmAlloc = svmData->cpuAllocation;
dc.dstOffset = {svmOffset, 0, 0};
dc.srcPtr = reinterpret_cast<void *>(svmData->gpuAllocation->getGpuAddressToPatch());
dc.srcSvmAlloc = svmData->gpuAllocation;
dc.srcPtr = reinterpret_cast<void *>(gpuAllocation->getGpuAddressToPatch());
dc.srcSvmAlloc = gpuAllocation;
dc.srcOffset = {svmOffset, 0, 0};
dc.size = {size, 0, 0};
dc.unifiedMemoryArgsRequireMemSync = externalAppCall;
@@ -159,7 +161,7 @@ cl_int CommandQueueHw<GfxFamily>::enqueueSVMUnmap(void *svmPtr,
return CL_INVALID_VALUE;
}
if (svmData->gpuAllocation->getAllocationType() == GraphicsAllocation::AllocationType::SVM_ZERO_COPY) {
if (svmData->gpuAllocations.getAllocationType() == GraphicsAllocation::AllocationType::SVM_ZERO_COPY) {
NullSurface s;
Surface *surfaces[] = {&s};
enqueueHandler<CL_COMMAND_SVM_UNMAP>(surfaces,
@@ -196,22 +198,24 @@ cl_int CommandQueueHw<GfxFamily>::enqueueSVMUnmap(void *svmPtr,
return CL_SUCCESS;
}
svmData->gpuAllocation->setAubWritable(true, GraphicsAllocation::defaultBank);
svmData->gpuAllocation->setTbxWritable(true, GraphicsAllocation::defaultBank);
auto gpuAllocation = svmData->gpuAllocations.getGraphicsAllocation(getDevice().getRootDeviceIndex());
gpuAllocation->setAubWritable(true, GraphicsAllocation::defaultBank);
gpuAllocation->setTbxWritable(true, GraphicsAllocation::defaultBank);
MultiDispatchInfo dispatchInfo;
auto &builder = BuiltInDispatchBuilderOp::getBuiltinDispatchInfoBuilder(EBuiltInOps::CopyBufferToBuffer,
this->getDevice());
BuiltInOwnershipWrapper builtInLock(builder, this->context);
GeneralSurface dstSurface(svmData->gpuAllocation);
GeneralSurface dstSurface(gpuAllocation);
GeneralSurface srcSurface(svmData->cpuAllocation);
Surface *surfaces[] = {&dstSurface, &srcSurface};
BuiltinOpParams dc;
dc.dstPtr = reinterpret_cast<void *>(svmData->gpuAllocation->getGpuAddressToPatch());
dc.dstSvmAlloc = svmData->gpuAllocation;
dc.dstPtr = reinterpret_cast<void *>(gpuAllocation->getGpuAddressToPatch());
dc.dstSvmAlloc = gpuAllocation;
dc.dstOffset = {svmOperation->offset, 0, 0};
dc.srcPtr = reinterpret_cast<void *>(svmData->cpuAllocation->getGpuAddressToPatch());
dc.srcSvmAlloc = svmData->cpuAllocation;
@@ -298,6 +302,7 @@ cl_int CommandQueueHw<GfxFamily>::enqueueSVMMemcpy(cl_bool blockingCopy,
if ((dstPtr == nullptr) || (srcPtr == nullptr)) {
return CL_INVALID_VALUE;
}
auto rootDeviceIndex = getDevice().getRootDeviceIndex();
auto dstSvmData = context->getSVMAllocsManager()->getSVMAlloc(dstPtr);
auto srcSvmData = context->getSVMAllocsManager()->getSVMAlloc(srcPtr);
@@ -316,10 +321,10 @@ cl_int CommandQueueHw<GfxFamily>::enqueueSVMMemcpy(cl_bool blockingCopy,
auto pageFaultManager = context->getMemoryManager()->getPageFaultManager();
if (dstSvmData && pageFaultManager) {
pageFaultManager->moveAllocationToGpuDomain(reinterpret_cast<void *>(dstSvmData->gpuAllocation->getGpuAddress()));
pageFaultManager->moveAllocationToGpuDomain(reinterpret_cast<void *>(dstSvmData->gpuAllocations.getGraphicsAllocation(rootDeviceIndex)->getGpuAddress()));
}
if (srcSvmData && pageFaultManager) {
pageFaultManager->moveAllocationToGpuDomain(reinterpret_cast<void *>(srcSvmData->gpuAllocation->getGpuAddress()));
pageFaultManager->moveAllocationToGpuDomain(reinterpret_cast<void *>(srcSvmData->gpuAllocations.getGraphicsAllocation(rootDeviceIndex)->getGpuAddress()));
}
auto isStatelessRequired = false;
@@ -344,7 +349,7 @@ cl_int CommandQueueHw<GfxFamily>::enqueueSVMMemcpy(cl_bool blockingCopy,
cl_command_type cmdType;
if (copyType == SvmToHost) {
GeneralSurface srcSvmSurf(srcSvmData->gpuAllocation);
GeneralSurface srcSvmSurf(srcSvmData->gpuAllocations.getGraphicsAllocation(rootDeviceIndex));
HostPtrSurface dstHostPtrSurf(dstPtr, size);
cmdType = CL_COMMAND_READ_BUFFER;
if (size != 0) {
@@ -355,7 +360,7 @@ cl_int CommandQueueHw<GfxFamily>::enqueueSVMMemcpy(cl_bool blockingCopy,
}
dstPtr = reinterpret_cast<void *>(dstHostPtrSurf.getAllocation()->getGpuAddress());
}
setOperationParams(operationParams, size, srcPtr, srcSvmData->gpuAllocation, dstPtr, dstHostPtrSurf.getAllocation());
setOperationParams(operationParams, size, srcPtr, srcSvmData->gpuAllocations.getGraphicsAllocation(rootDeviceIndex), dstPtr, dstHostPtrSurf.getAllocation());
surfaces[0] = &srcSvmSurf;
surfaces[1] = &dstHostPtrSurf;
builder.buildDispatchInfos(dispatchInfo, operationParams);
@@ -368,7 +373,7 @@ cl_int CommandQueueHw<GfxFamily>::enqueueSVMMemcpy(cl_bool blockingCopy,
event);
} else if (copyType == HostToSvm) {
HostPtrSurface srcHostPtrSurf(const_cast<void *>(srcPtr), size);
GeneralSurface dstSvmSurf(dstSvmData->gpuAllocation);
GeneralSurface dstSvmSurf(dstSvmData->gpuAllocations.getGraphicsAllocation(rootDeviceIndex));
cmdType = CL_COMMAND_WRITE_BUFFER;
if (size != 0) {
auto &csr = getCommandStreamReceiverByCommandType(cmdType);
@@ -378,7 +383,8 @@ cl_int CommandQueueHw<GfxFamily>::enqueueSVMMemcpy(cl_bool blockingCopy,
}
srcPtr = reinterpret_cast<void *>(srcHostPtrSurf.getAllocation()->getGpuAddress());
}
setOperationParams(operationParams, size, srcPtr, srcHostPtrSurf.getAllocation(), dstPtr, dstSvmData->gpuAllocation);
setOperationParams(operationParams, size, srcPtr, srcHostPtrSurf.getAllocation(),
dstPtr, dstSvmData->gpuAllocations.getGraphicsAllocation(rootDeviceIndex));
surfaces[0] = &dstSvmSurf;
surfaces[1] = &srcHostPtrSurf;
builder.buildDispatchInfos(dispatchInfo, operationParams);
@@ -390,9 +396,10 @@ cl_int CommandQueueHw<GfxFamily>::enqueueSVMMemcpy(cl_bool blockingCopy,
eventWaitList,
event);
} else if (copyType == SvmToSvm) {
GeneralSurface srcSvmSurf(srcSvmData->gpuAllocation);
GeneralSurface dstSvmSurf(dstSvmData->gpuAllocation);
setOperationParams(operationParams, size, srcPtr, srcSvmData->gpuAllocation, dstPtr, dstSvmData->gpuAllocation);
GeneralSurface srcSvmSurf(srcSvmData->gpuAllocations.getGraphicsAllocation(rootDeviceIndex));
GeneralSurface dstSvmSurf(dstSvmData->gpuAllocations.getGraphicsAllocation(rootDeviceIndex));
setOperationParams(operationParams, size, srcPtr, srcSvmData->gpuAllocations.getGraphicsAllocation(rootDeviceIndex),
dstPtr, dstSvmData->gpuAllocations.getGraphicsAllocation(rootDeviceIndex));
surfaces[0] = &srcSvmSurf;
surfaces[1] = &dstSvmSurf;
builder.buildDispatchInfos(dispatchInfo, operationParams);
@@ -450,13 +457,14 @@ cl_int CommandQueueHw<GfxFamily>::enqueueSVMMemFill(void *svmPtr,
if (svmData == nullptr) {
return CL_INVALID_VALUE;
}
auto gpuAllocation = svmData->gpuAllocations.getGraphicsAllocation(getDevice().getRootDeviceIndex());
auto memoryManager = context->getMemoryManager();
DEBUG_BREAK_IF(nullptr == memoryManager);
auto pageFaultManager = memoryManager->getPageFaultManager();
if (pageFaultManager) {
pageFaultManager->moveAllocationToGpuDomain(reinterpret_cast<void *>(svmData->gpuAllocation->getGpuAddress()));
pageFaultManager->moveAllocationToGpuDomain(reinterpret_cast<void *>(gpuAllocation->getGpuAddress()));
}
auto commandStreamReceieverOwnership = getGpgpuCommandStreamReceiver().obtainUniqueOwnership();
@@ -498,14 +506,14 @@ cl_int CommandQueueHw<GfxFamily>::enqueueSVMMemFill(void *svmPtr,
operationParams.srcMemObj = &patternMemObj;
operationParams.dstPtr = alignedDstPtr;
operationParams.dstSvmAlloc = svmData->gpuAllocation;
operationParams.dstSvmAlloc = gpuAllocation;
operationParams.dstOffset = {dstPtrOffset, 0, 0};
operationParams.size = {size, 0, 0};
MultiDispatchInfo dispatchInfo;
builder.buildDispatchInfos(dispatchInfo, operationParams);
GeneralSurface s1(svmData->gpuAllocation);
GeneralSurface s1(gpuAllocation);
GeneralSurface s2(patternAllocation);
Surface *surfaces[] = {&s1, &s2};

View File

@@ -39,9 +39,10 @@ cl_int CommandQueueHw<GfxFamily>::enqueueWriteBuffer(
//check if we are dealing with SVM pointer here for which we already have an allocation
if (!mapAllocation && this->getContext().getSVMAllocsManager()) {
auto rootDeviceIndex = getDevice().getRootDeviceIndex();
auto svmEntry = this->getContext().getSVMAllocsManager()->getSVMAlloc(ptr);
if (svmEntry) {
if ((svmEntry->gpuAllocation->getGpuAddress() + svmEntry->size) < (castToUint64(ptr) + size)) {
if ((svmEntry->gpuAllocations.getGraphicsAllocation(rootDeviceIndex)->getGpuAddress() + svmEntry->size) < (castToUint64(ptr) + size)) {
return CL_INVALID_OPERATION;
}
@@ -51,7 +52,7 @@ cl_int CommandQueueHw<GfxFamily>::enqueueWriteBuffer(
}
}
mapAllocation = svmEntry->cpuAllocation ? svmEntry->cpuAllocation : svmEntry->gpuAllocation;
mapAllocation = svmEntry->cpuAllocation ? svmEntry->cpuAllocation : svmEntry->gpuAllocations.getGraphicsAllocation(rootDeviceIndex);
}
}

View File

@@ -220,7 +220,7 @@ Buffer *Buffer::create(Context *context,
if (svmManager) {
auto svmData = svmManager->getSVMAlloc(hostPtr);
if (svmData) {
memory = svmData->gpuAllocation;
memory = svmData->gpuAllocations.getDefaultGraphicsAllocation();
allocationType = memory->getAllocationType();
isHostPtrSVM = true;
zeroCopyAllowed = memory->getAllocationType() == GraphicsAllocation::AllocationType::SVM_ZERO_COPY;

View File

@@ -111,7 +111,7 @@ TEST_F(clEnqueueSVMMigrateMemTests, GivenNonZeroSizeIsNotContainedWithinAllocati
auto svmData = pContext->getSVMAllocsManager()->getSVMAlloc(ptrSvm);
ASSERT_NE(nullptr, svmData);
auto svmAlloc = svmData->gpuAllocation;
auto svmAlloc = svmData->gpuAllocations.getGraphicsAllocation(pDevice->getRootDeviceIndex());
EXPECT_NE(nullptr, svmAlloc);
size_t allocSize = svmAlloc->getUnderlyingBufferSize();

View File

@@ -198,7 +198,7 @@ TEST_F(clSetKernelArgSVMPointerTests, GivenSvmAndPointerWithInvalidOffsetWhenSet
void *ptrSvm = clSVMAlloc(pContext, CL_MEM_READ_WRITE, 256, 4);
auto svmData = pContext->getSVMAllocsManager()->getSVMAlloc(ptrSvm);
ASSERT_NE(nullptr, svmData);
auto svmAlloc = svmData->gpuAllocation;
auto svmAlloc = svmData->gpuAllocations.getGraphicsAllocation(pContext->getDevice(0)->getRootDeviceIndex());
EXPECT_NE(nullptr, svmAlloc);
size_t offset = svmAlloc->getUnderlyingBufferSize() + 1;

View File

@@ -36,7 +36,8 @@ TEST(clUnifiedSharedMemoryTests, whenClHostMemAllocIntelIsCalledThenItAllocatesH
auto graphicsAllocation = allocationsManager->getSVMAlloc(unifiedMemoryHostAllocation);
EXPECT_EQ(graphicsAllocation->size, 4u);
EXPECT_EQ(graphicsAllocation->memoryType, InternalMemoryType::HOST_UNIFIED_MEMORY);
EXPECT_EQ(graphicsAllocation->gpuAllocation->getGpuAddress(), castToUint64(unifiedMemoryHostAllocation));
EXPECT_EQ(graphicsAllocation->gpuAllocations.getGraphicsAllocation(mockContext.getDevice(0)->getRootDeviceIndex())->getGpuAddress(),
castToUint64(unifiedMemoryHostAllocation));
retVal = clMemFreeINTEL(&mockContext, unifiedMemoryHostAllocation);
EXPECT_EQ(CL_SUCCESS, retVal);
@@ -77,7 +78,8 @@ TEST(clUnifiedSharedMemoryTests, whenClDeviceMemAllocIntelIsCalledThenItAllocate
auto graphicsAllocation = allocationsManager->getSVMAlloc(unfiedMemoryDeviceAllocation);
EXPECT_EQ(graphicsAllocation->size, 4u);
EXPECT_EQ(graphicsAllocation->memoryType, InternalMemoryType::DEVICE_UNIFIED_MEMORY);
EXPECT_EQ(graphicsAllocation->gpuAllocation->getGpuAddress(), castToUint64(unfiedMemoryDeviceAllocation));
EXPECT_EQ(graphicsAllocation->gpuAllocations.getGraphicsAllocation(mockContext.getDevice(0)->getRootDeviceIndex())->getGpuAddress(),
castToUint64(unfiedMemoryDeviceAllocation));
retVal = clMemFreeINTEL(&mockContext, unfiedMemoryDeviceAllocation);
EXPECT_EQ(CL_SUCCESS, retVal);
@@ -143,7 +145,8 @@ TEST(clUnifiedSharedMemoryTests, whenClSharedMemAllocIntelIsCalledThenItAllocate
auto graphicsAllocation = allocationsManager->getSVMAlloc(unfiedMemorySharedAllocation);
EXPECT_EQ(graphicsAllocation->size, 4u);
EXPECT_EQ(graphicsAllocation->memoryType, InternalMemoryType::SHARED_UNIFIED_MEMORY);
EXPECT_EQ(graphicsAllocation->gpuAllocation->getGpuAddress(), castToUint64(unfiedMemorySharedAllocation));
EXPECT_EQ(graphicsAllocation->gpuAllocations.getGraphicsAllocation(mockContext.getDevice(0)->getRootDeviceIndex())->getGpuAddress(),
castToUint64(unfiedMemorySharedAllocation));
retVal = clMemFreeINTEL(&mockContext, unfiedMemorySharedAllocation);
EXPECT_EQ(CL_SUCCESS, retVal);
@@ -559,7 +562,7 @@ TEST(clUnifiedSharedMemoryTests, whenClGetMemAllocInfoINTELisCalledWithAllocatio
retVal = clGetMemAllocInfoINTEL(&mockContext, unifiedMemorySharedAllocation, CL_MEM_ALLOC_BASE_PTR_INTEL, paramValueSize, &paramValue, &paramValueSizeRet);
EXPECT_EQ(graphicsAllocation->memoryType, InternalMemoryType::SHARED_UNIFIED_MEMORY);
EXPECT_EQ(graphicsAllocation->gpuAllocation->getGpuAddress(), paramValue);
EXPECT_EQ(graphicsAllocation->gpuAllocations.getGraphicsAllocation(mockContext.getDevice(0)->getRootDeviceIndex())->getGpuAddress(), paramValue);
EXPECT_EQ(sizeof(uint64_t), paramValueSizeRet);
EXPECT_EQ(CL_SUCCESS, retVal);
@@ -643,7 +646,8 @@ TEST(clUnifiedSharedMemoryTests, whenClSetKernelArgMemPointerINTELisCalledWithVa
retVal = clSetKernelArgMemPointerINTEL(mockKernel.mockKernel, 0, unfiedMemoryDeviceAllocation);
EXPECT_EQ(CL_SUCCESS, retVal);
auto svmAlloc = mockContext->getSVMAllocsManager()->getSVMAlloc(unfiedMemoryDeviceAllocation);
EXPECT_EQ(mockKernel.mockKernel->kernelArguments[0].object, svmAlloc->gpuAllocation);
EXPECT_EQ(mockKernel.mockKernel->kernelArguments[0].object,
svmAlloc->gpuAllocations.getGraphicsAllocation(mockContext->getDevice(0)->getRootDeviceIndex()));
retVal = clMemFreeINTEL(mockContext.get(), unfiedMemoryDeviceAllocation);
EXPECT_EQ(CL_SUCCESS, retVal);
@@ -922,11 +926,12 @@ TEST(clUnifiedSharedMemoryTests, givenDefaulMemPropertiesWhenClDeviceMemAllocInt
auto allocationsManager = mockContext.getSVMAllocsManager();
EXPECT_EQ(1u, allocationsManager->getNumAllocs());
auto graphicsAllocation = allocationsManager->getSVMAlloc(unfiedMemoryDeviceAllocation);
auto gpuAllocation = graphicsAllocation->gpuAllocations.getGraphicsAllocation(mockContext.getDevice(0)->getRootDeviceIndex());
EXPECT_EQ(graphicsAllocation->size, allocationSize);
EXPECT_EQ(graphicsAllocation->memoryType, InternalMemoryType::DEVICE_UNIFIED_MEMORY);
EXPECT_EQ(GraphicsAllocation::AllocationType::BUFFER, graphicsAllocation->gpuAllocation->getAllocationType());
EXPECT_EQ(graphicsAllocation->gpuAllocation->getGpuAddress(), castToUint64(unfiedMemoryDeviceAllocation));
EXPECT_EQ(alignUp(allocationSize, MemoryConstants::pageSize64k), graphicsAllocation->gpuAllocation->getUnderlyingBufferSize());
EXPECT_EQ(GraphicsAllocation::AllocationType::BUFFER, gpuAllocation->getAllocationType());
EXPECT_EQ(gpuAllocation->getGpuAddress(), castToUint64(unfiedMemoryDeviceAllocation));
EXPECT_EQ(alignUp(allocationSize, MemoryConstants::pageSize64k), gpuAllocation->getUnderlyingBufferSize());
retVal = clMemFreeINTEL(&mockContext, unfiedMemoryDeviceAllocation);
EXPECT_EQ(CL_SUCCESS, retVal);
@@ -944,11 +949,12 @@ TEST(clUnifiedSharedMemoryTests, givenValidMemPropertiesWhenClDeviceMemAllocInte
auto allocationsManager = mockContext.getSVMAllocsManager();
EXPECT_EQ(1u, allocationsManager->getNumAllocs());
auto graphicsAllocation = allocationsManager->getSVMAlloc(unfiedMemoryDeviceAllocation);
auto gpuAllocation = graphicsAllocation->gpuAllocations.getGraphicsAllocation(mockContext.getDevice(0)->getRootDeviceIndex());
EXPECT_EQ(graphicsAllocation->size, allocationSize);
EXPECT_EQ(graphicsAllocation->memoryType, InternalMemoryType::DEVICE_UNIFIED_MEMORY);
EXPECT_EQ(graphicsAllocation->gpuAllocation->getAllocationType(), GraphicsAllocation::AllocationType::WRITE_COMBINED);
EXPECT_EQ(graphicsAllocation->gpuAllocation->getGpuAddress(), castToUint64(unfiedMemoryDeviceAllocation));
EXPECT_EQ(alignUp(allocationSize, MemoryConstants::pageSize64k), graphicsAllocation->gpuAllocation->getUnderlyingBufferSize());
EXPECT_EQ(gpuAllocation->getAllocationType(), GraphicsAllocation::AllocationType::WRITE_COMBINED);
EXPECT_EQ(gpuAllocation->getGpuAddress(), castToUint64(unfiedMemoryDeviceAllocation));
EXPECT_EQ(alignUp(allocationSize, MemoryConstants::pageSize64k), gpuAllocation->getUnderlyingBufferSize());
retVal = clMemFreeINTEL(&mockContext, unfiedMemoryDeviceAllocation);
EXPECT_EQ(CL_SUCCESS, retVal);

View File

@@ -41,11 +41,11 @@ struct EnqueueSvmMemCopyTest : public ClDeviceFixture,
ASSERT_NE(nullptr, dstSvmPtr);
auto srcSvmData = context->getSVMAllocsManager()->getSVMAlloc(srcSvmPtr);
ASSERT_NE(nullptr, srcSvmData);
srcSvmAlloc = srcSvmData->gpuAllocation;
srcSvmAlloc = srcSvmData->gpuAllocations.getGraphicsAllocation(pDevice->getRootDeviceIndex());
ASSERT_NE(nullptr, srcSvmAlloc);
auto dstSvmData = context->getSVMAllocsManager()->getSVMAlloc(dstSvmPtr);
ASSERT_NE(nullptr, dstSvmData);
dstSvmAlloc = dstSvmData->gpuAllocation;
dstSvmAlloc = dstSvmData->gpuAllocations.getGraphicsAllocation(pDevice->getRootDeviceIndex());
ASSERT_NE(nullptr, dstSvmAlloc);
}

View File

@@ -38,7 +38,7 @@ struct EnqueueSvmMemFillTest : public ClDeviceFixture,
ASSERT_NE(nullptr, svmPtr);
auto svmData = context->getSVMAllocsManager()->getSVMAlloc(svmPtr);
ASSERT_NE(nullptr, svmData);
svmAlloc = svmData->gpuAllocation;
svmAlloc = svmData->gpuAllocations.getGraphicsAllocation(pDevice->getRootDeviceIndex());
ASSERT_NE(nullptr, svmAlloc);
}

View File

@@ -733,7 +733,7 @@ TEST_F(EnqueueSvmTest, givenEnqueueSVMMemFillWhenPatternAllocationIsObtainedThen
TEST_F(EnqueueSvmTest, GivenSvmAllocationWhenEnqueingKernelThenSuccessIsReturned) {
auto svmData = context->getSVMAllocsManager()->getSVMAlloc(ptrSVM);
ASSERT_NE(nullptr, svmData);
GraphicsAllocation *pSvmAlloc = svmData->gpuAllocation;
GraphicsAllocation *pSvmAlloc = svmData->gpuAllocations.getGraphicsAllocation(context->getDevice(0)->getRootDeviceIndex());
EXPECT_NE(nullptr, ptrSVM);
std::unique_ptr<Program> program(Program::create("FillBufferBytes", context, *pClDevice, true, &retVal));
@@ -762,7 +762,7 @@ TEST_F(EnqueueSvmTest, GivenSvmAllocationWhenEnqueingKernelThenSuccessIsReturned
TEST_F(EnqueueSvmTest, givenEnqueueTaskBlockedOnUserEventWhenItIsEnqueuedThenSurfacesAreMadeResident) {
auto svmData = context->getSVMAllocsManager()->getSVMAlloc(ptrSVM);
ASSERT_NE(nullptr, svmData);
GraphicsAllocation *pSvmAlloc = svmData->gpuAllocation;
GraphicsAllocation *pSvmAlloc = svmData->gpuAllocations.getGraphicsAllocation(context->getDevice(0)->getRootDeviceIndex());
EXPECT_NE(nullptr, ptrSVM);
auto program = clUniquePtr(Program::create("FillBufferBytes", context, *pClDevice, true, &retVal));
@@ -811,7 +811,7 @@ TEST_F(EnqueueSvmTest, GivenMultipleThreasWhenAllocatingSvmThenOnlyOneAllocation
svmPtrs[i] = context->getSVMAllocsManager()->createSVMAlloc(pDevice->getRootDeviceIndex(), 1, {}, pDevice->getDeviceBitfield());
auto svmData = context->getSVMAllocsManager()->getSVMAlloc(svmPtrs[i]);
ASSERT_NE(nullptr, svmData);
auto ga = svmData->gpuAllocation;
auto ga = svmData->gpuAllocations.getGraphicsAllocation(context->getDevice(0)->getRootDeviceIndex());
EXPECT_NE(nullptr, ga);
EXPECT_EQ(ga->getUnderlyingBuffer(), svmPtrs[i]);
}
@@ -1209,7 +1209,7 @@ HWTEST_F(EnqueueSvmTestLocalMemory, givenNonReadOnlyMapWhenUnmappingThenSetAubTb
retVal = myQueue.enqueueSVMMap(CL_TRUE, CL_MAP_WRITE, svmPtr, size, 0, nullptr, nullptr, false);
EXPECT_EQ(CL_SUCCESS, retVal);
auto gpuAllocation = mockSvmManager->getSVMAlloc(svmPtr)->gpuAllocation;
auto gpuAllocation = mockSvmManager->getSVMAlloc(svmPtr)->gpuAllocations.getGraphicsAllocation(context->getDevice(0)->getRootDeviceIndex());
myQueue.allocationToVerify = gpuAllocation;
gpuAllocation->setAubWritable(false, GraphicsAllocation::defaultBank);
@@ -1227,7 +1227,7 @@ HWTEST_F(EnqueueSvmTestLocalMemory, givenReadOnlyMapWhenUnmappingThenDontResetAu
retVal = queue.enqueueSVMMap(CL_TRUE, CL_MAP_READ, svmPtr, size, 0, nullptr, nullptr, false);
EXPECT_EQ(CL_SUCCESS, retVal);
auto gpuAllocation = mockSvmManager->getSVMAlloc(svmPtr)->gpuAllocation;
auto gpuAllocation = mockSvmManager->getSVMAlloc(svmPtr)->gpuAllocations.getGraphicsAllocation(context->getDevice(0)->getRootDeviceIndex());
gpuAllocation->setAubWritable(false, GraphicsAllocation::defaultBank);
gpuAllocation->setTbxWritable(false, GraphicsAllocation::defaultBank);
@@ -1428,8 +1428,8 @@ HWTEST_P(UpdateResidencyContainerMultipleDevicesTest, givenAllocationItIsAddedTo
InternalMemoryType type = std::get<0>(GetParam());
uint32_t mask = std::get<1>(GetParam());
SvmAllocationData allocData;
allocData.gpuAllocation = &gfxAllocation;
SvmAllocationData allocData(gfxAllocation.getRootDeviceIndex());
allocData.gpuAllocations.addAllocation(&gfxAllocation);
allocData.memoryType = type;
allocData.device = &device->getDevice();
@@ -1463,15 +1463,15 @@ HWTEST_F(UpdateResidencyContainerMultipleDevicesTest,
uint32_t pCmdBuffer[1024];
MockGraphicsAllocation gfxAllocation(static_cast<void *>(pCmdBuffer), sizeof(pCmdBuffer));
SvmAllocationData allocData;
allocData.gpuAllocation = &gfxAllocation;
SvmAllocationData allocData(gfxAllocation.getRootDeviceIndex());
allocData.gpuAllocations.addAllocation(&gfxAllocation);
allocData.memoryType = InternalMemoryType::DEVICE_UNIFIED_MEMORY;
allocData.device = &device->getDevice();
uint32_t pCmdBufferPeer[1024];
MockGraphicsAllocation gfxAllocationPeer((void *)pCmdBufferPeer, sizeof(pCmdBufferPeer));
SvmAllocationData allocDataPeer;
allocDataPeer.gpuAllocation = &gfxAllocationPeer;
SvmAllocationData allocDataPeer(gfxAllocationPeer.getRootDeviceIndex());
allocDataPeer.gpuAllocations.addAllocation(&gfxAllocationPeer);
allocDataPeer.memoryType = InternalMemoryType::DEVICE_UNIFIED_MEMORY;
allocDataPeer.device = &peerDevice->getDevice();
@@ -1493,15 +1493,15 @@ HWTEST_F(UpdateResidencyContainerMultipleDevicesTest,
uint32_t pCmdBuffer[1024];
MockGraphicsAllocation gfxAllocation(static_cast<void *>(pCmdBuffer), sizeof(pCmdBuffer));
SvmAllocationData allocData0;
allocData0.gpuAllocation = &gfxAllocation;
SvmAllocationData allocData0(gfxAllocation.getRootDeviceIndex());
allocData0.gpuAllocations.addAllocation(&gfxAllocation);
allocData0.memoryType = InternalMemoryType::DEVICE_UNIFIED_MEMORY;
allocData0.device = &subDevice0->getDevice();
uint32_t pCmdBufferPeer[1024];
MockGraphicsAllocation gfxAllocationPeer((void *)pCmdBufferPeer, sizeof(pCmdBufferPeer));
SvmAllocationData allocData1;
allocData1.gpuAllocation = &gfxAllocationPeer;
SvmAllocationData allocData1(gfxAllocationPeer.getRootDeviceIndex());
allocData1.gpuAllocations.addAllocation(&gfxAllocationPeer);
allocData1.memoryType = InternalMemoryType::DEVICE_UNIFIED_MEMORY;
allocData1.device = &subDevice1->getDevice();
@@ -1522,15 +1522,15 @@ HWTEST_F(UpdateResidencyContainerMultipleDevicesTest,
uint32_t pCmdBuffer[1024];
MockGraphicsAllocation gfxAllocation(static_cast<void *>(pCmdBuffer), sizeof(pCmdBuffer));
SvmAllocationData allocData0;
allocData0.gpuAllocation = &gfxAllocation;
SvmAllocationData allocData0(gfxAllocation.getRootDeviceIndex());
allocData0.gpuAllocations.addAllocation(&gfxAllocation);
allocData0.memoryType = InternalMemoryType::DEVICE_UNIFIED_MEMORY;
allocData0.device = &subDevice0->getDevice();
uint32_t pCmdBufferPeer[1024];
MockGraphicsAllocation gfxAllocationPeer((void *)pCmdBufferPeer, sizeof(pCmdBufferPeer));
SvmAllocationData allocData1;
allocData1.gpuAllocation = &gfxAllocationPeer;
SvmAllocationData allocData1(gfxAllocationPeer.getRootDeviceIndex());
allocData1.gpuAllocations.addAllocation(&gfxAllocationPeer);
allocData1.memoryType = InternalMemoryType::DEVICE_UNIFIED_MEMORY;
allocData1.device = &subDevice1->getDevice();

View File

@@ -1593,14 +1593,16 @@ HWTEST_F(BcsTests, givenNonZeroCopySvmAllocationWhenConstructingBlitPropertiesFo
auto svmAlloc = svmAllocsManager.createSVMAlloc(csr.getRootDeviceIndex(), 1, svmAllocationProperties, pDevice->getDeviceBitfield());
auto svmData = svmAllocsManager.getSVMAlloc(svmAlloc);
EXPECT_NE(nullptr, svmData->gpuAllocation);
auto gpuAllocation = svmData->gpuAllocations.getGraphicsAllocation(pDevice->getRootDeviceIndex());
EXPECT_NE(nullptr, gpuAllocation);
EXPECT_NE(nullptr, svmData->cpuAllocation);
EXPECT_NE(svmData->gpuAllocation, svmData->cpuAllocation);
EXPECT_NE(gpuAllocation, svmData->cpuAllocation);
{
// from hostPtr
BuiltinOpParams builtinOpParams = {};
builtinOpParams.dstSvmAlloc = svmData->gpuAllocation;
builtinOpParams.dstSvmAlloc = gpuAllocation;
builtinOpParams.srcSvmAlloc = svmData->cpuAllocation;
builtinOpParams.srcPtr = reinterpret_cast<void *>(svmData->cpuAllocation->getGpuAddress());
builtinOpParams.size = {1, 1, 1};
@@ -1608,12 +1610,12 @@ HWTEST_F(BcsTests, givenNonZeroCopySvmAllocationWhenConstructingBlitPropertiesFo
auto blitProperties = ClBlitProperties::constructProperties(BlitterConstants::BlitDirection::HostPtrToBuffer,
csr, builtinOpParams);
EXPECT_EQ(svmData->cpuAllocation, blitProperties.srcAllocation);
EXPECT_EQ(svmData->gpuAllocation, blitProperties.dstAllocation);
EXPECT_EQ(gpuAllocation, blitProperties.dstAllocation);
}
{
// to hostPtr
BuiltinOpParams builtinOpParams = {};
builtinOpParams.srcSvmAlloc = svmData->gpuAllocation;
builtinOpParams.srcSvmAlloc = gpuAllocation;
builtinOpParams.dstSvmAlloc = svmData->cpuAllocation;
builtinOpParams.dstPtr = reinterpret_cast<void *>(svmData->cpuAllocation->getGpuAddress());
builtinOpParams.size = {1, 1, 1};
@@ -1621,7 +1623,7 @@ HWTEST_F(BcsTests, givenNonZeroCopySvmAllocationWhenConstructingBlitPropertiesFo
auto blitProperties = ClBlitProperties::constructProperties(BlitterConstants::BlitDirection::BufferToHostPtr,
csr, builtinOpParams);
EXPECT_EQ(svmData->cpuAllocation, blitProperties.dstAllocation);
EXPECT_EQ(svmData->gpuAllocation, blitProperties.srcAllocation);
EXPECT_EQ(gpuAllocation, blitProperties.srcAllocation);
}
svmAllocsManager.freeSVMAlloc(svmAlloc);
@@ -1635,10 +1637,11 @@ HWTEST_F(BcsTests, givenSvmAllocationWhenBlitCalledThenUsePassedPointers) {
auto svmAllocationProperties = MemObjHelper::getSvmAllocationProperties(CL_MEM_READ_WRITE);
auto svmAlloc = svmAllocsManager.createSVMAlloc(csr.getRootDeviceIndex(), 1, svmAllocationProperties, pDevice->getDeviceBitfield());
auto svmData = svmAllocsManager.getSVMAlloc(svmAlloc);
auto gpuAllocation = svmData->gpuAllocations.getGraphicsAllocation(pDevice->getRootDeviceIndex());
EXPECT_NE(nullptr, svmData->gpuAllocation);
EXPECT_NE(nullptr, gpuAllocation);
EXPECT_NE(nullptr, svmData->cpuAllocation);
EXPECT_NE(svmData->gpuAllocation, svmData->cpuAllocation);
EXPECT_NE(gpuAllocation, svmData->cpuAllocation);
uint64_t srcOffset = 2;
uint64_t dstOffset = 3;
@@ -1647,14 +1650,14 @@ HWTEST_F(BcsTests, givenSvmAllocationWhenBlitCalledThenUsePassedPointers) {
// from hostPtr
BuiltinOpParams builtinOpParams = {};
builtinOpParams.dstSvmAlloc = svmData->cpuAllocation;
builtinOpParams.srcSvmAlloc = svmData->gpuAllocation;
builtinOpParams.srcSvmAlloc = gpuAllocation;
builtinOpParams.srcPtr = reinterpret_cast<void *>(svmData->cpuAllocation->getGpuAddress() + srcOffset);
builtinOpParams.dstPtr = reinterpret_cast<void *>(svmData->cpuAllocation->getGpuAddress() + dstOffset);
builtinOpParams.size = {1, 1, 1};
auto blitProperties = ClBlitProperties::constructProperties(BlitterConstants::BlitDirection::HostPtrToBuffer,
csr, builtinOpParams);
EXPECT_EQ(svmData->gpuAllocation, blitProperties.srcAllocation);
EXPECT_EQ(gpuAllocation, blitProperties.srcAllocation);
EXPECT_EQ(svmData->cpuAllocation, blitProperties.dstAllocation);
blitBuffer(&csr, blitProperties, true);
@@ -1673,10 +1676,10 @@ HWTEST_F(BcsTests, givenSvmAllocationWhenBlitCalledThenUsePassedPointers) {
{
// to hostPtr
BuiltinOpParams builtinOpParams = {};
builtinOpParams.srcSvmAlloc = svmData->gpuAllocation;
builtinOpParams.srcSvmAlloc = gpuAllocation;
builtinOpParams.dstSvmAlloc = svmData->cpuAllocation;
builtinOpParams.dstPtr = reinterpret_cast<void *>(svmData->cpuAllocation + dstOffset);
builtinOpParams.srcPtr = reinterpret_cast<void *>(svmData->gpuAllocation + srcOffset);
builtinOpParams.srcPtr = reinterpret_cast<void *>(gpuAllocation + srcOffset);
builtinOpParams.size = {1, 1, 1};
auto blitProperties = ClBlitProperties::constructProperties(BlitterConstants::BlitDirection::BufferToHostPtr,

View File

@@ -518,7 +518,7 @@ TEST_F(CloneKernelTest, GivenExecInfoWhenCloningKernelThenSvmAllocationIsCorrect
auto svmData = pContext->getSVMAllocsManager()->getSVMAlloc(ptrSVM);
ASSERT_NE(nullptr, svmData);
GraphicsAllocation *pSvmAlloc = svmData->gpuAllocation;
GraphicsAllocation *pSvmAlloc = svmData->gpuAllocations.getGraphicsAllocation(pDevice->getRootDeviceIndex());
ASSERT_NE(nullptr, pSvmAlloc);
pSourceKernel->setSvmKernelExecInfo(pSvmAlloc);

View File

@@ -1818,7 +1818,7 @@ HWTEST_F(KernelResidencyTest, givenDeviceUnifiedMemoryAndPageFaultManagerWhenMak
auto unifiedMemoryGraphicsAllocation = svmAllocationsManager->getSVMAlloc(unifiedMemoryAllocation);
EXPECT_EQ(0u, mockKernel.mockKernel->kernelUnifiedMemoryGfxAllocations.size());
mockKernel.mockKernel->setUnifiedMemoryExecInfo(unifiedMemoryGraphicsAllocation->gpuAllocation);
mockKernel.mockKernel->setUnifiedMemoryExecInfo(unifiedMemoryGraphicsAllocation->gpuAllocations.getGraphicsAllocation(pDevice->getRootDeviceIndex()));
EXPECT_EQ(1u, mockKernel.mockKernel->kernelUnifiedMemoryGfxAllocations.size());
mockKernel.mockKernel->makeResident(commandStreamReceiver);
@@ -1849,7 +1849,7 @@ HWTEST_F(KernelResidencyTest, givenSharedUnifiedMemoryAndPageFaultManagerWhenMak
EXPECT_EQ(mockPageFaultManager->transferToCpuCalled, 1);
EXPECT_EQ(0u, mockKernel.mockKernel->kernelUnifiedMemoryGfxAllocations.size());
mockKernel.mockKernel->setUnifiedMemoryExecInfo(unifiedMemoryGraphicsAllocation->gpuAllocation);
mockKernel.mockKernel->setUnifiedMemoryExecInfo(unifiedMemoryGraphicsAllocation->gpuAllocations.getGraphicsAllocation(pDevice->getRootDeviceIndex()));
EXPECT_EQ(1u, mockKernel.mockKernel->kernelUnifiedMemoryGfxAllocations.size());
mockKernel.mockKernel->makeResident(commandStreamReceiver);
@@ -1882,7 +1882,8 @@ HWTEST_F(KernelResidencyTest, givenSharedUnifiedMemoryAndNotRequiredMemSyncWhenM
mockPageFaultManager->insertAllocation(unifiedMemoryAllocation, 4096u, svmAllocationsManager, mockKernel.mockContext->getSpecialQueue());
EXPECT_EQ(mockPageFaultManager->transferToCpuCalled, 1);
mockKernel.mockKernel->kernelArguments[0] = {Kernel::kernelArgType::SVM_ALLOC_OBJ, unifiedMemoryGraphicsAllocation->gpuAllocation, unifiedMemoryAllocation, 4096u, unifiedMemoryGraphicsAllocation->gpuAllocation, sizeof(uintptr_t)};
auto gpuAllocation = unifiedMemoryGraphicsAllocation->gpuAllocations.getGraphicsAllocation(pDevice->getRootDeviceIndex());
mockKernel.mockKernel->kernelArguments[0] = {Kernel::kernelArgType::SVM_ALLOC_OBJ, gpuAllocation, unifiedMemoryAllocation, 4096u, gpuAllocation, sizeof(uintptr_t)};
mockKernel.mockKernel->setUnifiedMemorySyncRequirement(false);
mockKernel.mockKernel->makeResident(commandStreamReceiver);
@@ -1909,8 +1910,9 @@ HWTEST_F(KernelResidencyTest, givenSharedUnifiedMemoryRequiredMemSyncWhenMakeRes
auto unifiedMemoryGraphicsAllocation = svmAllocationsManager->getSVMAlloc(unifiedMemoryAllocation);
mockPageFaultManager->insertAllocation(unifiedMemoryAllocation, 4096u, svmAllocationsManager, mockKernel.mockContext->getSpecialQueue());
auto gpuAllocation = unifiedMemoryGraphicsAllocation->gpuAllocations.getGraphicsAllocation(pDevice->getRootDeviceIndex());
EXPECT_EQ(mockPageFaultManager->transferToCpuCalled, 1);
mockKernel.mockKernel->kernelArguments[0] = {Kernel::kernelArgType::SVM_ALLOC_OBJ, unifiedMemoryGraphicsAllocation->gpuAllocation, unifiedMemoryAllocation, 4096u, unifiedMemoryGraphicsAllocation->gpuAllocation, sizeof(uintptr_t)};
mockKernel.mockKernel->kernelArguments[0] = {Kernel::kernelArgType::SVM_ALLOC_OBJ, gpuAllocation, unifiedMemoryAllocation, 4096u, gpuAllocation, sizeof(uintptr_t)};
mockKernel.mockKernel->setUnifiedMemorySyncRequirement(true);
mockKernel.mockKernel->makeResident(commandStreamReceiver);
@@ -1967,7 +1969,7 @@ HWTEST_F(KernelResidencyTest, givenKernelWhenSetKernelExecInfoWithUnifiedMemoryI
EXPECT_EQ(0u, mockKernel.mockKernel->kernelUnifiedMemoryGfxAllocations.size());
mockKernel.mockKernel->setUnifiedMemoryExecInfo(unifiedMemoryGraphicsAllocation->gpuAllocation);
mockKernel.mockKernel->setUnifiedMemoryExecInfo(unifiedMemoryGraphicsAllocation->gpuAllocations.getGraphicsAllocation(pDevice->getRootDeviceIndex()));
EXPECT_EQ(1u, mockKernel.mockKernel->kernelUnifiedMemoryGfxAllocations.size());
EXPECT_EQ(mockKernel.mockKernel->kernelUnifiedMemoryGfxAllocations[0]->getGpuAddress(), castToUint64(unifiedMemoryAllocation));

View File

@@ -296,7 +296,7 @@ TEST_F(BufferSetArgTest, GivenSvmPointerWhenSettingKernelArgThenAddressToPatchIs
auto svmData = pContext->getSVMAllocsManager()->getSVMAlloc(ptrSVM);
ASSERT_NE(nullptr, svmData);
GraphicsAllocation *pSvmAlloc = svmData->gpuAllocation;
GraphicsAllocation *pSvmAlloc = svmData->gpuAllocations.getGraphicsAllocation(pDevice->getRootDeviceIndex());
EXPECT_NE(nullptr, pSvmAlloc);
retVal = pKernel->setArgSvmAlloc(

View File

@@ -628,7 +628,7 @@ TEST_F(RenderCompressedBuffersSvmTests, givenSvmAllocationWhenCreatingBufferThen
hwInfo->capabilityTable.ftrRenderCompressedBuffers = true;
auto svmPtr = context->getSVMAllocsManager()->createSVMAlloc(device->getRootDeviceIndex(), sizeof(uint32_t), {}, device->getDeviceBitfield());
auto expectedAllocationType = context->getSVMAllocsManager()->getSVMAlloc(svmPtr)->gpuAllocation->getAllocationType();
auto expectedAllocationType = context->getSVMAllocsManager()->getSVMAlloc(svmPtr)->gpuAllocations.getGraphicsAllocation(device->getRootDeviceIndex())->getAllocationType();
buffer.reset(Buffer::create(context.get(), CL_MEM_USE_HOST_PTR, sizeof(uint32_t), svmPtr, retVal));
EXPECT_EQ(expectedAllocationType, buffer->getGraphicsAllocation(device->getRootDeviceIndex())->getAllocationType());
@@ -1878,13 +1878,16 @@ HWTEST_TEMPLATED_F(BcsSvmTests, givenSVMMAllocationWithOffsetWhenUsingBcsThenPro
auto dstSvmData = bcsMockContext.get()->getSVMAllocsManager()->getSVMAlloc(pDstPtr);
auto srcSvmData = bcsMockContext.get()->getSVMAllocsManager()->getSVMAlloc(pSrcPtr);
auto srcGpuAllocation = srcSvmData->gpuAllocations.getGraphicsAllocation(device->getRootDeviceIndex());
auto dstGpuAllocation = dstSvmData->gpuAllocations.getGraphicsAllocation(device->getRootDeviceIndex());
BuiltinOpParams builtinOpParams = {};
builtinOpParams.size = {allocSize, 0, 0};
builtinOpParams.srcPtr = const_cast<void *>(alignDown(pSrcPtr, 4));
builtinOpParams.srcSvmAlloc = srcSvmData->gpuAllocation;
builtinOpParams.srcSvmAlloc = srcGpuAllocation;
builtinOpParams.srcOffset = {ptrDiff(pSrcPtr, builtinOpParams.srcPtr), 0, 0};
builtinOpParams.dstPtr = alignDown(pDstPtr, 4);
builtinOpParams.dstSvmAlloc = dstSvmData->gpuAllocation;
builtinOpParams.dstSvmAlloc = dstGpuAllocation;
builtinOpParams.dstOffset = {ptrDiff(pDstPtr, builtinOpParams.dstPtr), 0, 0};
auto bcsCsr = static_cast<UltCommandStreamReceiver<FamilyType> *>(commandQueue->getBcsCommandStreamReceiver());
@@ -1894,10 +1897,10 @@ HWTEST_TEMPLATED_F(BcsSvmTests, givenSVMMAllocationWithOffsetWhenUsingBcsThenPro
EXPECT_EQ(srcOffset, blitProperties.srcOffset.x);
EXPECT_EQ(dstOffset, blitProperties.dstOffset.x);
EXPECT_EQ(dstSvmData->gpuAllocation, blitProperties.dstAllocation);
EXPECT_EQ(srcSvmData->gpuAllocation, blitProperties.srcAllocation);
EXPECT_EQ(dstSvmData->gpuAllocation->getGpuAddress(), blitProperties.dstGpuAddress);
EXPECT_EQ(srcSvmData->gpuAllocation->getGpuAddress(), blitProperties.srcGpuAddress);
EXPECT_EQ(dstGpuAllocation, blitProperties.dstAllocation);
EXPECT_EQ(srcGpuAllocation, blitProperties.srcAllocation);
EXPECT_EQ(dstGpuAllocation->getGpuAddress(), blitProperties.dstGpuAddress);
EXPECT_EQ(srcGpuAllocation->getGpuAddress(), blitProperties.srcGpuAddress);
EXPECT_EQ(pDstPtr, reinterpret_cast<void *>(blitProperties.dstGpuAddress + blitProperties.dstOffset.x));
EXPECT_EQ(pSrcPtr, reinterpret_cast<void *>(blitProperties.srcGpuAddress + blitProperties.srcOffset.x));
}
@@ -2296,7 +2299,7 @@ TEST_P(ValidHostPtr, SvmHostPtr) {
EXPECT_TRUE(bufferSvm->isMemObjWithHostPtrSVM());
auto svmData = context->getSVMAllocsManager()->getSVMAlloc(ptr);
ASSERT_NE(nullptr, svmData);
EXPECT_EQ(svmData->gpuAllocation, bufferSvm->getGraphicsAllocation(pClDevice->getRootDeviceIndex()));
EXPECT_EQ(svmData->gpuAllocations.getGraphicsAllocation(pDevice->getRootDeviceIndex()), bufferSvm->getGraphicsAllocation(pDevice->getRootDeviceIndex()));
EXPECT_EQ(CL_SUCCESS, retVal);
context->getSVMAllocsManager()->freeSVMAlloc(ptr);

View File

@@ -357,7 +357,7 @@ HWTEST_F(UsmDestructionTests, givenSharedUsmAllocationWhenBlockingFreeIsCalledTh
auto waitForCompletionWithTimeoutMock = [=](bool enableTimeout, int64_t timeoutMs, uint32_t taskCountToWait) -> bool { return true; };
ON_CALL(*mockCsr, waitForCompletionWithTimeout(::testing::_, ::testing::_, ::testing::_))
.WillByDefault(::testing::Invoke(waitForCompletionWithTimeoutMock));
svmEntry->gpuAllocation->updateTaskCount(6u, 0u);
svmEntry->gpuAllocations.getGraphicsAllocation(mockDevice.getRootDeviceIndex())->updateTaskCount(6u, 0u);
svmEntry->cpuAllocation->updateTaskCount(6u, 0u);
EXPECT_CALL(*mockCsr, waitForCompletionWithTimeout(::testing::_, TimeoutControls::maxTimeout, 6u))
.Times(2);
@@ -397,7 +397,7 @@ HWTEST_F(UsmDestructionTests, givenUsmAllocationWhenBlockingFreeIsCalledThenWait
auto waitForCompletionWithTimeoutMock = [=](bool enableTimeout, int64_t timeoutMs, uint32_t taskCountToWait) -> bool { return true; };
ON_CALL(*mockCsr, waitForCompletionWithTimeout(::testing::_, ::testing::_, ::testing::_))
.WillByDefault(::testing::Invoke(waitForCompletionWithTimeoutMock));
svmEntry->gpuAllocation->updateTaskCount(6u, 0u);
svmEntry->gpuAllocations.getGraphicsAllocation(mockDevice.getRootDeviceIndex())->updateTaskCount(6u, 0u);
EXPECT_CALL(*mockCsr, waitForCompletionWithTimeout(::testing::_, TimeoutControls::maxTimeout, 6u))
.Times(1);

View File

@@ -72,12 +72,12 @@ TEST_F(SVMMemoryAllocatorTest, whenSVMAllocationIsFreedThenCannotBeGotAgain) {
EXPECT_NE(nullptr, ptr);
auto svmData = svmManager->getSVMAlloc(ptr);
ASSERT_NE(nullptr, svmData);
EXPECT_NE(nullptr, svmData->gpuAllocation);
EXPECT_NE(nullptr, svmData->gpuAllocations.getGraphicsAllocation(mockRootDeviceIndex));
svmData = svmManager->getSVMAlloc(ptr);
ASSERT_NE(nullptr, svmData);
EXPECT_NE(nullptr, svmData->gpuAllocation);
EXPECT_NE(nullptr, svmData->gpuAllocations.getGraphicsAllocation(mockRootDeviceIndex));
EXPECT_EQ(1u, svmManager->SVMAllocs.getNumAllocs());
auto svmAllocation = svmManager->getSVMAlloc(ptr)->gpuAllocation;
auto svmAllocation = svmManager->getSVMAlloc(ptr)->gpuAllocations.getGraphicsAllocation(mockRootDeviceIndex);
EXPECT_FALSE(svmAllocation->isCoherent());
svmManager->freeSVMAlloc(ptr);
@@ -90,8 +90,8 @@ TEST_F(SVMMemoryAllocatorTest, givenSvmManagerWhenOperatedOnThenCorrectAllocatio
size_t size = sizeof(data);
auto allocation = memoryManager->allocateGraphicsMemoryWithProperties({mockRootDeviceIndex, size, GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY, mockDeviceBitfield});
NEO::SvmAllocationData svmData;
svmData.gpuAllocation = allocation;
NEO::SvmAllocationData svmData(mockRootDeviceIndex);
svmData.gpuAllocations.addAllocation(allocation);
svmData.cpuAllocation = nullptr;
svmData.size = size;
svmData.memoryType = InternalMemoryType::SHARED_UNIFIED_MEMORY;
@@ -101,9 +101,9 @@ TEST_F(SVMMemoryAllocatorTest, givenSvmManagerWhenOperatedOnThenCorrectAllocatio
svmManager->insertSVMAlloc(svmData);
auto svmDataTemp = svmManager->getSVMAlloc(ptr);
ASSERT_NE(nullptr, svmDataTemp);
EXPECT_NE(nullptr, svmDataTemp->gpuAllocation);
EXPECT_NE(nullptr, svmDataTemp->gpuAllocations.getGraphicsAllocation(mockRootDeviceIndex));
EXPECT_EQ(1u, svmManager->SVMAllocs.getNumAllocs());
auto svmAllocation = svmManager->getSVMAlloc(ptr)->gpuAllocation;
auto svmAllocation = svmManager->getSVMAlloc(ptr)->gpuAllocations.getGraphicsAllocation(mockRootDeviceIndex);
EXPECT_FALSE(svmAllocation->isCoherent());
svmManager->removeSVMAlloc(svmData);
@@ -118,13 +118,13 @@ TEST_F(SVMMemoryAllocatorTest, whenGetSVMAllocationFromReturnedPointerAreaThenRe
EXPECT_NE(ptr, nullptr);
auto svmData = svmManager->getSVMAlloc(ptr);
ASSERT_NE(nullptr, svmData);
GraphicsAllocation *graphicsAllocation = svmData->gpuAllocation;
GraphicsAllocation *graphicsAllocation = svmData->gpuAllocations.getGraphicsAllocation(mockRootDeviceIndex);
EXPECT_NE(nullptr, graphicsAllocation);
auto ptrInRange = ptrOffset(ptr, MemoryConstants::pageSize - 4);
svmData = svmManager->getSVMAlloc(ptrInRange);
ASSERT_NE(nullptr, svmData);
GraphicsAllocation *graphicsAllocationInRange = svmData->gpuAllocation;
GraphicsAllocation *graphicsAllocationInRange = svmData->gpuAllocations.getGraphicsAllocation(mockRootDeviceIndex);
EXPECT_NE(nullptr, graphicsAllocationInRange);
EXPECT_EQ(graphicsAllocation, graphicsAllocationInRange);
@@ -137,7 +137,7 @@ TEST_F(SVMMemoryAllocatorTest, whenGetSVMAllocationFromOutsideOfReturnedPointerA
EXPECT_NE(ptr, nullptr);
auto svmData = svmManager->getSVMAlloc(ptr);
ASSERT_NE(nullptr, svmData);
GraphicsAllocation *graphicsAllocation = svmData->gpuAllocation;
GraphicsAllocation *graphicsAllocation = svmData->gpuAllocations.getGraphicsAllocation(mockRootDeviceIndex);
EXPECT_NE(nullptr, graphicsAllocation);
auto ptrBefore = ptrOffset(ptr, -4);
@@ -184,22 +184,24 @@ TEST_F(SVMMemoryAllocatorTest, given64kbAllowedWhenAllocatingSvmMemoryThenDontPr
TEST_F(SVMMemoryAllocatorTest, given64kbAllowedwhenAllocatingSvmMemoryThenAllocationIsIn64kbPagePool) {
MockMemoryManager memoryManager64Kb(true, false, executionEnvironment);
svmManager->memoryManager = &memoryManager64Kb;
auto ptr = svmManager->createSVMAlloc(0, MemoryConstants::pageSize, {}, mockDeviceBitfield);
EXPECT_EQ(MemoryPool::System64KBPages, svmManager->getSVMAlloc(ptr)->gpuAllocation->getMemoryPool());
auto ptr = svmManager->createSVMAlloc(mockRootDeviceIndex, MemoryConstants::pageSize, {}, mockDeviceBitfield);
EXPECT_EQ(MemoryPool::System64KBPages,
svmManager->getSVMAlloc(ptr)->gpuAllocations.getGraphicsAllocation(mockRootDeviceIndex)->getMemoryPool());
svmManager->freeSVMAlloc(ptr);
}
TEST_F(SVMMemoryAllocatorTest, given64kbDisallowedWhenAllocatingSvmMemoryThenAllocationIsIn4kbPagePool) {
auto ptr = svmManager->createSVMAlloc(0, MemoryConstants::pageSize, {}, mockDeviceBitfield);
EXPECT_EQ(MemoryPool::System4KBPages, svmManager->getSVMAlloc(ptr)->gpuAllocation->getMemoryPool());
auto ptr = svmManager->createSVMAlloc(mockRootDeviceIndex, MemoryConstants::pageSize, {}, mockDeviceBitfield);
EXPECT_EQ(MemoryPool::System4KBPages,
svmManager->getSVMAlloc(ptr)->gpuAllocations.getGraphicsAllocation(mockRootDeviceIndex)->getMemoryPool());
svmManager->freeSVMAlloc(ptr);
}
TEST_F(SVMMemoryAllocatorTest, whenCoherentFlagIsPassedThenAllocationIsCoherent) {
SVMAllocsManager::SvmAllocationProperties svmProperties;
svmProperties.coherent = true;
auto ptr = svmManager->createSVMAlloc(0, MemoryConstants::pageSize, svmProperties, mockDeviceBitfield);
EXPECT_TRUE(svmManager->getSVMAlloc(ptr)->gpuAllocation->isCoherent());
auto ptr = svmManager->createSVMAlloc(mockRootDeviceIndex, MemoryConstants::pageSize, svmProperties, mockDeviceBitfield);
EXPECT_TRUE(svmManager->getSVMAlloc(ptr)->gpuAllocations.getGraphicsAllocation(mockRootDeviceIndex)->isCoherent());
svmManager->freeSVMAlloc(ptr);
}
@@ -209,17 +211,18 @@ TEST_F(SVMLocalMemoryAllocatorTest, whenDeviceAllocationIsCreatedThenItIsStoredW
unifiedMemoryProperties.allocationFlags.allocFlags.allocWriteCombined = true;
unifiedMemoryProperties.subdeviceBitfield = mockDeviceBitfield;
auto allocationSize = 4000u;
auto ptr = svmManager->createUnifiedMemoryAllocation(0, 4000u, unifiedMemoryProperties);
auto ptr = svmManager->createUnifiedMemoryAllocation(mockRootDeviceIndex, 4000u, unifiedMemoryProperties);
EXPECT_NE(nullptr, ptr);
auto allocation = svmManager->getSVMAlloc(ptr);
EXPECT_EQ(nullptr, allocation->cpuAllocation);
EXPECT_NE(nullptr, allocation->gpuAllocation);
auto gpuAllocation = allocation->gpuAllocations.getGraphicsAllocation(mockRootDeviceIndex);
EXPECT_NE(nullptr, gpuAllocation);
EXPECT_EQ(InternalMemoryType::DEVICE_UNIFIED_MEMORY, allocation->memoryType);
EXPECT_EQ(allocationSize, allocation->size);
EXPECT_EQ(allocation->gpuAllocation->getMemoryPool(), MemoryPool::LocalMemory);
EXPECT_EQ(gpuAllocation->getMemoryPool(), MemoryPool::LocalMemory);
EXPECT_EQ(alignUp(allocationSize, MemoryConstants::pageSize64k), allocation->gpuAllocation->getUnderlyingBufferSize());
EXPECT_EQ(GraphicsAllocation::AllocationType::WRITE_COMBINED, allocation->gpuAllocation->getAllocationType());
EXPECT_EQ(alignUp(allocationSize, MemoryConstants::pageSize64k), gpuAllocation->getUnderlyingBufferSize());
EXPECT_EQ(GraphicsAllocation::AllocationType::WRITE_COMBINED, gpuAllocation->getAllocationType());
svmManager->freeSVMAlloc(ptr);
}
@@ -237,12 +240,13 @@ TEST_F(SVMMemoryAllocatorTest, givenNoWriteCombinedFlagwhenDeviceAllocationIsCre
EXPECT_NE(nullptr, ptr);
auto allocation = svmManager->getSVMAlloc(ptr);
EXPECT_EQ(nullptr, allocation->cpuAllocation);
EXPECT_NE(nullptr, allocation->gpuAllocation);
auto gpuAllocation = allocation->gpuAllocations.getGraphicsAllocation(mockRootDeviceIndex);
EXPECT_NE(nullptr, gpuAllocation);
EXPECT_EQ(InternalMemoryType::DEVICE_UNIFIED_MEMORY, allocation->memoryType);
EXPECT_EQ(allocationSize, allocation->size);
EXPECT_EQ(alignUp(allocationSize, MemoryConstants::pageSize64k), allocation->gpuAllocation->getUnderlyingBufferSize());
EXPECT_EQ(GraphicsAllocation::AllocationType::BUFFER, allocation->gpuAllocation->getAllocationType());
EXPECT_EQ(alignUp(allocationSize, MemoryConstants::pageSize64k), gpuAllocation->getUnderlyingBufferSize());
EXPECT_EQ(GraphicsAllocation::AllocationType::BUFFER, gpuAllocation->getAllocationType());
svmManager->freeSVMAlloc(ptr);
}
@@ -252,18 +256,19 @@ TEST_F(SVMMemoryAllocatorTest, whenHostAllocationIsCreatedThenItIsStoredWithProp
unifiedMemoryProperties.memoryType = InternalMemoryType::HOST_UNIFIED_MEMORY;
unifiedMemoryProperties.subdeviceBitfield = mockDeviceBitfield;
auto allocationSize = 4096u;
auto ptr = svmManager->createUnifiedMemoryAllocation(0, 4096u, unifiedMemoryProperties);
auto ptr = svmManager->createUnifiedMemoryAllocation(mockRootDeviceIndex, 4096u, unifiedMemoryProperties);
EXPECT_NE(nullptr, ptr);
auto allocation = svmManager->getSVMAlloc(ptr);
EXPECT_EQ(nullptr, allocation->cpuAllocation);
EXPECT_NE(nullptr, allocation->gpuAllocation);
auto gpuAllocation = allocation->gpuAllocations.getGraphicsAllocation(mockRootDeviceIndex);
EXPECT_NE(nullptr, gpuAllocation);
EXPECT_EQ(InternalMemoryType::HOST_UNIFIED_MEMORY, allocation->memoryType);
EXPECT_EQ(allocationSize, allocation->size);
EXPECT_EQ(alignUp(allocationSize, MemoryConstants::pageSize64k), allocation->gpuAllocation->getUnderlyingBufferSize());
EXPECT_EQ(GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY, allocation->gpuAllocation->getAllocationType());
EXPECT_NE(allocation->gpuAllocation->getMemoryPool(), MemoryPool::LocalMemory);
EXPECT_NE(nullptr, allocation->gpuAllocation->getUnderlyingBuffer());
EXPECT_EQ(alignUp(allocationSize, MemoryConstants::pageSize64k), gpuAllocation->getUnderlyingBufferSize());
EXPECT_EQ(GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY, gpuAllocation->getAllocationType());
EXPECT_NE(gpuAllocation->getMemoryPool(), MemoryPool::LocalMemory);
EXPECT_NE(nullptr, gpuAllocation->getUnderlyingBuffer());
svmManager->freeSVMAlloc(ptr);
}
@@ -290,18 +295,19 @@ TEST_F(SVMMemoryAllocatorTest, whenSharedAllocationIsCreatedThenItIsStoredWithPr
unifiedMemoryProperties.memoryType = InternalMemoryType::SHARED_UNIFIED_MEMORY;
auto allocationSize = 4096u;
auto ptr = svmManager->createSharedUnifiedMemoryAllocation(0, 4096u, unifiedMemoryProperties, &cmdQ);
auto ptr = svmManager->createSharedUnifiedMemoryAllocation(mockRootDeviceIndex, 4096u, unifiedMemoryProperties, &cmdQ);
EXPECT_NE(nullptr, ptr);
auto allocation = svmManager->getSVMAlloc(ptr);
EXPECT_EQ(nullptr, allocation->cpuAllocation);
EXPECT_NE(nullptr, allocation->gpuAllocation);
auto gpuAllocation = allocation->gpuAllocations.getGraphicsAllocation(mockRootDeviceIndex);
EXPECT_NE(nullptr, gpuAllocation);
EXPECT_EQ(InternalMemoryType::SHARED_UNIFIED_MEMORY, allocation->memoryType);
EXPECT_EQ(allocationSize, allocation->size);
EXPECT_EQ(alignUp(allocationSize, MemoryConstants::pageSize64k), allocation->gpuAllocation->getUnderlyingBufferSize());
EXPECT_EQ(GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY, allocation->gpuAllocation->getAllocationType());
EXPECT_NE(allocation->gpuAllocation->getMemoryPool(), MemoryPool::LocalMemory);
EXPECT_NE(nullptr, allocation->gpuAllocation->getUnderlyingBuffer());
EXPECT_EQ(alignUp(allocationSize, MemoryConstants::pageSize64k), gpuAllocation->getUnderlyingBufferSize());
EXPECT_EQ(GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY, gpuAllocation->getAllocationType());
EXPECT_NE(gpuAllocation->getMemoryPool(), MemoryPool::LocalMemory);
EXPECT_NE(nullptr, gpuAllocation->getUnderlyingBuffer());
svmManager->freeSVMAlloc(ptr);
}
@@ -310,31 +316,33 @@ TEST_F(SVMLocalMemoryAllocatorTest, whenSharedAllocationIsCreatedWithDebugFlagSe
MockContext mockContext;
DebugManagerStateRestore restore;
DebugManager.flags.AllocateSharedAllocationsWithCpuAndGpuStorage.set(true);
auto device = mockContext.getDevice(0u);
SVMAllocsManager::UnifiedMemoryProperties unifiedMemoryProperties;
unifiedMemoryProperties.memoryType = InternalMemoryType::SHARED_UNIFIED_MEMORY;
unifiedMemoryProperties.device = mockContext.getDevice(0u);
unifiedMemoryProperties.subdeviceBitfield = mockContext.getDevice(0)->getDeviceBitfield();
unifiedMemoryProperties.device = device;
unifiedMemoryProperties.subdeviceBitfield = device->getDeviceBitfield();
auto allocationSize = 4096u;
auto ptr = svmManager->createSharedUnifiedMemoryAllocation(0, 4096u, unifiedMemoryProperties, &cmdQ);
auto ptr = svmManager->createSharedUnifiedMemoryAllocation(device->getRootDeviceIndex(), 4096u, unifiedMemoryProperties, &cmdQ);
EXPECT_NE(nullptr, ptr);
auto allocation = svmManager->getSVMAlloc(ptr);
auto gpuAllocation = allocation->gpuAllocations.getGraphicsAllocation(device->getRootDeviceIndex());
EXPECT_NE(nullptr, allocation->cpuAllocation);
EXPECT_NE(nullptr, allocation->gpuAllocation);
EXPECT_NE(nullptr, gpuAllocation);
EXPECT_EQ(InternalMemoryType::SHARED_UNIFIED_MEMORY, allocation->memoryType);
EXPECT_EQ(allocationSize, allocation->size);
EXPECT_EQ(mockContext.getDevice(0u), allocation->device);
EXPECT_EQ(alignUp(allocationSize, 2u * MB), allocation->gpuAllocation->getUnderlyingBufferSize());
EXPECT_EQ(alignUp(allocationSize, 2u * MB), gpuAllocation->getUnderlyingBufferSize());
EXPECT_EQ(alignUp(allocationSize, 2u * MB), allocation->cpuAllocation->getUnderlyingBufferSize());
EXPECT_EQ(GraphicsAllocation::AllocationType::SVM_GPU, allocation->gpuAllocation->getAllocationType());
EXPECT_EQ(GraphicsAllocation::AllocationType::SVM_GPU, gpuAllocation->getAllocationType());
EXPECT_EQ(GraphicsAllocation::AllocationType::SVM_CPU, allocation->cpuAllocation->getAllocationType());
EXPECT_EQ(allocation->gpuAllocation->getMemoryPool(), MemoryPool::LocalMemory);
EXPECT_EQ(gpuAllocation->getMemoryPool(), MemoryPool::LocalMemory);
EXPECT_NE(allocation->cpuAllocation->getMemoryPool(), MemoryPool::LocalMemory);
EXPECT_NE(nullptr, allocation->gpuAllocation->getUnderlyingBuffer());
EXPECT_NE(nullptr, gpuAllocation->getUnderlyingBuffer());
svmManager->freeSVMAlloc(ptr);
}
@@ -347,24 +355,26 @@ TEST_F(SVMLocalMemoryAllocatorTest, whenSharedAllocationIsCreatedWithLocalMemory
unifiedMemoryProperties.memoryType = InternalMemoryType::SHARED_UNIFIED_MEMORY;
unifiedMemoryProperties.subdeviceBitfield = mockDeviceBitfield;
auto allocationSize = 4096u;
auto ptr = svmManager->createSharedUnifiedMemoryAllocation(0, 4096u, unifiedMemoryProperties, &cmdQ);
auto rootDeviceIndex = 0u;
auto ptr = svmManager->createSharedUnifiedMemoryAllocation(rootDeviceIndex, 4096u, unifiedMemoryProperties, &cmdQ);
EXPECT_NE(nullptr, ptr);
auto allocation = svmManager->getSVMAlloc(ptr);
auto gpuAllocation = allocation->gpuAllocations.getGraphicsAllocation(rootDeviceIndex);
EXPECT_NE(nullptr, allocation->cpuAllocation);
EXPECT_NE(nullptr, allocation->gpuAllocation);
EXPECT_NE(nullptr, gpuAllocation);
EXPECT_EQ(InternalMemoryType::SHARED_UNIFIED_MEMORY, allocation->memoryType);
EXPECT_EQ(allocationSize, allocation->size);
EXPECT_EQ(alignUp(allocationSize, 2u * MB), allocation->gpuAllocation->getUnderlyingBufferSize());
EXPECT_EQ(alignUp(allocationSize, 2u * MB), gpuAllocation->getUnderlyingBufferSize());
EXPECT_EQ(alignUp(allocationSize, 2u * MB), allocation->cpuAllocation->getUnderlyingBufferSize());
EXPECT_EQ(GraphicsAllocation::AllocationType::SVM_GPU, allocation->gpuAllocation->getAllocationType());
EXPECT_EQ(GraphicsAllocation::AllocationType::SVM_GPU, gpuAllocation->getAllocationType());
EXPECT_EQ(GraphicsAllocation::AllocationType::SVM_CPU, allocation->cpuAllocation->getAllocationType());
EXPECT_EQ(allocation->gpuAllocation->getMemoryPool(), MemoryPool::LocalMemory);
EXPECT_EQ(gpuAllocation->getMemoryPool(), MemoryPool::LocalMemory);
EXPECT_NE(allocation->cpuAllocation->getMemoryPool(), MemoryPool::LocalMemory);
EXPECT_NE(nullptr, allocation->gpuAllocation->getUnderlyingBuffer());
EXPECT_NE(nullptr, gpuAllocation->getUnderlyingBuffer());
svmManager->freeSVMAlloc(ptr);
}
@@ -376,16 +386,17 @@ TEST_F(SVMMemoryAllocatorTest, givenSharedAllocationsDebugFlagWhenDeviceMemoryIs
unifiedMemoryProperties.memoryType = InternalMemoryType::DEVICE_UNIFIED_MEMORY;
unifiedMemoryProperties.subdeviceBitfield = mockDeviceBitfield;
auto allocationSize = 4096u;
auto ptr = svmManager->createUnifiedMemoryAllocation(0, 4096u, unifiedMemoryProperties);
auto ptr = svmManager->createUnifiedMemoryAllocation(mockRootDeviceIndex, 4096u, unifiedMemoryProperties);
EXPECT_NE(nullptr, ptr);
auto allocation = svmManager->getSVMAlloc(ptr);
EXPECT_EQ(nullptr, allocation->cpuAllocation);
EXPECT_NE(nullptr, allocation->gpuAllocation);
auto gpuAllocation = allocation->gpuAllocations.getGraphicsAllocation(mockRootDeviceIndex);
EXPECT_NE(nullptr, gpuAllocation);
EXPECT_EQ(InternalMemoryType::DEVICE_UNIFIED_MEMORY, allocation->memoryType);
EXPECT_EQ(allocationSize, allocation->size);
EXPECT_EQ(alignUp(allocationSize, MemoryConstants::pageSize64k), allocation->gpuAllocation->getUnderlyingBufferSize());
EXPECT_EQ(GraphicsAllocation::AllocationType::BUFFER, allocation->gpuAllocation->getAllocationType());
EXPECT_EQ(alignUp(allocationSize, MemoryConstants::pageSize64k), gpuAllocation->getUnderlyingBufferSize());
EXPECT_EQ(GraphicsAllocation::AllocationType::BUFFER, gpuAllocation->getAllocationType());
svmManager->freeSVMAlloc(ptr);
}
@@ -430,12 +441,12 @@ TEST(SvmAllocationPropertiesTests, givenDifferentMemFlagsWhenGettingSvmAllocatio
TEST_F(SVMMemoryAllocatorTest, whenReadOnlySvmAllocationCreatedThenGraphicsAllocationHasWriteableFlagFalse) {
SVMAllocsManager::SvmAllocationProperties svmProperties;
svmProperties.readOnly = true;
void *svm = svmManager->createSVMAlloc(0, 4096, svmProperties, mockDeviceBitfield);
void *svm = svmManager->createSVMAlloc(mockRootDeviceIndex, 4096, svmProperties, mockDeviceBitfield);
EXPECT_NE(nullptr, svm);
auto svmData = svmManager->getSVMAlloc(svm);
ASSERT_NE(nullptr, svmData);
GraphicsAllocation *svmAllocation = svmData->gpuAllocation;
GraphicsAllocation *svmAllocation = svmData->gpuAllocations.getGraphicsAllocation(mockRootDeviceIndex);
EXPECT_NE(nullptr, svmAllocation);
EXPECT_FALSE(svmAllocation->isMemObjectsAllocationWithWritableFlags());
@@ -443,7 +454,7 @@ TEST_F(SVMMemoryAllocatorTest, whenReadOnlySvmAllocationCreatedThenGraphicsAlloc
}
TEST_F(SVMLocalMemoryAllocatorTest, whenAllocatingSvmThenExpectCpuAllocationWithPointerAndGpuAllocationWithSameGpuAddress) {
auto ptr = svmManager->createSVMAlloc(0, MemoryConstants::pageSize, {}, mockDeviceBitfield);
auto ptr = svmManager->createSVMAlloc(mockRootDeviceIndex, MemoryConstants::pageSize, {}, mockDeviceBitfield);
EXPECT_NE(ptr, nullptr);
auto svmData = svmManager->getSVMAlloc(ptr);
ASSERT_NE(nullptr, svmData);
@@ -451,7 +462,7 @@ TEST_F(SVMLocalMemoryAllocatorTest, whenAllocatingSvmThenExpectCpuAllocationWith
EXPECT_NE(nullptr, cpuAllocation);
EXPECT_EQ(ptr, cpuAllocation->getUnderlyingBuffer());
GraphicsAllocation *gpuAllocation = svmData->gpuAllocation;
GraphicsAllocation *gpuAllocation = svmData->gpuAllocations.getGraphicsAllocation(mockRootDeviceIndex);
EXPECT_NE(nullptr, gpuAllocation);
EXPECT_EQ(reinterpret_cast<uint64_t>(ptr), gpuAllocation->getGpuAddress());
@@ -459,11 +470,11 @@ TEST_F(SVMLocalMemoryAllocatorTest, whenAllocatingSvmThenExpectCpuAllocationWith
}
TEST_F(SVMLocalMemoryAllocatorTest, whenGetSVMAllocationFromOutsideOfReturnedPointerAreaThenDontReturnThisAllocation) {
auto ptr = svmManager->createSVMAlloc(0, MemoryConstants::pageSize, {}, mockDeviceBitfield);
auto ptr = svmManager->createSVMAlloc(mockRootDeviceIndex, MemoryConstants::pageSize, {}, mockDeviceBitfield);
EXPECT_NE(ptr, nullptr);
auto svmData = svmManager->getSVMAlloc(ptr);
ASSERT_NE(nullptr, svmData);
GraphicsAllocation *graphicsAllocation = svmData->gpuAllocation;
GraphicsAllocation *graphicsAllocation = svmData->gpuAllocations.getGraphicsAllocation(mockRootDeviceIndex);
EXPECT_NE(nullptr, graphicsAllocation);
auto ptrBefore = ptrOffset(ptr, -4);
@@ -643,12 +654,13 @@ TEST(UnfiedSharedMemoryTransferCalls, givenHostUsmAllocationWhenPointerIsUsedFor
MockContext mockContext;
cl_context clContext = &mockContext;
auto status = CL_SUCCESS;
auto status = CL_INVALID_PLATFORM;
auto hostMemory = clHostMemAllocINTEL(clContext, nullptr, 4096u, 0u, &status);
auto svmAllocation = mockContext.getSVMAllocsManager()->getSVMAlloc(hostMemory);
ASSERT_EQ(CL_SUCCESS, status);
auto svmAllocation = mockContext.getSVMAllocsManager()->getSVMAlloc(hostMemory);
auto gpuAllocation = svmAllocation->gpuAllocations.getGraphicsAllocation(mockContext.getDevice(0)->getRootDeviceIndex());
auto buffer = clCreateBuffer(clContext, CL_MEM_READ_WRITE, 4096u, nullptr, &status);
ASSERT_EQ(CL_SUCCESS, status);
@@ -665,12 +677,12 @@ TEST(UnfiedSharedMemoryTransferCalls, givenHostUsmAllocationWhenPointerIsUsedFor
EXPECT_TRUE(temporaryAllocations.peekIsEmpty());
auto osContextId = neoQueue->getGpgpuCommandStreamReceiver().getOsContext().getContextId();
EXPECT_EQ(1u, svmAllocation->gpuAllocation->getTaskCount(osContextId));
EXPECT_EQ(1u, gpuAllocation->getTaskCount(osContextId));
status = clEnqueueReadBuffer(commandQueue, buffer, false, 0u, 4096u, hostMemory, 0u, nullptr, nullptr);
ASSERT_EQ(CL_SUCCESS, status);
EXPECT_TRUE(temporaryAllocations.peekIsEmpty());
EXPECT_EQ(2u, svmAllocation->gpuAllocation->getTaskCount(osContextId));
EXPECT_EQ(2u, gpuAllocation->getTaskCount(osContextId));
status = clReleaseMemObject(buffer);
ASSERT_EQ(CL_SUCCESS, status);
@@ -683,13 +695,14 @@ TEST(UnfiedSharedMemoryTransferCalls, givenDeviceUsmAllocationWhenPtrIsUsedForTr
MockContext mockContext;
cl_context clContext = &mockContext;
auto status = CL_SUCCESS;
auto status = CL_INVALID_PLATFORM;
cl_device_id clDevice = mockContext.getDevice(0u);
auto deviceMemory = clDeviceMemAllocINTEL(clContext, clDevice, nullptr, 4096u, 0u, &status);
auto svmAllocation = mockContext.getSVMAllocsManager()->getSVMAlloc(deviceMemory);
ASSERT_EQ(CL_SUCCESS, status);
auto svmAllocation = mockContext.getSVMAllocsManager()->getSVMAlloc(deviceMemory);
auto gpuAllocation = svmAllocation->gpuAllocations.getGraphicsAllocation(mockContext.getDevice(0)->getRootDeviceIndex());
auto buffer = clCreateBuffer(clContext, CL_MEM_READ_WRITE, 4096u, nullptr, &status);
ASSERT_EQ(CL_SUCCESS, status);
@@ -704,12 +717,12 @@ TEST(UnfiedSharedMemoryTransferCalls, givenDeviceUsmAllocationWhenPtrIsUsedForTr
EXPECT_TRUE(temporaryAllocations.peekIsEmpty());
auto osContextId = neoQueue->getGpgpuCommandStreamReceiver().getOsContext().getContextId();
EXPECT_EQ(1u, svmAllocation->gpuAllocation->getTaskCount(osContextId));
EXPECT_EQ(1u, gpuAllocation->getTaskCount(osContextId));
status = clEnqueueReadBuffer(commandQueue, buffer, false, 0u, 4096u, deviceMemory, 0u, nullptr, nullptr);
ASSERT_EQ(CL_SUCCESS, status);
EXPECT_EQ(2u, svmAllocation->gpuAllocation->getTaskCount(osContextId));
EXPECT_EQ(2u, gpuAllocation->getTaskCount(osContextId));
status = clReleaseMemObject(buffer);
ASSERT_EQ(CL_SUCCESS, status);
@@ -722,13 +735,14 @@ TEST(UnfiedSharedMemoryTransferCalls, givenDeviceUsmAllocationWhenPtrIsUsedForTr
MockContext mockContext;
cl_context clContext = &mockContext;
auto status = CL_SUCCESS;
auto status = CL_INVALID_PLATFORM;
cl_device_id clDevice = mockContext.getDevice(0u);
auto deviceMemory = clDeviceMemAllocINTEL(clContext, clDevice, nullptr, 4096u, 0u, &status);
auto svmAllocation = mockContext.getSVMAllocsManager()->getSVMAlloc(deviceMemory);
ASSERT_EQ(CL_SUCCESS, status);
auto svmAllocation = mockContext.getSVMAllocsManager()->getSVMAlloc(deviceMemory);
auto gpuAllocation = svmAllocation->gpuAllocations.getGraphicsAllocation(mockContext.getDevice(0)->getRootDeviceIndex());
auto buffer = clCreateBuffer(clContext, CL_MEM_READ_WRITE, 4096u, nullptr, &status);
ASSERT_EQ(CL_SUCCESS, status);
@@ -743,12 +757,12 @@ TEST(UnfiedSharedMemoryTransferCalls, givenDeviceUsmAllocationWhenPtrIsUsedForTr
EXPECT_TRUE(temporaryAllocations.peekIsEmpty());
auto osContextId = neoQueue->getGpgpuCommandStreamReceiver().getOsContext().getContextId();
EXPECT_EQ(1u, svmAllocation->gpuAllocation->getTaskCount(osContextId));
EXPECT_EQ(1u, gpuAllocation->getTaskCount(osContextId));
status = clEnqueueReadBuffer(commandQueue, buffer, true, 0u, 4096u, deviceMemory, 0u, nullptr, nullptr);
ASSERT_EQ(CL_SUCCESS, status);
EXPECT_EQ(2u, svmAllocation->gpuAllocation->getTaskCount(osContextId));
EXPECT_EQ(2u, gpuAllocation->getTaskCount(osContextId));
status = clReleaseMemObject(buffer);
ASSERT_EQ(CL_SUCCESS, status);
@@ -767,13 +781,14 @@ TEST(UnfiedSharedMemoryTransferCalls, givenHostUsmAllocationWhenPtrIsUsedForTran
GTEST_SKIP();
}
auto status = CL_SUCCESS;
auto status = CL_INVALID_PLATFORM;
cl_device_id clDevice = mockContext.getDevice(0u);
auto sharedMemory = clSharedMemAllocINTEL(clContext, clDevice, nullptr, 4096u, 0u, &status);
auto svmAllocation = mockContext.getSVMAllocsManager()->getSVMAlloc(sharedMemory);
ASSERT_EQ(CL_SUCCESS, status);
auto svmAllocation = mockContext.getSVMAllocsManager()->getSVMAlloc(sharedMemory);
auto gpuAllocation = svmAllocation->gpuAllocations.getGraphicsAllocation(mockContext.getDevice(0)->getRootDeviceIndex());
auto buffer = clCreateBuffer(clContext, CL_MEM_READ_WRITE, 4096u, nullptr, &status);
ASSERT_EQ(CL_SUCCESS, status);
@@ -788,12 +803,12 @@ TEST(UnfiedSharedMemoryTransferCalls, givenHostUsmAllocationWhenPtrIsUsedForTran
EXPECT_TRUE(temporaryAllocations.peekIsEmpty());
auto osContextId = neoQueue->getGpgpuCommandStreamReceiver().getOsContext().getContextId();
EXPECT_EQ(GraphicsAllocation::objectNotUsed, svmAllocation->gpuAllocation->getTaskCount(osContextId));
EXPECT_EQ(GraphicsAllocation::objectNotUsed, gpuAllocation->getTaskCount(osContextId));
status = clEnqueueReadBuffer(commandQueue, buffer, true, 0u, 4096u, sharedMemory, 0u, nullptr, nullptr);
ASSERT_EQ(CL_SUCCESS, status);
EXPECT_EQ(GraphicsAllocation::objectNotUsed, svmAllocation->gpuAllocation->getTaskCount(osContextId));
EXPECT_EQ(GraphicsAllocation::objectNotUsed, gpuAllocation->getTaskCount(osContextId));
status = clReleaseMemObject(buffer);
ASSERT_EQ(CL_SUCCESS, status);
@@ -840,12 +855,13 @@ TEST(UnfiedSharedMemoryTransferCalls, givenSharedUsmAllocationWithoutLocalMemory
cl_context clContext = &mockContext;
cl_device_id clDevice = mockContext.getDevice(0u);
auto status = CL_SUCCESS;
auto status = CL_INVALID_PLATFORM;
auto sharedMemory = clSharedMemAllocINTEL(clContext, clDevice, nullptr, 4096u, 0u, &status);
auto svmAllocation = mockContext.getSVMAllocsManager()->getSVMAlloc(sharedMemory);
ASSERT_EQ(CL_SUCCESS, status);
auto svmAllocation = mockContext.getSVMAllocsManager()->getSVMAlloc(sharedMemory);
auto gpuAllocation = svmAllocation->gpuAllocations.getGraphicsAllocation(mockContext.getDevice(0)->getRootDeviceIndex());
auto buffer = clCreateBuffer(clContext, CL_MEM_READ_WRITE, 4096u, nullptr, &status);
ASSERT_EQ(CL_SUCCESS, status);
@@ -860,12 +876,12 @@ TEST(UnfiedSharedMemoryTransferCalls, givenSharedUsmAllocationWithoutLocalMemory
EXPECT_TRUE(temporaryAllocations.peekIsEmpty());
auto osContextId = neoQueue->getGpgpuCommandStreamReceiver().getOsContext().getContextId();
EXPECT_EQ(1u, svmAllocation->gpuAllocation->getTaskCount(osContextId));
EXPECT_EQ(1u, gpuAllocation->getTaskCount(osContextId));
status = clEnqueueReadBuffer(commandQueue, buffer, false, 0u, 4096u, sharedMemory, 0u, nullptr, nullptr);
ASSERT_EQ(CL_SUCCESS, status);
EXPECT_TRUE(temporaryAllocations.peekIsEmpty());
EXPECT_EQ(2u, svmAllocation->gpuAllocation->getTaskCount(osContextId));
EXPECT_EQ(2u, gpuAllocation->getTaskCount(osContextId));
status = clReleaseMemObject(buffer);
ASSERT_EQ(CL_SUCCESS, status);

View File

@@ -44,4 +44,8 @@ bool MultiGraphicsAllocation::isCoherent() const {
return getDefaultGraphicsAllocation()->isCoherent();
}
std::vector<GraphicsAllocation *> const &MultiGraphicsAllocation::getGraphicsAllocations() const {
return graphicsAllocations;
}
} // namespace NEO

View File

@@ -27,6 +27,8 @@ class MultiGraphicsAllocation : NonCopyableClass {
bool isCoherent() const;
std::vector<GraphicsAllocation *> const &getGraphicsAllocations() const;
protected:
std::vector<GraphicsAllocation *> graphicsAllocations;
};

View File

@@ -16,12 +16,12 @@
namespace NEO {
void SVMAllocsManager::MapBasedAllocationTracker::insert(SvmAllocationData allocationsPair) {
allocations.insert(std::make_pair(reinterpret_cast<void *>(allocationsPair.gpuAllocation->getGpuAddress()), allocationsPair));
allocations.insert(std::make_pair(reinterpret_cast<void *>(allocationsPair.gpuAllocations.getDefaultGraphicsAllocation()->getGpuAddress()), allocationsPair));
}
void SVMAllocsManager::MapBasedAllocationTracker::remove(SvmAllocationData allocationsPair) {
SvmAllocationContainer::iterator iter;
iter = allocations.find(reinterpret_cast<void *>(allocationsPair.gpuAllocation->getGpuAddress()));
iter = allocations.find(reinterpret_cast<void *>(allocationsPair.gpuAllocations.getDefaultGraphicsAllocation()->getGpuAddress()));
allocations.erase(iter);
}
@@ -43,7 +43,7 @@ SvmAllocationData *SVMAllocsManager::MapBasedAllocationTracker::get(const void *
}
if (Iter != End) {
svmAllocData = &Iter->second;
char *charPtr = reinterpret_cast<char *>(svmAllocData->gpuAllocation->getGpuAddress());
char *charPtr = reinterpret_cast<char *>(svmAllocData->gpuAllocations.getDefaultGraphicsAllocation()->getGpuAddress());
if (ptr < (charPtr + svmAllocData->size)) {
return svmAllocData;
}
@@ -83,7 +83,7 @@ void SVMAllocsManager::addInternalAllocationsToResidencyContainer(uint32_t rootD
(static_cast<Device *>(allocation.second.device)->getRootDeviceIndex() != rootDeviceIndex)) {
continue;
}
residencyContainer.push_back(allocation.second.gpuAllocation);
residencyContainer.push_back(allocation.second.gpuAllocations.getGraphicsAllocation(rootDeviceIndex));
}
}
@@ -91,7 +91,9 @@ void SVMAllocsManager::makeInternalAllocationsResident(CommandStreamReceiver &co
std::unique_lock<SpinLock> lock(mtx);
for (auto &allocation : this->SVMAllocs.allocations) {
if (allocation.second.memoryType & requestedTypesMask) {
commandStreamReceiver.makeResident(*allocation.second.gpuAllocation);
auto gpuAllocation = allocation.second.gpuAllocations.getGraphicsAllocation(commandStreamReceiver.getRootDeviceIndex());
UNRECOVERABLE_IF(nullptr == gpuAllocation);
commandStreamReceiver.makeResident(*gpuAllocation);
}
}
}
@@ -139,8 +141,8 @@ void *SVMAllocsManager::createUnifiedMemoryAllocation(uint32_t rootDeviceIndex,
return nullptr;
}
SvmAllocationData allocData;
allocData.gpuAllocation = unifiedMemoryAllocation;
SvmAllocationData allocData(rootDeviceIndex);
allocData.gpuAllocations.addAllocation(unifiedMemoryAllocation);
allocData.cpuAllocation = nullptr;
allocData.size = size;
allocData.memoryType = memoryProperties.memoryType;
@@ -199,7 +201,7 @@ bool SVMAllocsManager::freeSVMAlloc(void *ptr, bool blocking) {
if (svmData->cpuAllocation) {
this->memoryManager->waitForEnginesCompletion(*svmData->cpuAllocation);
}
this->memoryManager->waitForEnginesCompletion(*svmData->gpuAllocation);
this->memoryManager->waitForEnginesCompletion(*svmData->gpuAllocations.getDefaultGraphicsAllocation());
}
auto pageFaultManager = this->memoryManager->getPageFaultManager();
@@ -207,7 +209,7 @@ bool SVMAllocsManager::freeSVMAlloc(void *ptr, bool blocking) {
pageFaultManager->removeAllocation(ptr);
}
std::unique_lock<SpinLock> lock(mtx);
if (svmData->gpuAllocation->getAllocationType() == GraphicsAllocation::AllocationType::SVM_ZERO_COPY) {
if (svmData->gpuAllocations.getAllocationType() == GraphicsAllocation::AllocationType::SVM_ZERO_COPY) {
freeZeroCopySvmAllocation(svmData);
} else {
freeSvmAllocationWithDeviceStorage(svmData);
@@ -232,8 +234,8 @@ void *SVMAllocsManager::createZeroCopySvmAllocation(uint32_t rootDeviceIndex, si
allocation->setMemObjectsAllocationWithWritableFlags(!svmProperties.readOnly && !svmProperties.hostPtrReadOnly);
allocation->setCoherent(svmProperties.coherent);
SvmAllocationData allocData;
allocData.gpuAllocation = allocation;
SvmAllocationData allocData(rootDeviceIndex);
allocData.gpuAllocations.addAllocation(allocation);
allocData.size = size;
this->SVMAllocs.insert(allocData);
@@ -275,8 +277,8 @@ void *SVMAllocsManager::createUnifiedAllocationWithDeviceStorage(uint32_t rootDe
allocationGpu->setMemObjectsAllocationWithWritableFlags(!svmProperties.readOnly && !svmProperties.hostPtrReadOnly);
allocationGpu->setCoherent(svmProperties.coherent);
SvmAllocationData allocData;
allocData.gpuAllocation = allocationGpu;
SvmAllocationData allocData(rootDeviceIndex);
allocData.gpuAllocations.addAllocation(allocationGpu);
allocData.cpuAllocation = allocationCpu;
allocData.device = unifiedMemoryProperties.device;
allocData.size = size;
@@ -286,14 +288,14 @@ void *SVMAllocsManager::createUnifiedAllocationWithDeviceStorage(uint32_t rootDe
}
void SVMAllocsManager::freeZeroCopySvmAllocation(SvmAllocationData *svmData) {
GraphicsAllocation *gpuAllocation = svmData->gpuAllocation;
GraphicsAllocation *gpuAllocation = svmData->gpuAllocations.getDefaultGraphicsAllocation();
SVMAllocs.remove(*svmData);
memoryManager->freeGraphicsMemory(gpuAllocation);
}
void SVMAllocsManager::freeSvmAllocationWithDeviceStorage(SvmAllocationData *svmData) {
GraphicsAllocation *gpuAllocation = svmData->gpuAllocation;
GraphicsAllocation *gpuAllocation = svmData->gpuAllocations.getDefaultGraphicsAllocation();
GraphicsAllocation *cpuAllocation = svmData->cpuAllocation;
SVMAllocs.remove(*svmData);

View File

@@ -7,6 +7,7 @@
#pragma once
#include "shared/source/helpers/common_types.h"
#include "shared/source/memory_manager/multi_graphics_allocation.h"
#include "shared/source/memory_manager/residency_container.h"
#include "shared/source/unified_memory/unified_memory.h"
#include "shared/source/utilities/spinlock.h"
@@ -23,12 +24,28 @@ class GraphicsAllocation;
class MemoryManager;
struct SvmAllocationData {
SvmAllocationData(uint32_t maxRootDeviceIndex) : gpuAllocations(maxRootDeviceIndex), maxRootDeviceIndex(maxRootDeviceIndex){};
SvmAllocationData(const SvmAllocationData &svmAllocData) : SvmAllocationData(svmAllocData.maxRootDeviceIndex) {
this->allocationFlagsProperty = svmAllocData.allocationFlagsProperty;
this->cpuAllocation = svmAllocData.cpuAllocation;
this->device = svmAllocData.device;
this->size = svmAllocData.size;
this->memoryType = svmAllocData.memoryType;
for (auto allocation : svmAllocData.gpuAllocations.getGraphicsAllocations()) {
if (allocation) {
this->gpuAllocations.addAllocation(allocation);
}
}
}
GraphicsAllocation *cpuAllocation = nullptr;
GraphicsAllocation *gpuAllocation = nullptr;
MultiGraphicsAllocation gpuAllocations;
size_t size = 0;
InternalMemoryType memoryType = InternalMemoryType::SVM;
MemoryProperties allocationFlagsProperty;
void *device = nullptr;
protected:
const uint32_t maxRootDeviceIndex;
};
struct SvmMapOperation {

View File

@@ -9,7 +9,6 @@
#include "shared/source/helpers/debug_helpers.h"
#include "shared/source/helpers/ptr_math.h"
#include "shared/source/memory_manager/graphics_allocation.h"
#include "shared/source/memory_manager/unified_memory_manager.h"
#include <mutex>
@@ -79,7 +78,7 @@ bool PageFaultManager::verifyPageFault(void *ptr) {
void PageFaultManager::setAubWritable(bool writable, void *ptr, SVMAllocsManager *unifiedMemoryManager) {
UNRECOVERABLE_IF(ptr == nullptr);
auto gpuAlloc = unifiedMemoryManager->getSVMAlloc(ptr)->gpuAllocation;
auto gpuAlloc = unifiedMemoryManager->getSVMAlloc(ptr)->gpuAllocations.getDefaultGraphicsAllocation();
gpuAlloc->setAubWritable(writable, GraphicsAllocation::allBanks);
}
} // namespace NEO

View File

@@ -10,7 +10,6 @@
#include "shared/source/compiler_interface/linker.h"
#include "shared/source/device/device.h"
#include "shared/source/helpers/string.h"
#include "shared/source/memory_manager/graphics_allocation.h"
#include "shared/source/memory_manager/memory_manager.h"
#include "shared/source/memory_manager/unified_memory_manager.h"
#include "shared/source/program/program_info.h"
@@ -35,10 +34,10 @@ GraphicsAllocation *allocateGlobalsSurface(NEO::SVMAllocsManager *const svmAlloc
}
auto svmAlloc = svmAllocManager->getSVMAlloc(ptr);
UNRECOVERABLE_IF(svmAlloc == nullptr);
auto gpuAlloc = svmAlloc->gpuAllocation;
auto gpuAlloc = svmAlloc->gpuAllocations.getGraphicsAllocation(device.getRootDeviceIndex());
UNRECOVERABLE_IF(gpuAlloc == nullptr);
device.getMemoryManager()->copyMemoryToAllocation(gpuAlloc, initData, static_cast<uint32_t>(size));
return svmAllocManager->getSVMAlloc(ptr)->gpuAllocation;
return gpuAlloc;
} else {
auto allocationType = constant ? GraphicsAllocation::AllocationType::CONSTANT_SURFACE : GraphicsAllocation::AllocationType::GLOBAL_SURFACE;
auto gpuAlloc = device.getMemoryManager()->allocateGraphicsMemoryWithProperties({device.getRootDeviceIndex(),

View File

@@ -216,7 +216,7 @@ TEST_F(PageFaultManagerTest, givenUnifiedMemoryAllocWhenSetAubWritableIsCalledTh
pageFaultManager->baseAubWritable(false, alloc1, unifiedMemoryManager.get());
auto gpuAlloc = unifiedMemoryManager->getSVMAlloc(alloc1)->gpuAllocation;
auto gpuAlloc = unifiedMemoryManager->getSVMAlloc(alloc1)->gpuAllocations.getGraphicsAllocation(mockRootDeviceIndex);
EXPECT_FALSE(gpuAlloc->isAubWritable(GraphicsAllocation::allBanks));
unifiedMemoryManager->freeSVMAlloc(alloc1);