From 4fb5ceeb89e4df9d0c4003fd96d3e23ee8934ca2 Mon Sep 17 00:00:00 2001 From: Bartosz Dunajski Date: Wed, 18 Aug 2021 15:34:29 +0000 Subject: [PATCH] Add helper engines to EngineInstanced Device Signed-off-by: Bartosz Dunajski --- .../command_queue/command_queue_tests.cpp | 4 +-- .../device/get_device_info_tests.cpp | 4 +-- .../unit_test/device/sub_device_tests.cpp | 33 ++++++++++++++----- shared/source/device/device.cpp | 27 +++++++++++---- shared/source/device/device.h | 2 +- shared/source/gen12lp/hw_helper_gen12lp.cpp | 2 +- shared/source/helpers/engine_node_helper.h | 2 ++ shared/source/helpers/hw_helper.h | 1 - .../helpers/hw_helper_bdw_and_later.inl | 2 +- .../helpers/hw_helper_xehp_and_later.inl | 2 +- 10 files changed, 55 insertions(+), 24 deletions(-) diff --git a/opencl/test/unit_test/command_queue/command_queue_tests.cpp b/opencl/test/unit_test/command_queue/command_queue_tests.cpp index b7fc293539..56ff5c8bdd 100644 --- a/opencl/test/unit_test/command_queue/command_queue_tests.cpp +++ b/opencl/test/unit_test/command_queue/command_queue_tests.cpp @@ -1552,8 +1552,8 @@ struct CommandQueueOnSpecificEngineTests : ::testing::Test { template class MockHwHelper : public HwHelperHw { public: - const HwHelper::EngineInstancesContainer getGpgpuEngineInstances(const HardwareInfo &hwInfo) const override { - HwHelper::EngineInstancesContainer result{}; + const EngineInstancesContainer getGpgpuEngineInstances(const HardwareInfo &hwInfo) const override { + EngineInstancesContainer result{}; for (int i = 0; i < rcsCount; i++) { result.push_back({aub_stream::ENGINE_RCS, EngineUsage::Regular}); } diff --git a/opencl/test/unit_test/device/get_device_info_tests.cpp b/opencl/test/unit_test/device/get_device_info_tests.cpp index a942789520..a113ad9b57 100644 --- a/opencl/test/unit_test/device/get_device_info_tests.cpp +++ b/opencl/test/unit_test/device/get_device_info_tests.cpp @@ -678,8 +678,8 @@ TEST(GetDeviceInfo, WhenQueryingGenericAddressSpaceSupportThenProperValueIsRetur template class MockHwHelper : public HwHelperHw { public: - const HwHelper::EngineInstancesContainer getGpgpuEngineInstances(const HardwareInfo &hwInfo) const override { - HwHelper::EngineInstancesContainer result{}; + const EngineInstancesContainer getGpgpuEngineInstances(const HardwareInfo &hwInfo) const override { + EngineInstancesContainer result{}; for (int i = 0; i < ccsCount; i++) { result.push_back({aub_stream::ENGINE_CCS, EngineUsage::Regular}); } diff --git a/opencl/test/unit_test/device/sub_device_tests.cpp b/opencl/test/unit_test/device/sub_device_tests.cpp index a3531756de..5d456fe1c1 100644 --- a/opencl/test/unit_test/device/sub_device_tests.cpp +++ b/opencl/test/unit_test/device/sub_device_tests.cpp @@ -366,7 +366,14 @@ struct EngineInstancedDeviceTests : public ::testing::Test { template bool hasEngineInstancedEngines(MockDeviceT *device, aub_stream::EngineType engineType) { - bool ccsFound = false; + bool regularCcsFound = false; + bool internalCcsFound = false; + bool lowPriorityCcsFound = false; + + OsContext *defaultOsContext = device->getDefaultEngine().osContext; + EXPECT_EQ(engineType, defaultOsContext->getEngineType()); + EXPECT_EQ(EngineUsage::Regular, defaultOsContext->getEngineUsage()); + EXPECT_TRUE(defaultOsContext->isDefaultContext()); for (auto &engine : device->engines) { if ((engine.getEngineType() != engineType) && !EngineHelpers::isBcs(engine.getEngineType())) { @@ -377,17 +384,25 @@ struct EngineInstancedDeviceTests : public ::testing::Test { auto osContext = engine.osContext; - if ((engine.getEngineType() == engineType) && - osContext->isDefaultContext() && - osContext->isRegular() && - !osContext->isLowPriority() && - !osContext->isInternalEngine()) { - EXPECT_FALSE(ccsFound); - ccsFound = true; + if (engine.getEngineType() == engineType) { + if (osContext->isRegular()) { + EXPECT_FALSE(regularCcsFound); + regularCcsFound = true; + } else if (osContext->isLowPriority()) { + EXPECT_FALSE(lowPriorityCcsFound); + lowPriorityCcsFound = true; + } else if (osContext->isInternalEngine()) { + EXPECT_FALSE(internalCcsFound); + internalCcsFound = true; + } else { + EXPECT_TRUE(false); + } + } else if (!EngineHelpers::isBcs(engine.getEngineType())) { + EXPECT_TRUE(false); } } - return ccsFound; + return (regularCcsFound && internalCcsFound && lowPriorityCcsFound); } DebugManagerStateRestore restorer; diff --git a/shared/source/device/device.cpp b/shared/source/device/device.cpp index d687130691..53a147810f 100644 --- a/shared/source/device/device.cpp +++ b/shared/source/device/device.cpp @@ -261,21 +261,36 @@ bool Device::createDeviceImpl() { return true; } -bool Device::engineSupported(const EngineTypeUsage &engineTypeUsage) const { - if (engineInstanced) { - return (EngineHelpers::isBcs(engineTypeUsage.first) || (engineTypeUsage.first == this->engineInstancedType)); +void Device::translateToEngineInstanced(EngineInstancesContainer &engineInstancesContainer) { + EngineInstancesContainer newEngines; + + for (auto &engine : engineInstancesContainer) { + if (EngineHelpers::isBcs(engine.first) || (engine.first == this->engineInstancedType) || (engine.second != EngineUsage::Regular)) { + newEngines.push_back(engine); + } else { + continue; + } + + // Override non-Regular (internal, low priority, ..) to engineInstancedType + if (newEngines.rbegin()->second != EngineUsage::Regular && !EngineHelpers::isBcs(newEngines.rbegin()->first)) { + newEngines.rbegin()->first = this->engineInstancedType; + } } - return true; + std::swap(newEngines, engineInstancesContainer); } bool Device::createEngines() { auto &hwInfo = getHardwareInfo(); auto gpgpuEngines = HwHelper::get(hwInfo.platform.eRenderCoreFamily).getGpgpuEngineInstances(hwInfo); + if (engineInstanced) { + translateToEngineInstanced(gpgpuEngines); + } + uint32_t deviceCsrIndex = 0; for (auto &engine : gpgpuEngines) { - if (engineSupported(engine) && !createEngine(deviceCsrIndex++, engine)) { + if (!createEngine(deviceCsrIndex++, engine)) { return false; } } @@ -307,7 +322,7 @@ bool Device::createEngine(uint32_t deviceCsrIndex, EngineTypeUsage engineTypeUsa const auto &hwInfo = getHardwareInfo(); const auto engineType = engineTypeUsage.first; const auto engineUsage = engineTypeUsage.second; - const auto defaultEngineType = getChosenEngineType(hwInfo); + const auto defaultEngineType = engineInstanced ? this->engineInstancedType : getChosenEngineType(hwInfo); const bool isDefaultEngine = defaultEngineType == engineType && engineUsage == EngineUsage::Regular; const bool createAsEngineInstanced = engineInstanced && EngineHelpers::isCcs(engineType); diff --git a/shared/source/device/device.h b/shared/source/device/device.h index 561eb457f8..06e60e4ef3 100644 --- a/shared/source/device/device.h +++ b/shared/source/device/device.h @@ -143,7 +143,6 @@ class Device : public ReferenceTrackedObject { virtual bool createEngines(); void addEngineToEngineGroup(EngineControl &engine); - bool engineSupported(const EngineTypeUsage &engineTypeUsage) const; MOCKABLE_VIRTUAL bool createEngine(uint32_t deviceCsrIndex, EngineTypeUsage engineTypeUsage); MOCKABLE_VIRTUAL std::unique_ptr createCommandStreamReceiver() const; MOCKABLE_VIRTUAL SubDevice *createSubDevice(uint32_t subDeviceIndex); @@ -156,6 +155,7 @@ class Device : public ReferenceTrackedObject { virtual bool genericSubDevicesAllowed(); bool engineInstancedSubDevicesAllowed(); void setAsEngineInstanced(); + void translateToEngineInstanced(EngineInstancesContainer &engineInstancesContainer); DeviceInfo deviceInfo = {}; diff --git a/shared/source/gen12lp/hw_helper_gen12lp.cpp b/shared/source/gen12lp/hw_helper_gen12lp.cpp index bff3552faa..0e43fe2e27 100644 --- a/shared/source/gen12lp/hw_helper_gen12lp.cpp +++ b/shared/source/gen12lp/hw_helper_gen12lp.cpp @@ -181,7 +181,7 @@ uint32_t HwHelperHw::getMetricsLibraryGenId() const { } template <> -const HwHelper::EngineInstancesContainer HwHelperHw::getGpgpuEngineInstances(const HardwareInfo &hwInfo) const { +const EngineInstancesContainer HwHelperHw::getGpgpuEngineInstances(const HardwareInfo &hwInfo) const { auto defaultEngine = getChosenEngineType(hwInfo); EngineInstancesContainer engines = { diff --git a/shared/source/helpers/engine_node_helper.h b/shared/source/helpers/engine_node_helper.h index 738b0c1e5d..67b0b099f5 100644 --- a/shared/source/helpers/engine_node_helper.h +++ b/shared/source/helpers/engine_node_helper.h @@ -9,6 +9,7 @@ #include "shared/source/command_stream/preemption_mode.h" #include "shared/source/helpers/common_types.h" +#include "shared/source/utilities/stackvec.h" #include "engine_node.h" @@ -29,6 +30,7 @@ enum class EngineUsage : uint32_t { }; using EngineTypeUsage = std::pair; +using EngineInstancesContainer = StackVec; struct EngineDescriptor { EngineDescriptor() = delete; diff --git a/shared/source/helpers/hw_helper.h b/shared/source/helpers/hw_helper.h index f8f404c2a3..ac9d8a8fe6 100644 --- a/shared/source/helpers/hw_helper.h +++ b/shared/source/helpers/hw_helper.h @@ -44,7 +44,6 @@ enum class LocalMemoryAccessMode { class HwHelper { public: - using EngineInstancesContainer = StackVec; static HwHelper &get(GFXCORE_FAMILY gfxCore); virtual uint32_t getBindingTableStateSurfaceStatePointer(const void *pBindingTable, uint32_t index) = 0; virtual size_t getBindingTableStateSize() const = 0; diff --git a/shared/source/helpers/hw_helper_bdw_and_later.inl b/shared/source/helpers/hw_helper_bdw_and_later.inl index dac192ffda..ab46579629 100644 --- a/shared/source/helpers/hw_helper_bdw_and_later.inl +++ b/shared/source/helpers/hw_helper_bdw_and_later.inl @@ -51,7 +51,7 @@ bool HwHelperHw::timestampPacketWriteSupported() const { } template -const HwHelper::EngineInstancesContainer HwHelperHw::getGpgpuEngineInstances(const HardwareInfo &hwInfo) const { +const EngineInstancesContainer HwHelperHw::getGpgpuEngineInstances(const HardwareInfo &hwInfo) const { return { {aub_stream::ENGINE_RCS, EngineUsage::Regular}, {aub_stream::ENGINE_RCS, EngineUsage::LowPriority}, diff --git a/shared/source/helpers/hw_helper_xehp_and_later.inl b/shared/source/helpers/hw_helper_xehp_and_later.inl index cce9104979..8163ef59f4 100644 --- a/shared/source/helpers/hw_helper_xehp_and_later.inl +++ b/shared/source/helpers/hw_helper_xehp_and_later.inl @@ -65,7 +65,7 @@ bool HwHelperHw::timestampPacketWriteSupported() const { } template -const HwHelper::EngineInstancesContainer HwHelperHw::getGpgpuEngineInstances(const HardwareInfo &hwInfo) const { +const EngineInstancesContainer HwHelperHw::getGpgpuEngineInstances(const HardwareInfo &hwInfo) const { auto defaultEngine = getChosenEngineType(hwInfo); EngineInstancesContainer engines;