From 6f6ee90aa59545d26414caec509c9196e4ba0a63 Mon Sep 17 00:00:00 2001 From: Maciej Dziuban Date: Fri, 2 Jul 2021 11:34:07 +0000 Subject: [PATCH] Extend copy engine selector data Signed-off-by: Maciej Dziuban --- opencl/source/cl_device/cl_device.cpp | 2 +- opencl/source/cl_device/cl_device.h | 3 ++- opencl/source/command_queue/command_queue.cpp | 14 ++++++++++++-- opencl/source/command_queue/command_queue.h | 2 ++ opencl/source/command_queue/command_queue_hw.h | 2 +- shared/source/device/device.h | 11 ++++++++--- shared/source/helpers/engine_node_helper.h | 4 +++- shared/source/helpers/engine_node_helper_extra.cpp | 4 +++- 8 files changed, 32 insertions(+), 10 deletions(-) diff --git a/opencl/source/cl_device/cl_device.cpp b/opencl/source/cl_device/cl_device.cpp index a8f5af8e3b..da85075b5e 100644 --- a/opencl/source/cl_device/cl_device.cpp +++ b/opencl/source/cl_device/cl_device.cpp @@ -132,7 +132,7 @@ const HardwareInfo &ClDevice::getHardwareInfo() const { return device.getHardwar EngineControl &ClDevice::getEngine(aub_stream::EngineType engineType, EngineUsage engineUsage) { return device.getEngine(engineType, engineUsage); } EngineControl &ClDevice::getDefaultEngine() { return device.getDefaultEngine(); } EngineControl &ClDevice::getInternalEngine() { return device.getInternalEngine(); } -std::atomic &ClDevice::getSelectorCopyEngine() { return device.getSelectorCopyEngine(); } +SelectorCopyEngine &ClDevice::getSelectorCopyEngine() { return device.getSelectorCopyEngine(); } MemoryManager *ClDevice::getMemoryManager() const { return device.getMemoryManager(); } GmmHelper *ClDevice::getGmmHelper() const { return device.getGmmHelper(); } GmmClientContext *ClDevice::getGmmClientContext() const { return device.getGmmClientContext(); } diff --git a/opencl/source/cl_device/cl_device.h b/opencl/source/cl_device/cl_device.h index 99d1a0de66..0a5c60ead0 100644 --- a/opencl/source/cl_device/cl_device.h +++ b/opencl/source/cl_device/cl_device.h @@ -36,6 +36,7 @@ struct EngineControl; struct HardwareCapabilities; struct HardwareInfo; struct RootDeviceEnvironment; +struct SelectorCopyEngine; template <> struct OpenCLObjectMapper<_cl_device_id> { @@ -69,7 +70,7 @@ class ClDevice : public BaseObject<_cl_device_id> { EngineControl &getDefaultEngine(); EngineControl &getInternalEngine(); EngineControl *getInternalCopyEngine(); - std::atomic &getSelectorCopyEngine(); + SelectorCopyEngine &getSelectorCopyEngine(); MemoryManager *getMemoryManager() const; GmmHelper *getGmmHelper() const; GmmClientContext *getGmmClientContext() const; diff --git a/opencl/source/command_queue/command_queue.cpp b/opencl/source/command_queue/command_queue.cpp index 7fe89b9a99..d0871a2455 100644 --- a/opencl/source/command_queue/command_queue.cpp +++ b/opencl/source/command_queue/command_queue.cpp @@ -60,6 +60,9 @@ CommandQueue *CommandQueue::create(Context *context, } CommandQueue::CommandQueue(Context *context, ClDevice *device, const cl_queue_properties *properties) + : CommandQueue(context, device, properties, false) {} + +CommandQueue::CommandQueue(Context *context, ClDevice *device, const cl_queue_properties *properties, bool internalUsage) : context(context), device(device) { if (context) { context->incRefInternal(); @@ -83,8 +86,10 @@ CommandQueue::CommandQueue(Context *context, ClDevice *device, const cl_queue_pr deferredTimestampPackets = std::make_unique(); } if (bcsAllowed) { - auto &selectorCopyEngine = device->getDeviceById(0)->getSelectorCopyEngine(); - bcsEngine = device->getDeviceById(0)->getDevice().tryGetEngine(EngineHelpers::getBcsEngineType(hwInfo, selectorCopyEngine), EngineUsage::Regular); + auto &neoDevice = device->getDeviceById(0)->getDevice(); + auto &selectorCopyEngine = neoDevice.getSelectorCopyEngine(); + auto bcsEngineType = EngineHelpers::getBcsEngineType(hwInfo, selectorCopyEngine, internalUsage); + bcsEngine = neoDevice.tryGetEngine(bcsEngineType, EngineUsage::Regular); } } @@ -109,6 +114,11 @@ CommandQueue::~CommandQueue() { if (this->perfCountersEnabled) { device->getPerformanceCounters()->shutdown(); } + + if (bcsEngine) { + auto &selectorCopyEngine = device->getDeviceById(0)->getSelectorCopyEngine(); + EngineHelpers::releaseBcsEngineType(bcsEngine->getEngineType(), selectorCopyEngine); + } } timestampPacketContainer.reset(); diff --git a/opencl/source/command_queue/command_queue.h b/opencl/source/command_queue/command_queue.h index 5e1b8ed88a..76a3da021a 100644 --- a/opencl/source/command_queue/command_queue.h +++ b/opencl/source/command_queue/command_queue.h @@ -67,6 +67,8 @@ class CommandQueue : public BaseObject<_cl_command_queue> { CommandQueue() = delete; + CommandQueue(Context *context, ClDevice *device, const cl_queue_properties *properties, bool internalUsage); + CommandQueue(Context *context, ClDevice *device, const cl_queue_properties *properties); diff --git a/opencl/source/command_queue/command_queue_hw.h b/opencl/source/command_queue/command_queue_hw.h index 6688ee56a7..71e9fc3c0b 100644 --- a/opencl/source/command_queue/command_queue_hw.h +++ b/opencl/source/command_queue/command_queue_hw.h @@ -36,7 +36,7 @@ class CommandQueueHw : public CommandQueue { CommandQueueHw(Context *context, ClDevice *device, const cl_queue_properties *properties, - bool internalUsage) : BaseClass(context, device, properties) { + bool internalUsage) : BaseClass(context, device, properties, internalUsage) { auto clPriority = getCmdQueueProperties(properties, CL_QUEUE_PRIORITY_KHR); diff --git a/shared/source/device/device.h b/shared/source/device/device.h index 75f093e3e0..d86256ccb8 100644 --- a/shared/source/device/device.h +++ b/shared/source/device/device.h @@ -26,6 +26,11 @@ class OSTime; class SourceLevelDebugger; class SubDevice; +struct SelectorCopyEngine : NonCopyableOrMovableClass { + std::atomic isMainUsed = false; + std::atomic selector = 0; +}; + class Device : public ReferenceTrackedObject { public: Device &operator=(const Device &) = delete; @@ -60,7 +65,7 @@ class Device : public ReferenceTrackedObject { EngineControl &getDefaultEngine(); EngineControl &getInternalEngine(); EngineControl *getInternalCopyEngine(); - std::atomic &getSelectorCopyEngine(); + SelectorCopyEngine &getSelectorCopyEngine(); MemoryManager *getMemoryManager() const; GmmHelper *getGmmHelper() const; GmmClientContext *getGmmClientContext() const; @@ -166,7 +171,7 @@ class Device : public ReferenceTrackedObject { bool hasGenericSubDevices = false; bool engineInstanced = false; - std::atomic selectorCopyEngine{0}; + SelectorCopyEngine selectorCopyEngine = {}; DeviceBitfield deviceBitfield = 1; @@ -195,7 +200,7 @@ inline BuiltIns *Device::getBuiltIns() const { return executionEnvironment->rootDeviceEnvironments[getRootDeviceIndex()]->getBuiltIns(); } -inline std::atomic &Device::getSelectorCopyEngine() { +inline SelectorCopyEngine &Device::getSelectorCopyEngine() { return selectorCopyEngine; } diff --git a/shared/source/helpers/engine_node_helper.h b/shared/source/helpers/engine_node_helper.h index d06e22d3bd..5b2b70584d 100644 --- a/shared/source/helpers/engine_node_helper.h +++ b/shared/source/helpers/engine_node_helper.h @@ -15,6 +15,7 @@ namespace NEO { struct HardwareInfo; +struct SelectorCopyEngine; enum class EngineUsage : uint32_t { Regular, @@ -29,7 +30,8 @@ using EngineTypeUsage = std::pair; namespace EngineHelpers { bool isCcs(aub_stream::EngineType engineType); bool isBcs(aub_stream::EngineType engineType); -aub_stream::EngineType getBcsEngineType(const HardwareInfo &hwInfo, std::atomic &selectorCopyEngine); +aub_stream::EngineType getBcsEngineType(const HardwareInfo &hwInfo, SelectorCopyEngine &selectorCopyEngine, bool internalUsage = false); +void releaseBcsEngineType(aub_stream::EngineType engineType, SelectorCopyEngine &selectorCopyEngine); std::string engineTypeToString(aub_stream::EngineType engineType); std::string engineTypeToStringAdditional(aub_stream::EngineType engineType); diff --git a/shared/source/helpers/engine_node_helper_extra.cpp b/shared/source/helpers/engine_node_helper_extra.cpp index 9dd71b850a..41bf5655a2 100644 --- a/shared/source/helpers/engine_node_helper_extra.cpp +++ b/shared/source/helpers/engine_node_helper_extra.cpp @@ -13,10 +13,12 @@ bool isBcs(aub_stream::EngineType engineType) { return engineType == aub_stream::ENGINE_BCS; } -aub_stream::EngineType getBcsEngineType(const HardwareInfo &hwInfo, std::atomic &selectorCopyEngine) { +aub_stream::EngineType getBcsEngineType(const HardwareInfo &hwInfo, SelectorCopyEngine &selectorCopyEngine, bool internalUsage) { return aub_stream::EngineType::ENGINE_BCS; } +void releaseBcsEngineType(aub_stream::EngineType engineType, SelectorCopyEngine &selectorCopyEngine) {} + std::string engineTypeToStringAdditional(aub_stream::EngineType engineType) { return "Unknown"; }