Optimize binding process.

- Do not iterate when all devices are parsed
- Early continue if given device not present in context

200ns (+10%) in below scenario from compute-benchmarks
ZE_AFFINITY_MASK=0.0 PrintDebugSettings=1 ./api_overhead_benchmark_l0
--test=ExecuteCommandListImmediate --api=l0 --UseProfiling=0
--CallsCount=1 --MeasureCompletionTime=0 --useBarrierSynchronization=0
--KernelExecutionTime=1 --iterations=1000

Signed-off-by: Michal Mrozek <michal.mrozek@intel.com>
This commit is contained in:
Michal Mrozek 2022-09-19 15:23:38 +00:00 committed by Compute-Runtime-Automation
parent 48aab6ce44
commit fc9352cfcb
1 changed files with 18 additions and 11 deletions

View File

@ -35,19 +35,26 @@ MemoryOperationsStatus DrmMemoryOperationsHandlerBind::makeResident(Device *devi
}
MemoryOperationsStatus DrmMemoryOperationsHandlerBind::makeResidentWithinOsContext(OsContext *osContext, ArrayRef<GraphicsAllocation *> gfxAllocations, bool evictable) {
auto deviceBitfield = osContext->getDeviceBitfield();
std::lock_guard<std::mutex> lock(mutex);
for (auto gfxAllocation = gfxAllocations.begin(); gfxAllocation != gfxAllocations.end(); gfxAllocation++) {
auto drmAllocation = static_cast<DrmAllocation *>(*gfxAllocation);
for (auto drmIterator = 0u; drmIterator < osContext->getDeviceBitfield().size(); drmIterator++) {
if (osContext->getDeviceBitfield().test(drmIterator)) {
int result = drmAllocation->makeBOsResident(osContext, drmIterator, nullptr, true);
if (result) {
return MemoryOperationsStatus::OUT_OF_MEMORY;
}
}
auto devicesDone = 0u;
for (auto drmIterator = 0u; devicesDone < deviceBitfield.count(); drmIterator++) {
if (!deviceBitfield.test(drmIterator)) {
continue;
}
if (!evictable) {
drmAllocation->updateResidencyTaskCount(GraphicsAllocation::objectAlwaysResident, osContext->getContextId());
devicesDone++;
for (auto gfxAllocation = gfxAllocations.begin(); gfxAllocation != gfxAllocations.end(); gfxAllocation++) {
auto drmAllocation = static_cast<DrmAllocation *>(*gfxAllocation);
int result = drmAllocation->makeBOsResident(osContext, drmIterator, nullptr, true);
if (result) {
return MemoryOperationsStatus::OUT_OF_MEMORY;
}
if (!evictable) {
drmAllocation->updateResidencyTaskCount(GraphicsAllocation::objectAlwaysResident, osContext->getContextId());
}
}
}
return MemoryOperationsStatus::SUCCESS;