Fix gpu address alignment for SVM CPU allocations

Signed-off-by: Lukasz Jobczyk <lukasz.jobczyk@intel.com>
This commit is contained in:
Lukasz Jobczyk
2021-06-09 08:03:22 +00:00
committed by Compute-Runtime-Automation
parent 52f736c048
commit 13632ebbc9
2 changed files with 18 additions and 7 deletions

View File

@@ -252,27 +252,36 @@ DrmAllocation *DrmMemoryManager::allocateGraphicsMemoryWithAlignmentImpl(const A
// It's needed to prevent overlapping pages with user pointers
size_t cSize = std::max(alignUp(allocationData.size, minAlignment), minAlignment);
uint64_t gpuAddress = 0;
size_t alignedSize = cSize;
uint64_t gpuReservationAddress = 0;
uint64_t alignedGpuAddress = 0;
size_t alignedStorageSize = cSize;
size_t alignedVirtualAdressRangeSize = cSize;
auto svmCpuAllocation = allocationData.type == GraphicsAllocation::AllocationType::SVM_CPU;
if (svmCpuAllocation) {
//add 2MB padding in case reserved addr is not 2MB aligned
alignedSize = alignUp(cSize, cAlignment) + cAlignment;
alignedStorageSize = alignUp(cSize, cAlignment);
alignedVirtualAdressRangeSize = alignedStorageSize + cAlignment;
}
// if limitedRangeAlloction is enabled, memory allocation for bo in the limited Range heap is required
if ((isLimitedRange(allocationData.rootDeviceIndex) || svmCpuAllocation) && !allocationData.flags.isUSMHostAllocation) {
gpuAddress = acquireGpuRange(alignedSize, allocationData.rootDeviceIndex, HeapIndex::HEAP_STANDARD);
if (!gpuAddress) {
gpuReservationAddress = acquireGpuRange(alignedVirtualAdressRangeSize, allocationData.rootDeviceIndex, HeapIndex::HEAP_STANDARD);
if (!gpuReservationAddress) {
return nullptr;
}
alignedGpuAddress = gpuReservationAddress;
if (svmCpuAllocation) {
gpuAddress = alignUp(gpuAddress, cAlignment);
alignedGpuAddress = alignUp(gpuReservationAddress, cAlignment);
}
}
return createAllocWithAlignment(allocationData, cSize, cAlignment, alignedSize, gpuAddress);
auto drmAllocation = createAllocWithAlignment(allocationData, cSize, cAlignment, alignedStorageSize, alignedGpuAddress);
if (drmAllocation != nullptr) {
drmAllocation->setReservedAddressRange(reinterpret_cast<void *>(gpuReservationAddress), alignedVirtualAdressRangeSize);
}
return drmAllocation;
}
DrmAllocation *DrmMemoryManager::createAllocWithAlignmentFromUserptr(const AllocationData &allocationData, size_t size, size_t alignment, size_t alignedSVMSize, uint64_t gpuAddress) {