diff --git a/level_zero/core/source/device/device_imp.cpp b/level_zero/core/source/device/device_imp.cpp index 709072646f..e6beb6d4ef 100644 --- a/level_zero/core/source/device/device_imp.cpp +++ b/level_zero/core/source/device/device_imp.cpp @@ -1712,7 +1712,7 @@ ze_result_t DeviceImp::getCsrForOrdinalAndIndex(NEO::CommandStreamReceiver **csr NEO::EngineTypeUsage engineTypeUsage; engineTypeUsage.first = osContext.getEngineType(); engineTypeUsage.second = NEO::EngineUsage::regular; - auto engine = neoDevice->getSecondaryEngineCsr(index, engineTypeUsage); + auto engine = neoDevice->getSecondaryEngineCsr(engineTypeUsage); if (engine) { *csr = engine->commandStreamReceiver; } @@ -1754,7 +1754,7 @@ ze_result_t DeviceImp::getCsrForOrdinalAndIndexWithPriority(NEO::CommandStreamRe NEO::EngineTypeUsage engineTypeUsage; engineTypeUsage.first = osContext.getEngineType(); engineTypeUsage.second = NEO::EngineUsage::highPriority; - auto engine = neoDevice->getSecondaryEngineCsr(index, engineTypeUsage); + auto engine = neoDevice->getSecondaryEngineCsr(engineTypeUsage); if (engine) { *csr = engine->commandStreamReceiver; return ZE_RESULT_SUCCESS; diff --git a/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_6.cpp b/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_6.cpp index 65a9606d58..fa79683f7c 100644 --- a/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_6.cpp +++ b/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_6.cpp @@ -2893,7 +2893,6 @@ HWTEST2_F(ContextGroupStateBaseAddressGlobalStatelessTest, hwInfo.gtSystemInfo.CCSInfo.NumberOfCCSEnabled = 1; auto neoDevice = std::unique_ptr(NEO::MockDevice::createWithNewExecutionEnvironment(&hwInfo)); - const auto ccsIndex = 0; auto defaultCsr = neoDevice->getDefaultEngine().commandStreamReceiver; defaultCsr->createGlobalStatelessHeap(); @@ -2901,11 +2900,11 @@ HWTEST2_F(ContextGroupStateBaseAddressGlobalStatelessTest, NEO::EngineTypeUsage engineTypeUsage; engineTypeUsage.first = hwInfo.capabilityTable.defaultEngineType; engineTypeUsage.second = NEO::EngineUsage::regular; - auto primaryCsr = neoDevice->getSecondaryEngineCsr(ccsIndex, engineTypeUsage)->commandStreamReceiver; + auto primaryCsr = neoDevice->getSecondaryEngineCsr(engineTypeUsage)->commandStreamReceiver; EXPECT_EQ(nullptr, primaryCsr->getOsContext().getPrimaryContext()); EXPECT_TRUE(primaryCsr->getOsContext().isPartOfContextGroup()); - auto secondaryCsr = neoDevice->getSecondaryEngineCsr(ccsIndex, engineTypeUsage)->commandStreamReceiver; + auto secondaryCsr = neoDevice->getSecondaryEngineCsr(engineTypeUsage)->commandStreamReceiver; ze_command_queue_desc_t desc = {}; auto otherCommandQueue = new MockCommandQueueHw(device, secondaryCsr, &desc); 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 b10d8f8e05..9cf0971959 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 @@ -4018,10 +4018,12 @@ HWTEST_F(DeviceTest, givenContextGroupSupportedWhenGettingLowPriorityCsrThenCorr EXPECT_EQ(ZE_RESULT_SUCCESS, result); ASSERT_NE(nullptr, lowPriorityCsr); - ASSERT_EQ(8u, neoMockDevice->secondaryEngines[0].engines.size()); + auto &secondaryEngines = neoMockDevice->secondaryEngines[aub_stream::EngineType::ENGINE_CCS]; + + ASSERT_EQ(8u, secondaryEngines.engines.size()); for (int i = 0; i < 8; i++) { - EXPECT_NE(neoMockDevice->secondaryEngines[0].engines[i].osContext, &lowPriorityCsr->getOsContext()); - EXPECT_NE(neoMockDevice->secondaryEngines[0].engines[i].commandStreamReceiver, lowPriorityCsr); + EXPECT_NE(secondaryEngines.engines[i].osContext, &lowPriorityCsr->getOsContext()); + EXPECT_NE(secondaryEngines.engines[i].commandStreamReceiver, lowPriorityCsr); } EXPECT_FALSE(lowPriorityCsr->getOsContext().isPartOfContextGroup()); @@ -4101,13 +4103,15 @@ HWTEST_F(DeviceTest, givenContextGroupSupportedWhenGettingHighPriorityCsrThenCor EXPECT_EQ(ZE_RESULT_SUCCESS, result); ASSERT_NE(nullptr, highPriorityCsr); - ASSERT_EQ(8u, neoMockDevice->secondaryEngines[index].engines.size()); + auto &secondaryEngines = neoMockDevice->secondaryEngines[EngineHelpers::mapCcsIndexToEngineType(index)]; - auto highPriorityIndex = neoMockDevice->secondaryEngines[index].regularEnginesTotal; - ASSERT_LT(highPriorityIndex, static_cast(neoMockDevice->secondaryEngines[index].engines.size())); + ASSERT_EQ(8u, secondaryEngines.engines.size()); - EXPECT_EQ(neoMockDevice->secondaryEngines[index].engines[highPriorityIndex].osContext, &highPriorityCsr->getOsContext()); - EXPECT_EQ(neoMockDevice->secondaryEngines[index].engines[highPriorityIndex].commandStreamReceiver, highPriorityCsr); + auto highPriorityIndex = secondaryEngines.regularEnginesTotal; + ASSERT_LT(highPriorityIndex, static_cast(secondaryEngines.engines.size())); + + EXPECT_EQ(secondaryEngines.engines[highPriorityIndex].osContext, &highPriorityCsr->getOsContext()); + EXPECT_EQ(secondaryEngines.engines[highPriorityIndex].commandStreamReceiver, highPriorityCsr); EXPECT_TRUE(highPriorityCsr->getOsContext().isPartOfContextGroup()); EXPECT_NE(nullptr, highPriorityCsr->getOsContext().getPrimaryContext()); @@ -4117,7 +4121,7 @@ HWTEST_F(DeviceTest, givenContextGroupSupportedWhenGettingHighPriorityCsrThenCor ASSERT_NE(nullptr, highPriorityCsr2); EXPECT_NE(highPriorityCsr, highPriorityCsr2); - EXPECT_EQ(neoMockDevice->secondaryEngines[index].engines[highPriorityIndex + 1].commandStreamReceiver, highPriorityCsr2); + EXPECT_EQ(secondaryEngines.engines[highPriorityIndex + 1].commandStreamReceiver, highPriorityCsr2); EXPECT_TRUE(highPriorityCsr2->getOsContext().isPartOfContextGroup()); index = 100; diff --git a/opencl/source/command_queue/command_queue.cpp b/opencl/source/command_queue/command_queue.cpp index 3b60f3212d..3c79cd753f 100644 --- a/opencl/source/command_queue/command_queue.cpp +++ b/opencl/source/command_queue/command_queue.cpp @@ -202,7 +202,7 @@ void CommandQueue::initializeGpgpu() const { } else { if (secondaryContextsEnabled && EngineHelpers::isCcs(defaultEngineType)) { - gpgpuEngine = device->getDevice().getSecondaryEngineCsr(0, {defaultEngineType, EngineUsage::regular}); + gpgpuEngine = device->getDevice().getSecondaryEngineCsr({defaultEngineType, EngineUsage::regular}); } if (gpgpuEngine == nullptr) { @@ -1227,8 +1227,7 @@ void CommandQueue::overrideEngine(aub_stream::EngineType engineType, EngineUsage if (multiRegularContextAllowed) { gpgpuEngine = &device->getDevice().getNextEngineForMultiRegularContextMode(engineType); } else if (secondaryContextsEnabled && EngineHelpers::isCcs(engineType)) { - auto index = EngineHelpers::getCcsIndex(engineType); - gpgpuEngine = device->getDevice().getSecondaryEngineCsr(index, {engineType, engineUsage}); + gpgpuEngine = device->getDevice().getSecondaryEngineCsr({engineType, engineUsage}); } else { gpgpuEngine = &device->getEngine(engineType, engineUsage); } diff --git a/shared/source/device/device.cpp b/shared/source/device/device.cpp index f28daa76bd..4fdb37659d 100644 --- a/shared/source/device/device.cpp +++ b/shared/source/device/device.cpp @@ -313,32 +313,31 @@ bool Device::createEngines() { } if (gfxCoreHelper.areSecondaryContextsSupported()) { + auto engineGroupType = EngineGroupType::compute; - auto &hardwareInfo = this->getHardwareInfo(); - auto engineType = aub_stream::EngineType::ENGINE_CCS; + auto engineGroup = tryGetRegularEngineGroup(engineGroupType); - if (tryGetEngine(engineType, EngineUsage::regular)) { + if (engineGroup) { auto contextCount = gfxCoreHelper.getContextGroupContextsCount(); auto highPriorityContextCount = std::min(contextCount / 2, 4u); - const EngineGroupType engineGroupType = gfxCoreHelper.getEngineGroupType(engineType, EngineUsage::regular, hardwareInfo); - const auto engineGroupIndex = this->getEngineGroupIndexFromEngineGroupType(engineGroupType); - auto &engineGroup = this->getRegularEngineGroups()[engineGroupIndex]; + for (uint32_t engineIndex = 0; engineIndex < static_cast(engineGroup->engines.size()); engineIndex++) { + auto engineType = engineGroup->engines[engineIndex].getEngineType(); - secondaryEngines.resize(engineGroup.engines.size()); + UNRECOVERABLE_IF(secondaryEngines.find(engineType) != secondaryEngines.end()); + auto &secondaryEnginesForType = secondaryEngines[engineType]; - for (uint32_t engineIndex = 0; engineIndex < static_cast(engineGroup.engines.size()); engineIndex++) { - auto primaryEngine = engineGroup.engines[engineIndex]; + auto primaryEngine = engineGroup->engines[engineIndex]; - secondaryEngines[engineIndex].regularEnginesTotal = contextCount - highPriorityContextCount; - secondaryEngines[engineIndex].highPriorityEnginesTotal = highPriorityContextCount; - secondaryEngines[engineIndex].regularCounter = 0; - secondaryEngines[engineIndex].highPriorityCounter = 0; + secondaryEnginesForType.regularEnginesTotal = contextCount - highPriorityContextCount; + secondaryEnginesForType.highPriorityEnginesTotal = highPriorityContextCount; + secondaryEnginesForType.regularCounter = 0; + secondaryEnginesForType.highPriorityCounter = 0; NEO::EngineTypeUsage engineTypeUsage; engineTypeUsage.first = primaryEngine.getEngineType(); - secondaryEngines[engineIndex].engines.push_back(primaryEngine); + secondaryEnginesForType.engines.push_back(primaryEngine); for (uint32_t i = 1; i < contextCount; i++) { engineTypeUsage.second = EngineUsage::regular; @@ -346,7 +345,7 @@ bool Device::createEngines() { if (i >= contextCount - highPriorityContextCount) { engineTypeUsage.second = EngineUsage::highPriority; } - createSecondaryEngine(primaryEngine.commandStreamReceiver, engineIndex, engineTypeUsage); + createSecondaryEngine(primaryEngine.commandStreamReceiver, engineTypeUsage); } primaryEngine.osContext->setContextGroup(true); @@ -486,7 +485,7 @@ bool Device::createEngine(uint32_t deviceCsrIndex, EngineTypeUsage engineTypeUsa return true; } -bool Device::createSecondaryEngine(CommandStreamReceiver *primaryCsr, uint32_t index, EngineTypeUsage engineTypeUsage) { +bool Device::createSecondaryEngine(CommandStreamReceiver *primaryCsr, EngineTypeUsage engineTypeUsage) { auto engineUsage = engineTypeUsage.second; std::unique_ptr commandStreamReceiver = createCommandStreamReceiver(); if (!commandStreamReceiver) { @@ -506,30 +505,32 @@ bool Device::createSecondaryEngine(CommandStreamReceiver *primaryCsr, uint32_t i commandStreamReceiver->setPrimaryCsr(primaryCsr); EngineControl engine{commandStreamReceiver.get(), osContext}; - secondaryEngines[index].engines.push_back(engine); + + secondaryEngines[engineTypeUsage.first].engines.push_back(engine); secondaryCsrs.push_back(std::move(commandStreamReceiver)); return true; } -EngineControl *Device::getSecondaryEngineCsr(uint32_t engineIndex, EngineTypeUsage engineTypeUsage) { - - if (secondaryEngines.size() == 0 || !EngineHelpers::isCcs(engineTypeUsage.first) || engineIndex >= secondaryEngines.size()) { +EngineControl *Device::getSecondaryEngineCsr(EngineTypeUsage engineTypeUsage) { + if (secondaryEngines.find(engineTypeUsage.first) == secondaryEngines.end()) { return nullptr; } + auto &secondaryEnginesForType = secondaryEngines[engineTypeUsage.first]; + auto secondaryEngineIndex = 0; if (engineTypeUsage.second == EngineUsage::highPriority) { - secondaryEngineIndex = (secondaryEngines[engineIndex].highPriorityCounter.fetch_add(1)) % (secondaryEngines[engineIndex].highPriorityEnginesTotal); - secondaryEngineIndex += secondaryEngines[engineIndex].regularEnginesTotal; + secondaryEngineIndex = (secondaryEnginesForType.highPriorityCounter.fetch_add(1)) % (secondaryEnginesForType.highPriorityEnginesTotal); + secondaryEngineIndex += secondaryEnginesForType.regularEnginesTotal; } else if (engineTypeUsage.second == EngineUsage::regular) { - secondaryEngineIndex = (secondaryEngines[engineIndex].regularCounter.fetch_add(1)) % (secondaryEngines[engineIndex].regularEnginesTotal); + secondaryEngineIndex = (secondaryEnginesForType.regularCounter.fetch_add(1)) % (secondaryEnginesForType.regularEnginesTotal); } else { DEBUG_BREAK_IF(true); } if (secondaryEngineIndex > 0) { - auto commandStreamReceiver = secondaryEngines[engineIndex].engines[secondaryEngineIndex].commandStreamReceiver; + auto commandStreamReceiver = secondaryEnginesForType.engines[secondaryEngineIndex].commandStreamReceiver; auto lock = commandStreamReceiver->obtainUniqueOwnership(); @@ -554,7 +555,7 @@ EngineControl *Device::getSecondaryEngineCsr(uint32_t engineIndex, EngineTypeUsa } } } - return &secondaryEngines[engineIndex].engines[secondaryEngineIndex]; + return &secondaryEnginesForType.engines[secondaryEngineIndex]; } const HardwareInfo &Device::getHardwareInfo() const { return *getRootDeviceEnvironment().getHardwareInfo(); } @@ -1145,4 +1146,13 @@ bool Device::isMultiRegularContextSelectionAllowed(aub_stream::EngineType engine return EngineHelpers::isCcs(engineType); } + +const EngineGroupT *Device::tryGetRegularEngineGroup(EngineGroupType engineGroupType) const { + for (auto &engineGroup : regularEngineGroups) { + if (engineGroup.engineGroupType == engineGroupType) { + return &engineGroup; + } + } + return nullptr; +} } // namespace NEO diff --git a/shared/source/device/device.h b/shared/source/device/device.h index 2b91c964c5..fc6be4fa3a 100644 --- a/shared/source/device/device.h +++ b/shared/source/device/device.h @@ -102,6 +102,7 @@ class Device : public ReferenceTrackedObject { EngineGroupsT &getRegularEngineGroups() { return this->regularEngineGroups; } + const EngineGroupT *tryGetRegularEngineGroup(EngineGroupType engineGroupType) const; size_t getEngineGroupIndexFromEngineGroupType(EngineGroupType engineGroupType) const; EngineControl &getEngine(uint32_t index); EngineControl &getDefaultEngine(); @@ -192,7 +193,7 @@ class Device : public ReferenceTrackedObject { return getPreemptionMode() == PreemptionMode::MidThread || getDebugger() != nullptr; } - MOCKABLE_VIRTUAL EngineControl *getSecondaryEngineCsr(uint32_t engineIndex, EngineTypeUsage engineTypeUsage); + MOCKABLE_VIRTUAL EngineControl *getSecondaryEngineCsr(EngineTypeUsage engineTypeUsage); bool isSecondaryContextEngineType(aub_stream::EngineType type) { return EngineHelpers::isCcs(type); } @@ -219,7 +220,7 @@ class Device : public ReferenceTrackedObject { void addEngineToEngineGroup(EngineControl &engine); MOCKABLE_VIRTUAL bool createEngine(uint32_t deviceCsrIndex, EngineTypeUsage engineTypeUsage); - MOCKABLE_VIRTUAL bool createSecondaryEngine(CommandStreamReceiver *primaryCsr, uint32_t index, EngineTypeUsage engineTypeUsage); + MOCKABLE_VIRTUAL bool createSecondaryEngine(CommandStreamReceiver *primaryCsr, EngineTypeUsage engineTypeUsage); MOCKABLE_VIRTUAL std::unique_ptr createCommandStreamReceiver() const; MOCKABLE_VIRTUAL SubDevice *createSubDevice(uint32_t subDeviceIndex); @@ -241,7 +242,7 @@ class Device : public ReferenceTrackedObject { std::vector> commandStreamReceivers; EnginesT allEngines; - std::vector secondaryEngines; + std::unordered_map secondaryEngines; std::vector> secondaryCsrs; EngineGroupsT regularEngineGroups; diff --git a/shared/test/unit_test/command_stream/command_stream_receiver_tests.cpp b/shared/test/unit_test/command_stream/command_stream_receiver_tests.cpp index 394988b1a8..4d3d42c364 100644 --- a/shared/test/unit_test/command_stream/command_stream_receiver_tests.cpp +++ b/shared/test/unit_test/command_stream/command_stream_receiver_tests.cpp @@ -5307,36 +5307,37 @@ HWTEST_F(CommandStreamReceiverContextGroupTest, givenSecondaryCsrWhenGettingInte const auto &gfxCoreHelper = device->getRootDeviceEnvironment().getHelper(); const auto ccsIndex = 0; - auto secondaryEnginesCount = device->secondaryEngines[ccsIndex].engines.size(); + auto &secondaryEngines = device->secondaryEngines[EngineHelpers::mapCcsIndexToEngineType(ccsIndex)]; + auto secondaryEnginesCount = secondaryEngines.engines.size(); ASSERT_EQ(5u, secondaryEnginesCount); - EXPECT_TRUE(device->secondaryEngines[ccsIndex].engines[0].commandStreamReceiver->isInitialized()); + EXPECT_TRUE(secondaryEngines.engines[0].commandStreamReceiver->isInitialized()); - auto primaryCsr = device->secondaryEngines[ccsIndex].engines[0].commandStreamReceiver; + auto primaryCsr = secondaryEngines.engines[0].commandStreamReceiver; primaryCsr->createGlobalStatelessHeap(); for (uint32_t secondaryIndex = 1; secondaryIndex < secondaryEnginesCount; secondaryIndex++) { - device->getSecondaryEngineCsr(ccsIndex, {EngineHelpers::mapCcsIndexToEngineType(ccsIndex), EngineUsage::regular}); + device->getSecondaryEngineCsr({EngineHelpers::mapCcsIndexToEngineType(ccsIndex), EngineUsage::regular}); } - for (uint32_t i = 0; i < device->secondaryEngines[ccsIndex].highPriorityEnginesTotal; i++) { - device->getSecondaryEngineCsr(ccsIndex, {EngineHelpers::mapCcsIndexToEngineType(ccsIndex), EngineUsage::highPriority}); + for (uint32_t i = 0; i < secondaryEngines.highPriorityEnginesTotal; i++) { + device->getSecondaryEngineCsr({EngineHelpers::mapCcsIndexToEngineType(ccsIndex), EngineUsage::highPriority}); } for (uint32_t secondaryIndex = 0; secondaryIndex < secondaryEnginesCount; secondaryIndex++) { if (secondaryIndex > 0) { - EXPECT_NE(primaryCsr->getTagAllocation(), device->secondaryEngines[ccsIndex].engines[secondaryIndex].commandStreamReceiver->getTagAllocation()); + EXPECT_NE(primaryCsr->getTagAllocation(), secondaryEngines.engines[secondaryIndex].commandStreamReceiver->getTagAllocation()); } if (gfxCoreHelper.isFenceAllocationRequired(hwInfo)) { - EXPECT_EQ(primaryCsr->getGlobalFenceAllocation(), device->secondaryEngines[ccsIndex].engines[secondaryIndex].commandStreamReceiver->getGlobalFenceAllocation()); + EXPECT_EQ(primaryCsr->getGlobalFenceAllocation(), secondaryEngines.engines[secondaryIndex].commandStreamReceiver->getGlobalFenceAllocation()); } - EXPECT_EQ(primaryCsr->getPreemptionAllocation(), device->secondaryEngines[ccsIndex].engines[secondaryIndex].commandStreamReceiver->getPreemptionAllocation()); - EXPECT_EQ(primaryCsr->getGlobalStatelessHeapAllocation(), device->secondaryEngines[ccsIndex].engines[secondaryIndex].commandStreamReceiver->getGlobalStatelessHeapAllocation()); - EXPECT_EQ(primaryCsr->getGlobalStatelessHeap(), device->secondaryEngines[ccsIndex].engines[secondaryIndex].commandStreamReceiver->getGlobalStatelessHeap()); - EXPECT_EQ(primaryCsr->getPrimaryScratchSpaceController(), device->secondaryEngines[ccsIndex].engines[secondaryIndex].commandStreamReceiver->getPrimaryScratchSpaceController()); + EXPECT_EQ(primaryCsr->getPreemptionAllocation(), secondaryEngines.engines[secondaryIndex].commandStreamReceiver->getPreemptionAllocation()); + EXPECT_EQ(primaryCsr->getGlobalStatelessHeapAllocation(), secondaryEngines.engines[secondaryIndex].commandStreamReceiver->getGlobalStatelessHeapAllocation()); + EXPECT_EQ(primaryCsr->getGlobalStatelessHeap(), secondaryEngines.engines[secondaryIndex].commandStreamReceiver->getGlobalStatelessHeap()); + EXPECT_EQ(primaryCsr->getPrimaryScratchSpaceController(), secondaryEngines.engines[secondaryIndex].commandStreamReceiver->getPrimaryScratchSpaceController()); } } @@ -5357,8 +5358,8 @@ HWTEST_F(CommandStreamReceiverContextGroupTest, givenSecondaryCsrsWhenSameResour auto device = std::unique_ptr(MockDevice::createWithNewExecutionEnvironment(&hwInfo)); const auto ccsIndex = 0; - auto &commandStreamReceiver0 = *device->getSecondaryEngineCsr(ccsIndex, {EngineHelpers::mapCcsIndexToEngineType(ccsIndex), EngineUsage::regular})->commandStreamReceiver; - auto &commandStreamReceiver1 = *device->getSecondaryEngineCsr(ccsIndex, {EngineHelpers::mapCcsIndexToEngineType(ccsIndex), EngineUsage::regular})->commandStreamReceiver; + auto &commandStreamReceiver0 = *device->getSecondaryEngineCsr({EngineHelpers::mapCcsIndexToEngineType(ccsIndex), EngineUsage::regular})->commandStreamReceiver; + auto &commandStreamReceiver1 = *device->getSecondaryEngineCsr({EngineHelpers::mapCcsIndexToEngineType(ccsIndex), EngineUsage::regular})->commandStreamReceiver; auto csr0ContextId = commandStreamReceiver0.getOsContext().getContextId(); auto csr1ContextId = commandStreamReceiver1.getOsContext().getContextId(); diff --git a/shared/test/unit_test/device/neo_device_tests.cpp b/shared/test/unit_test/device/neo_device_tests.cpp index 8b50c84d45..5b131f6306 100644 --- a/shared/test/unit_test/device/neo_device_tests.cpp +++ b/shared/test/unit_test/device/neo_device_tests.cpp @@ -1173,51 +1173,53 @@ HWTEST_F(DeviceTests, givenCCSEnginesAndContextGroupSizeEnabledWhenDeviceIsCreat } ASSERT_EQ(computeEnginesCount, device->secondaryEngines.size()); - ASSERT_EQ(contextGroupSize, device->secondaryEngines[0].engines.size()); + ASSERT_EQ(contextGroupSize, device->secondaryEngines[aub_stream::EngineType::ENGINE_CCS].engines.size()); auto defaultEngine = device->getDefaultEngine(); - EXPECT_EQ(defaultEngine.commandStreamReceiver, device->secondaryEngines[0].engines[0].commandStreamReceiver); + EXPECT_EQ(defaultEngine.commandStreamReceiver, device->secondaryEngines[aub_stream::EngineType::ENGINE_CCS].engines[0].commandStreamReceiver); const uint32_t regularContextCount = std::min(contextGroupSize / 2, 4u); for (uint32_t ccsIndex = 0; ccsIndex < computeEnginesCount; ccsIndex++) { - EXPECT_TRUE(device->secondaryEngines[ccsIndex].engines[0].osContext->isPartOfContextGroup()); - EXPECT_EQ(nullptr, device->secondaryEngines[ccsIndex].engines[0].osContext->getPrimaryContext()); + auto &secondaryEngines = device->secondaryEngines[EngineHelpers::mapCcsIndexToEngineType(ccsIndex)]; - for (size_t i = 1; i < device->secondaryEngines[0].engines.size(); i++) { - EXPECT_EQ(device->secondaryEngines[ccsIndex].engines[0].osContext, device->secondaryEngines[ccsIndex].engines[i].osContext->getPrimaryContext()); - EXPECT_TRUE(device->secondaryEngines[ccsIndex].engines[i].osContext->isPartOfContextGroup()); + EXPECT_TRUE(secondaryEngines.engines[0].osContext->isPartOfContextGroup()); + EXPECT_EQ(nullptr, secondaryEngines.engines[0].osContext->getPrimaryContext()); + + for (size_t i = 1; i < device->secondaryEngines[aub_stream::EngineType::ENGINE_CCS].engines.size(); i++) { + EXPECT_EQ(secondaryEngines.engines[0].osContext, secondaryEngines.engines[i].osContext->getPrimaryContext()); + EXPECT_TRUE(secondaryEngines.engines[i].osContext->isPartOfContextGroup()); } - EXPECT_EQ(0u, device->secondaryEngines[ccsIndex].regularCounter.load()); - EXPECT_EQ(0u, device->secondaryEngines[ccsIndex].highPriorityCounter.load()); + EXPECT_EQ(0u, secondaryEngines.regularCounter.load()); + EXPECT_EQ(0u, secondaryEngines.highPriorityCounter.load()); - EXPECT_EQ(regularContextCount, device->secondaryEngines[ccsIndex].regularEnginesTotal); - EXPECT_EQ(contextGroupSize - regularContextCount, device->secondaryEngines[ccsIndex].highPriorityEnginesTotal); + EXPECT_EQ(regularContextCount, secondaryEngines.regularEnginesTotal); + EXPECT_EQ(contextGroupSize - regularContextCount, secondaryEngines.highPriorityEnginesTotal); for (size_t contextId = 0; contextId < regularContextCount + 1; contextId++) { - auto engine = device->getSecondaryEngineCsr(ccsIndex, {EngineHelpers::mapCcsIndexToEngineType(ccsIndex), EngineUsage::regular}); + auto engine = device->getSecondaryEngineCsr({EngineHelpers::mapCcsIndexToEngineType(ccsIndex), EngineUsage::regular}); ASSERT_NE(nullptr, engine); - EXPECT_EQ(contextId + 1, device->secondaryEngines[ccsIndex].regularCounter.load()); + EXPECT_EQ(contextId + 1, secondaryEngines.regularCounter.load()); if (contextId == regularContextCount) { - EXPECT_EQ(&device->secondaryEngines[ccsIndex].engines[0], engine); + EXPECT_EQ(&secondaryEngines.engines[0], engine); } } for (size_t contextId = 0; contextId < contextGroupSize - regularContextCount + 1; contextId++) { - auto engine = device->getSecondaryEngineCsr(ccsIndex, {EngineHelpers::mapCcsIndexToEngineType(ccsIndex), EngineUsage::highPriority}); + auto engine = device->getSecondaryEngineCsr({EngineHelpers::mapCcsIndexToEngineType(ccsIndex), EngineUsage::highPriority}); ASSERT_NE(nullptr, engine); - EXPECT_EQ(contextId + 1, device->secondaryEngines[ccsIndex].highPriorityCounter.load()); + EXPECT_EQ(contextId + 1, secondaryEngines.highPriorityCounter.load()); if (contextId == contextGroupSize - regularContextCount) { - EXPECT_EQ(&device->secondaryEngines[ccsIndex].engines[regularContextCount], engine); + EXPECT_EQ(&secondaryEngines.engines[regularContextCount], engine); } } } auto internalEngine = device->getInternalEngine(); - EXPECT_NE(internalEngine.commandStreamReceiver, device->getSecondaryEngineCsr(0, {aub_stream::EngineType::ENGINE_CCS, EngineUsage::internal})->commandStreamReceiver); + EXPECT_NE(internalEngine.commandStreamReceiver, device->getSecondaryEngineCsr({aub_stream::EngineType::ENGINE_CCS, EngineUsage::internal})->commandStreamReceiver); } HWTEST_F(DeviceTests, givenContextGroupEnabledWhenGettingSecondaryEngineThenResourcesAndContextAreInitialized) { @@ -1239,43 +1241,46 @@ HWTEST_F(DeviceTests, givenContextGroupEnabledWhenGettingSecondaryEngineThenReso const auto &gfxCoreHelper = device->getRootDeviceEnvironment().getHelper(); const auto ccsIndex = 0; - auto secondaryEnginesCount = device->secondaryEngines[ccsIndex].engines.size(); + + auto &secondaryEngines = device->secondaryEngines[EngineHelpers::mapCcsIndexToEngineType(ccsIndex)]; + + auto secondaryEnginesCount = secondaryEngines.engines.size(); ASSERT_EQ(5u, secondaryEnginesCount); - EXPECT_TRUE(device->secondaryEngines[ccsIndex].engines[0].commandStreamReceiver->isInitialized()); - EXPECT_EQ(1u, device->secondaryEngines[ccsIndex].engines[0].commandStreamReceiver->peekLatestSentTaskCount()); + EXPECT_TRUE(secondaryEngines.engines[0].commandStreamReceiver->isInitialized()); + EXPECT_EQ(1u, secondaryEngines.engines[0].commandStreamReceiver->peekLatestSentTaskCount()); - auto primaryCsr = device->secondaryEngines[ccsIndex].engines[0].commandStreamReceiver; + auto primaryCsr = secondaryEngines.engines[0].commandStreamReceiver; for (uint32_t secondaryIndex = 1; secondaryIndex < secondaryEnginesCount; secondaryIndex++) { - EXPECT_FALSE(device->secondaryEngines[ccsIndex].engines[secondaryIndex].osContext->isInitialized()); - EXPECT_FALSE(device->secondaryEngines[ccsIndex].engines[secondaryIndex].commandStreamReceiver->isInitialized()); + EXPECT_FALSE(secondaryEngines.engines[secondaryIndex].osContext->isInitialized()); + EXPECT_FALSE(secondaryEngines.engines[secondaryIndex].commandStreamReceiver->isInitialized()); - EXPECT_EQ(nullptr, device->secondaryEngines[ccsIndex].engines[secondaryIndex].commandStreamReceiver->getTagAllocation()); - EXPECT_EQ(primaryCsr->getGlobalFenceAllocation(), device->secondaryEngines[ccsIndex].engines[secondaryIndex].commandStreamReceiver->getGlobalFenceAllocation()); + EXPECT_EQ(nullptr, secondaryEngines.engines[secondaryIndex].commandStreamReceiver->getTagAllocation()); + EXPECT_EQ(primaryCsr->getGlobalFenceAllocation(), secondaryEngines.engines[secondaryIndex].commandStreamReceiver->getGlobalFenceAllocation()); if (device->getPreemptionMode() == PreemptionMode::MidThread) { - EXPECT_EQ(primaryCsr->getPreemptionAllocation(), device->secondaryEngines[ccsIndex].engines[secondaryIndex].commandStreamReceiver->getPreemptionAllocation()); + EXPECT_EQ(primaryCsr->getPreemptionAllocation(), secondaryEngines.engines[secondaryIndex].commandStreamReceiver->getPreemptionAllocation()); } - device->getSecondaryEngineCsr(ccsIndex, {EngineHelpers::mapCcsIndexToEngineType(ccsIndex), EngineUsage::regular}); + device->getSecondaryEngineCsr({EngineHelpers::mapCcsIndexToEngineType(ccsIndex), EngineUsage::regular}); } - for (uint32_t i = 0; i < device->secondaryEngines[ccsIndex].highPriorityEnginesTotal; i++) { - device->getSecondaryEngineCsr(ccsIndex, {EngineHelpers::mapCcsIndexToEngineType(ccsIndex), EngineUsage::highPriority}); + for (uint32_t i = 0; i < secondaryEngines.highPriorityEnginesTotal; i++) { + device->getSecondaryEngineCsr({EngineHelpers::mapCcsIndexToEngineType(ccsIndex), EngineUsage::highPriority}); } for (uint32_t secondaryIndex = 0; secondaryIndex < secondaryEnginesCount; secondaryIndex++) { - EXPECT_TRUE(device->secondaryEngines[ccsIndex].engines[secondaryIndex].osContext->isInitialized()); - EXPECT_TRUE(device->secondaryEngines[ccsIndex].engines[secondaryIndex].commandStreamReceiver->isInitialized()); + EXPECT_TRUE(secondaryEngines.engines[secondaryIndex].osContext->isInitialized()); + EXPECT_TRUE(secondaryEngines.engines[secondaryIndex].commandStreamReceiver->isInitialized()); - EXPECT_NE(nullptr, device->secondaryEngines[ccsIndex].engines[secondaryIndex].commandStreamReceiver->getTagAllocation()); + EXPECT_NE(nullptr, secondaryEngines.engines[secondaryIndex].commandStreamReceiver->getTagAllocation()); if (gfxCoreHelper.isFenceAllocationRequired(hwInfo)) { - EXPECT_NE(nullptr, device->secondaryEngines[ccsIndex].engines[secondaryIndex].commandStreamReceiver->getGlobalFenceAllocation()); + EXPECT_NE(nullptr, secondaryEngines.engines[secondaryIndex].commandStreamReceiver->getGlobalFenceAllocation()); } if (device->getPreemptionMode() == PreemptionMode::MidThread) { - EXPECT_NE(nullptr, device->secondaryEngines[ccsIndex].engines[secondaryIndex].commandStreamReceiver->getPreemptionAllocation()); + EXPECT_NE(nullptr, secondaryEngines.engines[secondaryIndex].commandStreamReceiver->getPreemptionAllocation()); } } } @@ -1300,7 +1305,8 @@ HWTEST_F(DeviceTests, givenContextGroupEnabledWhenDeviceIsDestroyedThenSecondary auto memoryManager = static_cast(executionEnvironment->memoryManager.get()); const auto ccsIndex = 0; - auto secondaryEnginesCount = device->secondaryEngines[ccsIndex].engines.size(); + auto &secondaryEngines = device->secondaryEngines[EngineHelpers::mapCcsIndexToEngineType(ccsIndex)]; + auto secondaryEnginesCount = secondaryEngines.engines.size(); ASSERT_EQ(5u, secondaryEnginesCount); ASSERT_LE(1u, memoryManager->secondaryEngines.size()); EXPECT_EQ(secondaryEnginesCount - 1, memoryManager->secondaryEngines[0].size()); @@ -1330,14 +1336,15 @@ HWTEST_F(DeviceTests, givenContextGroupEnabledAndAllocationUsedBySeconadryContex auto device = std::unique_ptr(MockDevice::createWithExecutionEnvironment(&hwInfo, executionEnvironment, 0)); auto memoryManager = static_cast(executionEnvironment->memoryManager.get()); - const auto ccsIndex = 0; - auto secondaryEnginesCount = device->secondaryEngines[ccsIndex].engines.size(); + EXPECT_NE(device->secondaryEngines.end(), device->secondaryEngines.find(aub_stream::ENGINE_CCS)); + auto &secondaryEngines = device->secondaryEngines[aub_stream::ENGINE_CCS]; + auto secondaryEnginesCount = secondaryEngines.engines.size(); ASSERT_EQ(5u, secondaryEnginesCount); - auto engine = device->getSecondaryEngineCsr(ccsIndex, {aub_stream::ENGINE_CCS, EngineUsage::regular}); + auto engine = device->getSecondaryEngineCsr({aub_stream::ENGINE_CCS, EngineUsage::regular}); ASSERT_NE(nullptr, engine); auto csr = engine->commandStreamReceiver; - auto engine2 = device->getSecondaryEngineCsr(ccsIndex, {aub_stream::ENGINE_CCS, EngineUsage::regular}); + auto engine2 = device->getSecondaryEngineCsr({aub_stream::ENGINE_CCS, EngineUsage::regular}); ASSERT_NE(nullptr, engine2); auto csr2 = engine2->commandStreamReceiver; ASSERT_NE(csr, csr2);