Files
compute-runtime/runtime/memory_manager/deferrable_allocation_deletion.cpp
Mateusz Jablonski 7747db13e1 Deferred deleter: move to next deletion if current deletion cannot be applied
Change-Id: I7067bc2bc74f92518a33ccb9f9dce9b57cc28637
Signed-off-by: Mateusz Jablonski <mateusz.jablonski@intel.com>
2018-12-03 15:24:35 +01:00

39 lines
1.5 KiB
C++

/*
* Copyright (C) 2018 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "runtime/command_stream/command_stream_receiver.h"
#include "runtime/memory_manager/deferrable_allocation_deletion.h"
#include "runtime/memory_manager/memory_manager.h"
#include "runtime/os_interface/os_context.h"
namespace OCLRT {
DeferrableAllocationDeletion::DeferrableAllocationDeletion(MemoryManager &memoryManager, GraphicsAllocation &graphicsAllocation) : memoryManager(memoryManager),
graphicsAllocation(graphicsAllocation) {}
bool DeferrableAllocationDeletion::apply() {
if (graphicsAllocation.isUsed()) {
for (auto &deviceCsrs : memoryManager.getCommandStreamReceivers()) {
for (auto &csr : deviceCsrs) {
auto contextId = csr->getOsContext().getContextId();
if (graphicsAllocation.isUsedByContext(contextId)) {
auto currentContextTaskCount = *csr->getTagAddress();
if (graphicsAllocation.getTaskCount(contextId) <= currentContextTaskCount) {
graphicsAllocation.resetTaskCount(contextId);
}
}
}
}
if (graphicsAllocation.isUsed()) {
return false;
}
}
memoryManager.freeGraphicsMemory(&graphicsAllocation);
return true;
}
} // namespace OCLRT