feature: limit contexts in group based on number of CCS engines

Related-To: NEO-12258, HSD-14023076222

Signed-off-by: Mateusz Hoppe <mateusz.hoppe@intel.com>
This commit is contained in:
Mateusz Hoppe
2024-08-30 11:51:09 +00:00
committed by Compute-Runtime-Automation
parent 847180dc9a
commit ae3edba369
3 changed files with 70 additions and 56 deletions

View File

@@ -7,6 +7,7 @@
#include "shared/source/device/device.h"
#include "shared/source/gmm_helper/gmm.h"
#include "shared/source/helpers/array_count.h"
#include "shared/source/helpers/driver_model_type.h"
#include "shared/source/helpers/gfx_core_helper.h"
#include "shared/source/memory_manager/allocations_list.h"
@@ -1195,71 +1196,78 @@ HWTEST_F(DeviceTests, givenCCSEnginesAndContextGroupSizeEnabledWhenDeviceIsCreat
hwInfo.featureTable.flags.ftrCCSNode = true;
hwInfo.featureTable.ftrBcsInfo = 0;
hwInfo.capabilityTable.defaultEngineType = aub_stream::ENGINE_CCS;
hwInfo.gtSystemInfo.CCSInfo.NumberOfCCSEnabled = 2;
auto device = std::unique_ptr<MockDevice>(MockDevice::createWithNewExecutionEnvironment<MockDevice>(&hwInfo));
auto &engineGroups = device->getRegularEngineGroups();
uint32_t numOfCCS[] = {1, 2, 4};
auto engineGroupType = EngineGroupType::compute;
size_t computeEnginesCount = 0;
for (const auto &engine : engineGroups) {
if (engine.engineGroupType == engineGroupType) {
computeEnginesCount = engine.engines.size();
}
}
for (size_t i = 0; i < arrayCount(numOfCCS); i++) {
if (computeEnginesCount == 0) {
GTEST_SKIP();
}
hwInfo.gtSystemInfo.CCSInfo.NumberOfCCSEnabled = numOfCCS[i];
ASSERT_EQ(computeEnginesCount, device->secondaryEngines.size());
ASSERT_EQ(contextGroupSize, device->secondaryEngines[aub_stream::EngineType::ENGINE_CCS].engines.size());
auto device = std::unique_ptr<MockDevice>(MockDevice::createWithNewExecutionEnvironment<MockDevice>(&hwInfo));
auto &engineGroups = device->getRegularEngineGroups();
auto defaultEngine = device->getDefaultEngine();
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++) {
auto &secondaryEngines = device->secondaryEngines[EngineHelpers::mapCcsIndexToEngineType(ccsIndex)];
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, secondaryEngines.regularCounter.load());
EXPECT_EQ(0u, secondaryEngines.highPriorityCounter.load());
EXPECT_EQ(regularContextCount, secondaryEngines.regularEnginesTotal);
EXPECT_EQ(contextGroupSize - regularContextCount, secondaryEngines.highPriorityEnginesTotal);
for (size_t contextId = 0; contextId < regularContextCount + 1; contextId++) {
auto engine = device->getSecondaryEngineCsr({EngineHelpers::mapCcsIndexToEngineType(ccsIndex), EngineUsage::regular}, false);
ASSERT_NE(nullptr, engine);
EXPECT_EQ(contextId + 1, secondaryEngines.regularCounter.load());
if (contextId == regularContextCount) {
EXPECT_EQ(&secondaryEngines.engines[0], engine);
auto engineGroupType = EngineGroupType::compute;
size_t computeEnginesCount = 0;
for (const auto &engine : engineGroups) {
if (engine.engineGroupType == engineGroupType) {
computeEnginesCount = engine.engines.size();
}
}
for (size_t contextId = 0; contextId < contextGroupSize - regularContextCount + 1; contextId++) {
auto engine = device->getSecondaryEngineCsr({EngineHelpers::mapCcsIndexToEngineType(ccsIndex), EngineUsage::highPriority}, false);
ASSERT_NE(nullptr, engine);
if (computeEnginesCount == 0) {
GTEST_SKIP();
}
EXPECT_EQ(contextId + 1, secondaryEngines.highPriorityCounter.load());
if (contextId == contextGroupSize - regularContextCount) {
EXPECT_EQ(&secondaryEngines.engines[regularContextCount], engine);
ASSERT_EQ(computeEnginesCount, device->secondaryEngines.size());
ASSERT_EQ(contextGroupSize / numOfCCS[i], device->secondaryEngines[aub_stream::EngineType::ENGINE_CCS].engines.size());
auto defaultEngine = device->getDefaultEngine();
EXPECT_EQ(defaultEngine.commandStreamReceiver, device->secondaryEngines[aub_stream::EngineType::ENGINE_CCS].engines[0].commandStreamReceiver);
const uint32_t regularContextCount = std::min(contextGroupSize / 2, 4u) / numOfCCS[i];
for (uint32_t ccsIndex = 0; ccsIndex < computeEnginesCount; ccsIndex++) {
auto &secondaryEngines = device->secondaryEngines[EngineHelpers::mapCcsIndexToEngineType(ccsIndex)];
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, secondaryEngines.regularCounter.load());
EXPECT_EQ(0u, secondaryEngines.highPriorityCounter.load());
EXPECT_EQ(regularContextCount, secondaryEngines.regularEnginesTotal);
EXPECT_EQ(contextGroupSize / numOfCCS[i] - regularContextCount, secondaryEngines.highPriorityEnginesTotal);
for (size_t contextId = 0; contextId < regularContextCount + 1; contextId++) {
auto engine = device->getSecondaryEngineCsr({EngineHelpers::mapCcsIndexToEngineType(ccsIndex), EngineUsage::regular}, false);
ASSERT_NE(nullptr, engine);
EXPECT_EQ(contextId + 1, secondaryEngines.regularCounter.load());
if (contextId == regularContextCount) {
EXPECT_EQ(&secondaryEngines.engines[0], engine);
}
}
auto hpCount = contextGroupSize / numOfCCS[i] - regularContextCount;
for (size_t contextId = 0; contextId < hpCount + 1; contextId++) {
auto engine = device->getSecondaryEngineCsr({EngineHelpers::mapCcsIndexToEngineType(ccsIndex), EngineUsage::highPriority}, false);
ASSERT_NE(nullptr, engine);
EXPECT_EQ(contextId + 1, secondaryEngines.highPriorityCounter.load());
if (contextId == hpCount) {
EXPECT_EQ(&secondaryEngines.engines[regularContextCount], engine);
}
}
}
}
auto internalEngine = device->getInternalEngine();
EXPECT_NE(internalEngine.commandStreamReceiver, device->getSecondaryEngineCsr({aub_stream::EngineType::ENGINE_CCS, EngineUsage::internal}, false)->commandStreamReceiver);
auto internalEngine = device->getInternalEngine();
EXPECT_NE(internalEngine.commandStreamReceiver, device->getSecondaryEngineCsr({aub_stream::EngineType::ENGINE_CCS, EngineUsage::internal}, false)->commandStreamReceiver);
}
}
HWTEST_F(DeviceTests, givenRootDeviceWithCCSEngineAndContextGroupSizeEnabledWhenDeviceIsCreatedThenSecondaryEnginesAreCreated) {
@@ -1275,7 +1283,7 @@ HWTEST_F(DeviceTests, givenRootDeviceWithCCSEngineAndContextGroupSizeEnabledWhen
hwInfo.featureTable.flags.ftrCCSNode = true;
hwInfo.featureTable.ftrBcsInfo = 0;
hwInfo.capabilityTable.defaultEngineType = aub_stream::ENGINE_CCS;
hwInfo.gtSystemInfo.CCSInfo.NumberOfCCSEnabled = 2;
hwInfo.gtSystemInfo.CCSInfo.NumberOfCCSEnabled = 1;
auto device = std::unique_ptr<MockDevice>(MockDevice::createWithNewExecutionEnvironment<MockDevice>(&hwInfo));
auto &engineGroups = device->getRegularEngineGroups();