Skip to content

Commit 94be802

Browse files
fix: Check if provided CCS number is correct
Check if `ZEX_NUMBER_OF_CCS` env variable provided by the user is correct. If it isn't then return false and print debug message. Related-To: NEO-15230, GSD-11251 Signed-off-by: Kindracki, Jakub Tomasz <[email protected]>
1 parent b4983f2 commit 94be802

File tree

13 files changed

+175
-27
lines changed

13 files changed

+175
-27
lines changed

shared/source/execution_environment/execution_environment.cpp

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -354,8 +354,10 @@ void ExecutionEnvironment::adjustCcsCountImpl(RootDeviceEnvironment *rootDeviceE
354354
productHelper.adjustNumberOfCcs(*hwInfo);
355355
}
356356

357-
void ExecutionEnvironment::adjustCcsCount() {
358-
parseCcsCountLimitations();
357+
bool ExecutionEnvironment::adjustCcsCount() {
358+
if (!parseCcsCountLimitations()) {
359+
return false;
360+
}
359361

360362
for (auto rootDeviceIndex = 0u; rootDeviceIndex < rootDeviceEnvironments.size(); rootDeviceIndex++) {
361363
auto &rootDeviceEnvironment = rootDeviceEnvironments[rootDeviceIndex];
@@ -364,32 +366,42 @@ void ExecutionEnvironment::adjustCcsCount() {
364366
adjustCcsCountImpl(rootDeviceEnvironment.get());
365367
}
366368
}
369+
370+
return true;
367371
}
368372

369-
void ExecutionEnvironment::adjustCcsCount(const uint32_t rootDeviceIndex) const {
373+
bool ExecutionEnvironment::adjustCcsCount(const uint32_t rootDeviceIndex) const {
370374
auto &rootDeviceEnvironment = rootDeviceEnvironments[rootDeviceIndex];
371375
UNRECOVERABLE_IF(!rootDeviceEnvironment);
372376
if (rootDeviceNumCcsMap.find(rootDeviceIndex) != rootDeviceNumCcsMap.end()) {
373-
rootDeviceEnvironment->setNumberOfCcs(rootDeviceNumCcsMap.at(rootDeviceIndex));
377+
if (!rootDeviceEnvironment->setNumberOfCcs(rootDeviceNumCcsMap.at(rootDeviceIndex))) {
378+
return false;
379+
}
374380
} else {
375381
adjustCcsCountImpl(rootDeviceEnvironment.get());
376382
}
383+
384+
return true;
377385
}
378386

379-
void ExecutionEnvironment::parseCcsCountLimitations() {
387+
bool ExecutionEnvironment::parseCcsCountLimitations() {
380388
const auto &numberOfCcsString = debugManager.flags.ZEX_NUMBER_OF_CCS.get();
381389

382390
if (numberOfCcsString.compare("default") == 0 ||
383391
numberOfCcsString.empty()) {
384-
return;
392+
return true;
385393
}
386394

387395
for (auto rootDeviceIndex = 0u; rootDeviceIndex < rootDeviceEnvironments.size(); rootDeviceIndex++) {
388396
auto &rootDeviceEnvironment = rootDeviceEnvironments[rootDeviceIndex];
389397
UNRECOVERABLE_IF(!rootDeviceEnvironment);
390398
auto &productHelper = rootDeviceEnvironment->getHelper<ProductHelper>();
391-
productHelper.parseCcsMode(numberOfCcsString, rootDeviceNumCcsMap, rootDeviceIndex, rootDeviceEnvironment.get());
399+
if (!productHelper.parseCcsMode(numberOfCcsString, rootDeviceNumCcsMap, rootDeviceIndex, rootDeviceEnvironment.get())) {
400+
return false;
401+
}
392402
}
403+
404+
return true;
393405
}
394406

395407
void ExecutionEnvironment::configureNeoEnvironment() {

shared/source/execution_environment/execution_environment.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ class ExecutionEnvironment : public ReferenceTrackedObject<ExecutionEnvironment>
3737
virtual void prepareRootDeviceEnvironments(uint32_t numRootDevices);
3838
void prepareRootDeviceEnvironment(const uint32_t rootDeviceIndexForReInit);
3939
void parseAffinityMask();
40-
void adjustCcsCount();
41-
void adjustCcsCount(const uint32_t rootDeviceIndex) const;
40+
bool adjustCcsCount();
41+
bool adjustCcsCount(const uint32_t rootDeviceIndex) const;
4242
void sortNeoDevices();
4343
void setDeviceHierarchyMode(const GfxCoreHelper &gfxCoreHelper);
4444
void setDeviceHierarchyMode(const DeviceHierarchyMode deviceHierarchyMode) {
@@ -47,7 +47,7 @@ class ExecutionEnvironment : public ReferenceTrackedObject<ExecutionEnvironment>
4747
DeviceHierarchyMode getDeviceHierarchyMode() const { return deviceHierarchyMode; }
4848
void adjustRootDeviceEnvironments();
4949
void prepareForCleanup() const;
50-
void configureCcsMode();
50+
MOCKABLE_VIRTUAL void configureCcsMode();
5151
void setDebuggingMode(DebuggingMode debuggingMode) {
5252
debuggingEnabledMode = debuggingMode;
5353
}
@@ -97,7 +97,7 @@ class ExecutionEnvironment : public ReferenceTrackedObject<ExecutionEnvironment>
9797

9898
protected:
9999
static bool comparePciIdBusNumber(std::unique_ptr<RootDeviceEnvironment> &rootDeviceEnvironment1, std::unique_ptr<RootDeviceEnvironment> &rootDeviceEnvironment2);
100-
void parseCcsCountLimitations();
100+
bool parseCcsCountLimitations();
101101
void adjustCcsCountImpl(RootDeviceEnvironment *rootDeviceEnvironment) const;
102102
void configureNeoEnvironment();
103103
void restoreCcsMode();

shared/source/execution_environment/root_device_environment.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,12 +246,19 @@ BuiltIns *RootDeviceEnvironment::getBuiltIns() {
246246
return this->builtins.get();
247247
}
248248

249-
void RootDeviceEnvironment::setNumberOfCcs(uint32_t numberOfCcs) {
250-
hwInfo->gtSystemInfo.CCSInfo.NumberOfCCSEnabled = std::min(hwInfo->gtSystemInfo.CCSInfo.NumberOfCCSEnabled, numberOfCcs);
249+
bool RootDeviceEnvironment::setNumberOfCcs(uint32_t numberOfCcs) {
250+
if (hwInfo->gtSystemInfo.CCSInfo.NumberOfCCSEnabled < numberOfCcs || numberOfCcs == 0) {
251+
NEO::printDebugString(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, "Error: Invalid number of CCS: %u. Maximum available number of CCS: %u\n", numberOfCcs, hwInfo->gtSystemInfo.CCSInfo.NumberOfCCSEnabled);
252+
return false;
253+
}
254+
255+
hwInfo->gtSystemInfo.CCSInfo.NumberOfCCSEnabled = numberOfCcs;
251256
limitedNumberOfCcs = true;
252257
if (aubCenter) {
253258
aubCenter->getAubManager()->setCCSMode(hwInfo->gtSystemInfo.CCSInfo.NumberOfCCSEnabled);
254259
}
260+
261+
return true;
255262
}
256263

257264
uint32_t RootDeviceEnvironment::getNumberOfCcs() const {

shared/source/execution_environment/root_device_environment.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ struct RootDeviceEnvironment : NonCopyableClass {
8181
BindlessHeapsHelper *getBindlessHeapsHelper() const;
8282
AssertHandler *getAssertHandler(Device *neoDevice);
8383
void createBindlessHeapsHelper(Device *rootDevice, bool availableDevices);
84-
void setNumberOfCcs(uint32_t numberOfCcs);
84+
bool setNumberOfCcs(uint32_t numberOfCcs);
8585
uint32_t getNumberOfCcs() const;
8686
bool isNumberOfCcsLimited() const;
8787
void setRcsExposure();

shared/source/os_interface/device_factory.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,9 @@ bool DeviceFactory::prepareDeviceEnvironmentsForProductFamilyOverride(ExecutionE
164164

165165
executionEnvironment.setDeviceHierarchyMode(executionEnvironment.rootDeviceEnvironments[0]->getHelper<GfxCoreHelper>());
166166
executionEnvironment.parseAffinityMask();
167-
executionEnvironment.adjustCcsCount();
167+
if (!executionEnvironment.adjustCcsCount()) {
168+
return false;
169+
}
168170
executionEnvironment.calculateMaxOsContextCount();
169171
return true;
170172
}
@@ -272,7 +274,9 @@ bool DeviceFactory::prepareDeviceEnvironments(ExecutionEnvironment &executionEnv
272274
executionEnvironment.sortNeoDevices();
273275
executionEnvironment.parseAffinityMask();
274276
executionEnvironment.adjustRootDeviceEnvironments();
275-
executionEnvironment.adjustCcsCount();
277+
if (!executionEnvironment.adjustCcsCount()) {
278+
return false;
279+
}
276280
executionEnvironment.calculateMaxOsContextCount();
277281

278282
return true;
@@ -294,7 +298,9 @@ bool DeviceFactory::prepareDeviceEnvironment(ExecutionEnvironment &executionEnvi
294298
return false;
295299
}
296300

297-
executionEnvironment.adjustCcsCount(rootDeviceIndex);
301+
if (!executionEnvironment.adjustCcsCount(rootDeviceIndex)) {
302+
return false;
303+
}
298304
return true;
299305
}
300306

shared/source/os_interface/product_helper.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ class ProductHelper {
227227
virtual void fillPipelineSelectPropertiesSupportStructure(PipelineSelectPropertiesSupport &propertiesSupport, const HardwareInfo &hwInfo) const = 0;
228228
virtual void fillStateBaseAddressPropertiesSupportStructure(StateBaseAddressPropertiesSupport &propertiesSupport) const = 0;
229229

230-
virtual void parseCcsMode(std::string ccsModeString, std::unordered_map<uint32_t, uint32_t> &rootDeviceNumCcsMap, uint32_t rootDeviceIndex, RootDeviceEnvironment *rootDeviceEnvironment) const = 0;
230+
virtual bool parseCcsMode(std::string ccsModeString, std::unordered_map<uint32_t, uint32_t> &rootDeviceNumCcsMap, uint32_t rootDeviceIndex, RootDeviceEnvironment *rootDeviceEnvironment) const = 0;
231231

232232
virtual bool isFusedEuDisabledForDpas(bool kernelHasDpasInstructions, const uint32_t *lws, const uint32_t *groupCount, const HardwareInfo &hwInfo) const = 0;
233233
virtual bool isCalculationForDisablingEuFusionWithDpasNeeded(const HardwareInfo &hwInfo) const = 0;

shared/source/os_interface/product_helper.inl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -715,12 +715,16 @@ void ProductHelperHw<gfxProduct>::fillStateBaseAddressPropertiesSupportStructure
715715
}
716716

717717
template <PRODUCT_FAMILY gfxProduct>
718-
void ProductHelperHw<gfxProduct>::parseCcsMode(std::string ccsModeString, std::unordered_map<uint32_t, uint32_t> &rootDeviceNumCcsMap, uint32_t rootDeviceIndex, RootDeviceEnvironment *rootDeviceEnvironment) const {
718+
bool ProductHelperHw<gfxProduct>::parseCcsMode(std::string ccsModeString, std::unordered_map<uint32_t, uint32_t> &rootDeviceNumCcsMap, uint32_t rootDeviceIndex, RootDeviceEnvironment *rootDeviceEnvironment) const {
719719

720720
auto ccsCount = StringHelpers::toUint32t(ccsModeString);
721721

722722
rootDeviceNumCcsMap.insert({rootDeviceIndex, ccsCount});
723-
rootDeviceEnvironment->setNumberOfCcs(ccsCount);
723+
if (!rootDeviceEnvironment->setNumberOfCcs(ccsCount)) {
724+
return false;
725+
}
726+
727+
return true;
724728
}
725729

726730
template <PRODUCT_FAMILY gfxProduct>

shared/source/os_interface/product_helper_hw.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ class ProductHelperHw : public ProductHelper {
165165
void fillFrontEndPropertiesSupportStructure(FrontEndPropertiesSupport &propertiesSupport, const HardwareInfo &hwInfo) const override;
166166
void fillPipelineSelectPropertiesSupportStructure(PipelineSelectPropertiesSupport &propertiesSupport, const HardwareInfo &hwInfo) const override;
167167
void fillStateBaseAddressPropertiesSupportStructure(StateBaseAddressPropertiesSupport &propertiesSupport) const override;
168-
void parseCcsMode(std::string ccsModeString, std::unordered_map<uint32_t, uint32_t> &rootDeviceNumCcsMap, uint32_t rootDeviceIndex, RootDeviceEnvironment *rootDeviceEnvironment) const override;
168+
bool parseCcsMode(std::string ccsModeString, std::unordered_map<uint32_t, uint32_t> &rootDeviceNumCcsMap, uint32_t rootDeviceIndex, RootDeviceEnvironment *rootDeviceEnvironment) const override;
169169

170170
bool isFusedEuDisabledForDpas(bool kernelHasDpasInstructions, const uint32_t *lws, const uint32_t *groupCount, const HardwareInfo &hwInfo) const override;
171171
bool isCalculationForDisablingEuFusionWithDpasNeeded(const HardwareInfo &hwInfo) const override;

shared/source/xe_hpc_core/pvc/os_agnostic_product_helper_pvc.inl

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -153,21 +153,28 @@ bool ProductHelperHw<gfxProduct>::isBlitCopyRequiredForLocalMemory(const RootDev
153153
}
154154

155155
template <>
156-
void ProductHelperHw<gfxProduct>::parseCcsMode(std::string ccsModeString, std::unordered_map<uint32_t, uint32_t> &rootDeviceNumCcsMap, uint32_t rootDeviceIndex, RootDeviceEnvironment *rootDeviceEnvironment) const {
156+
bool ProductHelperHw<gfxProduct>::parseCcsMode(std::string ccsModeString, std::unordered_map<uint32_t, uint32_t> &rootDeviceNumCcsMap, uint32_t rootDeviceIndex, RootDeviceEnvironment *rootDeviceEnvironment) const {
157157
auto numberOfCcsEntries = StringHelpers::split(ccsModeString, ",");
158158

159159
for (const auto &entry : numberOfCcsEntries) {
160160
auto subEntries = StringHelpers::split(entry, ":");
161+
if (subEntries.size() < 2) {
162+
NEO::printDebugString(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, "Error: Invalid ZEX_NUMBER_OF_CCS format '%s'\n", ccsModeString.c_str());
163+
return false;
164+
}
165+
161166
uint32_t rootDeviceIndexParsed = StringHelpers::toUint32t(subEntries[0]);
162167

163168
if (rootDeviceIndexParsed == rootDeviceIndex) {
164-
if (subEntries.size() > 1) {
165-
uint32_t maxCcsCount = StringHelpers::toUint32t(subEntries[1]);
166-
rootDeviceNumCcsMap.insert({rootDeviceIndex, maxCcsCount});
167-
rootDeviceEnvironment->setNumberOfCcs(maxCcsCount);
169+
uint32_t maxCcsCount = StringHelpers::toUint32t(subEntries[1]);
170+
rootDeviceNumCcsMap.insert({rootDeviceIndex, maxCcsCount});
171+
if (!rootDeviceEnvironment->setNumberOfCcs(maxCcsCount)) {
172+
return false;
168173
}
169174
}
170175
}
176+
177+
return true;
171178
}
172179

173180
template <>

shared/test/common/mocks/mock_execution_environment.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,4 +91,8 @@ void MockExecutionEnvironment::initGmm() {
9191
}
9292
}
9393

94+
void MockExecutionEnvironment::addToRootDeviceNumCcsMap(uint32_t rootDeviceIndex, uint32_t numCcs) {
95+
this->rootDeviceNumCcsMap.insert({rootDeviceIndex, numCcs});
96+
}
97+
9498
} // namespace NEO

0 commit comments

Comments
 (0)