Skip to content

Commit 7f8e937

Browse files
Adjust ccs on reinit
Parse and adjust ccs count on reset so that initial environment is restored. Related-To: LOCI-3435 Signed-off-by: Bellekallu Rajkiran <bellekallu.rajkiran@intel.com>
1 parent a95ab1d commit 7f8e937

File tree

5 files changed

+96
-10
lines changed

5 files changed

+96
-10
lines changed

opencl/test/unit_test/execution_environment/execution_environment_tests.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ static_assert(sizeof(ExecutionEnvironment) == sizeof(std::unique_ptr<HardwareInf
199199
sizeof(std::vector<RootDeviceEnvironment>) +
200200
sizeof(std::unique_ptr<OsEnvironment>) +
201201
sizeof(std::unique_ptr<DirectSubmissionController>) +
202+
sizeof(std::unordered_map<uint32_t, uint32_t>) +
202203
sizeof(bool) +
203204
(is64bit ? 23 : 15),
204205
"New members detected in ExecutionEnvironment, please ensure that destruction sequence of objects is correct");

shared/source/execution_environment/execution_environment.cpp

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -200,20 +200,35 @@ void ExecutionEnvironment::parseAffinityMask() {
200200
rootDeviceEnvironments.swap(filteredEnvironments);
201201
}
202202

203-
void ExecutionEnvironment::adjustCcsCount() const {
203+
void ExecutionEnvironment::adjustCcsCountImpl(RootDeviceEnvironment *rootDeviceEnvironment) const {
204+
auto hwInfo = rootDeviceEnvironment->getMutableHardwareInfo();
205+
auto hwInfoConfig = HwInfoConfig::get(hwInfo->platform.eProductFamily);
206+
hwInfoConfig->adjustNumberOfCcs(*hwInfo);
207+
}
208+
209+
void ExecutionEnvironment::adjustCcsCount() {
204210
parseCcsCountLimitations();
205211

206-
for (auto &rootDeviceEnvironment : rootDeviceEnvironments) {
212+
for (auto rootDeviceIndex = 0u; rootDeviceIndex < rootDeviceEnvironments.size(); rootDeviceIndex++) {
213+
auto &rootDeviceEnvironment = rootDeviceEnvironments[rootDeviceIndex];
207214
UNRECOVERABLE_IF(!rootDeviceEnvironment);
208215
if (!rootDeviceEnvironment->isNumberOfCcsLimited()) {
209-
auto hwInfo = rootDeviceEnvironment->getMutableHardwareInfo();
210-
auto hwInfoConfig = HwInfoConfig::get(hwInfo->platform.eProductFamily);
211-
hwInfoConfig->adjustNumberOfCcs(*hwInfo);
216+
adjustCcsCountImpl(rootDeviceEnvironment.get());
212217
}
213218
}
214219
}
215220

216-
void ExecutionEnvironment::parseCcsCountLimitations() const {
221+
void ExecutionEnvironment::adjustCcsCount(const uint32_t rootDeviceIndex) const {
222+
auto &rootDeviceEnvironment = rootDeviceEnvironments[rootDeviceIndex];
223+
UNRECOVERABLE_IF(!rootDeviceEnvironment);
224+
if (rootDeviceNumCcsMap.find(rootDeviceIndex) != rootDeviceNumCcsMap.end()) {
225+
rootDeviceEnvironment->limitNumberOfCcs(rootDeviceNumCcsMap.at(rootDeviceIndex));
226+
} else {
227+
adjustCcsCountImpl(rootDeviceEnvironment.get());
228+
}
229+
}
230+
231+
void ExecutionEnvironment::parseCcsCountLimitations() {
217232
const auto &numberOfCcsString = DebugManager.flags.ZEX_NUMBER_OF_CCS.get();
218233

219234
if (numberOfCcsString.compare("default") == 0 ||
@@ -232,6 +247,7 @@ void ExecutionEnvironment::parseCcsCountLimitations() const {
232247
if (rootDeviceIndex < numRootDevices) {
233248
if (subEntries.size() > 1) {
234249
uint32_t maxCcsCount = StringHelpers::toUint32t(subEntries[1]);
250+
rootDeviceNumCcsMap.insert({rootDeviceIndex, maxCcsCount});
235251
rootDeviceEnvironments[rootDeviceIndex]->limitNumberOfCcs(maxCcsCount);
236252
}
237253
}

shared/source/execution_environment/execution_environment.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#pragma once
99
#include "shared/source/utilities/reference_tracked_object.h"
1010

11+
#include <unordered_map>
1112
#include <vector>
1213

1314
namespace NEO {
@@ -27,7 +28,8 @@ class ExecutionEnvironment : public ReferenceTrackedObject<ExecutionEnvironment>
2728
virtual void prepareRootDeviceEnvironments(uint32_t numRootDevices);
2829
void prepareRootDeviceEnvironment(const uint32_t rootDeviceIndexForReInit);
2930
void parseAffinityMask();
30-
void adjustCcsCount() const;
31+
void adjustCcsCount();
32+
void adjustCcsCount(const uint32_t rootDeviceIndex) const;
3133
void sortNeoDevices();
3234
void sortNeoDevicesDRM();
3335
void sortNeoDevicesWDDM();
@@ -45,7 +47,9 @@ class ExecutionEnvironment : public ReferenceTrackedObject<ExecutionEnvironment>
4547
void releaseRootDeviceEnvironmentResources(RootDeviceEnvironment *rootDeviceEnvironment);
4648

4749
protected:
48-
void parseCcsCountLimitations() const;
50+
void parseCcsCountLimitations();
51+
void adjustCcsCountImpl(RootDeviceEnvironment *rootDeviceEnvironment) const;
4952
bool debuggingEnabled = false;
53+
std::unordered_map<uint32_t, uint32_t> rootDeviceNumCcsMap;
5054
};
5155
} // namespace NEO

shared/source/os_interface/device_factory.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,12 @@ bool DeviceFactory::prepareDeviceEnvironment(ExecutionEnvironment &executionEnvi
176176

177177
// HwDeviceIds should contain only one entry corresponding to osPciPath
178178
UNRECOVERABLE_IF(hwDeviceIds.size() > 1);
179-
return initHwDeviceIdResources(executionEnvironment, std::move(hwDeviceIds[0]), rootDeviceIndex);
179+
if (!initHwDeviceIdResources(executionEnvironment, std::move(hwDeviceIds[0]), rootDeviceIndex)) {
180+
return false;
181+
}
182+
183+
executionEnvironment.adjustCcsCount(rootDeviceIndex);
184+
return true;
180185
}
181186

182187
std::unique_ptr<Device> DeviceFactory::createDevice(ExecutionEnvironment &executionEnvironment, std::string &osPciPath, const uint32_t rootDeviceIndex) {

shared/test/unit_test/device/neo_device_tests.cpp

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,6 @@ HWCMDTEST_F(IGFX_XE_HP_CORE, DeviceTests, givenZexNumberOfCssEnvVariableDefinedW
430430

431431
MockExecutionEnvironment executionEnvironment(&hwInfo, false, 4);
432432
executionEnvironment.incRefInternal();
433-
434433
UltDeviceFactory deviceFactory{4, 0, executionEnvironment};
435434

436435
{
@@ -465,6 +464,67 @@ HWCMDTEST_F(IGFX_XE_HP_CORE, DeviceTests, givenZexNumberOfCssEnvVariableDefinedW
465464
}
466465
}
467466

467+
HWCMDTEST_F(IGFX_XE_HP_CORE, DeviceTests, givenDeviceIsCreatedWithZexNumberOfCssEnvVariableDefinedAndHwInfoCcsCountIsSetToDefaultWhenAdjustCcsCountForSpecificRootDeviceIsInvokedThenVerifyHwInfoCcsCountIsRestored) {
468+
VariableBackup<UltHwConfig> backup(&ultHwConfig);
469+
ultHwConfig.useMockedPrepareDeviceEnvironmentsFunc = false;
470+
DebugManagerStateRestore restorer;
471+
472+
DebugManager.flags.ZEX_NUMBER_OF_CCS.set("0:1,1:2");
473+
DebugManager.flags.SetCommandStreamReceiver.set(1);
474+
475+
auto hwInfo = *defaultHwInfo;
476+
477+
MockExecutionEnvironment executionEnvironment(&hwInfo, false, 2);
478+
executionEnvironment.incRefInternal();
479+
480+
UltDeviceFactory deviceFactory{1, 0, executionEnvironment};
481+
{
482+
auto hardwareInfo = executionEnvironment.rootDeviceEnvironments[0]->getMutableHardwareInfo();
483+
hardwareInfo->gtSystemInfo.CCSInfo.NumberOfCCSEnabled = defaultHwInfo->gtSystemInfo.CCSInfo.NumberOfCCSEnabled;
484+
485+
executionEnvironment.adjustCcsCount(0);
486+
EXPECT_EQ(1u, hardwareInfo->gtSystemInfo.CCSInfo.NumberOfCCSEnabled);
487+
}
488+
489+
{
490+
auto hardwareInfo = executionEnvironment.rootDeviceEnvironments[1]->getMutableHardwareInfo();
491+
hardwareInfo->gtSystemInfo.CCSInfo.NumberOfCCSEnabled = defaultHwInfo->gtSystemInfo.CCSInfo.NumberOfCCSEnabled;
492+
493+
executionEnvironment.adjustCcsCount(1);
494+
EXPECT_EQ(std::min(2u, defaultHwInfo->gtSystemInfo.CCSInfo.NumberOfCCSEnabled), hardwareInfo->gtSystemInfo.CCSInfo.NumberOfCCSEnabled);
495+
}
496+
}
497+
498+
HWTEST2_F(DeviceTests, givenDeviceIsCreatedWithAmbiguousZexNumberOfCssEnvVariableAndHwInfoCcsCountIsModifiedWhenAdjustCcsCountForSpecificDeviceIsInvokedThenVerifyCcsCountIsAdjustedToOne, IsPVC) {
499+
VariableBackup<UltHwConfig> backup(&ultHwConfig);
500+
ultHwConfig.useMockedPrepareDeviceEnvironmentsFunc = false;
501+
DebugManagerStateRestore restorer;
502+
DebugManager.flags.SetCommandStreamReceiver.set(1);
503+
504+
for (const auto &numberOfCcsString : {"default", "", "0"}) {
505+
DebugManager.flags.ZEX_NUMBER_OF_CCS.set(numberOfCcsString);
506+
507+
auto hwInfo = *defaultHwInfo;
508+
509+
MockExecutionEnvironment executionEnvironment(&hwInfo);
510+
executionEnvironment.incRefInternal();
511+
512+
UltDeviceFactory deviceFactory{1, 0, executionEnvironment};
513+
514+
auto device = deviceFactory.rootDevices[0];
515+
516+
auto computeEngineGroupIndex = device->getEngineGroupIndexFromEngineGroupType(EngineGroupType::Compute);
517+
auto computeEngineGroup = device->getRegularEngineGroups()[computeEngineGroupIndex];
518+
EXPECT_EQ(1u, computeEngineGroup.engines.size());
519+
520+
auto hardwareInfo = executionEnvironment.rootDeviceEnvironments[0]->getMutableHardwareInfo();
521+
hardwareInfo->gtSystemInfo.CCSInfo.NumberOfCCSEnabled = defaultHwInfo->gtSystemInfo.CCSInfo.NumberOfCCSEnabled;
522+
523+
executionEnvironment.adjustCcsCount(0);
524+
EXPECT_EQ(1u, hardwareInfo->gtSystemInfo.CCSInfo.NumberOfCCSEnabled);
525+
}
526+
}
527+
468528
HWCMDTEST_F(IGFX_XE_HP_CORE, DeviceTests, givenZexNumberOfCssAndZeAffinityMaskSetWhenDeviceIsCreatedThenProperNumberOfCcsIsExposed) {
469529
VariableBackup<UltHwConfig> backup(&ultHwConfig);
470530
ultHwConfig.useMockedPrepareDeviceEnvironmentsFunc = false;

0 commit comments

Comments
 (0)