diff --git a/level_zero/core/source/driver/driver.cpp b/level_zero/core/source/driver/driver.cpp index 6a983702e8..b28f55451d 100644 --- a/level_zero/core/source/driver/driver.cpp +++ b/level_zero/core/source/driver/driver.cpp @@ -9,6 +9,7 @@ #include "shared/source/device/device.h" #include "shared/source/execution_environment/execution_environment.h" +#include "shared/source/helpers/gfx_core_helper.h" #include "shared/source/os_interface/debug_env_reader.h" #include "shared/source/os_interface/device_factory.h" #include "shared/source/pin/pin.h" @@ -47,7 +48,7 @@ void DriverImp::initialize(ze_result_t *result) { envVariables.fp64Emulation = envReader.getSetting("NEO_FP64_EMULATION", false); envVariables.deviceHierarchyMode = - envReader.getSetting("ZE_FLAT_DEVICE_HIERARCHY", std::string("COMPOSITE")); + envReader.getSetting("ZE_FLAT_DEVICE_HIERARCHY", std::string(NEO::deviceHierarchyUnk)); auto executionEnvironment = new NEO::ExecutionEnvironment(); UNRECOVERABLE_IF(nullptr == executionEnvironment); diff --git a/level_zero/core/source/driver/driver_handle_imp.cpp b/level_zero/core/source/driver/driver_handle_imp.cpp index 42806a72e6..ebd2d6885e 100644 --- a/level_zero/core/source/driver/driver_handle_imp.cpp +++ b/level_zero/core/source/driver/driver_handle_imp.cpp @@ -12,6 +12,7 @@ #include "shared/source/device/device.h" #include "shared/source/execution_environment/execution_environment.h" #include "shared/source/execution_environment/root_device_environment.h" +#include "shared/source/helpers/gfx_core_helper.h" #include "shared/source/helpers/hw_info.h" #include "shared/source/helpers/string.h" #include "shared/source/helpers/string_helpers.h" @@ -270,11 +271,15 @@ DriverHandle *DriverHandle::create(std::vector> dev driverHandle->enableProgramDebugging = static_cast(envVariables.programDebugging); driverHandle->enableSysman = envVariables.sysman; driverHandle->enablePciIdDeviceOrder = envVariables.pciIdDeviceOrder; - if (strcmp(envVariables.deviceHierarchyMode.c_str(), "COMPOSITE") == 0) { + char const *preferredDeviceHierarchy = envVariables.deviceHierarchyMode.c_str(); + if (strcmp(preferredDeviceHierarchy, NEO::deviceHierarchyUnk) == 0) { + preferredDeviceHierarchy = devices[0]->getGfxCoreHelper().getDefaultDeviceHierarchy(); + } + if (strcmp(preferredDeviceHierarchy, "COMPOSITE") == 0) { driverHandle->deviceHierarchyMode = L0::L0DeviceHierarchyMode::L0_DEVICE_HIERARCHY_COMPOSITE; - } else if (strcmp(envVariables.deviceHierarchyMode.c_str(), "FLAT") == 0) { + } else if (strcmp(preferredDeviceHierarchy, "FLAT") == 0) { driverHandle->deviceHierarchyMode = L0::L0DeviceHierarchyMode::L0_DEVICE_HIERARCHY_FLAT; - } else if (strcmp(envVariables.deviceHierarchyMode.c_str(), "COMBINED") == 0) { + } else if (strcmp(preferredDeviceHierarchy, "COMBINED") == 0) { driverHandle->deviceHierarchyMode = L0::L0DeviceHierarchyMode::L0_DEVICE_HIERARCHY_COMBINED; } ze_result_t res = driverHandle->initialize(std::move(devices)); diff --git a/level_zero/core/test/unit_tests/sources/driver/test_driver.cpp b/level_zero/core/test/unit_tests/sources/driver/test_driver.cpp index b7dd2e0a66..6829d06b58 100644 --- a/level_zero/core/test/unit_tests/sources/driver/test_driver.cpp +++ b/level_zero/core/test/unit_tests/sources/driver/test_driver.cpp @@ -7,6 +7,7 @@ #include "shared/source/built_ins/sip.h" #include "shared/source/gmm_helper/gmm.h" +#include "shared/source/helpers/gfx_core_helper.h" #include "shared/source/helpers/string.h" #include "shared/source/memory_manager/allocation_properties.h" #include "shared/source/memory_manager/os_agnostic_memory_manager.h" @@ -473,7 +474,7 @@ TEST(DriverImpTest, givenEnabledProgramDebuggingWhenCreatingExecutionEnvironment L0::GlobalDriver = nullptr; } -TEST(DriverImpTest, givenDefaultFlatDeviceHierarchyWhenCreatingExecutionEnvironmentThenCompositeHierarchyIsEnabled) { +TEST(DriverImpTest, whenCreatingExecutionEnvironmentThenDefaultHierarchyIsEnabled) { NEO::HardwareInfo hwInfo = *NEO::defaultHwInfo.get(); hwInfo.capabilityTable.levelZeroSupported = true; @@ -482,7 +483,12 @@ TEST(DriverImpTest, givenDefaultFlatDeviceHierarchyWhenCreatingExecutionEnvironm DriverImp driverImp; driverImp.initialize(&result); L0::DriverHandleImp *driverHandleImp = reinterpret_cast(L0::GlobalDriverHandle); - EXPECT_EQ(driverHandleImp->deviceHierarchyMode, L0::L0DeviceHierarchyMode::L0_DEVICE_HIERARCHY_COMPOSITE); + auto &gfxCoreHelper = driverHandleImp->memoryManager->peekExecutionEnvironment().rootDeviceEnvironments[0]->getHelper(); + if (strcmp(gfxCoreHelper.getDefaultDeviceHierarchy(), "COMPOSITE") == 0) { + EXPECT_EQ(driverHandleImp->deviceHierarchyMode, L0::L0DeviceHierarchyMode::L0_DEVICE_HIERARCHY_COMPOSITE); + } else { + EXPECT_EQ(driverHandleImp->deviceHierarchyMode, L0::L0DeviceHierarchyMode::L0_DEVICE_HIERARCHY_FLAT); + } ASSERT_NE(nullptr, L0::GlobalDriver); ASSERT_NE(0u, L0::GlobalDriver->numDevices); @@ -513,6 +519,28 @@ TEST(DriverImpTest, givenFlatDeviceHierarchyWhenCreatingExecutionEnvironmentThen L0::GlobalDriver = nullptr; } +TEST(DriverImpTest, givenCompositeDeviceHierarchyWhenCreatingExecutionEnvironmentThenCompositeHierarchyIsEnabled) { + + NEO::HardwareInfo hwInfo = *NEO::defaultHwInfo.get(); + hwInfo.capabilityTable.levelZeroSupported = true; + + VariableBackup mockGetenvCalledBackup(&IoFunctions::mockGetenvCalled, 0); + std::unordered_map mockableEnvs = {{"ZE_FLAT_DEVICE_HIERARCHY", "COMPOSITE"}}; + VariableBackup *> mockableEnvValuesBackup(&IoFunctions::mockableEnvValues, &mockableEnvs); + + ze_result_t result = ZE_RESULT_ERROR_UNINITIALIZED; + DriverImp driverImp; + driverImp.initialize(&result); + L0::DriverHandleImp *driverHandleImp = reinterpret_cast(L0::GlobalDriverHandle); + EXPECT_EQ(driverHandleImp->deviceHierarchyMode, L0::L0DeviceHierarchyMode::L0_DEVICE_HIERARCHY_COMPOSITE); + ASSERT_NE(nullptr, L0::GlobalDriver); + ASSERT_NE(0u, L0::GlobalDriver->numDevices); + + delete L0::GlobalDriver; + L0::GlobalDriverHandle = nullptr; + L0::GlobalDriver = nullptr; +} + TEST(DriverImpTest, givenCombinedDeviceHierarchyWhenCreatingExecutionEnvironmentThenCombinedHierarchyIsEnabled) { NEO::HardwareInfo hwInfo = *NEO::defaultHwInfo.get(); diff --git a/opencl/test/unit_test/api/cl_create_sub_devices_tests.inl b/opencl/test/unit_test/api/cl_create_sub_devices_tests.inl index 7d1c7037fe..e8fdf0b2ca 100644 --- a/opencl/test/unit_test/api/cl_create_sub_devices_tests.inl +++ b/opencl/test/unit_test/api/cl_create_sub_devices_tests.inl @@ -7,6 +7,7 @@ #include "shared/test/common/helpers/debug_manager_state_restore.h" #include "shared/test/common/helpers/variable_backup.h" +#include "shared/test/common/mocks/mock_io_functions.h" #include "shared/test/common/test_macros/test.h" #include "opencl/source/api/api.h" @@ -114,6 +115,8 @@ TEST_F(ClCreateSubDevicesTests, GivenValidInputWhenCreatingSubDevicesThenSubDevi } TEST_F(ClCreateSubDevicesTests, GivenValidInputWhenCreatingSubDevicesThenDeviceApiReferenceCountIsIncreasedEveryTime) { + std::unordered_map mockableEnvs = {{"ZE_FLAT_DEVICE_HIERARCHY", "COMPOSITE"}}; + VariableBackup *> mockableEnvValuesBackup(&IoFunctions::mockableEnvValues, &mockableEnvs); setup(2); EXPECT_EQ(0, device->getSubDevice(0)->getRefApiCount()); @@ -131,6 +134,8 @@ TEST_F(ClCreateSubDevicesTests, GivenValidInputWhenCreatingSubDevicesThenDeviceA } TEST_F(ClCreateSubDevicesTests, GivenValidInputAndReturnSubDevicesAsApiDevicesIsSetWhenCreatingSubDevicesThenDeviceApiReferenceCountIsNotIncreased) { + std::unordered_map mockableEnvs = {{"ZE_FLAT_DEVICE_HIERARCHY", "COMPOSITE"}}; + VariableBackup *> mockableEnvValuesBackup(&IoFunctions::mockableEnvValues, &mockableEnvs); DebugManager.flags.ReturnSubDevicesAsApiDevices.set(1); setup(2); diff --git a/opencl/test/unit_test/device/sub_device_tests.cpp b/opencl/test/unit_test/device/sub_device_tests.cpp index 1d75d1bab5..0f811b4c49 100644 --- a/opencl/test/unit_test/device/sub_device_tests.cpp +++ b/opencl/test/unit_test/device/sub_device_tests.cpp @@ -14,6 +14,7 @@ #include "shared/test/common/helpers/ult_hw_config.h" #include "shared/test/common/helpers/variable_backup.h" #include "shared/test/common/mocks/mock_graphics_allocation.h" +#include "shared/test/common/mocks/mock_io_functions.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" @@ -67,6 +68,8 @@ TEST(SubDevicesTest, givenCreateMultipleSubDevicesFlagSetWhenCreateRootDeviceThe TEST(SubDevicesTest, givenDeviceWithSubDevicesWhenSubDeviceApiRefCountsAreChangedThenChangeIsPropagatedToRootDevice) { DebugManagerStateRestore restorer; + std::unordered_map mockableEnvs = {{"ZE_FLAT_DEVICE_HIERARCHY", "COMPOSITE"}}; + VariableBackup *> mockableEnvValuesBackup(&IoFunctions::mockableEnvValues, &mockableEnvs); DebugManager.flags.CreateMultipleSubDevices.set(2); VariableBackup mockDeviceFlagBackup(&MockDevice::createSingleDevice, false); initPlatform(); diff --git a/opencl/test/unit_test/os_interface/device_factory_tests.cpp b/opencl/test/unit_test/os_interface/device_factory_tests.cpp index fb3e9916e4..f27082f709 100644 --- a/opencl/test/unit_test/os_interface/device_factory_tests.cpp +++ b/opencl/test/unit_test/os_interface/device_factory_tests.cpp @@ -18,6 +18,7 @@ #include "shared/test/common/helpers/ult_hw_config.h" #include "shared/test/common/helpers/variable_backup.h" #include "shared/test/common/mocks/mock_execution_environment.h" +#include "shared/test/common/mocks/mock_io_functions.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" @@ -126,6 +127,9 @@ TEST_F(DeviceFactoryTest, givenDebugFlagSetWhenCreatingDevicesThenForceImagesSup } TEST_F(DeviceFactoryTest, givenZeAffinityMaskSetWhenCreateDevicesThenProperNumberOfDevicesIsReturned) { + std::unordered_map mockableEnvs = {{"ZE_FLAT_DEVICE_HIERARCHY", "COMPOSITE"}}; + VariableBackup *> mockableEnvValuesBackup(&IoFunctions::mockableEnvValues, &mockableEnvs); + DebugManagerStateRestore restorer; DebugManager.flags.CreateMultipleRootDevices.set(5); DebugManager.flags.CreateMultipleSubDevices.set(4); @@ -143,6 +147,9 @@ TEST_F(DeviceFactoryTest, givenZeAffinityMaskSetWhenCreateDevicesThenProperNumbe } TEST_F(DeviceFactoryTest, givenZeAffinityMaskSetToGreaterRootDeviceThanAvailableWhenCreateDevicesThenProperNumberOfDevicesIsReturned) { + std::unordered_map mockableEnvs = {{"ZE_FLAT_DEVICE_HIERARCHY", "COMPOSITE"}}; + VariableBackup *> mockableEnvValuesBackup(&IoFunctions::mockableEnvValues, &mockableEnvs); + DebugManagerStateRestore restorer; DebugManager.flags.CreateMultipleRootDevices.set(2); DebugManager.flags.CreateMultipleSubDevices.set(4); @@ -159,6 +166,9 @@ TEST_F(DeviceFactoryTest, givenZeAffinityMaskSetToGreaterRootDeviceThanAvailable } TEST_F(DeviceFactoryTest, givenZeAffinityMaskSetToGreaterSubDeviceThanAvailableWhenCreateDevicesThenProperNumberOfDevicesIsReturned) { + std::unordered_map mockableEnvs = {{"ZE_FLAT_DEVICE_HIERARCHY", "COMPOSITE"}}; + VariableBackup *> mockableEnvValuesBackup(&IoFunctions::mockableEnvValues, &mockableEnvs); + DebugManagerStateRestore restorer; DebugManager.flags.CreateMultipleRootDevices.set(2); DebugManager.flags.CreateMultipleSubDevices.set(4); @@ -173,6 +183,9 @@ TEST_F(DeviceFactoryTest, givenZeAffinityMaskSetToGreaterSubDeviceThanAvailableW } TEST_F(DeviceFactoryTest, givenZeAffinityMaskSetToRootDevicesOnlyWhenCreateDevicesThenProperNumberOfDevicesIsReturned) { + std::unordered_map mockableEnvs = {{"ZE_FLAT_DEVICE_HIERARCHY", "COMPOSITE"}}; + VariableBackup *> mockableEnvValuesBackup(&IoFunctions::mockableEnvValues, &mockableEnvs); + DebugManagerStateRestore restorer; DebugManager.flags.CreateMultipleRootDevices.set(2); DebugManager.flags.CreateMultipleSubDevices.set(4); diff --git a/shared/source/debug_settings/debug_variables_base.inl b/shared/source/debug_settings/debug_variables_base.inl index d67e7673c6..1be62002f9 100644 --- a/shared/source/debug_settings/debug_variables_base.inl +++ b/shared/source/debug_settings/debug_variables_base.inl @@ -398,7 +398,7 @@ DECLARE_DEBUG_VARIABLE(bool, EngineInstancedSubDevices, false, "Create subdevice DECLARE_DEBUG_VARIABLE(bool, AllowSingleTileEngineInstancedSubDevices, false, "Create subdevices assigned to specific engine on single tile config") DECLARE_DEBUG_VARIABLE(bool, EnablePrivateBO, false, "Enable PRELIM_I915_GEM_CREATE_EXT_VM_PRIVATE extension creating VM_PRIVATE BOs") DECLARE_DEBUG_VARIABLE(bool, UseDeprecatedClDeviceIpVersion, false, "When enabled, the deprecated ip version scheme distinguishing between families and integrated devices will be queried in OCL") -DECLARE_DEBUG_VARIABLE(int32_t, ReturnSubDevicesAsApiDevices, -1, "Expose each subdevice as a separate device during clGetDeviceIDs or zeDeviceGet API call") +DECLARE_DEBUG_VARIABLE(int32_t, ReturnSubDevicesAsApiDevices, -1, "Expose each subdevice as a separate device during clGetDeviceIDs or zeDeviceGet API call, -1:default, 0:disable, 1:enable") DECLARE_DEBUG_VARIABLE(int32_t, ForceRunAloneContext, -1, "Control creation of run-alone HW context, -1:default, 0:disable, 1:enable") DECLARE_DEBUG_VARIABLE(int32_t, AddClGlSharing, -1, "Add cl-gl extension") DECLARE_DEBUG_VARIABLE(int32_t, EnableKernelTunning, -1, "Perform a tunning of enqueue kernel, -1:default(disabled), 0:disable, 1:enable simple kernel tunning, 2:enable full kernel tunning") diff --git a/shared/source/execution_environment/execution_environment.cpp b/shared/source/execution_environment/execution_environment.cpp index c96bf1202e..32ea052615 100644 --- a/shared/source/execution_environment/execution_environment.cpp +++ b/shared/source/execution_environment/execution_environment.cpp @@ -287,6 +287,24 @@ void ExecutionEnvironment::sortNeoDevices() { std::sort(rootDeviceEnvironments.begin(), rootDeviceEnvironments.end(), comparePciIdBusNumber); } +void ExecutionEnvironment::setDeviceHierarchy(const GfxCoreHelper &gfxCoreHelper) { + NEO::EnvironmentVariableReader envReader; + std::string hierarchyModel = envReader.getSetting("ZE_FLAT_DEVICE_HIERARCHY", std::string(gfxCoreHelper.getDefaultDeviceHierarchy())); + if (strcmp(hierarchyModel.c_str(), "COMPOSITE") == 0) { + setExposeSubDevicesAsDevices(false); + } + if (strcmp(hierarchyModel.c_str(), "FLAT") == 0) { + setExposeSubDevicesAsDevices(true); + } + if (strcmp(hierarchyModel.c_str(), "COMBINED") == 0) { + setCombinedDeviceHierarchy(true); + } + + if (NEO::DebugManager.flags.ReturnSubDevicesAsApiDevices.get() != -1) { + setExposeSubDevicesAsDevices(NEO::DebugManager.flags.ReturnSubDevicesAsApiDevices.get()); + } +} + void ExecutionEnvironment::adjustCcsCountImpl(RootDeviceEnvironment *rootDeviceEnvironment) const { auto hwInfo = rootDeviceEnvironment->getMutableHardwareInfo(); auto &productHelper = rootDeviceEnvironment->getHelper(); @@ -346,21 +364,6 @@ void ExecutionEnvironment::configureNeoEnvironment() { DebugManager.flags.UseKmdMigration.setIfDefault(0); DebugManager.flags.SplitBcsSize.setIfDefault(256); } - NEO::EnvironmentVariableReader envReader; - std::string hierarchyModel = envReader.getSetting("ZE_FLAT_DEVICE_HIERARCHY", std::string("COMPOSITE")); - if (strcmp(hierarchyModel.c_str(), "COMPOSITE") == 0) { - setExposeSubDevicesAsDevices(false); - } - if (strcmp(hierarchyModel.c_str(), "FLAT") == 0) { - setExposeSubDevicesAsDevices(true); - } - if (strcmp(hierarchyModel.c_str(), "COMBINED") == 0) { - setCombinedDeviceHierarchy(true); - } - - if (NEO::DebugManager.flags.ReturnSubDevicesAsApiDevices.get() == 1) { - setExposeSubDevicesAsDevices(true); - } } bool ExecutionEnvironment::comparePciIdBusNumber(std::unique_ptr &rootDeviceEnvironment1, std::unique_ptr &rootDeviceEnvironment2) { diff --git a/shared/source/execution_environment/execution_environment.h b/shared/source/execution_environment/execution_environment.h index 7f4eb3a842..0f10719984 100644 --- a/shared/source/execution_environment/execution_environment.h +++ b/shared/source/execution_environment/execution_environment.h @@ -15,6 +15,7 @@ namespace NEO { class DirectSubmissionController; +class GfxCoreHelper; class MemoryManager; struct OsEnvironment; struct RootDeviceEnvironment; @@ -33,6 +34,7 @@ class ExecutionEnvironment : public ReferenceTrackedObject void adjustCcsCount(); void adjustCcsCount(const uint32_t rootDeviceIndex) const; void sortNeoDevices(); + void setDeviceHierarchy(const GfxCoreHelper &gfxCoreHelper); void adjustRootDeviceEnvironments(); void prepareForCleanup() const; void setDebuggingMode(DebuggingMode debuggingMode) { diff --git a/shared/source/helpers/gfx_core_helper.cpp b/shared/source/helpers/gfx_core_helper.cpp index 9057a291e7..e7869f78d7 100644 --- a/shared/source/helpers/gfx_core_helper.cpp +++ b/shared/source/helpers/gfx_core_helper.cpp @@ -18,6 +18,10 @@ namespace NEO { GfxCoreHelperCreateFunctionType gfxCoreHelperFactory[IGFX_MAX_CORE] = {}; +const char *deviceHierarchyComposite = "COMPOSITE"; +const char *deviceHierarchyFlat = "FLAT"; +const char *deviceHierarchyUnk = "UNK"; + std::unique_ptr GfxCoreHelper::create(const GFXCORE_FAMILY gfxCoreFamily) { auto createFunction = gfxCoreHelperFactory[gfxCoreFamily]; diff --git a/shared/source/helpers/gfx_core_helper.h b/shared/source/helpers/gfx_core_helper.h index fc765dbc16..ad03a311f1 100644 --- a/shared/source/helpers/gfx_core_helper.h +++ b/shared/source/helpers/gfx_core_helper.h @@ -48,6 +48,10 @@ class GfxCoreHelper; using EngineInstancesContainer = StackVec; using GfxCoreHelperCreateFunctionType = std::unique_ptr (*)(); +extern const char *deviceHierarchyComposite; +extern const char *deviceHierarchyFlat; +extern const char *deviceHierarchyUnk; + class GfxCoreHelper { public: static std::unique_ptr create(const GFXCORE_FAMILY gfxCoreFamily); @@ -168,6 +172,7 @@ class GfxCoreHelper { virtual bool isRelaxedOrderingSupported() const = 0; virtual uint32_t calculateNumThreadsPerThreadGroup(uint32_t simd, uint32_t totalWorkItems, uint32_t grfSize, bool isHwLocalIdGeneration) const = 0; virtual uint32_t overrideMaxWorkGroupSize(uint32_t maxWG) const = 0; + virtual char const *getDefaultDeviceHierarchy() const = 0; static bool isWorkaroundRequired(uint32_t lowestSteppingWithBug, uint32_t steppingWithFix, const HardwareInfo &hwInfo, const ProductHelper &productHelper); virtual ~GfxCoreHelper() = default; @@ -380,6 +385,7 @@ class GfxCoreHelperHw : public GfxCoreHelper { bool isRelaxedOrderingSupported() const override; uint32_t calculateNumThreadsPerThreadGroup(uint32_t simd, uint32_t totalWorkItems, uint32_t grfSize, bool isHwLocalIdGeneration) const override; uint32_t overrideMaxWorkGroupSize(uint32_t maxWG) const override; + char const *getDefaultDeviceHierarchy() const override; ~GfxCoreHelperHw() override = default; protected: diff --git a/shared/source/helpers/gfx_core_helper_base.inl b/shared/source/helpers/gfx_core_helper_base.inl index 4234dba068..1309bdd19c 100644 --- a/shared/source/helpers/gfx_core_helper_base.inl +++ b/shared/source/helpers/gfx_core_helper_base.inl @@ -709,4 +709,10 @@ template uint32_t GfxCoreHelperHw::calculateNumThreadsPerThreadGroup(uint32_t simd, uint32_t totalWorkItems, uint32_t grfSize, bool isHwLocalIdGeneration) const { return getThreadsPerWG(simd, totalWorkItems); } + +template +char const *GfxCoreHelperHw::getDefaultDeviceHierarchy() const { + return deviceHierarchyComposite; +} + } // namespace NEO diff --git a/shared/source/os_interface/device_factory.cpp b/shared/source/os_interface/device_factory.cpp index 051dff28f1..187bc48552 100644 --- a/shared/source/os_interface/device_factory.cpp +++ b/shared/source/os_interface/device_factory.cpp @@ -116,6 +116,7 @@ bool DeviceFactory::prepareDeviceEnvironmentsForProductFamilyOverride(ExecutionE } } + executionEnvironment.setDeviceHierarchy(executionEnvironment.rootDeviceEnvironments[0]->getHelper()); executionEnvironment.parseAffinityMask(); executionEnvironment.adjustCcsCount(); executionEnvironment.calculateMaxOsContextCount(); @@ -175,6 +176,7 @@ bool DeviceFactory::prepareDeviceEnvironments(ExecutionEnvironment &executionEnv rootDeviceIndex++; } + executionEnvironment.setDeviceHierarchy(executionEnvironment.rootDeviceEnvironments[0]->getHelper()); executionEnvironment.sortNeoDevices(); executionEnvironment.parseAffinityMask(); executionEnvironment.adjustRootDeviceEnvironments(); diff --git a/shared/test/common/mocks/mock_device.cpp b/shared/test/common/mocks/mock_device.cpp index cdd1a28508..286572021a 100644 --- a/shared/test/common/mocks/mock_device.cpp +++ b/shared/test/common/mocks/mock_device.cpp @@ -111,6 +111,7 @@ ExecutionEnvironment *MockDevice::prepareExecutionEnvironment(const HardwareInfo executionEnvironment->rootDeviceEnvironments[i]->setHwInfoAndInitHelpers(pHwInfo); executionEnvironment->rootDeviceEnvironments[i]->initGmm(); } + executionEnvironment->setDeviceHierarchy(executionEnvironment->rootDeviceEnvironments[0]->getHelper()); executionEnvironment->calculateMaxOsContextCount(); return executionEnvironment; } @@ -146,6 +147,7 @@ ExecutionEnvironment *MockDevice::prepareExecutionEnvironment(const HardwareInfo auto hwInfo = pHwInfo ? pHwInfo : defaultHwInfo.get(); executionEnvironment->rootDeviceEnvironments[0]->setHwInfoAndInitHelpers(hwInfo); + executionEnvironment->setDeviceHierarchy(executionEnvironment->rootDeviceEnvironments[0]->getHelper()); MockAubCenterFixture::setMockAubCenter(*executionEnvironment->rootDeviceEnvironments[0]); executionEnvironment->initializeMemoryManager(); diff --git a/shared/test/unit_test/device/neo_device_tests.cpp b/shared/test/unit_test/device/neo_device_tests.cpp index 2333f506f4..ca22d303f4 100644 --- a/shared/test/unit_test/device/neo_device_tests.cpp +++ b/shared/test/unit_test/device/neo_device_tests.cpp @@ -23,6 +23,7 @@ #include "shared/test/common/mocks/mock_compiler_interface.h" #include "shared/test/common/mocks/mock_compilers.h" #include "shared/test/common/mocks/mock_device.h" +#include "shared/test/common/mocks/mock_io_functions.h" #include "shared/test/common/mocks/mock_memory_manager.h" #include "shared/test/common/mocks/mock_product_helper.h" #include "shared/test/common/mocks/ult_device_factory.h" @@ -757,7 +758,10 @@ HWCMDTEST_F(IGFX_XE_HP_CORE, DeviceTests, givenZeAffinityMaskSetAndTilesAsDevice } } -HWCMDTEST_F(IGFX_XE_HP_CORE, DeviceTests, givenZeAffinityMaskSetThenProperSubDeviceHierarchyMapisSet) { +HWCMDTEST_F(IGFX_XE_HP_CORE, DeviceTests, givenZeAffinityMaskSetThenProperSubDeviceHierarchyMapIsSet) { + std::unordered_map mockableEnvs = {{"ZE_FLAT_DEVICE_HIERARCHY", "COMPOSITE"}}; + VariableBackup *> mockableEnvValuesBackup(&IoFunctions::mockableEnvValues, &mockableEnvs); + VariableBackup backup(&ultHwConfig); ultHwConfig.useMockedPrepareDeviceEnvironmentsFunc = false; DebugManagerStateRestore restorer; @@ -795,6 +799,9 @@ HWCMDTEST_F(IGFX_XE_HP_CORE, DeviceTests, givenZeAffinityMaskSetThenProperSubDev } HWCMDTEST_F(IGFX_XE_HP_CORE, DeviceTests, givenZeAffinityMaskSetWithoutTilesThenProperSubDeviceHierarchyMapisUnset) { + std::unordered_map mockableEnvs = {{"ZE_FLAT_DEVICE_HIERARCHY", "COMPOSITE"}}; + VariableBackup *> mockableEnvValuesBackup(&IoFunctions::mockableEnvValues, &mockableEnvs); + VariableBackup backup(&ultHwConfig); ultHwConfig.useMockedPrepareDeviceEnvironmentsFunc = false; DebugManagerStateRestore restorer; diff --git a/shared/test/unit_test/execution_environment/execution_environment_tests.cpp b/shared/test/unit_test/execution_environment/execution_environment_tests.cpp index 0c4f06d0b9..dbaff6b128 100644 --- a/shared/test/unit_test/execution_environment/execution_environment_tests.cpp +++ b/shared/test/unit_test/execution_environment/execution_environment_tests.cpp @@ -41,18 +41,24 @@ TEST(ExecutionEnvironment, givenDefaultConstructorWhenItIsCalledThenExecutionEnv EXPECT_EQ(0, environment.getRefApiCount()); } -TEST(ExecutionEnvironment, givenDefaultConstructorWhenItIsCalledThenSubDevicesAsDevicesIsFalse) { - ExecutionEnvironment environment; - EXPECT_FALSE(environment.isExposingSubDevicesAsDevices()); -} - -TEST(ExecutionEnvironment, givenDefaultConstructoWhenItIsCalledAndReturnSubDevicesAsApiDevicesIsSetThenSubDevicesAsDevicesIsTrue) { +TEST(ExecutionEnvironment, givenDefaultConstructoWhenItIsCalledAndReturnSubDevicesAsApiDevicesIsSetTrueThenSubDevicesAsDevicesIsTrue) { DebugManagerStateRestore dbgRestore; DebugManager.flags.ReturnSubDevicesAsApiDevices.set(1); - ExecutionEnvironment environment; + MockExecutionEnvironment environment; + environment.rootDeviceEnvironments[0]->setHwInfoAndInitHelpers(defaultHwInfo.get()); + environment.setDeviceHierarchy(environment.rootDeviceEnvironments[0]->getHelper()); EXPECT_TRUE(environment.isExposingSubDevicesAsDevices()); } +TEST(ExecutionEnvironment, givenDefaultConstructoWhenItIsCalledAndReturnSubDevicesAsApiDevicesIsSetFalseThenSubDevicesAsDevicesIsFalse) { + DebugManagerStateRestore dbgRestore; + DebugManager.flags.ReturnSubDevicesAsApiDevices.set(0); + MockExecutionEnvironment environment; + environment.rootDeviceEnvironments[0]->setHwInfoAndInitHelpers(defaultHwInfo.get()); + environment.setDeviceHierarchy(environment.rootDeviceEnvironments[0]->getHelper()); + EXPECT_FALSE(environment.isExposingSubDevicesAsDevices()); +} + TEST(ExecutionEnvironment, WhenCreatingDevicesThenThoseDevicesAddRefcountsToExecutionEnvironment) { auto executionEnvironment = new ExecutionEnvironment(); @@ -488,11 +494,23 @@ TEST(ExecutionEnvironment, givenExecutionEnvironmentWhenSettingFP64EmulationEnab EXPECT_TRUE(executionEnvironment.isFP64EmulationEnabled()); } +TEST(ExecutionEnvironmentDeviceHierarchy, givenExecutionEnvironmentWithDefaultDeviceHierarchyThenExecutionEnvironmentIsInitializedCorrectly) { + VariableBackup mockGetenvCalledBackup(&IoFunctions::mockGetenvCalled, 0); + MockExecutionEnvironment executionEnvironment; + executionEnvironment.rootDeviceEnvironments[0]->setHwInfoAndInitHelpers(defaultHwInfo.get()); + auto &gfxCoreHelper = executionEnvironment.rootDeviceEnvironments[0]->getHelper(); + executionEnvironment.setDeviceHierarchy(gfxCoreHelper); + EXPECT_EQ((strcmp(gfxCoreHelper.getDefaultDeviceHierarchy(), "COMPOSITE") != 0), + executionEnvironment.isExposingSubDevicesAsDevices()); +} + TEST(ExecutionEnvironmentDeviceHierarchy, givenExecutionEnvironmentWithCompositeDeviceHierarchyThenExposeSubDevicesAsDevicesIsFalse) { VariableBackup mockGetenvCalledBackup(&IoFunctions::mockGetenvCalled, 0); std::unordered_map mockableEnvs = {{"ZE_FLAT_DEVICE_HIERARCHY", "COMPOSITE"}}; VariableBackup *> mockableEnvValuesBackup(&IoFunctions::mockableEnvValues, &mockableEnvs); - ExecutionEnvironment executionEnvironment{}; + MockExecutionEnvironment executionEnvironment; + executionEnvironment.rootDeviceEnvironments[0]->setHwInfoAndInitHelpers(defaultHwInfo.get()); + executionEnvironment.setDeviceHierarchy(executionEnvironment.rootDeviceEnvironments[0]->getHelper()); EXPECT_FALSE(executionEnvironment.isExposingSubDevicesAsDevices()); } @@ -500,7 +518,9 @@ TEST(ExecutionEnvironmentDeviceHierarchy, givenExecutionEnvironmentWithFlatDevic VariableBackup mockGetenvCalledBackup(&IoFunctions::mockGetenvCalled, 0); std::unordered_map mockableEnvs = {{"ZE_FLAT_DEVICE_HIERARCHY", "FLAT"}}; VariableBackup *> mockableEnvValuesBackup(&IoFunctions::mockableEnvValues, &mockableEnvs); - ExecutionEnvironment executionEnvironment{}; + MockExecutionEnvironment executionEnvironment; + executionEnvironment.rootDeviceEnvironments[0]->setHwInfoAndInitHelpers(defaultHwInfo.get()); + executionEnvironment.setDeviceHierarchy(executionEnvironment.rootDeviceEnvironments[0]->getHelper()); EXPECT_TRUE(executionEnvironment.isExposingSubDevicesAsDevices()); } @@ -508,7 +528,9 @@ TEST(ExecutionEnvironmentDeviceHierarchy, givenExecutionEnvironmentWithCombinedD VariableBackup mockGetenvCalledBackup(&IoFunctions::mockGetenvCalled, 0); std::unordered_map mockableEnvs = {{"ZE_FLAT_DEVICE_HIERARCHY", "COMBINED"}}; VariableBackup *> mockableEnvValuesBackup(&IoFunctions::mockableEnvValues, &mockableEnvs); - ExecutionEnvironment executionEnvironment{}; + MockExecutionEnvironment executionEnvironment; + executionEnvironment.rootDeviceEnvironments[0]->setHwInfoAndInitHelpers(defaultHwInfo.get()); + executionEnvironment.setDeviceHierarchy(executionEnvironment.rootDeviceEnvironments[0]->getHelper()); EXPECT_FALSE(executionEnvironment.isExposingSubDevicesAsDevices()); } diff --git a/shared/test/unit_test/os_interface/device_uuid_tests.cpp b/shared/test/unit_test/os_interface/device_uuid_tests.cpp index c50f84df7d..242929ea52 100644 --- a/shared/test/unit_test/os_interface/device_uuid_tests.cpp +++ b/shared/test/unit_test/os_interface/device_uuid_tests.cpp @@ -15,6 +15,7 @@ #include "shared/test/common/mocks/mock_device.h" #include "shared/test/common/mocks/mock_driver_model.h" #include "shared/test/common/mocks/mock_execution_environment.h" +#include "shared/test/common/mocks/mock_io_functions.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" @@ -37,6 +38,9 @@ struct MultipleDeviceBdfUuidTest : public ::testing::Test { HWTEST2_F(MultipleDeviceBdfUuidTest, GivenValidBdfWithCombinationOfAffinityMaskThenUuidIsCorrectForRootAndSubDevices, MatchAny) { + std::unordered_map mockableEnvs = {{"ZE_FLAT_DEVICE_HIERARCHY", "COMPOSITE"}}; + VariableBackup *> mockableEnvValuesBackup(&IoFunctions::mockableEnvValues, &mockableEnvs); + std::unique_ptr deviceFactory; auto mockExecutionEnvironment = std::make_unique(defaultHwInfo.get(), false, 1); RAIIProductHelperFactory> raii(*mockExecutionEnvironment->rootDeviceEnvironments[0]); @@ -238,6 +242,9 @@ HWTEST2_F(MultipleDeviceBdfUuidTest, GivenValidBdfWithOneBitEnabledInAffinityMas HWTEST2_F(MultipleDeviceBdfUuidTest, GivenValidBdfWithOneBitEnabledInAffinityMaskSetToSubDeviceThenUuidOfRootDeviceIsBasedOnAffinityMask, MatchAny) { + std::unordered_map mockableEnvs = {{"ZE_FLAT_DEVICE_HIERARCHY", "COMPOSITE"}}; + VariableBackup *> mockableEnvValuesBackup(&IoFunctions::mockableEnvValues, &mockableEnvs); + std::unique_ptr deviceFactory; auto mockExecutionEnvironment = std::make_unique(defaultHwInfo.get(), false, 1); RAIIProductHelperFactory> raii(*mockExecutionEnvironment->rootDeviceEnvironments[0]);