2018-11-28 10:09:56 +00:00
|
|
|
/*
|
2019-12-30 14:40:24 +01:00
|
|
|
* Copyright (C) 2018-2020 Intel Corporation
|
2018-11-28 10:09:56 +00:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: MIT
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
2020-02-23 18:46:50 +01:00
|
|
|
#include "memory_manager/deferrable_allocation_deletion.h"
|
2019-02-27 11:39:32 +01:00
|
|
|
|
2020-02-23 18:46:50 +01:00
|
|
|
#include "command_stream/command_stream_receiver.h"
|
|
|
|
|
#include "helpers/engine_control.h"
|
|
|
|
|
#include "memory_manager/memory_manager.h"
|
|
|
|
|
#include "os_interface/os_context.h"
|
2018-11-28 10:09:56 +00:00
|
|
|
|
2019-03-26 11:59:46 +01:00
|
|
|
namespace NEO {
|
2018-11-28 10:09:56 +00:00
|
|
|
|
|
|
|
|
DeferrableAllocationDeletion::DeferrableAllocationDeletion(MemoryManager &memoryManager, GraphicsAllocation &graphicsAllocation) : memoryManager(memoryManager),
|
|
|
|
|
graphicsAllocation(graphicsAllocation) {}
|
2018-11-29 11:20:02 +01:00
|
|
|
bool DeferrableAllocationDeletion::apply() {
|
|
|
|
|
if (graphicsAllocation.isUsed()) {
|
2019-11-05 13:13:20 +01:00
|
|
|
bool isStillUsed = false;
|
2019-02-18 13:59:16 +01:00
|
|
|
for (auto &engine : memoryManager.getRegisteredEngines()) {
|
|
|
|
|
auto contextId = engine.osContext->getContextId();
|
|
|
|
|
if (graphicsAllocation.isUsedByOsContext(contextId)) {
|
|
|
|
|
auto currentContextTaskCount = *engine.commandStreamReceiver->getTagAddress();
|
|
|
|
|
if (graphicsAllocation.getTaskCount(contextId) <= currentContextTaskCount) {
|
|
|
|
|
graphicsAllocation.releaseUsageInOsContext(contextId);
|
|
|
|
|
} else {
|
2019-11-05 13:13:20 +01:00
|
|
|
isStillUsed = true;
|
2019-02-18 13:59:16 +01:00
|
|
|
engine.commandStreamReceiver->flushBatchedSubmissions();
|
2018-11-28 10:09:56 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-11-05 13:13:20 +01:00
|
|
|
if (isStillUsed) {
|
2018-11-29 11:20:02 +01:00
|
|
|
return false;
|
|
|
|
|
}
|
2018-11-28 10:09:56 +00:00
|
|
|
}
|
|
|
|
|
memoryManager.freeGraphicsMemory(&graphicsAllocation);
|
2018-11-29 11:20:02 +01:00
|
|
|
return true;
|
2018-11-28 10:09:56 +00:00
|
|
|
}
|
2019-03-26 11:59:46 +01:00
|
|
|
} // namespace NEO
|