2019-08-21 16:53:07 +08:00
|
|
|
/*
|
2021-02-16 18:20:34 +08:00
|
|
|
* Copyright (C) 2019-2021 Intel Corporation
|
2019-08-21 16:53:07 +08:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: MIT
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2020-02-24 05:44:01 +08:00
|
|
|
#include "shared/source/os_interface/aub_memory_operations_handler.h"
|
2019-08-21 16:53:07 +08:00
|
|
|
|
2020-10-16 18:10:52 +08:00
|
|
|
#include "shared/source/aub_mem_dump/aub_mem_dump.h"
|
2020-02-24 05:44:01 +08:00
|
|
|
#include "shared/source/memory_manager/graphics_allocation.h"
|
2020-02-24 17:22:30 +08:00
|
|
|
|
2021-02-16 18:20:34 +08:00
|
|
|
#include "third_party/aub_stream/headers/allocation_params.h"
|
|
|
|
|
2019-08-21 16:53:07 +08:00
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
namespace NEO {
|
|
|
|
|
|
|
|
AubMemoryOperationsHandler::AubMemoryOperationsHandler(aub_stream::AubManager *aubManager) {
|
|
|
|
this->aubManager = aubManager;
|
|
|
|
}
|
|
|
|
|
2020-07-02 17:49:46 +08:00
|
|
|
MemoryOperationsStatus AubMemoryOperationsHandler::makeResident(Device *device, ArrayRef<GraphicsAllocation *> gfxAllocations) {
|
2019-08-21 16:53:07 +08:00
|
|
|
if (!aubManager) {
|
2019-08-29 19:46:49 +08:00
|
|
|
return MemoryOperationsStatus::DEVICE_UNINITIALIZED;
|
2019-08-21 16:53:07 +08:00
|
|
|
}
|
|
|
|
auto lock = acquireLock(resourcesLock);
|
|
|
|
int hint = AubMemDump::DataTypeHintValues::TraceNotype;
|
2020-01-10 00:21:52 +08:00
|
|
|
for (const auto &allocation : gfxAllocations) {
|
2021-02-16 18:20:34 +08:00
|
|
|
aubManager->writeMemory2({allocation->getGpuAddress(),
|
|
|
|
allocation->getUnderlyingBuffer(),
|
|
|
|
allocation->getUnderlyingBufferSize(),
|
|
|
|
allocation->storageInfo.getMemoryBanks(),
|
|
|
|
hint,
|
|
|
|
allocation->getUsedPageSize()});
|
2020-01-10 00:21:52 +08:00
|
|
|
residentAllocations.push_back(allocation);
|
|
|
|
}
|
2019-08-29 19:46:49 +08:00
|
|
|
return MemoryOperationsStatus::SUCCESS;
|
2019-08-21 16:53:07 +08:00
|
|
|
}
|
|
|
|
|
2020-07-02 17:49:46 +08:00
|
|
|
MemoryOperationsStatus AubMemoryOperationsHandler::evict(Device *device, GraphicsAllocation &gfxAllocation) {
|
2019-08-21 16:53:07 +08:00
|
|
|
auto lock = acquireLock(resourcesLock);
|
|
|
|
auto itor = std::find(residentAllocations.begin(), residentAllocations.end(), &gfxAllocation);
|
|
|
|
if (itor == residentAllocations.end()) {
|
2019-08-29 19:46:49 +08:00
|
|
|
return MemoryOperationsStatus::MEMORY_NOT_FOUND;
|
2019-08-21 16:53:07 +08:00
|
|
|
} else {
|
|
|
|
residentAllocations.erase(itor, itor + 1);
|
2019-08-29 19:46:49 +08:00
|
|
|
return MemoryOperationsStatus::SUCCESS;
|
2019-08-21 16:53:07 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-02 17:49:46 +08:00
|
|
|
MemoryOperationsStatus AubMemoryOperationsHandler::isResident(Device *device, GraphicsAllocation &gfxAllocation) {
|
2019-08-21 16:53:07 +08:00
|
|
|
auto lock = acquireLock(resourcesLock);
|
|
|
|
auto itor = std::find(residentAllocations.begin(), residentAllocations.end(), &gfxAllocation);
|
|
|
|
if (itor == residentAllocations.end()) {
|
2019-08-29 19:46:49 +08:00
|
|
|
return MemoryOperationsStatus::MEMORY_NOT_FOUND;
|
2019-08-21 16:53:07 +08:00
|
|
|
} else {
|
2019-08-29 19:46:49 +08:00
|
|
|
return MemoryOperationsStatus::SUCCESS;
|
2019-08-21 16:53:07 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
void AubMemoryOperationsHandler::setAubManager(aub_stream::AubManager *aubManager) {
|
|
|
|
this->aubManager = aubManager;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace NEO
|