From 482e07725276b01b4c0197826e59bf78552d8fe1 Mon Sep 17 00:00:00 2001 From: Mateusz Hoppe Date: Wed, 28 Aug 2024 07:04:42 +0000 Subject: [PATCH] feature: add regular and hp contexts in group without dedicated hp engine - if no hp copy engine available, create group with regular and hp contexts Related-To: NEO-11983 Signed-off-by: Mateusz Hoppe --- level_zero/core/source/device/device_imp.cpp | 4 +--- .../test/unit_tests/sources/device/test_l0_device.cpp | 11 ++++++++--- shared/source/device/device.cpp | 11 +++++++++-- shared/source/device/root_device.cpp | 2 +- shared/source/helpers/gfx_core_helper.h | 4 ++-- shared/source/helpers/gfx_core_helper_base.inl | 5 ++++- .../test/unit_test/helpers/gfx_core_helper_tests.cpp | 2 ++ 7 files changed, 27 insertions(+), 12 deletions(-) diff --git a/level_zero/core/source/device/device_imp.cpp b/level_zero/core/source/device/device_imp.cpp index fed34bdea1..16233db088 100644 --- a/level_zero/core/source/device/device_imp.cpp +++ b/level_zero/core/source/device/device_imp.cpp @@ -1736,9 +1736,7 @@ ze_result_t DeviceImp::getCsrForOrdinalAndIndex(NEO::CommandStreamReceiver **csr *csr = engines[index].commandStreamReceiver; if (copyOnly && contextPriority == NEO::EngineUsage::highPriority) { - if (getCsrForHighPriority(csr, copyOnly) != ZE_RESULT_SUCCESS) { - contextPriority = NEO::EngineUsage::regular; - } + getCsrForHighPriority(csr, copyOnly); } } else { diff --git a/level_zero/core/test/unit_tests/sources/device/test_l0_device.cpp b/level_zero/core/test/unit_tests/sources/device/test_l0_device.cpp index 6a9e604f6f..1ce27aaf02 100644 --- a/level_zero/core/test/unit_tests/sources/device/test_l0_device.cpp +++ b/level_zero/core/test/unit_tests/sources/device/test_l0_device.cpp @@ -4762,14 +4762,19 @@ HWTEST_F(DeviceTest, givenContextGroupSupportedWhenGettingHighPriorityCsrThenCor result = deviceImp.getCsrForOrdinalAndIndex(&highPriorityCsr, ordinal, index, ZE_COMMAND_QUEUE_PRIORITY_PRIORITY_HIGH, false); EXPECT_EQ(ZE_RESULT_ERROR_INVALID_ARGUMENT, result); - // When no HP copy engine, then regular engine is returned - NEO::CommandStreamReceiver *bcsEngine = nullptr; + // When no HP copy engine, then hp csr from group is returned + NEO::CommandStreamReceiver *bcsEngine = nullptr, *bcsEngine2 = nullptr; EXPECT_EQ(nullptr, neoMockDevice->getHpCopyEngine()); result = deviceImp.getCsrForOrdinalAndIndex(&bcsEngine, ordinalCopy, index, ZE_COMMAND_QUEUE_PRIORITY_PRIORITY_HIGH, false); EXPECT_EQ(ZE_RESULT_SUCCESS, result); ASSERT_NE(nullptr, bcsEngine); - EXPECT_TRUE(bcsEngine->getOsContext().isRegular()); + EXPECT_TRUE(bcsEngine->getOsContext().isHighPriority()); + + result = deviceImp.getCsrForOrdinalAndIndex(&bcsEngine2, ordinalCopy, index, ZE_COMMAND_QUEUE_PRIORITY_NORMAL, false); + EXPECT_EQ(ZE_RESULT_SUCCESS, result); + ASSERT_EQ(bcsEngine2, bcsEngine->getPrimaryCsr()); + EXPECT_TRUE(bcsEngine2->getOsContext().isRegular()); } } diff --git a/shared/source/device/device.cpp b/shared/source/device/device.cpp index 75d6aa51b7..85d9ea1be0 100644 --- a/shared/source/device/device.cpp +++ b/shared/source/device/device.cpp @@ -365,6 +365,8 @@ bool Device::createEngines() { if (gfxCoreHelper.areSecondaryContextsSupported()) { + auto hpCopyEngine = getHpCopyEngine(); + for (auto engineGroupType : {EngineGroupType::compute, EngineGroupType::copy, EngineGroupType::linkedCopy}) { auto engineGroup = tryGetRegularEngineGroup(engineGroupType); @@ -373,7 +375,13 @@ bool Device::createEngines() { } auto contextCount = gfxCoreHelper.getContextGroupContextsCount(); - auto highPriorityContextCount = gfxCoreHelper.getContextGroupHpContextsCount(engineGroupType); + bool hpEngineAvailable = false; + + if (NEO::EngineHelper::isCopyOnlyEngineType(engineGroupType)) { + hpEngineAvailable = hpCopyEngine != nullptr; + } + + auto highPriorityContextCount = gfxCoreHelper.getContextGroupHpContextsCount(engineGroupType, hpEngineAvailable); if (debugManager.flags.OverrideNumHighPriorityContexts.get() != -1) { highPriorityContextCount = static_cast(debugManager.flags.OverrideNumHighPriorityContexts.get()); @@ -395,7 +403,6 @@ bool Device::createEngines() { } } - auto hpCopyEngine = getHpCopyEngine(); if (hpCopyEngine) { auto engineType = hpCopyEngine->getEngineType(); if ((static_cast(debugManager.flags.SecondaryContextEngineTypeMask.get()) & (1 << static_cast(engineType))) != 0) { diff --git a/shared/source/device/root_device.cpp b/shared/source/device/root_device.cpp index 9b8ada86ec..5467097993 100644 --- a/shared/source/device/root_device.cpp +++ b/shared/source/device/root_device.cpp @@ -97,7 +97,7 @@ void RootDevice::initializeRootCommandStreamReceiver() { if (useContextGroup) { auto contextCount = gfxCoreHelper.getContextGroupContextsCount(); EngineGroupType engineGroupType = gfxCoreHelper.getEngineGroupType(engine.getEngineType(), engine.getEngineUsage(), hwInfo); - auto highPriorityContextCount = gfxCoreHelper.getContextGroupHpContextsCount(engineGroupType); + auto highPriorityContextCount = gfxCoreHelper.getContextGroupHpContextsCount(engineGroupType, false); if (debugManager.flags.OverrideNumHighPriorityContexts.get() != -1) { highPriorityContextCount = static_cast(debugManager.flags.OverrideNumHighPriorityContexts.get()); diff --git a/shared/source/helpers/gfx_core_helper.h b/shared/source/helpers/gfx_core_helper.h index e65f14f922..ad31d6928f 100644 --- a/shared/source/helpers/gfx_core_helper.h +++ b/shared/source/helpers/gfx_core_helper.h @@ -179,7 +179,7 @@ class GfxCoreHelper { virtual bool areSecondaryContextsSupported() const = 0; virtual uint32_t getContextGroupContextsCount() const = 0; - virtual uint32_t getContextGroupHpContextsCount(EngineGroupType type) const = 0; + virtual uint32_t getContextGroupHpContextsCount(EngineGroupType type, bool hpEngineAvailable) const = 0; virtual aub_stream::EngineType getDefaultHpCopyEngine(const HardwareInfo &hwInfo) const = 0; virtual bool is48ResourceNeededForCmdBuffer() const = 0; @@ -413,7 +413,7 @@ class GfxCoreHelperHw : public GfxCoreHelper { bool areSecondaryContextsSupported() const override; uint32_t getContextGroupContextsCount() const override; - uint32_t getContextGroupHpContextsCount(EngineGroupType type) const override; + uint32_t getContextGroupHpContextsCount(EngineGroupType type, bool hpEngineAvailable) const override; aub_stream::EngineType getDefaultHpCopyEngine(const HardwareInfo &hwInfo) const override; bool is48ResourceNeededForCmdBuffer() const override; diff --git a/shared/source/helpers/gfx_core_helper_base.inl b/shared/source/helpers/gfx_core_helper_base.inl index ddf877fb24..052031738d 100644 --- a/shared/source/helpers/gfx_core_helper_base.inl +++ b/shared/source/helpers/gfx_core_helper_base.inl @@ -732,7 +732,10 @@ uint32_t GfxCoreHelperHw::getContextGroupContextsCount() const { } template -uint32_t GfxCoreHelperHw::getContextGroupHpContextsCount(EngineGroupType type) const { +uint32_t GfxCoreHelperHw::getContextGroupHpContextsCount(EngineGroupType type, bool hpEngineAvailable) const { + if (hpEngineAvailable) { + return 0; + } return std::min(getContextGroupContextsCount() / 2, 4u); } diff --git a/shared/test/unit_test/helpers/gfx_core_helper_tests.cpp b/shared/test/unit_test/helpers/gfx_core_helper_tests.cpp index 3bc4ccf739..230b51bb70 100644 --- a/shared/test/unit_test/helpers/gfx_core_helper_tests.cpp +++ b/shared/test/unit_test/helpers/gfx_core_helper_tests.cpp @@ -1808,6 +1808,8 @@ TEST_F(GfxCoreHelperTest, givenContextGroupEnabledWithDebugKeyWhenContextGroupCo debugManager.flags.ContextGroupSize.set(2); EXPECT_EQ(2u, gfxCoreHelper.getContextGroupContextsCount()); EXPECT_TRUE(gfxCoreHelper.areSecondaryContextsSupported()); + EXPECT_EQ(1u, gfxCoreHelper.getContextGroupHpContextsCount(EngineGroupType::copy, false)); + EXPECT_EQ(0u, gfxCoreHelper.getContextGroupHpContextsCount(EngineGroupType::copy, true)); } HWTEST_F(GfxCoreHelperTest, whenAskingIf48bResourceNeededForCmdBufferThenReturnTrue) {