From 9a82e3439a3768c1a9762a42d22c46da3c28e550 Mon Sep 17 00:00:00 2001 From: Maciej Bielski Date: Tue, 19 Aug 2025 16:13:07 +0000 Subject: [PATCH] fix: serialize constructBcsEngine Related-To: NEO-15630 Signed-off-by: Maciej Bielski --- opencl/source/command_queue/command_queue.cpp | 63 ++++++++++--------- opencl/source/command_queue/command_queue.h | 2 + .../source/decoder/binary_encoder.cpp | 2 +- 3 files changed, 38 insertions(+), 29 deletions(-) diff --git a/opencl/source/command_queue/command_queue.cpp b/opencl/source/command_queue/command_queue.cpp index 6f35137fa1..797c3ddd53 100644 --- a/opencl/source/command_queue/command_queue.cpp +++ b/opencl/source/command_queue/command_queue.cpp @@ -348,40 +348,47 @@ CommandStreamReceiver &CommandQueue::selectCsrForBuiltinOperation(const CsrSelec } void CommandQueue::constructBcsEngine(bool internalUsage) { - if (bcsAllowed && !bcsInitialized) { - auto &gfxCoreHelper = device->getGfxCoreHelper(); - auto &neoDevice = device->getNearestGenericSubDevice(0)->getDevice(); - auto &selectorCopyEngine = neoDevice.getSelectorCopyEngine(); - auto bcsEngineType = EngineHelpers::getBcsEngineType(device->getRootDeviceEnvironment(), device->getDeviceBitfield(), selectorCopyEngine, internalUsage); - auto bcsIndex = EngineHelpers::getBcsIndex(bcsEngineType); - auto engineUsage = (internalUsage && gfxCoreHelper.preferInternalBcsEngine()) ? EngineUsage::internal : EngineUsage::regular; + if (!bcsAllowed) { + return; + } + if (!bcsInitialized) { + const std::lock_guard lock{bcsInitMutex}; - if (priority == QueuePriority::high) { - auto hpBcs = neoDevice.getHpCopyEngine(); + if (!bcsInitialized) { + auto &gfxCoreHelper = device->getGfxCoreHelper(); + auto &neoDevice = device->getNearestGenericSubDevice(0)->getDevice(); + auto &selectorCopyEngine = neoDevice.getSelectorCopyEngine(); + auto bcsEngineType = EngineHelpers::getBcsEngineType(device->getRootDeviceEnvironment(), device->getDeviceBitfield(), selectorCopyEngine, internalUsage); + auto bcsIndex = EngineHelpers::getBcsIndex(bcsEngineType); + auto engineUsage = (internalUsage && gfxCoreHelper.preferInternalBcsEngine()) ? EngineUsage::internal : EngineUsage::regular; - if (hpBcs) { - bcsEngineType = hpBcs->getEngineType(); - engineUsage = EngineUsage::highPriority; - bcsIndex = EngineHelpers::getBcsIndex(bcsEngineType); - bcsEngines[bcsIndex] = hpBcs; - } - } + if (priority == QueuePriority::high) { + auto hpBcs = neoDevice.getHpCopyEngine(); - if (bcsEngines[bcsIndex] == nullptr) { - bcsEngines[bcsIndex] = neoDevice.tryGetEngine(bcsEngineType, engineUsage); - } - - if (bcsEngines[bcsIndex]) { - bcsQueueEngineType = bcsEngineType; - - if (gfxCoreHelper.areSecondaryContextsSupported() && !internalUsage) { - tryAssignSecondaryEngine(device->getDevice(), bcsEngines[bcsIndex], {bcsEngineType, engineUsage}); + if (hpBcs) { + bcsEngineType = hpBcs->getEngineType(); + engineUsage = EngineUsage::highPriority; + bcsIndex = EngineHelpers::getBcsIndex(bcsEngineType); + bcsEngines[bcsIndex] = hpBcs; + } } - bcsEngines[bcsIndex]->osContext->ensureContextInitialized(false); - bcsEngines[bcsIndex]->commandStreamReceiver->initDirectSubmission(); + if (bcsEngines[bcsIndex] == nullptr) { + bcsEngines[bcsIndex] = neoDevice.tryGetEngine(bcsEngineType, engineUsage); + } + + if (bcsEngines[bcsIndex]) { + bcsQueueEngineType = bcsEngineType; + + if (gfxCoreHelper.areSecondaryContextsSupported() && !internalUsage) { + tryAssignSecondaryEngine(device->getDevice(), bcsEngines[bcsIndex], {bcsEngineType, engineUsage}); + } + + bcsEngines[bcsIndex]->osContext->ensureContextInitialized(false); + bcsEngines[bcsIndex]->commandStreamReceiver->initDirectSubmission(); + } + bcsInitialized = true; } - bcsInitialized = true; } } diff --git a/opencl/source/command_queue/command_queue.h b/opencl/source/command_queue/command_queue.h index b5250ae969..42e0c1bd75 100644 --- a/opencl/source/command_queue/command_queue.h +++ b/opencl/source/command_queue/command_queue.h @@ -23,6 +23,7 @@ #include "opencl/source/helpers/properties_helper.h" #include +#include #include #include @@ -509,6 +510,7 @@ class CommandQueue : public BaseObject<_cl_command_queue> { mutable EngineControl *gpgpuEngine = nullptr; std::array bcsEngines = {}; std::optional bcsQueueEngineType{}; + std::mutex bcsInitMutex; size_t bcsEngineCount = bcsInfoMaskSize; cl_command_queue_properties commandQueueProperties = 0; diff --git a/shared/offline_compiler/source/decoder/binary_encoder.cpp b/shared/offline_compiler/source/decoder/binary_encoder.cpp index 9ff4b80ee2..38919f83f8 100644 --- a/shared/offline_compiler/source/decoder/binary_encoder.cpp +++ b/shared/offline_compiler/source/decoder/binary_encoder.cpp @@ -167,7 +167,7 @@ int BinaryEncoder::processBinary(const std::vector &ptmFileLines, s std::stringstream ss(ptmFileLines[deviceMarker]); ss.ignore(32, ' '); ss.ignore(32, ' '); - uint32_t gfxCore = 0; + int32_t gfxCore = 0; ss >> gfxCore; iga->setGfxCore(static_cast(gfxCore)); }