Skip to content

Commit

Permalink
fix: handle not aligned gtt size reported by i915
Browse files Browse the repository at this point in the history
when i915 reports gtt size between 47 and 48 bits we consider
it as 48 bit VA space

Related-To: GSD-8215
Signed-off-by: Mateusz Jablonski <mateusz.jablonski@intel.com>
  • Loading branch information
JablonskiMateusz authored and Compute-Runtime-Automation committed Mar 29, 2024
1 parent d6a14d4 commit 420e139
Show file tree
Hide file tree
Showing 19 changed files with 150 additions and 73 deletions.
3 changes: 1 addition & 2 deletions shared/source/memory_manager/gfx_partition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ uint64_t GfxPartition::getHeapMinimalAddress(HeapIndex heapIndex) {
}
}

bool GfxPartition::init(uint64_t gpuAddressSpace, size_t cpuAddressRangeSizeToReserve, uint32_t rootDeviceIndex, size_t numRootDevices, bool useExternalFrontWindowPool, uint64_t systemMemorySize) {
bool GfxPartition::init(uint64_t gpuAddressSpace, size_t cpuAddressRangeSizeToReserve, uint32_t rootDeviceIndex, size_t numRootDevices, bool useExternalFrontWindowPool, uint64_t systemMemorySize, uint64_t gfxTop) {

/*
* I. 64-bit builds:
Expand Down Expand Up @@ -238,7 +238,6 @@ bool GfxPartition::init(uint64_t gpuAddressSpace, size_t cpuAddressRangeSizeToRe
* 0x0 0x100000000 gpuAddressSpace
*/

uint64_t gfxTop = gpuAddressSpace + 1;
uint64_t gfxBase = 0x0ull;
const uint64_t gfxHeap32Size = 4 * MemoryConstants::gigaByte;

Expand Down
4 changes: 2 additions & 2 deletions shared/source/memory_manager/gfx_partition.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2019-2023 Intel Corporation
* Copyright (C) 2019-2024 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
Expand Down Expand Up @@ -39,7 +39,7 @@ class GfxPartition {
GfxPartition(OSMemory::ReservedCpuAddressRange &reservedCpuAddressRangeForHeapSvm);
MOCKABLE_VIRTUAL ~GfxPartition();

MOCKABLE_VIRTUAL bool init(uint64_t gpuAddressSpace, size_t cpuAddressRangeSizeToReserve, uint32_t rootDeviceIndex, size_t numRootDevices, bool useExternalFrontWindowPool, uint64_t systemMemorySize);
MOCKABLE_VIRTUAL bool init(uint64_t gpuAddressSpace, size_t cpuAddressRangeSizeToReserve, uint32_t rootDeviceIndex, size_t numRootDevices, bool useExternalFrontWindowPool, uint64_t systemMemorySize, uint64_t gfxTop);

void heapInit(HeapIndex heapIndex, uint64_t base, uint64_t size) {
getHeap(heapIndex).init(base, size, MemoryConstants::pageSize);
Expand Down
3 changes: 2 additions & 1 deletion shared/source/memory_manager/os_agnostic_memory_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ void OsAgnosticMemoryManager::initialize(bool aubUsage) {
this->enable64kbpages[rootDeviceIndex] = is64kbPagesEnabled(hwInfo);
this->localMemorySupported.push_back(gfxCoreHelper.getEnableLocalMemory(*hwInfo));
auto gpuAddressSpace = executionEnvironment.rootDeviceEnvironments[rootDeviceIndex]->getHardwareInfo()->capabilityTable.gpuAddressSpace;
if (!getGfxPartition(rootDeviceIndex)->init(gpuAddressSpace, reservedCpuAddressRangeSize, rootDeviceIndex, gfxPartitions.size(), heapAssigners[rootDeviceIndex]->apiAllowExternalHeapForSshAndDsh, OsAgnosticMemoryManager::getSystemSharedMemory(rootDeviceIndex))) {
auto gfxTop = gpuAddressSpace + 1;
if (!getGfxPartition(rootDeviceIndex)->init(gpuAddressSpace, reservedCpuAddressRangeSize, rootDeviceIndex, gfxPartitions.size(), heapAssigners[rootDeviceIndex]->apiAllowExternalHeapForSshAndDsh, OsAgnosticMemoryManager::getSystemSharedMemory(rootDeviceIndex), gfxTop)) {
initialized = false;
return;
}
Expand Down
6 changes: 4 additions & 2 deletions shared/source/os_interface/linux/drm_memory_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,9 @@ void DrmMemoryManager::initialize(GemCloseWorkerMode mode) {

for (uint32_t rootDeviceIndex = 0; rootDeviceIndex < gfxPartitions.size(); ++rootDeviceIndex) {
auto gpuAddressSpace = executionEnvironment.rootDeviceEnvironments[rootDeviceIndex]->getHardwareInfo()->capabilityTable.gpuAddressSpace;
if (!getGfxPartition(rootDeviceIndex)->init(gpuAddressSpace, getSizeToReserve(), rootDeviceIndex, gfxPartitions.size(), heapAssigners[rootDeviceIndex]->apiAllowExternalHeapForSshAndDsh, DrmMemoryManager::getSystemSharedMemory(rootDeviceIndex))) {
uint64_t gfxTop{};
getDrm(rootDeviceIndex).queryGttSize(gfxTop, false);
if (!getGfxPartition(rootDeviceIndex)->init(gpuAddressSpace, getSizeToReserve(), rootDeviceIndex, gfxPartitions.size(), heapAssigners[rootDeviceIndex]->apiAllowExternalHeapForSshAndDsh, DrmMemoryManager::getSystemSharedMemory(rootDeviceIndex), gfxTop)) {
initialized = false;
return;
}
Expand Down Expand Up @@ -1251,7 +1253,7 @@ uint64_t DrmMemoryManager::getSystemSharedMemory(uint32_t rootDeviceIndex) {

uint64_t gpuMemorySize = 0u;

[[maybe_unused]] auto ret = getDrm(rootDeviceIndex).queryGttSize(gpuMemorySize);
[[maybe_unused]] auto ret = getDrm(rootDeviceIndex).queryGttSize(gpuMemorySize, false);
DEBUG_BREAK_IF(ret != 0);

return std::min(hostMemorySize, gpuMemorySize);
Expand Down
19 changes: 17 additions & 2 deletions shared/source/os_interface/linux/drm_neo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,13 +232,17 @@ bool Drm::readSysFsAsString(const std::string &relativeFilePath, std::string &re
return true;
}

int Drm::queryGttSize(uint64_t &gttSizeOutput) {
int Drm::queryGttSize(uint64_t &gttSizeOutput, bool alignUpToFullRange) {
GemContextParam contextParam = {0};
contextParam.param = ioctlHelper->getDrmParamValue(DrmParam::contextParamGttSize);

int ret = ioctlHelper->ioctl(DrmIoctl::gemContextGetparam, &contextParam);
if (ret == 0) {
gttSizeOutput = contextParam.value;
if (alignUpToFullRange) {
gttSizeOutput = Drm::alignUpGttSize(contextParam.value);
} else {
gttSizeOutput = contextParam.value;
}
}

return ret;
Expand Down Expand Up @@ -1580,6 +1584,17 @@ void Drm::waitOnUserFences(const OsContextLinux &osContext, uint64_t address, ui
}
const HardwareInfo *Drm::getHardwareInfo() const { return rootDeviceEnvironment.getHardwareInfo(); }

uint64_t Drm::alignUpGttSize(uint64_t inputGttSize) {

constexpr uint64_t gttSize47bit = (1ull << 47);
constexpr uint64_t gttSize48bit = (1ull << 48);

if (inputGttSize > gttSize47bit && inputGttSize < gttSize48bit) {
return gttSize48bit;
}
return inputGttSize;
}

template std::vector<uint16_t> Drm::query<uint16_t>(uint32_t queryId, uint32_t queryItemFlags);
template std::vector<uint32_t> Drm::query<uint32_t>(uint32_t queryId, uint32_t queryItemFlags);
template std::vector<uint64_t> Drm::query<uint64_t>(uint32_t queryId, uint32_t queryItemFlags);
Expand Down
3 changes: 2 additions & 1 deletion shared/source/os_interface/linux/drm_neo.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class Drm : public DriverModel {
int getTimestampFrequency(int &frequency);
int getOaTimestampFrequency(int &frequency);

MOCKABLE_VIRTUAL int queryGttSize(uint64_t &gttSizeOutput);
MOCKABLE_VIRTUAL int queryGttSize(uint64_t &gttSizeOutput, bool alignUpToFullRange);
bool isPreemptionSupported() const { return preemptionSupported; }

MOCKABLE_VIRTUAL void checkPreemptionSupport();
Expand Down Expand Up @@ -269,6 +269,7 @@ class Drm : public DriverModel {
void queryAndSetVmBindPatIndexProgrammingSupport();
bool queryDeviceIdAndRevision();
bool queryI915DeviceIdAndRevision();
static uint64_t alignUpGttSize(uint64_t inputGttSize);

#pragma pack(1)
struct PCIConfig {
Expand Down
2 changes: 1 addition & 1 deletion shared/source/os_interface/linux/product_helper_drm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ int ProductHelper::configureHwInfoDrm(const HardwareInfo *inHwInfo, HardwareInfo
uint64_t gttSizeQuery = 0;
featureTable->flags.ftrSVM = true;

ret = drm->queryGttSize(gttSizeQuery);
ret = drm->queryGttSize(gttSizeQuery, true);

if (ret == 0) {
featureTable->flags.ftrSVM = (gttSizeQuery > MemoryConstants::max64BitAppAddress);
Expand Down
4 changes: 2 additions & 2 deletions shared/test/common/libult/linux/drm_mock.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ class DrmMock : public Drm {
else
return Drm::useVMBindImmediate();
}
int queryGttSize(uint64_t &gttSizeOutput) override {
int queryGttSize(uint64_t &gttSizeOutput, bool alignUpToFullRange) override {
gttSizeOutput = storedGTTSize;
return storedRetValForGetGttSize;
}
Expand Down Expand Up @@ -276,7 +276,7 @@ class DrmMock : public Drm {
GemVmControl receivedGemVmControl{};
uint32_t latestCreatedVmId = 0u;

uint64_t storedGTTSize = 1ull << 47;
uint64_t storedGTTSize = defaultHwInfo->capabilityTable.gpuAddressSpace + 1;
uint64_t storedParamSseu = ULONG_MAX;

Ioctls ioctlCount{};
Expand Down
4 changes: 2 additions & 2 deletions shared/test/common/mocks/linux/mock_drm_memory_manager.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2020-2023 Intel Corporation
* Copyright (C) 2020-2024 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
Expand Down Expand Up @@ -69,7 +69,7 @@ void TestedDrmMemoryManager::injectPinBB(BufferObject *newPinBB, uint32_t rootDe
DrmGemCloseWorker *TestedDrmMemoryManager::getgemCloseWorker() { return this->gemCloseWorker.get(); }
void TestedDrmMemoryManager::forceLimitedRangeAllocator(uint64_t range) {
for (auto &gfxPartition : gfxPartitions) {
gfxPartition->init(range, getSizeToReserve(), 0, 1, false, 0u);
gfxPartition->init(range, getSizeToReserve(), 0, 1, false, 0u, range + 1);
}
}
void TestedDrmMemoryManager::overrideGfxPartition(GfxPartition *newGfxPartition) { gfxPartitions[0].reset(newGfxPartition); }
Expand Down
4 changes: 2 additions & 2 deletions shared/test/common/mocks/mock_gfx_partition.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2019-2023 Intel Corporation
* Copyright (C) 2019-2024 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
Expand Down Expand Up @@ -92,7 +92,7 @@ class MockGfxPartitionBasic : public GfxPartition {

class FailedInitGfxPartition : public MockGfxPartition {
public:
bool init(uint64_t gpuAddressSpace, size_t cpuAddressRangeSizeToReserve, uint32_t rootDeviceIndex, size_t numRootDevices, bool useFrontWindowPool, uint64_t systemMemorySize) override {
bool init(uint64_t gpuAddressSpace, size_t cpuAddressRangeSizeToReserve, uint32_t rootDeviceIndex, size_t numRootDevices, bool useFrontWindowPool, uint64_t systemMemorySize, uint64_t gfxTop) override {
return false;
}
};
2 changes: 1 addition & 1 deletion shared/test/common/mocks/mock_memory_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ GraphicsAllocation *MockMemoryManager::allocate32BitGraphicsMemoryImpl(const All
}

void MockMemoryManager::forceLimitedRangeAllocator(uint32_t rootDeviceIndex, uint64_t range) {
getGfxPartition(rootDeviceIndex)->init(range, 0, 0, gfxPartitions.size(), false, 0u);
getGfxPartition(rootDeviceIndex)->init(range, 0, 0, gfxPartitions.size(), false, 0u, range + 1);
}

bool MockMemoryManager::hasPageFaultsEnabled(const Device &neoDevice) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,11 @@ class DrmMockCustom : public Drm {

virtual void execBufferExtensions(void *execbuf) {
}
int queryGttSize(uint64_t &gttSizeOutput) override {
int queryGttSize(uint64_t &gttSizeOutput, bool alignUpToFullRange) override {
if (callBaseQueryGttSize) {
return Drm::queryGttSize(gttSizeOutput);
return Drm::queryGttSize(gttSizeOutput, alignUpToFullRange);
}
gttSizeOutput = 1;
gttSizeOutput = NEO::defaultHwInfo->capabilityTable.gpuAddressSpace + 1;
return 0u;
}

Expand Down
4 changes: 2 additions & 2 deletions shared/test/unit_test/fixtures/front_window_fixture.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2021-2023 Intel Corporation
* Copyright (C) 2021-2024 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
Expand All @@ -17,7 +17,7 @@
using namespace NEO;

MemManagerFixture::FrontWindowMemManagerMock::FrontWindowMemManagerMock(NEO::ExecutionEnvironment &executionEnvironment) : MockMemoryManager(executionEnvironment) {}
void MemManagerFixture::FrontWindowMemManagerMock::forceLimitedRangeAllocator(uint32_t rootDeviceIndex, uint64_t range) { getGfxPartition(rootDeviceIndex)->init(range, 0, 0, gfxPartitions.size(), true, 0u); }
void MemManagerFixture::FrontWindowMemManagerMock::forceLimitedRangeAllocator(uint32_t rootDeviceIndex, uint64_t range) { getGfxPartition(rootDeviceIndex)->init(range, 0, 0, gfxPartitions.size(), true, 0u, range + 1); }

void MemManagerFixture::setUp() {
DebugManagerStateRestore dbgRestorer;
Expand Down
Loading

0 comments on commit 420e139

Please sign in to comment.