diff --git a/shared/source/debug_settings/release_variables.inl b/shared/source/debug_settings/release_variables.inl index 00ea573d91..8936a86844 100644 --- a/shared/source/debug_settings/release_variables.inl +++ b/shared/source/debug_settings/release_variables.inl @@ -12,4 +12,5 @@ DECLARE_DEBUG_VARIABLE(bool, MakeAllBuffersResident, false, "Make all buffers resident after creation") DECLARE_DEBUG_VARIABLE(int32_t, OverrideDefaultFP64Settings, -1, "-1: dont override, 0: disable, 1: enable.") DECLARE_DEBUG_VARIABLE(std::string, ZE_AFFINITY_MASK, std::string("default"), "Refer to the Level Zero Specification for a description") +DECLARE_DEBUG_VARIABLE(std::string, ZEX_NUMBER_OF_CCS, std::string("default"), "Define number of CCS engines per root device, e.g. setting Root Device Index 0 to 4 CCS, and Root Device Index 1 To 1 CCS: ZEX_NUMBER_OF_CCS=0:4,1:1") DECLARE_DEBUG_VARIABLE(bool, ZE_ENABLE_PCI_ID_DEVICE_ORDER, true, "Refer to the Level Zero Specification for a description") diff --git a/shared/source/execution_environment/execution_environment.cpp b/shared/source/execution_environment/execution_environment.cpp index e5371a969a..b82e1579e8 100644 --- a/shared/source/execution_environment/execution_environment.cpp +++ b/shared/source/execution_environment/execution_environment.cpp @@ -199,4 +199,42 @@ void ExecutionEnvironment::parseAffinityMask() { rootDeviceEnvironments.swap(filteredEnvironments); } + +void ExecutionEnvironment::adjustCcsCount() const { + parseCcsCountLimitations(); + + for (auto &rootDeviceEnvironment : rootDeviceEnvironments) { + UNRECOVERABLE_IF(!rootDeviceEnvironment); + if (!rootDeviceEnvironment->isNumberOfCcsLimited()) { + auto hwInfo = rootDeviceEnvironment->getMutableHardwareInfo(); + auto hwInfoConfig = HwInfoConfig::get(hwInfo->platform.eProductFamily); + hwInfoConfig->adjustNumberOfCcs(*hwInfo); + } + } +} + +void ExecutionEnvironment::parseCcsCountLimitations() const { + const auto &numberOfCcsString = DebugManager.flags.ZEX_NUMBER_OF_CCS.get(); + + if (numberOfCcsString.compare("default") == 0 || + numberOfCcsString.empty()) { + return; + } + + const uint32_t numRootDevices = static_cast(rootDeviceEnvironments.size()); + + auto numberOfCcsEntries = StringHelpers::split(numberOfCcsString, ","); + + for (const auto &entry : numberOfCcsEntries) { + auto subEntries = StringHelpers::split(entry, ":"); + uint32_t rootDeviceIndex = StringHelpers::toUint32t(subEntries[0]); + + if (rootDeviceIndex < numRootDevices) { + if (subEntries.size() > 1) { + uint32_t maxCcsCount = StringHelpers::toUint32t(subEntries[1]); + rootDeviceEnvironments[rootDeviceIndex]->limitNumberOfCcs(maxCcsCount); + } + } + } +} } // namespace NEO diff --git a/shared/source/execution_environment/execution_environment.h b/shared/source/execution_environment/execution_environment.h index 0284e34177..7595b9f379 100644 --- a/shared/source/execution_environment/execution_environment.h +++ b/shared/source/execution_environment/execution_environment.h @@ -27,6 +27,7 @@ class ExecutionEnvironment : public ReferenceTrackedObject virtual void prepareRootDeviceEnvironments(uint32_t numRootDevices); void prepareRootDeviceEnvironment(const uint32_t rootDeviceIndexForReInit); void parseAffinityMask(); + void adjustCcsCount() const; void sortNeoDevices(); void sortNeoDevicesDRM(); void sortNeoDevicesWDDM(); @@ -44,6 +45,7 @@ class ExecutionEnvironment : public ReferenceTrackedObject void releaseRootDeviceEnvironmentResources(RootDeviceEnvironment *rootDeviceEnvironment); protected: + void parseCcsCountLimitations() const; bool debuggingEnabled = false; }; } // namespace NEO diff --git a/shared/source/execution_environment/root_device_environment.cpp b/shared/source/execution_environment/root_device_environment.cpp index 8d6214cd39..8e5c3b9dc1 100644 --- a/shared/source/execution_environment/root_device_environment.cpp +++ b/shared/source/execution_environment/root_device_environment.cpp @@ -147,4 +147,14 @@ BuiltIns *RootDeviceEnvironment::getBuiltIns() { } return this->builtins.get(); } + +void RootDeviceEnvironment::limitNumberOfCcs(uint32_t numberOfCcs) { + + hwInfo->gtSystemInfo.CCSInfo.NumberOfCCSEnabled = std::min(hwInfo->gtSystemInfo.CCSInfo.NumberOfCCSEnabled, numberOfCcs); + limitedNumberOfCcs = true; +} + +bool RootDeviceEnvironment::isNumberOfCcsLimited() const { + return limitedNumberOfCcs; +} } // namespace NEO diff --git a/shared/source/execution_environment/root_device_environment.h b/shared/source/execution_environment/root_device_environment.h index 12af66f1a8..3992894a64 100644 --- a/shared/source/execution_environment/root_device_environment.h +++ b/shared/source/execution_environment/root_device_environment.h @@ -64,6 +64,8 @@ struct RootDeviceEnvironment { BuiltIns *getBuiltIns(); BindlessHeapsHelper *getBindlessHeapsHelper() const; void createBindlessHeapsHelper(MemoryManager *memoryManager, bool availableDevices, uint32_t rootDeviceIndex, DeviceBitfield deviceBitfield); + void limitNumberOfCcs(uint32_t numberOfCcs); + bool isNumberOfCcsLimited() const; std::unique_ptr sipKernels[static_cast(SipKernelType::COUNT)]; std::unique_ptr gmmHelper; @@ -81,6 +83,9 @@ struct RootDeviceEnvironment { AffinityMaskHelper deviceAffinityMask{true}; + protected: + bool limitedNumberOfCcs = false; + private: std::mutex mtx; }; diff --git a/shared/source/os_interface/device_factory.cpp b/shared/source/os_interface/device_factory.cpp index 43f052a0fe..db7b8e4c54 100644 --- a/shared/source/os_interface/device_factory.cpp +++ b/shared/source/os_interface/device_factory.cpp @@ -99,6 +99,7 @@ bool DeviceFactory::prepareDeviceEnvironmentsForProductFamilyOverride(ExecutionE } executionEnvironment.parseAffinityMask(); + executionEnvironment.adjustCcsCount(); executionEnvironment.calculateMaxOsContextCount(); return true; } @@ -158,6 +159,7 @@ bool DeviceFactory::prepareDeviceEnvironments(ExecutionEnvironment &executionEnv executionEnvironment.sortNeoDevices(); executionEnvironment.parseAffinityMask(); + executionEnvironment.adjustCcsCount(); executionEnvironment.calculateMaxOsContextCount(); return true; diff --git a/shared/source/os_interface/hw_info_config.h b/shared/source/os_interface/hw_info_config.h index fffcf558e3..a9bea81957 100644 --- a/shared/source/os_interface/hw_info_config.h +++ b/shared/source/os_interface/hw_info_config.h @@ -132,6 +132,7 @@ class HwInfoConfig { virtual bool isAssignEngineRoundRobinSupported() const = 0; virtual uint32_t getL1CachePolicy() const = 0; virtual bool isEvictionWhenNecessaryFlagSupported() const = 0; + virtual void adjustNumberOfCcs(HardwareInfo &hwInfo) const = 0; MOCKABLE_VIRTUAL ~HwInfoConfig() = default; @@ -234,6 +235,7 @@ class HwInfoConfigHw : public HwInfoConfig { bool isAssignEngineRoundRobinSupported() const override; uint32_t getL1CachePolicy() const override; bool isEvictionWhenNecessaryFlagSupported() const override; + void adjustNumberOfCcs(HardwareInfo &hwInfo) const override; protected: HwInfoConfigHw() = default; diff --git a/shared/source/os_interface/hw_info_config.inl b/shared/source/os_interface/hw_info_config.inl index 7bea59134a..a7f797d317 100644 --- a/shared/source/os_interface/hw_info_config.inl +++ b/shared/source/os_interface/hw_info_config.inl @@ -480,4 +480,6 @@ uint32_t HwInfoConfigHw::getL1CachePolicy() const { return L1CachePolicyHelper::getL1CachePolicy(); } +template +void HwInfoConfigHw::adjustNumberOfCcs(HardwareInfo &hwInfo) const {} } // namespace NEO diff --git a/shared/source/xe_hpc_core/pvc/os_agnostic_hw_info_config_pvc.inl b/shared/source/xe_hpc_core/pvc/os_agnostic_hw_info_config_pvc.inl index 5dfb53dd5a..f391956ca7 100644 --- a/shared/source/xe_hpc_core/pvc/os_agnostic_hw_info_config_pvc.inl +++ b/shared/source/xe_hpc_core/pvc/os_agnostic_hw_info_config_pvc.inl @@ -193,4 +193,9 @@ bool HwInfoConfigHw::isComputeDispatchAllWalkerEnableInCfeStateRequi template <> bool HwInfoConfigHw::isIpSamplingSupported(const HardwareInfo &hwInfo) const { return PVC::isXt(hwInfo); +} + +template <> +void HwInfoConfigHw::adjustNumberOfCcs(HardwareInfo &hwInfo) const { + hwInfo.gtSystemInfo.CCSInfo.NumberOfCCSEnabled = 1; } \ No newline at end of file diff --git a/shared/test/common/test_files/igdrcl.config b/shared/test/common/test_files/igdrcl.config index 06f1664b23..8df12cde56 100644 --- a/shared/test/common/test_files/igdrcl.config +++ b/shared/test/common/test_files/igdrcl.config @@ -10,6 +10,7 @@ AUBDumpToggleFileName = unk OverrideGdiPath = unk AubDumpAddMmioRegistersList = unk ZE_AFFINITY_MASK = default +ZEX_NUMBER_OF_CCS = default ZE_ENABLE_PCI_ID_DEVICE_ORDER = 1 AUBDumpFilterNamedKernelStartIdx = 0 AUBDumpFilterNamedKernelEndIdx = -1 @@ -443,4 +444,4 @@ EnableBcsSwControlWa = -1 ExperimentalEnableL0DebuggerForOpenCL = 0 DebuggerDisableSingleAddressSbaTracking = 0 ForceImagesSupport = -1 -ForceCsrLockInBcsEnqueueOnlyForGpgpuSubmission = -1 \ No newline at end of file +ForceCsrLockInBcsEnqueueOnlyForGpgpuSubmission = -1 diff --git a/shared/test/unit_test/device/neo_device_tests.cpp b/shared/test/unit_test/device/neo_device_tests.cpp index 3db808ab9c..9075a3ddcc 100644 --- a/shared/test/unit_test/device/neo_device_tests.cpp +++ b/shared/test/unit_test/device/neo_device_tests.cpp @@ -6,9 +6,11 @@ */ #include "shared/source/device/device.h" +#include "shared/source/os_interface/device_factory.h" #include "shared/test/common/fixtures/device_fixture.h" #include "shared/test/common/helpers/debug_manager_state_restore.h" #include "shared/test/common/helpers/default_hw_info.h" +#include "shared/test/common/helpers/ult_hw_config.h" #include "shared/test/common/helpers/variable_backup.h" #include "shared/test/common/mocks/mock_builtins.h" #include "shared/test/common/mocks/mock_compiler_interface.h" @@ -16,6 +18,7 @@ #include "shared/test/common/mocks/mock_device.h" #include "shared/test/common/mocks/mock_memory_manager.h" #include "shared/test/common/mocks/ult_device_factory.h" +#include "shared/test/common/test_macros/hw_test.h" #include "shared/test/common/test_macros/test.h" using namespace NEO; @@ -384,7 +387,9 @@ TEST_F(DeviceGetCapsTest, givenFlagEnabled64kbPagesWhenCallConstructorMemoryMana EXPECT_TRUE(memoryManager->peek64kbPagesEnabled(0u)); } -TEST_F(DeviceTest, givenDispatchGlobalsAllocationFailsOnSecondSubDeviceThenRtDispatchGlobalsInfoIsNull) { +using DeviceTests = ::testing::Test; + +TEST_F(DeviceTests, givenDispatchGlobalsAllocationFailsOnSecondSubDeviceThenRtDispatchGlobalsInfoIsNull) { class FailMockMemoryManager : public MockMemoryManager { public: FailMockMemoryManager(NEO::ExecutionEnvironment &executionEnvironment) : MockMemoryManager(false, false, executionEnvironment) {} @@ -412,3 +417,122 @@ TEST_F(DeviceTest, givenDispatchGlobalsAllocationFailsOnSecondSubDeviceThenRtDis EXPECT_EQ(nullptr, rtDispatchGlobalsInfo); } + +HWCMDTEST_F(IGFX_XE_HP_CORE, DeviceTests, givenZexNumberOfCssEnvVariableDefinedWhenDeviceIsCreatedThenCreateDevicesWithProperCcsCount) { + VariableBackup backup(&ultHwConfig); + ultHwConfig.useMockedPrepareDeviceEnvironmentsFunc = false; + DebugManagerStateRestore restorer; + + DebugManager.flags.ZEX_NUMBER_OF_CCS.set("0:4,1:1,2:2,3:1"); + DebugManager.flags.SetCommandStreamReceiver.set(1); + + auto hwInfo = *defaultHwInfo; + + MockExecutionEnvironment executionEnvironment(&hwInfo, false, 4); + executionEnvironment.incRefInternal(); + + UltDeviceFactory deviceFactory{4, 0, executionEnvironment}; + + { + auto device = deviceFactory.rootDevices[0]; + + auto computeEngineGroupIndex = device->getEngineGroupIndexFromEngineGroupType(EngineGroupType::Compute); + auto computeEngineGroup = device->getRegularEngineGroups()[computeEngineGroupIndex]; + auto expectedNumberOfCcs = std::min(4u, defaultHwInfo->gtSystemInfo.CCSInfo.NumberOfCCSEnabled); + EXPECT_EQ(expectedNumberOfCcs, computeEngineGroup.engines.size()); + } + { + auto device = deviceFactory.rootDevices[1]; + + auto computeEngineGroupIndex = device->getEngineGroupIndexFromEngineGroupType(EngineGroupType::Compute); + auto computeEngineGroup = device->getRegularEngineGroups()[computeEngineGroupIndex]; + EXPECT_EQ(1u, computeEngineGroup.engines.size()); + } + { + auto device = deviceFactory.rootDevices[2]; + + auto computeEngineGroupIndex = device->getEngineGroupIndexFromEngineGroupType(EngineGroupType::Compute); + auto computeEngineGroup = device->getRegularEngineGroups()[computeEngineGroupIndex]; + auto expectedNumberOfCcs = std::min(2u, defaultHwInfo->gtSystemInfo.CCSInfo.NumberOfCCSEnabled); + EXPECT_EQ(expectedNumberOfCcs, computeEngineGroup.engines.size()); + } + { + auto device = deviceFactory.rootDevices[3]; + + auto computeEngineGroupIndex = device->getEngineGroupIndexFromEngineGroupType(EngineGroupType::Compute); + auto computeEngineGroup = device->getRegularEngineGroups()[computeEngineGroupIndex]; + EXPECT_EQ(1u, computeEngineGroup.engines.size()); + } +} + +HWCMDTEST_F(IGFX_XE_HP_CORE, DeviceTests, givenZexNumberOfCssAndZeAffinityMaskSetWhenDeviceIsCreatedThenProperNumberOfCcsIsExposed) { + VariableBackup backup(&ultHwConfig); + ultHwConfig.useMockedPrepareDeviceEnvironmentsFunc = false; + DebugManagerStateRestore restorer; + + DebugManager.flags.CreateMultipleRootDevices.set(2); + DebugManager.flags.ZE_AFFINITY_MASK.set("1"); + 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(); + + auto devices = DeviceFactory::createDevices(executionEnvironment); + + { + auto device = devices[0].get(); + + EXPECT_EQ(0u, device->getRootDeviceIndex()); + auto computeEngineGroupIndex = device->getEngineGroupIndexFromEngineGroupType(EngineGroupType::Compute); + auto computeEngineGroup = device->getRegularEngineGroups()[computeEngineGroupIndex]; + EXPECT_EQ(1u, computeEngineGroup.engines.size()); + } +} + +HWCMDTEST_F(IGFX_XE_HP_CORE, DeviceTests, givenZexNumberOfCssEnvVariableIsLargerThanNumberOfAvailableCcsCountWhenDeviceIsCreatedThenCreateDevicesWithAvailableCcsCount) { + VariableBackup backup(&ultHwConfig); + ultHwConfig.useMockedPrepareDeviceEnvironmentsFunc = false; + DebugManagerStateRestore restorer; + + DebugManager.flags.ZEX_NUMBER_OF_CCS.set("0:13"); + DebugManager.flags.SetCommandStreamReceiver.set(1); + + 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(defaultHwInfo->gtSystemInfo.CCSInfo.NumberOfCCSEnabled, computeEngineGroup.engines.size()); +} + +HWCMDTEST_F(IGFX_XE_HP_CORE, DeviceTests, givenZexNumberOfCssEnvVariableSetAmbigouslyWhenDeviceIsCreatedThenDontApplyAnyLimitations) { + 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(defaultHwInfo->gtSystemInfo.CCSInfo.NumberOfCCSEnabled, computeEngineGroup.engines.size()); + } +} diff --git a/shared/test/unit_test/xe_hpc_core/pvc/CMakeLists.txt b/shared/test/unit_test/xe_hpc_core/pvc/CMakeLists.txt index 937db3ee26..d283fd5b05 100644 --- a/shared/test/unit_test/xe_hpc_core/pvc/CMakeLists.txt +++ b/shared/test/unit_test/xe_hpc_core/pvc/CMakeLists.txt @@ -8,6 +8,7 @@ if(TESTS_PVC) set(NEO_SHARED_TESTS_PVC ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt ${CMAKE_CURRENT_SOURCE_DIR}/device_binary_format_ar_tests_pvc.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/device_tests_pvc.cpp ${CMAKE_CURRENT_SOURCE_DIR}/dispatch_walker_tests_pvc.cpp ${CMAKE_CURRENT_SOURCE_DIR}/hw_info_tests_pvc.cpp ${CMAKE_CURRENT_SOURCE_DIR}/product_config_helper_tests_pvc.cpp diff --git a/shared/test/unit_test/xe_hpc_core/pvc/device_tests_pvc.cpp b/shared/test/unit_test/xe_hpc_core/pvc/device_tests_pvc.cpp new file mode 100644 index 0000000000..903ca9d7a0 --- /dev/null +++ b/shared/test/unit_test/xe_hpc_core/pvc/device_tests_pvc.cpp @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2022 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "shared/source/xe_hpc_core/hw_cmds_pvc.h" +#include "shared/test/common/helpers/debug_manager_state_restore.h" +#include "shared/test/common/helpers/default_hw_info.h" +#include "shared/test/common/helpers/ult_hw_config.h" +#include "shared/test/common/mocks/mock_device.h" +#include "shared/test/common/mocks/mock_execution_environment.h" +#include "shared/test/common/mocks/ult_device_factory.h" +#include "shared/test/common/test_macros/header/per_product_test_definitions.h" +#include "shared/test/common/test_macros/test.h" + +using namespace NEO; + +using DeviceTestsPvc = ::testing::Test; + +HWTEST_EXCLUDE_PRODUCT(DeviceTests, givenZexNumberOfCssEnvVariableSetAmbigouslyWhenDeviceIsCreatedThenDontApplyAnyLimitations, IGFX_PVC) + +PVCTEST_F(DeviceTestsPvc, WhenDeviceIsCreatedThenOnlyOneCcsEngineIsExposed) { + VariableBackup backup(&ultHwConfig); + ultHwConfig.useMockedPrepareDeviceEnvironmentsFunc = false; + DebugManagerStateRestore restorer; + DebugManager.flags.SetCommandStreamReceiver.set(1); + auto hwInfo = *defaultHwInfo; + + hwInfo.featureTable.flags.ftrCCSNode = 1; + hwInfo.gtSystemInfo.CCSInfo.IsValid = 1; + hwInfo.gtSystemInfo.CCSInfo.NumberOfCCSEnabled = 4; + + 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()); +}