1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
|
/*
* Copyright (C) 2020 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "shared/source/os_interface/linux/drm_memory_operations_handler_default.h"
#include "shared/source/debug_settings/debug_settings_manager.h"
#include <algorithm>
namespace NEO {
DrmMemoryOperationsHandlerDefault::DrmMemoryOperationsHandlerDefault() = default;
DrmMemoryOperationsHandlerDefault::~DrmMemoryOperationsHandlerDefault() = default;
MemoryOperationsStatus DrmMemoryOperationsHandlerDefault::makeResidentWithinOsContext(OsContext *osContext, ArrayRef<GraphicsAllocation *> gfxAllocations, bool evictable) {
std::lock_guard<std::mutex> lock(mutex);
this->residency.insert(gfxAllocations.begin(), gfxAllocations.end());
return MemoryOperationsStatus::SUCCESS;
}
MemoryOperationsStatus DrmMemoryOperationsHandlerDefault::makeResident(Device *device, ArrayRef<GraphicsAllocation *> gfxAllocations) {
OsContext *osContext = nullptr;
return this->makeResidentWithinOsContext(osContext, gfxAllocations, false);
}
MemoryOperationsStatus DrmMemoryOperationsHandlerDefault::evictWithinOsContext(OsContext *osContext, GraphicsAllocation &gfxAllocation) {
std::lock_guard<std::mutex> lock(mutex);
this->residency.erase(&gfxAllocation);
return MemoryOperationsStatus::SUCCESS;
}
MemoryOperationsStatus DrmMemoryOperationsHandlerDefault::evict(Device *device, GraphicsAllocation &gfxAllocation) {
OsContext *osContext = nullptr;
return this->evictWithinOsContext(osContext, gfxAllocation);
}
MemoryOperationsStatus DrmMemoryOperationsHandlerDefault::isResident(Device *device, GraphicsAllocation &gfxAllocation) {
std::lock_guard<std::mutex> lock(mutex);
auto ret = this->residency.find(&gfxAllocation);
if (ret == this->residency.end()) {
return MemoryOperationsStatus::MEMORY_NOT_FOUND;
}
return MemoryOperationsStatus::SUCCESS;
}
void DrmMemoryOperationsHandlerDefault::mergeWithResidencyContainer(OsContext *osContext, ResidencyContainer &residencyContainer) {
for (auto gfxAllocation = this->residency.begin(); gfxAllocation != this->residency.end(); gfxAllocation++) {
auto ret = std::find(residencyContainer.begin(), residencyContainer.end(), *gfxAllocation);
if (ret == residencyContainer.end()) {
residencyContainer.push_back(*gfxAllocation);
}
}
}
std::unique_lock<std::mutex> DrmMemoryOperationsHandlerDefault::lockHandlerForExecWA() {
if (DebugManager.flags.MakeAllBuffersResident.get()) {
return std::unique_lock<std::mutex>(this->mutex);
}
return std::unique_lock<std::mutex>();
}
} // namespace NEO
|