Skip to content

Commit b44d8c9

Browse files
fix: Improve context creation for HP Copy Engine in multi-process scenario
Related-To: NEO-12952 Signed-off-by: Slawomir Milczarek <slawomir.milczarek@intel.com>
1 parent 0c7ca82 commit b44d8c9

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed

shared/source/device/device.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,12 @@ bool Device::createEngines() {
421421

422422
auto contextCount = gfxCoreHelper.getContextGroupContextsCount();
423423

424+
if (getRootDeviceEnvironment().osInterface && getRootDeviceEnvironment().osInterface->getAggregatedProcessCount() > 1) {
425+
const auto numProcesses = getRootDeviceEnvironment().osInterface->getAggregatedProcessCount();
426+
427+
contextCount = std::max(contextCount / numProcesses, 2u);
428+
}
429+
424430
createSecondaryContexts(primaryEngine, secondaryEnginesForType, contextCount, 0, contextCount);
425431
}
426432
}

shared/test/unit_test/device/neo_device_tests.cpp

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2468,6 +2468,66 @@ HWTEST_F(DeviceTests, givenHpCopyEngineAndDebugFlagSetWhenCreatingSecondaryEngin
24682468
EXPECT_EQ(device->secondaryEngines.end(), device->secondaryEngines.find(hpEngine));
24692469
}
24702470

2471+
HWTEST_F(DeviceTests, givenHpCopyEngineAndAggregatedProcessCountWhenCreatingSecondaryEnginesThenContextCountIsDividedByProcessCount) {
2472+
HardwareInfo hwInfo = *defaultHwInfo;
2473+
2474+
DebugManagerStateRestore dbgRestorer;
2475+
debugManager.flags.ContextGroupSize.set(64);
2476+
2477+
hwInfo.featureTable.flags.ftrCCSNode = true;
2478+
hwInfo.capabilityTable.defaultEngineType = aub_stream::ENGINE_CCS;
2479+
hwInfo.gtSystemInfo.CCSInfo.NumberOfCCSEnabled = 1;
2480+
hwInfo.capabilityTable.blitterOperationsSupported = true;
2481+
hwInfo.featureTable.ftrBcsInfo = 0b111;
2482+
2483+
// Determine hpEngine type first
2484+
auto executionEnvironment = std::unique_ptr<ExecutionEnvironment>(NEO::MockDevice::prepareExecutionEnvironment(&hwInfo, 0u));
2485+
const auto &gfxCoreHelper = executionEnvironment->rootDeviceEnvironments[0]->getHelper<GfxCoreHelper>();
2486+
auto hpEngine = gfxCoreHelper.getDefaultHpCopyEngine(hwInfo);
2487+
if (hpEngine == aub_stream::EngineType::NUM_ENGINES) {
2488+
GTEST_SKIP();
2489+
}
2490+
2491+
// Test single process scenario first
2492+
{
2493+
auto executionEnvironment = NEO::MockDevice::prepareExecutionEnvironment(&hwInfo, 0u);
2494+
auto device = std::unique_ptr<MockDevice>(MockDevice::createWithExecutionEnvironment<MockDevice>(&hwInfo, executionEnvironment, 0));
2495+
2496+
EXPECT_NE(nullptr, device->getHpCopyEngine());
2497+
2498+
if (device->secondaryEngines.find(hpEngine) != device->secondaryEngines.end()) {
2499+
auto &secondaryEngines = device->secondaryEngines[hpEngine];
2500+
auto expectedContextCount = gfxCoreHelper.getContextGroupContextsCount();
2501+
// Without process division, should have full context group count (64 contexts total)
2502+
EXPECT_EQ(expectedContextCount, secondaryEngines.engines.size());
2503+
}
2504+
}
2505+
2506+
// Test multi-process scenario with process count division
2507+
{
2508+
auto executionEnvironment = NEO::MockDevice::prepareExecutionEnvironment(&hwInfo, 0u);
2509+
auto osInterface = new MockOsInterface();
2510+
auto driverModelMock = std::make_unique<MockDriverModel>();
2511+
osInterface->setDriverModel(std::move(driverModelMock));
2512+
executionEnvironment->rootDeviceEnvironments[0]->osInterface.reset(osInterface);
2513+
2514+
const auto numProcesses = 4u;
2515+
osInterface->numberOfProcesses = numProcesses;
2516+
2517+
auto device = std::unique_ptr<MockDevice>(MockDevice::createWithExecutionEnvironment<MockDevice>(&hwInfo, executionEnvironment, 0));
2518+
2519+
EXPECT_NE(nullptr, device->getHpCopyEngine());
2520+
2521+
if (device->secondaryEngines.find(hpEngine) != device->secondaryEngines.end()) {
2522+
auto &secondaryEngines = device->secondaryEngines[hpEngine];
2523+
2524+
// With process division: max(64/4, 2) = max(16, 2) = 16 contexts total
2525+
const uint32_t expectedContextCount = std::max(gfxCoreHelper.getContextGroupContextsCount() / numProcesses, 2u);
2526+
EXPECT_EQ(expectedContextCount, secondaryEngines.engines.size());
2527+
}
2528+
}
2529+
}
2530+
24712531
TEST_F(DeviceTests, GivenDebuggingEnabledWhenDeviceIsInitializedThenL0DebuggerIsCreated) {
24722532
auto executionEnvironment = MockDevice::prepareExecutionEnvironment(defaultHwInfo.get(), 0u);
24732533
executionEnvironment->setDebuggingMode(NEO::DebuggingMode::online);

0 commit comments

Comments
 (0)