From 7f8e9378b6b9248fd4ec13a665e61bfe29c3f3c4 Mon Sep 17 00:00:00 2001 From: Bellekallu Rajkiran Date: Thu, 22 Sep 2022 08:48:55 +0000 Subject: [PATCH] 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 --- .../execution_environment_tests.cpp | 1 + .../execution_environment.cpp | 28 +++++++-- .../execution_environment.h | 8 ++- shared/source/os_interface/device_factory.cpp | 7 ++- .../unit_test/device/neo_device_tests.cpp | 62 ++++++++++++++++++- 5 files changed, 96 insertions(+), 10 deletions(-) diff --git a/opencl/test/unit_test/execution_environment/execution_environment_tests.cpp b/opencl/test/unit_test/execution_environment/execution_environment_tests.cpp index 7c66439c72..906484e4e3 100644 --- a/opencl/test/unit_test/execution_environment/execution_environment_tests.cpp +++ b/opencl/test/unit_test/execution_environment/execution_environment_tests.cpp @@ -199,6 +199,7 @@ static_assert(sizeof(ExecutionEnvironment) == sizeof(std::unique_ptr) + sizeof(std::unique_ptr) + sizeof(std::unique_ptr) + + sizeof(std::unordered_map) + sizeof(bool) + (is64bit ? 23 : 15), "New members detected in ExecutionEnvironment, please ensure that destruction sequence of objects is correct"); diff --git a/shared/source/execution_environment/execution_environment.cpp b/shared/source/execution_environment/execution_environment.cpp index b82e1579e8..046a9a3f31 100644 --- a/shared/source/execution_environment/execution_environment.cpp +++ b/shared/source/execution_environment/execution_environment.cpp @@ -200,20 +200,35 @@ void ExecutionEnvironment::parseAffinityMask() { rootDeviceEnvironments.swap(filteredEnvironments); } -void ExecutionEnvironment::adjustCcsCount() const { +void ExecutionEnvironment::adjustCcsCountImpl(RootDeviceEnvironment *rootDeviceEnvironment) const { + auto hwInfo = rootDeviceEnvironment->getMutableHardwareInfo(); + auto hwInfoConfig = HwInfoConfig::get(hwInfo->platform.eProductFamily); + hwInfoConfig->adjustNumberOfCcs(*hwInfo); +} + +void ExecutionEnvironment::adjustCcsCount() { parseCcsCountLimitations(); - for (auto &rootDeviceEnvironment : rootDeviceEnvironments) { + for (auto rootDeviceIndex = 0u; rootDeviceIndex < rootDeviceEnvironments.size(); rootDeviceIndex++) { + auto &rootDeviceEnvironment = rootDeviceEnvironments[rootDeviceIndex]; UNRECOVERABLE_IF(!rootDeviceEnvironment); if (!rootDeviceEnvironment->isNumberOfCcsLimited()) { - auto hwInfo = rootDeviceEnvironment->getMutableHardwareInfo(); - auto hwInfoConfig = HwInfoConfig::get(hwInfo->platform.eProductFamily); - hwInfoConfig->adjustNumberOfCcs(*hwInfo); + adjustCcsCountImpl(rootDeviceEnvironment.get()); } } } -void ExecutionEnvironment::parseCcsCountLimitations() const { +void ExecutionEnvironment::adjustCcsCount(const uint32_t rootDeviceIndex) const { + auto &rootDeviceEnvironment = rootDeviceEnvironments[rootDeviceIndex]; + UNRECOVERABLE_IF(!rootDeviceEnvironment); + if (rootDeviceNumCcsMap.find(rootDeviceIndex) != rootDeviceNumCcsMap.end()) { + rootDeviceEnvironment->limitNumberOfCcs(rootDeviceNumCcsMap.at(rootDeviceIndex)); + } else { + adjustCcsCountImpl(rootDeviceEnvironment.get()); + } +} + +void ExecutionEnvironment::parseCcsCountLimitations() { const auto &numberOfCcsString = DebugManager.flags.ZEX_NUMBER_OF_CCS.get(); if (numberOfCcsString.compare("default") == 0 || @@ -232,6 +247,7 @@ void ExecutionEnvironment::parseCcsCountLimitations() const { if (rootDeviceIndex < numRootDevices) { if (subEntries.size() > 1) { uint32_t maxCcsCount = StringHelpers::toUint32t(subEntries[1]); + rootDeviceNumCcsMap.insert({rootDeviceIndex, maxCcsCount}); rootDeviceEnvironments[rootDeviceIndex]->limitNumberOfCcs(maxCcsCount); } } diff --git a/shared/source/execution_environment/execution_environment.h b/shared/source/execution_environment/execution_environment.h index 7595b9f379..9a7966c26f 100644 --- a/shared/source/execution_environment/execution_environment.h +++ b/shared/source/execution_environment/execution_environment.h @@ -8,6 +8,7 @@ #pragma once #include "shared/source/utilities/reference_tracked_object.h" +#include #include namespace NEO { @@ -27,7 +28,8 @@ class ExecutionEnvironment : public ReferenceTrackedObject virtual void prepareRootDeviceEnvironments(uint32_t numRootDevices); void prepareRootDeviceEnvironment(const uint32_t rootDeviceIndexForReInit); void parseAffinityMask(); - void adjustCcsCount() const; + void adjustCcsCount(); + void adjustCcsCount(const uint32_t rootDeviceIndex) const; void sortNeoDevices(); void sortNeoDevicesDRM(); void sortNeoDevicesWDDM(); @@ -45,7 +47,9 @@ class ExecutionEnvironment : public ReferenceTrackedObject void releaseRootDeviceEnvironmentResources(RootDeviceEnvironment *rootDeviceEnvironment); protected: - void parseCcsCountLimitations() const; + void parseCcsCountLimitations(); + void adjustCcsCountImpl(RootDeviceEnvironment *rootDeviceEnvironment) const; bool debuggingEnabled = false; + std::unordered_map rootDeviceNumCcsMap; }; } // namespace NEO diff --git a/shared/source/os_interface/device_factory.cpp b/shared/source/os_interface/device_factory.cpp index 519ccedcf9..6ebc8a3e18 100644 --- a/shared/source/os_interface/device_factory.cpp +++ b/shared/source/os_interface/device_factory.cpp @@ -176,7 +176,12 @@ bool DeviceFactory::prepareDeviceEnvironment(ExecutionEnvironment &executionEnvi // HwDeviceIds should contain only one entry corresponding to osPciPath UNRECOVERABLE_IF(hwDeviceIds.size() > 1); - return initHwDeviceIdResources(executionEnvironment, std::move(hwDeviceIds[0]), rootDeviceIndex); + if (!initHwDeviceIdResources(executionEnvironment, std::move(hwDeviceIds[0]), rootDeviceIndex)) { + return false; + } + + executionEnvironment.adjustCcsCount(rootDeviceIndex); + return true; } std::unique_ptr DeviceFactory::createDevice(ExecutionEnvironment &executionEnvironment, std::string &osPciPath, const uint32_t rootDeviceIndex) { diff --git a/shared/test/unit_test/device/neo_device_tests.cpp b/shared/test/unit_test/device/neo_device_tests.cpp index a5acc325a8..5dfac841a9 100644 --- a/shared/test/unit_test/device/neo_device_tests.cpp +++ b/shared/test/unit_test/device/neo_device_tests.cpp @@ -430,7 +430,6 @@ HWCMDTEST_F(IGFX_XE_HP_CORE, DeviceTests, givenZexNumberOfCssEnvVariableDefinedW MockExecutionEnvironment executionEnvironment(&hwInfo, false, 4); executionEnvironment.incRefInternal(); - UltDeviceFactory deviceFactory{4, 0, executionEnvironment}; { @@ -465,6 +464,67 @@ HWCMDTEST_F(IGFX_XE_HP_CORE, DeviceTests, givenZexNumberOfCssEnvVariableDefinedW } } +HWCMDTEST_F(IGFX_XE_HP_CORE, DeviceTests, givenDeviceIsCreatedWithZexNumberOfCssEnvVariableDefinedAndHwInfoCcsCountIsSetToDefaultWhenAdjustCcsCountForSpecificRootDeviceIsInvokedThenVerifyHwInfoCcsCountIsRestored) { + VariableBackup backup(&ultHwConfig); + ultHwConfig.useMockedPrepareDeviceEnvironmentsFunc = false; + DebugManagerStateRestore restorer; + + DebugManager.flags.ZEX_NUMBER_OF_CCS.set("0:1,1:2"); + DebugManager.flags.SetCommandStreamReceiver.set(1); + + auto hwInfo = *defaultHwInfo; + + MockExecutionEnvironment executionEnvironment(&hwInfo, false, 2); + executionEnvironment.incRefInternal(); + + UltDeviceFactory deviceFactory{1, 0, executionEnvironment}; + { + auto hardwareInfo = executionEnvironment.rootDeviceEnvironments[0]->getMutableHardwareInfo(); + hardwareInfo->gtSystemInfo.CCSInfo.NumberOfCCSEnabled = defaultHwInfo->gtSystemInfo.CCSInfo.NumberOfCCSEnabled; + + executionEnvironment.adjustCcsCount(0); + EXPECT_EQ(1u, hardwareInfo->gtSystemInfo.CCSInfo.NumberOfCCSEnabled); + } + + { + auto hardwareInfo = executionEnvironment.rootDeviceEnvironments[1]->getMutableHardwareInfo(); + hardwareInfo->gtSystemInfo.CCSInfo.NumberOfCCSEnabled = defaultHwInfo->gtSystemInfo.CCSInfo.NumberOfCCSEnabled; + + executionEnvironment.adjustCcsCount(1); + EXPECT_EQ(std::min(2u, defaultHwInfo->gtSystemInfo.CCSInfo.NumberOfCCSEnabled), hardwareInfo->gtSystemInfo.CCSInfo.NumberOfCCSEnabled); + } +} + +HWTEST2_F(DeviceTests, givenDeviceIsCreatedWithAmbiguousZexNumberOfCssEnvVariableAndHwInfoCcsCountIsModifiedWhenAdjustCcsCountForSpecificDeviceIsInvokedThenVerifyCcsCountIsAdjustedToOne, IsPVC) { + VariableBackup backup(&ultHwConfig); + ultHwConfig.useMockedPrepareDeviceEnvironmentsFunc = false; + DebugManagerStateRestore restorer; + DebugManager.flags.SetCommandStreamReceiver.set(1); + + for (const auto &numberOfCcsString : {"default", "", "0"}) { + DebugManager.flags.ZEX_NUMBER_OF_CCS.set(numberOfCcsString); + + auto hwInfo = *defaultHwInfo; + + MockExecutionEnvironment executionEnvironment(&hwInfo); + executionEnvironment.incRefInternal(); + + UltDeviceFactory deviceFactory{1, 0, executionEnvironment}; + + auto device = deviceFactory.rootDevices[0]; + + auto computeEngineGroupIndex = device->getEngineGroupIndexFromEngineGroupType(EngineGroupType::Compute); + auto computeEngineGroup = device->getRegularEngineGroups()[computeEngineGroupIndex]; + EXPECT_EQ(1u, computeEngineGroup.engines.size()); + + auto hardwareInfo = executionEnvironment.rootDeviceEnvironments[0]->getMutableHardwareInfo(); + hardwareInfo->gtSystemInfo.CCSInfo.NumberOfCCSEnabled = defaultHwInfo->gtSystemInfo.CCSInfo.NumberOfCCSEnabled; + + executionEnvironment.adjustCcsCount(0); + EXPECT_EQ(1u, hardwareInfo->gtSystemInfo.CCSInfo.NumberOfCCSEnabled); + } +} + HWCMDTEST_F(IGFX_XE_HP_CORE, DeviceTests, givenZexNumberOfCssAndZeAffinityMaskSetWhenDeviceIsCreatedThenProperNumberOfCcsIsExposed) { VariableBackup backup(&ultHwConfig); ultHwConfig.useMockedPrepareDeviceEnvironmentsFunc = false;