From 9d5f8eb5873a4666e186dabb42dd7e55f09ec6c2 Mon Sep 17 00:00:00 2001 From: Mateusz Hoppe Date: Fri, 6 Sep 2024 12:38:55 +0000 Subject: [PATCH] refactor: save hpCopyEngine in Device - remove loop iteration to get hpCopyEngine Related-To: NEO-11983 Signed-off-by: Mateusz Hoppe --- level_zero/core/source/device/device_imp.cpp | 9 +++++---- opencl/source/command_queue/command_queue.cpp | 15 +++++++++------ shared/source/device/device.cpp | 15 +++++---------- shared/source/device/device.h | 1 + 4 files changed, 20 insertions(+), 20 deletions(-) diff --git a/level_zero/core/source/device/device_imp.cpp b/level_zero/core/source/device/device_imp.cpp index 1ef8f4c80b..bf0e1071bf 100644 --- a/level_zero/core/source/device/device_imp.cpp +++ b/level_zero/core/source/device/device_imp.cpp @@ -1788,10 +1788,11 @@ ze_result_t DeviceImp::getCsrForLowPriority(NEO::CommandStreamReceiver **csr, bo return ZE_RESULT_ERROR_UNKNOWN; } ze_result_t DeviceImp::getCsrForHighPriority(NEO::CommandStreamReceiver **csr, bool copyOnly) { - for (auto &it : getActiveDevice()->getAllEngines()) { - bool engineTypeMatch = NEO::EngineHelpers::isBcs(it.osContext->getEngineType()) == copyOnly; - if (it.osContext->isHighPriority() && engineTypeMatch) { - *csr = it.commandStreamReceiver; + + if (copyOnly) { + auto engine = getActiveDevice()->getHpCopyEngine(); + if (engine) { + *csr = engine->commandStreamReceiver; return ZE_RESULT_SUCCESS; } } diff --git a/opencl/source/command_queue/command_queue.cpp b/opencl/source/command_queue/command_queue.cpp index 486eca1abd..5afb9caf25 100644 --- a/opencl/source/command_queue/command_queue.cpp +++ b/opencl/source/command_queue/command_queue.cpp @@ -371,16 +371,19 @@ void CommandQueue::constructBcsEngine(bool internalUsage) { auto engineUsage = (internalUsage && gfxCoreHelper.preferInternalBcsEngine()) ? EngineUsage::internal : EngineUsage::regular; if (priority == QueuePriority::high) { - const auto &hwInfo = device->getHardwareInfo(); - auto hpEngine = gfxCoreHelper.getDefaultHpCopyEngine(hwInfo); - if (hpEngine != aub_stream::EngineType::NUM_ENGINES) { - bcsEngineType = hpEngine; - bcsIndex = EngineHelpers::getBcsIndex(bcsEngineType); + auto hpBcs = neoDevice.getHpCopyEngine(); + + if (hpBcs) { + bcsEngineType = hpBcs->getEngineType(); engineUsage = EngineUsage::highPriority; + bcsIndex = EngineHelpers::getBcsIndex(bcsEngineType); + bcsEngines[bcsIndex] = hpBcs; } } - bcsEngines[bcsIndex] = neoDevice.tryGetEngine(bcsEngineType, engineUsage); + if (bcsEngines[bcsIndex] == nullptr) { + bcsEngines[bcsIndex] = neoDevice.tryGetEngine(bcsEngineType, engineUsage); + } if (bcsEngines[bcsIndex]) { bcsQueueEngineType = bcsEngineType; diff --git a/shared/source/device/device.cpp b/shared/source/device/device.cpp index 14491026b4..b1dcb919a4 100644 --- a/shared/source/device/device.cpp +++ b/shared/source/device/device.cpp @@ -556,6 +556,10 @@ bool Device::createEngine(EngineTypeUsage engineTypeUsage) { addEngineToEngineGroup(engine); } + if (NEO::EngineHelpers::isBcs(engine.osContext->getEngineType()) && engine.osContext->isHighPriority()) { + hpCopyEngine = &allEngines[allEngines.size() - 1]; + } + commandStreamReceivers.push_back(std::move(commandStreamReceiver)); return true; @@ -920,16 +924,7 @@ EngineControl *Device::getInternalCopyEngine() { } EngineControl *Device::getHpCopyEngine() { - if (!getHardwareInfo().capabilityTable.blitterOperationsSupported) { - return nullptr; - } - for (auto &engine : allEngines) { - if (NEO::EngineHelpers::isBcs(engine.osContext->getEngineType()) && - engine.osContext->isHighPriority()) { - return &engine; - } - } - return nullptr; + return hpCopyEngine; } RTDispatchGlobalsInfo *Device::getRTDispatchGlobals(uint32_t maxBvhLevels) { diff --git a/shared/source/device/device.h b/shared/source/device/device.h index 3de477e4a4..d9e2a501cc 100644 --- a/shared/source/device/device.h +++ b/shared/source/device/device.h @@ -280,6 +280,7 @@ class Device : public ReferenceTrackedObject { GraphicsAllocation *debugSurface = nullptr; SelectorCopyEngine selectorCopyEngine = {}; + EngineControl *hpCopyEngine = nullptr; DeviceBitfield deviceBitfield = 1;