compute-runtime/shared/source/os_interface/aub_memory_operations_handl...

87 lines
3.3 KiB
C++

/*
* Copyright (C) 2019-2023 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "shared/source/os_interface/aub_memory_operations_handler.h"
#include "shared/source/aub_mem_dump/aub_mem_dump.h"
#include "shared/source/gmm_helper/cache_settings_helper.h"
#include "shared/source/gmm_helper/gmm.h"
#include "shared/source/memory_manager/graphics_allocation.h"
#include "aubstream/allocation_params.h"
#include <algorithm>
namespace NEO {
AubMemoryOperationsHandler::AubMemoryOperationsHandler(aub_stream::AubManager *aubManager) {
this->aubManager = aubManager;
}
MemoryOperationsStatus AubMemoryOperationsHandler::makeResident(Device *device, ArrayRef<GraphicsAllocation *> gfxAllocations) {
if (!aubManager) {
return MemoryOperationsStatus::DEVICE_UNINITIALIZED;
}
auto lock = acquireLock(resourcesLock);
int hint = AubMemDump::DataTypeHintValues::TraceNotype;
for (const auto &allocation : gfxAllocations) {
aub_stream::AllocationParams params(allocation->getGpuAddress(),
allocation->getUnderlyingBuffer(),
allocation->getUnderlyingBufferSize(),
allocation->storageInfo.getMemoryBanks(),
hint,
allocation->getUsedPageSize());
auto gmm = allocation->getDefaultGmm();
if (gmm) {
params.additionalParams.compressionEnabled = gmm->isCompressionEnabled;
params.additionalParams.uncached = CacheSettingsHelper::isUncachedType(gmm->resourceParams.Usage);
}
aubManager->writeMemory2(params);
if (!allocation->getAubInfo().writeMemoryOnly) {
residentAllocations.push_back(allocation);
}
}
return MemoryOperationsStatus::SUCCESS;
}
MemoryOperationsStatus AubMemoryOperationsHandler::evict(Device *device, GraphicsAllocation &gfxAllocation) {
auto lock = acquireLock(resourcesLock);
auto itor = std::find(residentAllocations.begin(), residentAllocations.end(), &gfxAllocation);
if (itor == residentAllocations.end()) {
return MemoryOperationsStatus::MEMORY_NOT_FOUND;
} else {
residentAllocations.erase(itor, itor + 1);
return MemoryOperationsStatus::SUCCESS;
}
}
MemoryOperationsStatus AubMemoryOperationsHandler::makeResidentWithinOsContext(OsContext *osContext, ArrayRef<GraphicsAllocation *> gfxAllocations, bool evictable) {
return makeResident(nullptr, gfxAllocations);
}
MemoryOperationsStatus AubMemoryOperationsHandler::evictWithinOsContext(OsContext *osContext, GraphicsAllocation &gfxAllocation) {
return evict(nullptr, gfxAllocation);
}
MemoryOperationsStatus AubMemoryOperationsHandler::isResident(Device *device, GraphicsAllocation &gfxAllocation) {
auto lock = acquireLock(resourcesLock);
auto itor = std::find(residentAllocations.begin(), residentAllocations.end(), &gfxAllocation);
if (itor == residentAllocations.end()) {
return MemoryOperationsStatus::MEMORY_NOT_FOUND;
} else {
return MemoryOperationsStatus::SUCCESS;
}
}
void AubMemoryOperationsHandler::setAubManager(aub_stream::AubManager *aubManager) {
this->aubManager = aubManager;
}
} // namespace NEO