mirror of
https://github.com/intel/compute-runtime.git
synced 2026-01-08 05:56:36 +08:00
Handle error in register memory allocation methods
Related-To: NEO-7412 Signed-off-by: Mateusz Jablonski <mateusz.jablonski@intel.com>
This commit is contained in:
committed by
Compute-Runtime-Automation
parent
d76f5f4c01
commit
6648adef15
@@ -481,15 +481,18 @@ GraphicsAllocation *MemoryManager::allocateGraphicsMemoryInPreferredPool(const A
|
||||
GraphicsAllocation *allocation = allocateGraphicsMemoryInDevicePool(allocationData, status);
|
||||
if (allocation) {
|
||||
getLocalMemoryUsageBankSelector(properties.allocationType, properties.rootDeviceIndex)->reserveOnBanks(allocationData.storageInfo.getMemoryBanks(), allocation->getUnderlyingBufferSize());
|
||||
this->registerLocalMemAlloc(allocation, properties.rootDeviceIndex);
|
||||
status = this->registerLocalMemAlloc(allocation, properties.rootDeviceIndex);
|
||||
}
|
||||
if (!allocation && status == AllocationStatus::RetryInNonDevicePool) {
|
||||
allocation = allocateGraphicsMemory(allocationData);
|
||||
if (allocation) {
|
||||
this->registerSysMemAlloc(allocation);
|
||||
status = this->registerSysMemAlloc(allocation);
|
||||
}
|
||||
}
|
||||
|
||||
if (allocation && status != AllocationStatus::Success) {
|
||||
freeGraphicsMemory(allocation);
|
||||
allocation = nullptr;
|
||||
}
|
||||
if (!allocation) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -220,8 +220,8 @@ class MemoryManager {
|
||||
virtual bool isCpuCopyRequired(const void *ptr) { return false; }
|
||||
virtual bool isWCMemory(const void *ptr) { return false; }
|
||||
|
||||
virtual void registerSysMemAlloc(GraphicsAllocation *allocation){};
|
||||
virtual void registerLocalMemAlloc(GraphicsAllocation *allocation, uint32_t rootDeviceIndex){};
|
||||
virtual AllocationStatus registerSysMemAlloc(GraphicsAllocation *allocation) { return AllocationStatus::Success; };
|
||||
virtual AllocationStatus registerLocalMemAlloc(GraphicsAllocation *allocation, uint32_t rootDeviceIndex) { return AllocationStatus::Success; };
|
||||
|
||||
virtual bool setMemAdvise(GraphicsAllocation *gfxAllocation, MemAdviseFlags flags, uint32_t rootDeviceIndex) { return true; }
|
||||
virtual bool setMemPrefetch(GraphicsAllocation *gfxAllocation, uint32_t subDeviceId, uint32_t rootDeviceIndex) { return true; }
|
||||
|
||||
@@ -1170,26 +1170,35 @@ std::vector<GraphicsAllocation *> &DrmMemoryManager::getLocalMemAllocs(uint32_t
|
||||
return this->localMemAllocs[rootDeviceIndex];
|
||||
}
|
||||
|
||||
void DrmMemoryManager::makeAllocationResident(GraphicsAllocation *allocation) {
|
||||
bool DrmMemoryManager::makeAllocationResident(GraphicsAllocation *allocation) {
|
||||
if (DebugManager.flags.MakeEachAllocationResident.get() == 1) {
|
||||
auto drmAllocation = static_cast<DrmAllocation *>(allocation);
|
||||
for (uint32_t i = 0; getDrm(allocation->getRootDeviceIndex()).getVirtualMemoryAddressSpace(i) > 0u; i++) {
|
||||
drmAllocation->makeBOsResident(registeredEngines[defaultEngineIndex[allocation->getRootDeviceIndex()]].osContext, i, nullptr, true);
|
||||
if (drmAllocation->makeBOsResident(registeredEngines[defaultEngineIndex[allocation->getRootDeviceIndex()]].osContext, i, nullptr, true)) {
|
||||
return false;
|
||||
}
|
||||
getDrm(allocation->getRootDeviceIndex()).waitForBind(i);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void DrmMemoryManager::registerSysMemAlloc(GraphicsAllocation *allocation) {
|
||||
makeAllocationResident(allocation);
|
||||
MemoryManager::AllocationStatus DrmMemoryManager::registerSysMemAlloc(GraphicsAllocation *allocation) {
|
||||
if (!makeAllocationResident(allocation)) {
|
||||
return AllocationStatus::Error;
|
||||
}
|
||||
std::lock_guard<std::mutex> lock(this->allocMutex);
|
||||
this->sysMemAllocs.push_back(allocation);
|
||||
return AllocationStatus::Success;
|
||||
}
|
||||
|
||||
void DrmMemoryManager::registerLocalMemAlloc(GraphicsAllocation *allocation, uint32_t rootDeviceIndex) {
|
||||
makeAllocationResident(allocation);
|
||||
MemoryManager::AllocationStatus DrmMemoryManager::registerLocalMemAlloc(GraphicsAllocation *allocation, uint32_t rootDeviceIndex) {
|
||||
if (!makeAllocationResident(allocation)) {
|
||||
return AllocationStatus::Error;
|
||||
}
|
||||
std::lock_guard<std::mutex> lock(this->allocMutex);
|
||||
this->localMemAllocs[rootDeviceIndex].push_back(allocation);
|
||||
return AllocationStatus::Success;
|
||||
}
|
||||
|
||||
void DrmMemoryManager::unregisterAllocation(GraphicsAllocation *allocation) {
|
||||
|
||||
@@ -75,8 +75,8 @@ class DrmMemoryManager : public MemoryManager {
|
||||
[[nodiscard]] std::unique_lock<std::mutex> acquireAllocLock();
|
||||
std::vector<GraphicsAllocation *> &getSysMemAllocs();
|
||||
std::vector<GraphicsAllocation *> &getLocalMemAllocs(uint32_t rootDeviceIndex);
|
||||
void registerSysMemAlloc(GraphicsAllocation *allocation) override;
|
||||
void registerLocalMemAlloc(GraphicsAllocation *allocation, uint32_t rootDeviceIndex) override;
|
||||
AllocationStatus registerSysMemAlloc(GraphicsAllocation *allocation) override;
|
||||
AllocationStatus registerLocalMemAlloc(GraphicsAllocation *allocation, uint32_t rootDeviceIndex) override;
|
||||
void unregisterAllocation(GraphicsAllocation *allocation);
|
||||
|
||||
static std::unique_ptr<MemoryManager> create(ExecutionEnvironment &executionEnvironment);
|
||||
@@ -112,7 +112,6 @@ class DrmMemoryManager : public MemoryManager {
|
||||
GraphicsAllocation *allocateMemoryByKMD(const AllocationData &allocationData) override;
|
||||
GraphicsAllocation *allocateGraphicsMemoryForImageImpl(const AllocationData &allocationData, std::unique_ptr<Gmm> gmm) override;
|
||||
GraphicsAllocation *allocateGraphicsMemoryWithGpuVa(const AllocationData &allocationData) override;
|
||||
GraphicsAllocation *createSharedUnifiedMemoryAllocationLegacy(const AllocationData &allocationData);
|
||||
GraphicsAllocation *createSharedUnifiedMemoryAllocation(const AllocationData &allocationData);
|
||||
|
||||
void *lockResourceImpl(GraphicsAllocation &graphicsAllocation) override;
|
||||
@@ -126,7 +125,7 @@ class DrmMemoryManager : public MemoryManager {
|
||||
void registerAllocationInOs(GraphicsAllocation *allocation) override;
|
||||
void waitOnCompletionFence(GraphicsAllocation *allocation);
|
||||
bool allocationTypeForCompletionFence(AllocationType allocationType);
|
||||
void makeAllocationResident(GraphicsAllocation *allocation);
|
||||
bool makeAllocationResident(GraphicsAllocation *allocation);
|
||||
|
||||
Drm &getDrm(uint32_t rootDeviceIndex) const;
|
||||
uint32_t getRootDeviceIndex(const Drm *drm);
|
||||
|
||||
@@ -70,6 +70,10 @@ class MockMemoryManager : public MemoryManagerCreate<OsAgnosticMemoryManager> {
|
||||
MockMemoryManager(bool enable64pages, bool enableLocalMemory) : MemoryManagerCreate(enable64pages, enableLocalMemory, *(new MockExecutionEnvironment(defaultHwInfo.get()))) {
|
||||
mockExecutionEnvironment.reset(static_cast<MockExecutionEnvironment *>(&executionEnvironment));
|
||||
}
|
||||
|
||||
ADDMETHOD_NOBASE(registerSysMemAlloc, AllocationStatus, AllocationStatus::Success, (GraphicsAllocation * allocation));
|
||||
ADDMETHOD_NOBASE(registerLocalMemAlloc, AllocationStatus, AllocationStatus::Success, (GraphicsAllocation * allocation, uint32_t rootDeviceIndex));
|
||||
|
||||
GraphicsAllocation *allocateGraphicsMemory64kb(const AllocationData &allocationData) override;
|
||||
void setDeferredDeleter(DeferredDeleter *deleter);
|
||||
void overrideAsyncDeleterFlag(bool newValue);
|
||||
|
||||
@@ -196,6 +196,11 @@ int DrmMockCustom::ioctl(DrmIoctl request, void *arg) {
|
||||
} break;
|
||||
case DrmIoctl::GemVmUnbind: {
|
||||
} break;
|
||||
case DrmIoctl::GemVmCreate: {
|
||||
auto vmCreate = reinterpret_cast<NEO::GemVmControl *>(arg);
|
||||
vmCreate->vmId = vmIdToCreate;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
int res = ioctlExtra(request, arg);
|
||||
if (returnIoctlExtraErrorValue) {
|
||||
|
||||
@@ -220,6 +220,8 @@ class DrmMockCustom : public Drm {
|
||||
uint32_t createExtHandle = 0;
|
||||
uint64_t createExtExtensions = 0;
|
||||
|
||||
uint32_t vmIdToCreate = 0;
|
||||
|
||||
int errnoValue = 0;
|
||||
|
||||
bool returnIoctlExtraErrorValue = false;
|
||||
|
||||
@@ -68,3 +68,17 @@ TEST(MemoryManagerTest, givenMemoryManagerWhenGettingDefaultContextThenCorrectCo
|
||||
EXPECT_EQ(mockMemoryManager->getRegisteredEngines()[mockMemoryManager->defaultEngineIndex[0]].osContext,
|
||||
executionEnvironment.memoryManager->getDefaultEngineContext(0, 2));
|
||||
}
|
||||
|
||||
TEST(MemoryManagerTest, givenFailureOnRegisterSystemMemoryAllocationWhenAllocatingMemoryThenNullptrIsReturned) {
|
||||
AllocationProperties properties(mockRootDeviceIndex, true, MemoryConstants::cacheLineSize, AllocationType::BUFFER, false, mockDeviceBitfield);
|
||||
MockMemoryManager memoryManager;
|
||||
memoryManager.registerSysMemAllocResult = MemoryManager::AllocationStatus::Error;
|
||||
EXPECT_EQ(nullptr, memoryManager.allocateGraphicsMemoryWithProperties(properties));
|
||||
}
|
||||
|
||||
TEST(MemoryManagerTest, givenFailureOnRegisterLocalMemoryAllocationWhenAllocatingMemoryThenNullptrIsReturned) {
|
||||
AllocationProperties properties(mockRootDeviceIndex, true, MemoryConstants::cacheLineSize, AllocationType::BUFFER, false, mockDeviceBitfield);
|
||||
MockMemoryManager memoryManager(true, true);
|
||||
memoryManager.registerLocalMemAllocResult = MemoryManager::AllocationStatus::Error;
|
||||
EXPECT_EQ(nullptr, memoryManager.allocateGraphicsMemoryWithProperties(properties));
|
||||
}
|
||||
@@ -5485,3 +5485,31 @@ TEST_F(DrmMemoryManagerTest, givenSingleSubDevicesBitfieldWhenAllocatingSbaTrack
|
||||
memoryManager->freeGraphicsMemory(sbaBuffer);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(DrmMemoryManagerTest, givenMakeBosResidentErrorWhenRegisteringMemoryAllocationThenErrorIsReturned) {
|
||||
DebugManagerStateRestore restorer;
|
||||
DebugManager.flags.MakeEachAllocationResident.set(1);
|
||||
auto &drm = static_cast<DrmMockCustom &>(memoryManager->getDrm(0));
|
||||
drm.vmIdToCreate = 1;
|
||||
drm.createVirtualMemoryAddressSpace(1);
|
||||
MockDrmAllocation allocation(AllocationType::BUFFER, MemoryPool::System4KBPages);
|
||||
allocation.makeBOsResidentResult = ENOSPC;
|
||||
|
||||
EXPECT_EQ(MemoryManager::AllocationStatus::Error, memoryManager->registerSysMemAlloc(&allocation));
|
||||
|
||||
EXPECT_EQ(MemoryManager::AllocationStatus::Error, memoryManager->registerLocalMemAlloc(&allocation, 0));
|
||||
}
|
||||
|
||||
TEST_F(DrmMemoryManagerTest, givenMakeBosResidentSuccessWhenRegisteringMemoryAllocationThenSuccessIsReturned) {
|
||||
DebugManagerStateRestore restorer;
|
||||
DebugManager.flags.MakeEachAllocationResident.set(1);
|
||||
auto &drm = static_cast<DrmMockCustom &>(memoryManager->getDrm(0));
|
||||
drm.vmIdToCreate = 1;
|
||||
drm.createVirtualMemoryAddressSpace(1);
|
||||
MockDrmAllocation allocation(AllocationType::BUFFER, MemoryPool::System4KBPages);
|
||||
allocation.makeBOsResidentResult = 0;
|
||||
|
||||
EXPECT_EQ(MemoryManager::AllocationStatus::Success, memoryManager->registerSysMemAlloc(&allocation));
|
||||
|
||||
EXPECT_EQ(MemoryManager::AllocationStatus::Success, memoryManager->registerLocalMemAlloc(&allocation, 0));
|
||||
}
|
||||
Reference in New Issue
Block a user