Skip to content

Commit d0edf01

Browse files
feature(sysman): reinitialize gfxPartition on reset
Related-To: NEO-13203 Signed-off-by: Mateusz Hoppe <mateusz.hoppe@intel.com> Source: 0589a70
1 parent 8a57337 commit d0edf01

File tree

9 files changed

+106
-1
lines changed

9 files changed

+106
-1
lines changed

level_zero/tools/source/sysman/linux/os_sysman_imp.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,7 @@ void LinuxSysmanImp::releaseDeviceResources() {
341341
executionEnvironment->memoryManager->releaseDeviceSpecificMemResources(rootDeviceIndex);
342342
executionEnvironment->releaseRootDeviceEnvironmentResources(executionEnvironment->rootDeviceEnvironments[rootDeviceIndex].get());
343343
executionEnvironment->rootDeviceEnvironments[rootDeviceIndex].reset();
344+
executionEnvironment->memoryManager->releaseDeviceSpecificGfxPartition(rootDeviceIndex);
344345
}
345346

346347
void LinuxSysmanImp::reInitSysmanDeviceResources() {

level_zero/tools/test/unit_tests/sources/sysman/diagnostics/linux/test_zes_sysman_diagnostics.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2020-2023 Intel Corporation
2+
* Copyright (C) 2020-2024 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -764,6 +764,19 @@ TEST_F(ZesDiagnosticsFixture, GivenValidSysmanImpPointerWhenCallingReleaseResour
764764
EXPECT_EQ(ZE_RESULT_SUCCESS, pLinuxSysmanImp->initDevice());
765765
}
766766

767+
TEST_F(ZesDiagnosticsFixture, GivenSysmanImpPointerWhenCallingReleaseResourcesThenGfxPartitionIsRemovedForRootDevice) {
768+
pLinuxSysmanImp->diagnosticsReset = true;
769+
auto devicePtr = static_cast<DeviceImp *>(pLinuxSysmanImp->pDevice);
770+
auto executionEnvironment = devicePtr->getNEODevice()->getExecutionEnvironment();
771+
auto rootIndex = devicePtr->getNEODevice()->getRootDeviceIndex();
772+
773+
pLinuxSysmanImp->releaseDeviceResources();
774+
775+
EXPECT_EQ(nullptr, executionEnvironment->memoryManager->getGfxPartition(rootIndex));
776+
EXPECT_EQ(ZE_RESULT_SUCCESS, pLinuxSysmanImp->initDevice());
777+
EXPECT_NE(nullptr, executionEnvironment->memoryManager->getGfxPartition(rootIndex));
778+
}
779+
767780
HWTEST2_F(ZesDiagnosticsFixture, GivenValidDiagnosticsHandleAndHandleCountZeroWhenCallingReInitThenValidCountIsReturnedAndVerifyzesDeviceEnumDiagnosticTestSuitesSucceeds, IsPVC) {
768781
uint32_t count = 0;
769782
ze_result_t result = zesDeviceEnumDiagnosticTestSuites(device->toHandle(), &count, nullptr);

shared/source/memory_manager/memory_manager.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,9 @@ class MemoryManager {
279279

280280
virtual void releaseDeviceSpecificMemResources(uint32_t rootDeviceIndex){};
281281
virtual void createDeviceSpecificMemResources(uint32_t rootDeviceIndex){};
282+
virtual void releaseDeviceSpecificGfxPartition(uint32_t rootDeviceIndex){};
283+
virtual bool reInitDeviceSpecificGfxPartition(uint32_t rootDeviceIndex) { return true; };
284+
282285
void reInitLatestContextId() {
283286
latestContextId = std::numeric_limits<uint32_t>::max();
284287
}

shared/source/os_interface/device_factory.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ std::unique_ptr<Device> DeviceFactory::createDevice(ExecutionEnvironment &execut
249249
return device;
250250
}
251251

252+
executionEnvironment.memoryManager->reInitDeviceSpecificGfxPartition(rootDeviceIndex);
252253
executionEnvironment.memoryManager->createDeviceSpecificMemResources(rootDeviceIndex);
253254
executionEnvironment.memoryManager->reInitLatestContextId();
254255
device = createRootDeviceFunc(executionEnvironment, rootDeviceIndex);

shared/source/os_interface/linux/drm_memory_manager.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2948,4 +2948,23 @@ void DrmMemoryManager::getExtraDeviceProperties(uint32_t rootDeviceIndex, uint32
29482948
getDrm(rootDeviceIndex).getIoctlHelper()->queryDeviceParams(moduleId, serverType);
29492949
}
29502950

2951+
bool DrmMemoryManager::reInitDeviceSpecificGfxPartition(uint32_t rootDeviceIndex) {
2952+
if (gfxPartitions.at(rootDeviceIndex) == nullptr) {
2953+
auto gpuAddressSpace = executionEnvironment.rootDeviceEnvironments[rootDeviceIndex]->getHardwareInfo()->capabilityTable.gpuAddressSpace;
2954+
2955+
gfxPartitions.at(rootDeviceIndex) = std::make_unique<GfxPartition>(reservedCpuAddressRange);
2956+
2957+
uint64_t gfxTop{};
2958+
getDrm(rootDeviceIndex).queryGttSize(gfxTop, false);
2959+
2960+
if (getGfxPartition(rootDeviceIndex)->init(gpuAddressSpace, getSizeToReserve(), rootDeviceIndex, gfxPartitions.size(), heapAssigners[rootDeviceIndex]->apiAllowExternalHeapForSshAndDsh, DrmMemoryManager::getSystemSharedMemory(rootDeviceIndex), gfxTop)) {
2961+
return true;
2962+
}
2963+
}
2964+
return false;
2965+
}
2966+
2967+
void DrmMemoryManager::releaseDeviceSpecificGfxPartition(uint32_t rootDeviceIndex) {
2968+
gfxPartitions.at(rootDeviceIndex).reset();
2969+
}
29512970
} // namespace NEO

shared/source/os_interface/linux/drm_memory_manager.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ class DrmMemoryManager : public MemoryManager {
100100
DrmAllocation *createUSMHostAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, void *mappedPtr, bool reuseSharedAllocation);
101101
void releaseDeviceSpecificMemResources(uint32_t rootDeviceIndex) override;
102102
void createDeviceSpecificMemResources(uint32_t rootDeviceIndex) override;
103+
void releaseDeviceSpecificGfxPartition(uint32_t rootDeviceIndex) override;
104+
bool reInitDeviceSpecificGfxPartition(uint32_t rootDeviceIndex) override;
103105
bool allowIndirectAllocationsAsPack(uint32_t rootDeviceIndex) override;
104106
Drm &getDrm(uint32_t rootDeviceIndex) const;
105107
size_t getSizeOfChunk(size_t allocSize);

shared/test/common/mocks/mock_memory_manager.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "shared/source/command_stream/command_stream_receiver.h"
1111
#include "shared/source/gmm_helper/gmm.h"
1212
#include "shared/source/helpers/aligned_memory.h"
13+
#include "shared/source/helpers/hw_info.h"
1314
#include "shared/source/helpers/surface_format_info.h"
1415
#include "shared/source/memory_manager/deferred_deleter.h"
1516
#include "shared/source/memory_manager/gfx_partition.h"
@@ -248,6 +249,25 @@ bool MockMemoryManager::copyMemoryToAllocationBanks(GraphicsAllocation *graphics
248249
return OsAgnosticMemoryManager::copyMemoryToAllocationBanks(graphicsAllocation, destinationOffset, memoryToCopy, sizeToCopy, handleMask);
249250
};
250251

252+
bool MockMemoryManager::reInitDeviceSpecificGfxPartition(uint32_t rootDeviceIndex) {
253+
if (gfxPartitions.at(rootDeviceIndex) == nullptr) {
254+
// 4 x sizeof(Heap32) + 2 x sizeof(Standard/Standard64k)
255+
size_t reservedCpuAddressRangeSize = static_cast<size_t>((4 * 4 + 2 * 4)) * static_cast<size_t>(MemoryConstants::gigaByte);
256+
gfxPartitions.at(rootDeviceIndex) = std::make_unique<GfxPartition>(reservedCpuAddressRange);
257+
258+
auto gpuAddressSpace = executionEnvironment.rootDeviceEnvironments[rootDeviceIndex]->getHardwareInfo()->capabilityTable.gpuAddressSpace;
259+
auto gfxTop = gpuAddressSpace + 1;
260+
if (getGfxPartition(rootDeviceIndex)->init(gpuAddressSpace, reservedCpuAddressRangeSize, rootDeviceIndex, gfxPartitions.size(), heapAssigners[rootDeviceIndex]->apiAllowExternalHeapForSshAndDsh, OsAgnosticMemoryManager::getSystemSharedMemory(rootDeviceIndex), gfxTop)) {
261+
return true;
262+
}
263+
}
264+
return false;
265+
}
266+
267+
void MockMemoryManager::releaseDeviceSpecificGfxPartition(uint32_t rootDeviceIndex) {
268+
gfxPartitions.at(rootDeviceIndex).reset();
269+
}
270+
251271
void *MockAllocSysMemAgnosticMemoryManager::allocateSystemMemory(size_t size, size_t alignment) {
252272
constexpr size_t minAlignment = 16;
253273
alignment = std::max(alignment, minAlignment);

shared/test/common/mocks/mock_memory_manager.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,9 @@ class MockMemoryManager : public MemoryManagerCreate<OsAgnosticMemoryManager> {
251251
*serverType = MockMemoryManager::serverType;
252252
}
253253

254+
bool reInitDeviceSpecificGfxPartition(uint32_t rootDeviceIndex) override;
255+
void releaseDeviceSpecificGfxPartition(uint32_t rootDeviceIndex) override;
256+
254257
MockGraphicsAllocation *mockGa;
255258
size_t ipcAllocationSize = 4096u;
256259
uint32_t copyMemoryToAllocationBanksCalled = 0u;

shared/test/unit_test/os_interface/linux/drm_memory_manager_tests.cpp

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8476,3 +8476,46 @@ TEST_F(DrmMemoryManagerTest, givenVmAdviseAtomicAttributeNotPresentWhenCreateSha
84768476

84778477
memoryManager->freeGraphicsMemory(sharedUSM);
84788478
}
8479+
8480+
TEST_F(DrmMemoryManagerTest, givenGfxPartitionWhenReleasedAndReinitializedThenNewGfxPartitionIsCorrect) {
8481+
8482+
auto gfxPartition = memoryManager->getGfxPartition(0);
8483+
8484+
auto heapExternal = gfxPartition->getHeapBase(HeapIndex::heapExternal);
8485+
auto heapStandard = gfxPartition->getHeapBase(HeapIndex::heapStandard);
8486+
auto heapStandard64KB = gfxPartition->getHeapBase(HeapIndex::heapStandard64KB);
8487+
auto heapSvm = gfxPartition->getHeapBase(HeapIndex::heapSvm);
8488+
auto heapExtended = gfxPartition->getHeapBase(HeapIndex::heapExtended);
8489+
auto heapExternalFrontWindow = gfxPartition->getHeapBase(HeapIndex::heapExternalFrontWindow);
8490+
auto heapExternalDeviceFrontWindow = gfxPartition->getHeapBase(HeapIndex::heapExternalDeviceFrontWindow);
8491+
auto heapInternalFrontWindow = gfxPartition->getHeapBase(HeapIndex::heapInternalFrontWindow);
8492+
auto heapInternalDeviceFrontWindow = gfxPartition->getHeapBase(HeapIndex::heapInternalDeviceFrontWindow);
8493+
8494+
memoryManager->releaseDeviceSpecificGfxPartition(0);
8495+
EXPECT_EQ(nullptr, memoryManager->getGfxPartition(0));
8496+
memoryManager->reInitDeviceSpecificGfxPartition(0);
8497+
8498+
EXPECT_NE(nullptr, memoryManager->getGfxPartition(0));
8499+
8500+
gfxPartition = memoryManager->getGfxPartition(0);
8501+
8502+
auto heapExternal2 = gfxPartition->getHeapBase(HeapIndex::heapExternal);
8503+
auto heapStandard2 = gfxPartition->getHeapBase(HeapIndex::heapStandard);
8504+
auto heapStandard64KB2 = gfxPartition->getHeapBase(HeapIndex::heapStandard64KB);
8505+
auto heapSvm2 = gfxPartition->getHeapBase(HeapIndex::heapSvm);
8506+
auto heapExtended2 = gfxPartition->getHeapBase(HeapIndex::heapExtended);
8507+
auto heapExternalFrontWindow2 = gfxPartition->getHeapBase(HeapIndex::heapExternalFrontWindow);
8508+
auto heapExternalDeviceFrontWindow2 = gfxPartition->getHeapBase(HeapIndex::heapExternalDeviceFrontWindow);
8509+
auto heapInternalFrontWindow2 = gfxPartition->getHeapBase(HeapIndex::heapInternalFrontWindow);
8510+
auto heapInternalDeviceFrontWindow2 = gfxPartition->getHeapBase(HeapIndex::heapInternalDeviceFrontWindow);
8511+
8512+
EXPECT_EQ(heapExternal, heapExternal2);
8513+
EXPECT_EQ(heapStandard, heapStandard2);
8514+
EXPECT_EQ(heapStandard64KB, heapStandard64KB2);
8515+
EXPECT_EQ(heapSvm, heapSvm2);
8516+
EXPECT_EQ(heapExtended, heapExtended2);
8517+
EXPECT_EQ(heapExternalFrontWindow, heapExternalFrontWindow2);
8518+
EXPECT_EQ(heapExternalDeviceFrontWindow, heapExternalDeviceFrontWindow2);
8519+
EXPECT_EQ(heapInternalFrontWindow, heapInternalFrontWindow2);
8520+
EXPECT_EQ(heapInternalDeviceFrontWindow, heapInternalDeviceFrontWindow2);
8521+
}

0 commit comments

Comments
 (0)