Pass canonized gpuAddress in setCpuPtrAndGpuAddress

Related-To: NEO-6523
Signed-off-by: Krzysztof Gibala <krzysztof.gibala@intel.com>
This commit is contained in:
Krzysztof Gibala
2022-06-06 20:34:20 +00:00
committed by Compute-Runtime-Automation
parent c51ce2a35c
commit 77dde01503
13 changed files with 90 additions and 35 deletions

View File

@@ -541,7 +541,10 @@ HWTEST_F(CommandStreamReceiverHwTest, WhenScratchSpaceIsRequiredThenCorrectAddre
uint64_t expectedScratchAddress = 0xAAABBBCCCDDD000ull;
auto scratchAllocation = scratchController->getScratchSpaceAllocation();
scratchAllocation->setCpuPtrAndGpuAddress(scratchAllocation->getUnderlyingBuffer(), expectedScratchAddress);
auto gmmHelper = pDevice->getGmmHelper();
auto canonizedGpuAddress = gmmHelper->canonize(expectedScratchAddress);
scratchAllocation->setCpuPtrAndGpuAddress(scratchAllocation->getUnderlyingBuffer(), canonizedGpuAddress);
EXPECT_TRUE(UnitTestHelper<FamilyType>::evaluateGshAddressForScratchSpace((scratchAllocation->getGpuAddress() - MemoryConstants::pageSize), scratchController->calculateNewGSH()));
}

View File

