fix: decanonize pointer to match GPU heap address space

* `zeVirtualMemReserve` `pStart` address may be passed in a canonizated form.

Resolves: NEO-10086

Signed-off-by: Kozlowski, Marek <marek.kozlowski@intel.com>
This commit is contained in:
Kozlowski, Marek
2024-02-28 12:05:04 +00:00
committed by Compute-Runtime-Automation
parent bbe1043f08
commit 6751d19c19
2 changed files with 27 additions and 2 deletions

View File

@@ -969,9 +969,10 @@ AddressRange WddmMemoryManager::reserveGpuAddressOnHeap(const uint64_t requiredS
*reservedOnRootDeviceIndex = 0;
size_t reservedSize = 0;
NTSTATUS status = STATUS_UNSUCCESSFUL;
auto gmmHelper = executionEnvironment.rootDeviceEnvironments[*reservedOnRootDeviceIndex]->getGmmHelper();
for (auto rootDeviceIndex : rootDeviceIndices) {
auto gfxPartition = getGfxPartition(rootDeviceIndex);
status = getWddm(rootDeviceIndex).reserveGpuVirtualAddress(requiredStartAddress, gfxPartition->getHeapMinimalAddress(heap), gfxPartition->getHeapLimit(heap), size, &gpuVa);
status = getWddm(rootDeviceIndex).reserveGpuVirtualAddress(gmmHelper->decanonize(requiredStartAddress), gfxPartition->getHeapMinimalAddress(heap), gfxPartition->getHeapLimit(heap), size, &gpuVa);
if (requiredStartAddress != 0ull && status != STATUS_SUCCESS) {
status = getWddm(rootDeviceIndex).reserveGpuVirtualAddress(0ull, gfxPartition->getHeapMinimalAddress(heap), gfxPartition->getHeapLimit(heap), size, &gpuVa);
}
@@ -984,7 +985,6 @@ AddressRange WddmMemoryManager::reserveGpuAddressOnHeap(const uint64_t requiredS
if (status != STATUS_SUCCESS) {
return AddressRange{0u, 0};
}
auto gmmHelper = executionEnvironment.rootDeviceEnvironments[*reservedOnRootDeviceIndex]->getGmmHelper();
gpuVa = gmmHelper->canonize(gpuVa);
return AddressRange{gpuVa, reservedSize};
}

View File

@@ -1245,6 +1245,31 @@ TEST_F(WddmMemoryManagerSimpleTest, givenWddmMemoryManagerWhenGpuAddressIsReserv
memoryManager->freeGpuAddress(addressRange, 0);
}
TEST_F(WddmMemoryManagerSimpleTest, givenWddmMemoryManagerWhenGpuAddressIsReservedAndFreedThenRequestingTheSameAddressButCanonizedReturnedRequestedAddress) {
RootDeviceIndicesContainer rootDeviceIndices;
rootDeviceIndices.pushUnique(0);
uint32_t rootDeviceIndexReserved = 1;
HeapIndex heap = HeapIndex::heapStandard;
auto alignment = memoryManager->selectAlignmentAndHeap(MemoryConstants::pageSize64k, &heap);
EXPECT_EQ(heap, HeapIndex::heapStandard64KB);
EXPECT_EQ(MemoryConstants::pageSize64k, alignment);
auto addressRange = memoryManager->reserveGpuAddressOnHeap(0ull, MemoryConstants::pageSize64k, rootDeviceIndices, &rootDeviceIndexReserved, heap, alignment);
auto gmmHelper = memoryManager->getGmmHelper(0);
EXPECT_EQ(0u, rootDeviceIndexReserved);
EXPECT_NE(0u, gmmHelper->decanonize(addressRange.address));
EXPECT_EQ(MemoryConstants::pageSize64k, addressRange.size);
const auto addressRangeOriginal = addressRange;
memoryManager->freeGpuAddress(addressRange, 0);
addressRange = memoryManager->reserveGpuAddressOnHeap(gmmHelper->canonize(addressRangeOriginal.address), MemoryConstants::pageSize64k, rootDeviceIndices, &rootDeviceIndexReserved, heap, alignment);
EXPECT_EQ(0u, rootDeviceIndexReserved);
EXPECT_EQ(addressRangeOriginal.address, addressRange.address);
EXPECT_EQ(MemoryConstants::pageSize64k, addressRange.size);
memoryManager->freeGpuAddress(addressRange, 0);
}
TEST_F(WddmMemoryManagerSimpleTest, givenWddmMemoryManagerWhenAllocatingWithGpuVaThenNullptrIsReturned) {
AllocationData allocationData;