mirror of
https://github.com/intel/compute-runtime.git
synced 2026-01-05 17:20:26 +08:00
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:
committed by
sys_ocldev
parent
5bc511b77d
commit
93c1e1b976
@@ -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,
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user