@@ -355,8 +355,10 @@ TEST_F(Image2dFromBufferTest, givenMemoryManagerSupportingVirtualPaddingWhenImag
uint64_t gpuAddress = 0x1234;
auto cpuAddress = buffer->getGraphicsAllocation(context.getDevice(0)->getRootDeviceIndex())->getUnderlyingBuffer();
auto gmmHelper = context.getDevice(0)->getGmmHelper();
auto canonizedGpuAddress = gmmHelper->canonize(gpuAddress);
buffer->getGraphicsAllocation(context.getDevice(0)->getRootDeviceIndex())->setCpuPtrAndGpuAddress(0, gpuAddress);
buffer->getGraphicsAllocation(context.getDevice(0)->getRootDeviceIndex())->setCpuPtrAndGpuAddress(0, canonizedGpuAddress);
ASSERT_NE(nullptr, buffer);
EXPECT_EQ(1, buffer->getRefInternalCount());
@@ -378,7 +380,7 @@ TEST_F(Image2dFromBufferTest, givenMemoryManagerSupportingVirtualPaddingWhenImag
EXPECT_EQ(bufferGraphicsAllocation, imageGraphicsAllocation);
buffer->getGraphicsAllocation(context.getDevice(0)->getRootDeviceIndex())->setCpuPtrAndGpuAddress(cpuAddress, gpuAddress);
buffer->getGraphicsAllocation(context.getDevice(0)->getRootDeviceIndex())->setCpuPtrAndGpuAddress(cpuAddress, canonizedGpuAddress);
}
TEST_F(Image2dFromBufferTest, givenMemoryManagerSupportingVirtualPaddingWhenImageIsCreatedThatDoesntFitInTheBufferThenPaddingIsApplied) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2018-2021 Intel Corporation
* Copyright (C) 2018-2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -106,7 +106,9 @@ TEST_F(PipeTest, givenPipeWithDifferentCpuAndGpuAddressesWhenSetArgPipeThenUseGp
EXPECT_EQ(21u, *reinterpret_cast<unsigned int *>(pipe->getCpuAddress()));
uint64_t gpuAddress = 0x12345;
auto pipeAllocation = pipe->getGraphicsAllocation(context.getDevice(0)->getRootDeviceIndex());
pipeAllocation->setCpuPtrAndGpuAddress(pipeAllocation->getUnderlyingBuffer(), gpuAddress);
auto gmmHelper = context.getDevice(0)->getGmmHelper();
auto canonizedGpuAddress = gmmHelper->canonize(gpuAddress);
pipeAllocation->setCpuPtrAndGpuAddress(pipeAllocation->getUnderlyingBuffer(), canonizedGpuAddress);
EXPECT_NE(reinterpret_cast<uint64_t>(pipeAllocation->getUnderlyingBuffer()), pipeAllocation->getGpuAddress());
uint64_t valueToPatch;
pipe->setPipeArg(&valueToPatch, sizeof(valueToPatch), context.getDevice(0)->getRootDeviceIndex());

View File

@@ -147,8 +147,11 @@ TEST(GraphicsAllocationTest, WhenGettingAddressesThenAddressesAreCorrect) {
cpuPtr = (void *)65535;
gpuAddr = 1ULL;
gfxAllocation.setCpuPtrAndGpuAddress(cpuPtr, gpuAddr);
EXPECT_EQ(gpuAddr, gfxAllocation.getGpuAddress());
auto gmmHelper = std::make_unique<GmmHelper>(nullptr, defaultHwInfo.get());
auto canonizedGpuAddress = gmmHelper->canonize(gpuAddr);
gfxAllocation.setCpuPtrAndGpuAddress(cpuPtr, canonizedGpuAddress);
EXPECT_EQ(canonizedGpuAddress, gfxAllocation.getGpuAddress());
EXPECT_EQ(cpuPtr, gfxAllocation.getUnderlyingBuffer());
}

View File

@@ -1362,7 +1362,9 @@ HWTEST_F(UnifiedSharedMemoryHWTest, givenDeviceUsmAllocationWhenWriteBufferThenC
auto gpuAddress = gpuAllocation->getGpuAddress();
void *gpuPtr = reinterpret_cast<void *>(gpuAddress);
char *shiftedPtr = cpuPtr + 0x10;
gpuAllocation->setCpuPtrAndGpuAddress(shiftedPtr, reinterpret_cast<uint64_t>(shiftedPtr));
auto gmmHelper = mockContext.getDevice(0)->getGmmHelper();
auto canonizedGpuAddress = gmmHelper->canonize(reinterpret_cast<uint64_t>(shiftedPtr));
gpuAllocation->setCpuPtrAndGpuAddress(shiftedPtr, canonizedGpuAddress);
cl_mem_flags flags = 0;
auto status = CL_INVALID_PLATFORM;
@@ -1373,7 +1375,8 @@ HWTEST_F(UnifiedSharedMemoryHWTest, givenDeviceUsmAllocationWhenWriteBufferThenC
myCmdQ.enqueueWriteBuffer(buffer, false, 0u, 4096u, deviceMemory, nullptr, 0u, nullptr, nullptr);
EXPECT_EQ(gpuPtr, myCmdQ.srcPtr);
gpuAllocation->setCpuPtrAndGpuAddress(cpuPtr, gpuAddress);
canonizedGpuAddress = gmmHelper->canonize(gpuAddress);
gpuAllocation->setCpuPtrAndGpuAddress(cpuPtr, canonizedGpuAddress);
delete buffer;
clMemFreeINTEL(&mockContext, deviceMemory);
}
@@ -1390,7 +1393,9 @@ HWTEST_F(UnifiedSharedMemoryHWTest, givenDeviceUsmAllocationWhenReadBufferThenCp
auto gpuAddress = gpuAllocation->getGpuAddress();
void *gpuPtr = reinterpret_cast<void *>(gpuAddress);
char *shiftedPtr = cpuPtr + 0x10;
gpuAllocation->setCpuPtrAndGpuAddress(shiftedPtr, reinterpret_cast<uint64_t>(shiftedPtr));
auto gmmHelper = mockContext.getDevice(0)->getGmmHelper();
auto canonizedGpuAddress = gmmHelper->canonize(reinterpret_cast<uint64_t>(shiftedPtr));
gpuAllocation->setCpuPtrAndGpuAddress(shiftedPtr, canonizedGpuAddress);
cl_mem_flags flags = 0;
auto status = CL_INVALID_PLATFORM;
@@ -1401,7 +1406,8 @@ HWTEST_F(UnifiedSharedMemoryHWTest, givenDeviceUsmAllocationWhenReadBufferThenCp
myCmdQ.enqueueReadBuffer(buffer, false, 0u, 4096u, deviceMemory, nullptr, 0u, nullptr, nullptr);
EXPECT_EQ(gpuPtr, myCmdQ.dstPtr);
gpuAllocation->setCpuPtrAndGpuAddress(cpuPtr, gpuAddress);
canonizedGpuAddress = gmmHelper->canonize(gpuAddress);
gpuAllocation->setCpuPtrAndGpuAddress(cpuPtr, canonizedGpuAddress);
delete buffer;
clMemFreeINTEL(&mockContext, deviceMemory);
}
@@ -1417,7 +1423,9 @@ HWTEST_F(UnifiedSharedMemoryHWTest, givenSharedUsmAllocationWhenWriteBufferThenC
auto gpuAddress = gpuAllocation->getGpuAddress();
void *gpuPtr = reinterpret_cast<void *>(gpuAddress);
char *shiftedPtr = cpuPtr + 0x10;
gpuAllocation->setCpuPtrAndGpuAddress(shiftedPtr, reinterpret_cast<uint64_t>(shiftedPtr));
auto gmmHelper = mockContext.getDevice(0)->getGmmHelper();
auto canonizedGpuAddress = gmmHelper->canonize(reinterpret_cast<uint64_t>(shiftedPtr));
gpuAllocation->setCpuPtrAndGpuAddress(shiftedPtr, canonizedGpuAddress);
cl_mem_flags flags = 0;
auto status = CL_INVALID_PLATFORM;
@@ -1428,7 +1436,8 @@ HWTEST_F(UnifiedSharedMemoryHWTest, givenSharedUsmAllocationWhenWriteBufferThenC
myCmdQ.enqueueWriteBuffer(buffer, false, 0u, 4096u, sharedMemory, nullptr, 0u, nullptr, nullptr);
EXPECT_EQ(gpuPtr, myCmdQ.srcPtr);
gpuAllocation->setCpuPtrAndGpuAddress(cpuPtr, gpuAddress);
canonizedGpuAddress = gmmHelper->canonize(gpuAddress);
gpuAllocation->setCpuPtrAndGpuAddress(cpuPtr, canonizedGpuAddress);
delete buffer;
clMemFreeINTEL(&mockContext, sharedMemory);
}
@@ -1444,7 +1453,9 @@ HWTEST_F(UnifiedSharedMemoryHWTest, givenSharedUsmAllocationWhenReadBufferThenCp
auto gpuAddress = gpuAllocation->getGpuAddress();
void *gpuPtr = reinterpret_cast<void *>(gpuAddress);
char *shiftedPtr = cpuPtr + 0x10;
gpuAllocation->setCpuPtrAndGpuAddress(shiftedPtr, reinterpret_cast<uint64_t>(shiftedPtr));
auto gmmHelper = mockContext.getDevice(0)->getGmmHelper();
auto canonizedGpuAddress = gmmHelper->canonize(reinterpret_cast<uint64_t>(shiftedPtr));
gpuAllocation->setCpuPtrAndGpuAddress(shiftedPtr, canonizedGpuAddress);
cl_mem_flags flags = 0;
auto status = CL_INVALID_PLATFORM;
@@ -1455,7 +1466,8 @@ HWTEST_F(UnifiedSharedMemoryHWTest, givenSharedUsmAllocationWhenReadBufferThenCp
myCmdQ.enqueueReadBuffer(buffer, false, 0u, 4096u, sharedMemory, nullptr, 0u, nullptr, nullptr);
EXPECT_EQ(gpuPtr, myCmdQ.dstPtr);
gpuAllocation->setCpuPtrAndGpuAddress(cpuPtr, gpuAddress);
canonizedGpuAddress = gmmHelper->canonize(gpuAddress);
gpuAllocation->setCpuPtrAndGpuAddress(cpuPtr, canonizedGpuAddress);
delete buffer;
clMemFreeINTEL(&mockContext, sharedMemory);
}

View File

@@ -27,8 +27,10 @@ TEST(FileLogger, GivenLogAllocationMemoryPoolFlagThenLogsCorrectInfo) {
DrmMock drm(*executionEnvironment->rootDeviceEnvironments[0]);
MockDrmAllocation allocation(AllocationType::BUFFER, MemoryPool::System64KBPages);
auto gmmHelper = std::make_unique<GmmHelper>(nullptr, defaultHwInfo.get());
auto canonizedGpuAddress = gmmHelper->canonize(0x12345);
allocation.setCpuPtrAndGpuAddress(&allocation, 0x12345);
allocation.setCpuPtrAndGpuAddress(&allocation, canonizedGpuAddress);
MockBufferObject bo(&drm);
bo.handle = 4;
@@ -77,8 +79,10 @@ TEST(FileLogger, givenLogAllocationStdoutWhenLogAllocationThenLogToStdoutInstead
DrmMock drm(*executionEnvironment->rootDeviceEnvironments[0]);
MockDrmAllocation allocation(AllocationType::BUFFER, MemoryPool::System64KBPages);
auto gmmHelper = std::make_unique<GmmHelper>(nullptr, defaultHwInfo.get());
auto canonizedGpuAddress = gmmHelper->canonize(0x12345);
allocation.setCpuPtrAndGpuAddress(&allocation, 0x12345);
allocation.setCpuPtrAndGpuAddress(&allocation, canonizedGpuAddress);
MockBufferObject bo(&drm);
bo.handle = 4;

View File

@@ -85,9 +85,9 @@ class GraphicsAllocation : public IDNode<GraphicsAllocation> {
void *getDriverAllocatedCpuPtr() const { return driverAllocatedCpuPointer; }
void setDriverAllocatedCpuPtr(void *allocatedCpuPtr) { driverAllocatedCpuPointer = allocatedCpuPtr; }
void setCpuPtrAndGpuAddress(void *cpuPtr, uint64_t gpuAddress) {
void setCpuPtrAndGpuAddress(void *cpuPtr, uint64_t canonizedGpuAddress) {
this->cpuPtr = cpuPtr;
this->gpuAddress = GmmHelper::canonize(gpuAddress);
this->gpuAddress = canonizedGpuAddress;
}
size_t getUnderlyingBufferSize() const { return size; }
void setSize(size_t size) { this->size = size; }

View File

@@ -98,7 +98,10 @@ GraphicsAllocation *OsAgnosticMemoryManager::allocateGraphicsMemoryWithAlignment
}
memoryAllocation->setReservedAddressRange(gpuPtr, reserveSize);
gpuPtr = alignUp(gpuPtr, alignment);
memoryAllocation->setCpuPtrAndGpuAddress(ptr, reinterpret_cast<uint64_t>(gpuPtr));
auto gmmHelper = getGmmHelper(allocationData.rootDeviceIndex);
auto canonizedGpuAddress = gmmHelper->canonize(reinterpret_cast<uint64_t>(gpuPtr));
memoryAllocation->setCpuPtrAndGpuAddress(ptr, canonizedGpuAddress);
}
if (allocationData.type == AllocationType::DEBUG_CONTEXT_SAVE_AREA ||
@@ -144,7 +147,10 @@ GraphicsAllocation *OsAgnosticMemoryManager::allocateGraphicsMemoryForNonSvmHost
GraphicsAllocation *OsAgnosticMemoryManager::allocateGraphicsMemoryWithGpuVa(const AllocationData &allocationData) {
auto memoryAllocation = static_cast<MemoryAllocation *>(allocateGraphicsMemoryWithAlignment(allocationData));
memoryAllocation->setCpuPtrAndGpuAddress(memoryAllocation->getUnderlyingBuffer(), allocationData.gpuAddress);
auto gmmHelper = getGmmHelper(allocationData.rootDeviceIndex);
auto canonizedGpuAddress = gmmHelper->canonize(allocationData.gpuAddress);
memoryAllocation->setCpuPtrAndGpuAddress(memoryAllocation->getUnderlyingBuffer(), canonizedGpuAddress);
return memoryAllocation;
}

View File

@@ -1514,8 +1514,11 @@ GraphicsAllocation *DrmMemoryManager::allocateGraphicsMemoryInDevicePool(const A
}
auto alignedCpuAddress = alignDown(cpuAddress, 2 * MemoryConstants::megaByte);
auto offset = ptrDiff(cpuAddress, alignedCpuAddress);
auto gmmHelper = getGmmHelper(allocationData.rootDeviceIndex);
auto canonizedGpuAddress = gmmHelper->canonize(reinterpret_cast<uint64_t>(alignedCpuAddress));
allocation->setAllocationOffset(offset);
allocation->setCpuPtrAndGpuAddress(cpuAddress, reinterpret_cast<uint64_t>(alignedCpuAddress));
allocation->setCpuPtrAndGpuAddress(cpuAddress, canonizedGpuAddress);
DEBUG_BREAK_IF(allocation->storageInfo.multiStorage);
allocation->getBO()->setAddress(reinterpret_cast<uint64_t>(cpuAddress));
}
@@ -1526,7 +1529,9 @@ GraphicsAllocation *DrmMemoryManager::allocateGraphicsMemoryInDevicePool(const A
status = AllocationStatus::Error;
return nullptr;
}
allocation->setCpuPtrAndGpuAddress(cpuAddress, gpuAddress);
auto gmmHelper = getGmmHelper(allocationData.rootDeviceIndex);
auto canonizedGpuAddress = gmmHelper->canonize(gpuAddress);
allocation->setCpuPtrAndGpuAddress(cpuAddress, canonizedGpuAddress);
}
if (heapAssigner.useInternal32BitHeap(allocationData.type)) {
allocation->setGpuBaseAddress(gmmHelper->canonize(getInternalHeapBaseAddress(allocationData.rootDeviceIndex, true)));

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2021 Intel Corporation
* Copyright (C) 2021-2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -21,7 +21,9 @@ void ImplicitScalingFixture::SetUp() {
alignedMemory = alignedMalloc(bufferSize, 4096);
cmdBufferAlloc.setCpuPtrAndGpuAddress(alignedMemory, gpuVa);
auto gmmHelper = pDevice->getGmmHelper();
auto canonizedGpuAddress = gmmHelper->canonize(gpuVa);
cmdBufferAlloc.setCpuPtrAndGpuAddress(alignedMemory, canonizedGpuAddress);
commandStream.replaceBuffer(alignedMemory, bufferSize);
commandStream.replaceGraphicsAllocation(&cmdBufferAlloc);

View File

@@ -538,12 +538,18 @@ class OsAgnosticMemoryManagerForImagesWithNoHostPtr : public OsAgnosticMemoryMan
GraphicsAllocation *allocateGraphicsMemoryForImage(const AllocationData &allocationData) override {
auto imageAllocation = OsAgnosticMemoryManager::allocateGraphicsMemoryForImage(allocationData);
auto gmmHelper = getGmmHelper(allocationData.rootDeviceIndex);
auto canonizedGpuAddress = gmmHelper->canonize(imageAllocation->getGpuAddress());
cpuPtr = imageAllocation->getUnderlyingBuffer();
imageAllocation->setCpuPtrAndGpuAddress(nullptr, imageAllocation->getGpuAddress());
imageAllocation->setCpuPtrAndGpuAddress(nullptr, canonizedGpuAddress);
return imageAllocation;
};
void freeGraphicsMemoryImpl(GraphicsAllocation *imageAllocation) override {
imageAllocation->setCpuPtrAndGpuAddress(cpuPtr, imageAllocation->getGpuAddress());
auto gmmHelper = getGmmHelper(imageAllocation->getRootDeviceIndex());
auto canonizedGpuAddress = gmmHelper->canonize(imageAllocation->getGpuAddress());
imageAllocation->setCpuPtrAndGpuAddress(cpuPtr, canonizedGpuAddress);
OsAgnosticMemoryManager::freeGraphicsMemoryImpl(imageAllocation);
};
void *lockResourceImpl(GraphicsAllocation &imageAllocation) override {

View File

@@ -41,11 +41,14 @@ TEST(LinearStreamSimpleTest, givenLinearStreamWithoutGraphicsAllocationWhenGetti
TEST(LinearStreamSimpleTest, givenLinearStreamWithGraphicsAllocationWhenGettingGpuBaseThenGpuAddressFromGraphicsAllocationIsReturned) {
MockGraphicsAllocation gfxAllocation;
gfxAllocation.setCpuPtrAndGpuAddress(nullptr, 0x5555000);
auto gmmHelper = std::make_unique<GmmHelper>(nullptr, defaultHwInfo.get());
auto canonizedGpuAddress = gmmHelper->canonize(0x5555000);
gfxAllocation.setCpuPtrAndGpuAddress(nullptr, canonizedGpuAddress);
uint32_t pCmdBuffer[1024]{};
LinearStream linearStream(&gfxAllocation, pCmdBuffer, 1000);
EXPECT_EQ(0x5555000u, linearStream.getGpuBase());
EXPECT_EQ(canonizedGpuAddress, linearStream.getGpuBase());
}
TEST_F(LinearStreamTest, GivenSizeZeroWhenGettingSpaceUsedThenNonNullPointerIsReturned) {
@@ -223,4 +226,4 @@ TEST_F(CommandContainerLinearStreamTest, givenLinearStreamWithCmdContainerWhenTh
auto ptr = stream->getSpace(0u);
stream->getSpace(dummyCommandSize);
EXPECT_EQ(memcmp(ptr, hwHelper.getBatchBufferEndReference(), hwHelper.getBatchBufferEndSize()), 0);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2018-2021 Intel Corporation
* Copyright (C) 2018-2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -9,6 +9,7 @@
#include "shared/source/helpers/ptr_math.h"
#include "shared/source/indirect_heap/indirect_heap.h"
#include "shared/source/memory_manager/graphics_allocation.h"
#include "shared/test/common/helpers/default_hw_info.h"
#include "shared/test/common/mocks/mock_graphics_allocation.h"
#include "gtest/gtest.h"
@@ -64,14 +65,17 @@ TEST_F(HeapDirtyStateTests, givenNonDirtyObjectWhenAddressChangedThenReturnDirty
auto newBuffer = ptrOffset(buffer, MemoryConstants::pageSize + 1);
auto graphicsAllocation = stream->getGraphicsAllocation();
graphicsAllocation->setCpuPtrAndGpuAddress(newBuffer, castToUint64(newBuffer));
auto gmmHelper = std::make_unique<GmmHelper>(nullptr, defaultHwInfo.get());
auto canonizedGpuAddress = gmmHelper->canonize(castToUint64(newBuffer));
graphicsAllocation->setCpuPtrAndGpuAddress(newBuffer, canonizedGpuAddress);
stream->replaceBuffer(newBuffer, bufferSize);
EXPECT_TRUE(mockHeapDirtyState.updateAndCheck(stream.get()));
EXPECT_EQ(1u, mockHeapDirtyState.sizeInPages);
EXPECT_EQ(castToUint64(newBuffer), mockHeapDirtyState.gpuBaseAddress);
EXPECT_EQ(canonizedGpuAddress, mockHeapDirtyState.gpuBaseAddress);
}
TEST_F(HeapDirtyStateTests, givenIndirectHeapWithoutGraphicsAllocationWhenUpdateAndCheckIsCalledThenSizeIsSetToZero) {
@@ -101,14 +105,17 @@ TEST_F(HeapDirtyStateTests, givenNonDirtyObjectWhenSizeAndBufferChangedThenRetur
auto newBuffer = ptrOffset(buffer, 1);
auto newBufferSize = bufferSize + MemoryConstants::pageSize;
auto graphicsAllocation = stream->getGraphicsAllocation();
auto gmmHelper = std::make_unique<GmmHelper>(nullptr, defaultHwInfo.get());
auto canonizedGpuAddress = gmmHelper->canonize(castToUint64(newBuffer));
graphicsAllocation->setSize(newBufferSize);
graphicsAllocation->setCpuPtrAndGpuAddress(newBuffer, castToUint64(newBuffer));
graphicsAllocation->setCpuPtrAndGpuAddress(newBuffer, canonizedGpuAddress);
stream->replaceBuffer(stream->getCpuBase(), newBufferSize);
EXPECT_TRUE(mockHeapDirtyState.updateAndCheck(stream.get()));
EXPECT_EQ(getSizeInPages(newBufferSize), mockHeapDirtyState.sizeInPages);
EXPECT_EQ(castToUint64(newBuffer), mockHeapDirtyState.gpuBaseAddress);
EXPECT_EQ(canonizedGpuAddress, mockHeapDirtyState.gpuBaseAddress);
}
TEST(DirtyStateHelpers, givenDirtyStateHelperWhenTwoDifferentIndirectHeapsAreCheckedButWithTheSame4GBbaseThenStateIsNotDirty) {