DrmBO: canonize GPU addresses

Related-To: NEO-6364
Signed-off-by: Artur Harasimiuk <artur.harasimiuk@intel.com>
This commit is contained in:
Artur Harasimiuk 2021-10-20 16:16:59 +00:00 committed by Compute-Runtime-Automation
parent 28b37aea72
commit d2a29ce458
6 changed files with 48 additions and 10 deletions

View File

@ -66,7 +66,7 @@ HWTEST2_F(CommandListCreate, givenCommandListWhenAppendWriteGlobalTimestampCalle
std::unique_ptr<L0::CommandList> commandList(CommandList::create(productFamily, device, NEO::EngineGroupType::RenderCompute, 0u, returnValue));
auto &commandContainer = commandList->commandContainer;
uint64_t timestampAddress = 0x12345678555500;
uint64_t timestampAddress = 0x123456785500;
uint32_t timestampAddressLow = (uint32_t)(timestampAddress & 0xFFFFFFFF);
uint32_t timestampAddressHigh = (uint32_t)(timestampAddress >> 32);
uint64_t *dstptr = reinterpret_cast<uint64_t *>(timestampAddress);
@ -92,7 +92,7 @@ HWTEST2_F(CommandListCreate, givenCommandListWhenAppendWriteGlobalTimestampCalle
HWTEST2_F(CommandListCreate, givenCommandListWhenAppendWriteGlobalTimestampCalledThenTimestampAllocationIsInsideResidencyContainer, Platforms) {
ze_result_t returnValue;
std::unique_ptr<L0::CommandList> commandList(CommandList::create(productFamily, device, NEO::EngineGroupType::RenderCompute, 0u, returnValue));
uint64_t timestampAddress = 0x12345678555500;
uint64_t timestampAddress = 0x123456785500;
uint64_t *dstptr = reinterpret_cast<uint64_t *>(timestampAddress);
commandList->appendWriteGlobalTimestamp(dstptr, nullptr, 0, nullptr);
@ -120,7 +120,7 @@ HWTEST2_F(CommandListCreate, givenImmediateCommandListWhenAppendWriteGlobalTimes
CommandQueueImp *cmdQueue = reinterpret_cast<CommandQueueImp *>(commandList0->cmdQImmediate);
EXPECT_EQ(cmdQueue->getCsr(), neoDevice->getInternalEngine().commandStreamReceiver);
uint64_t timestampAddress = 0x12345678555500;
uint64_t timestampAddress = 0x123456785500;
uint64_t *dstptr = reinterpret_cast<uint64_t *>(timestampAddress);
auto result = commandList0->appendWriteGlobalTimestamp(dstptr, nullptr, 0, nullptr);

View File

@ -499,4 +499,39 @@ TEST_F(DrmBufferObjectTest, givenAsyncDebugFlagWhenFillingExecObjectThenFlagIsSe
bo->fillExecObject(execObject, osContext.get(), 0, 1);
EXPECT_TRUE(execObject.flags & EXEC_OBJECT_ASYNC);
}
}
TEST_F(DrmBufferObjectTest, given47bitAddressWhenSetThenIsAddressNotCanonized) {
auto hwInfoAddressWidth = Math::log2(defaultHwInfo.get()->capabilityTable.gpuAddressSpace + 1);
MockExecutionEnvironment executionEnvironment(defaultHwInfo.get());
DrmMock drm(*(executionEnvironment.rootDeviceEnvironments[0].get()));
auto toShift = hwInfoAddressWidth - 36;
uint64_t address = 0x7fff00000 << toShift;
MockBufferObject bo(&drm, 0, 0, 1);
bo.setAddress(address);
auto boAddress = bo.peekAddress();
EXPECT_EQ(boAddress, address);
}
TEST_F(DrmBufferObjectTest, given48bitAddressWhenSetThenAddressIsCanonized) {
auto hwInfoAddressWidth = Math::log2(defaultHwInfo.get()->capabilityTable.gpuAddressSpace + 1);
MockExecutionEnvironment executionEnvironment(defaultHwInfo.get());
DrmMock drm(*(executionEnvironment.rootDeviceEnvironments[0].get()));
auto toShift = hwInfoAddressWidth - 36;
uint64_t address = 0x8fff00000 << toShift;
uint64_t expectedAddress = 0;
if (hwInfoAddressWidth < 48) {
expectedAddress = 0x8fff00000 << toShift;
} else {
expectedAddress = 0xfffffff8fff00000 << toShift;
}
MockBufferObject bo(&drm, 0, 0, 1);
bo.setAddress(address);
auto boAddress = bo.peekAddress();
EXPECT_EQ(boAddress, expectedAddress);
}

View File

@ -8,6 +8,7 @@
#include "graphics_allocation.h"
#include "shared/source/gmm_helper/gmm.h"
#include "shared/source/gmm_helper/gmm_helper.h"
#include "shared/source/helpers/aligned_memory.h"
#include "shared/source/memory_manager/memory_manager.h"
#include "shared/source/utilities/logger.h"
@ -22,7 +23,7 @@ GraphicsAllocation::GraphicsAllocation(uint32_t rootDeviceIndex, size_t numGmms,
uint64_t baseAddress, size_t sizeIn, MemoryPool::Type pool, size_t maxOsContextCount)
: rootDeviceIndex(rootDeviceIndex),
gpuBaseAddress(baseAddress),
gpuAddress(gpuAddress),
gpuAddress(GmmHelper::canonize(gpuAddress)),
size(sizeIn),
cpuPtr(cpuPtrIn),
memoryPool(pool),
@ -34,7 +35,7 @@ GraphicsAllocation::GraphicsAllocation(uint32_t rootDeviceIndex, size_t numGmms,
GraphicsAllocation::GraphicsAllocation(uint32_t rootDeviceIndex, size_t numGmms, AllocationType allocationType, void *cpuPtrIn, size_t sizeIn,
osHandle sharedHandleIn, MemoryPool::Type pool, size_t maxOsContextCount)
: rootDeviceIndex(rootDeviceIndex),
gpuAddress(castToUint64(cpuPtrIn)),
gpuAddress(GmmHelper::canonize(castToUint64(cpuPtrIn))),
size(sizeIn),
cpuPtr(cpuPtrIn),
memoryPool(pool),

View File

@ -7,6 +7,7 @@
#pragma once
#include "shared/source/gmm_helper/gmm_helper.h"
#include "shared/source/helpers/constants.h"
#include "shared/source/helpers/debug_helpers.h"
#include "shared/source/helpers/ptr_math.h"
@ -128,7 +129,7 @@ class GraphicsAllocation : public IDNode<GraphicsAllocation> {
void setCpuPtrAndGpuAddress(void *cpuPtr, uint64_t gpuAddress) {
this->cpuPtr = cpuPtr;
this->gpuAddress = gpuAddress;
this->gpuAddress = GmmHelper::canonize(gpuAddress);
}
size_t getUnderlyingBufferSize() const { return size; }
void setSize(size_t size) { this->size = size; }

View File

@ -7,6 +7,7 @@
#pragma once
#include "shared/source/gmm_helper/gmm_helper.h"
#include "shared/source/memory_manager/definitions/engine_limits.h"
#include "shared/source/os_interface/linux/cache_info.h"
#include "shared/source/utilities/stackvec.h"
@ -67,7 +68,7 @@ class BufferObject {
int peekHandle() const { return handle; }
const Drm *peekDrm() const { return drm; }
uint64_t peekAddress() const { return gpuAddress; }
void setAddress(uint64_t address) { this->gpuAddress = address; }
void setAddress(uint64_t address) { this->gpuAddress = GmmHelper::canonize(address); }
void *peekLockedAddress() const { return lockedAddress; }
void setLockedAddress(void *cpuAddress) { this->lockedAddress = cpuAddress; }
void setUnmapSize(uint64_t unmapSize) { this->unmapSize = unmapSize; }

View File

@ -561,7 +561,7 @@ DrmAllocation *DrmMemoryManager::allocate32BitGraphicsMemoryImpl(const Allocatio
return nullptr;
}
bo->setAddress(GmmHelper::canonize(gpuVirtualAddress));
bo->setAddress(gpuVirtualAddress);
auto allocation = new DrmAllocation(allocationData.rootDeviceIndex, allocationData.type, bo.get(), const_cast<void *>(allocationData.hostPtr), GmmHelper::canonize(ptrOffset(gpuVirtualAddress, inputPointerOffset)),
allocationSize, MemoryPool::System4KBPagesWith32BitGpuAddressing);
allocation->set32BitAllocation(true);
@ -595,7 +595,7 @@ DrmAllocation *DrmMemoryManager::allocate32BitGraphicsMemoryImpl(const Allocatio
return nullptr;
}
bo->setAddress(GmmHelper::canonize(gpuVA));
bo->setAddress(gpuVA);
// softpin to the GPU address, res if it uses limitedRange Allocation
auto allocation = new DrmAllocation(allocationData.rootDeviceIndex, allocationData.type, bo.get(), ptrAlloc, GmmHelper::canonize(gpuVA), alignedAllocationSize,