diff --git a/level_zero/core/source/device/device_imp.cpp b/level_zero/core/source/device/device_imp.cpp index b76c5ee0f5..358e29cfad 100644 --- a/level_zero/core/source/device/device_imp.cpp +++ b/level_zero/core/source/device/device_imp.cpp @@ -61,6 +61,7 @@ #include "level_zero/core/source/sampler/sampler.h" #include "level_zero/driver_experimental/zex_graph.h" #include "level_zero/driver_experimental/zex_module.h" +#include "level_zero/sysman/source/driver/sysman_driver.h" #include "level_zero/tools/source/debug/debug_session.h" #include "level_zero/tools/source/metrics/metric.h" #include "level_zero/tools/source/sysman/sysman.h" @@ -1691,6 +1692,11 @@ Device *Device::create(DriverHandle *driverHandle, NEO::Device *neoDevice, bool bool isHwMode = device->getNEODevice()->getAllEngines().size() ? device->getNEODevice()->getAllEngines()[0].commandStreamReceiver->getType() == NEO::CommandStreamReceiverType::hardware : device->getNEODevice()->getRootDevice()->getAllEngines()[0].commandStreamReceiver->getType() == NEO::CommandStreamReceiverType::hardware; if (isHwMode) { device->createSysmanHandle(isSubDevice); + auto osInterface = neoDevice->getRootDeviceEnvironment().osInterface.get(); + if (osInterface && osInterface->getDriverModel()->getDriverModelType() == NEO::DriverModelType::wddm && NEO::debugManager.flags.EnableSysmanLegacyModeUsingZesInit.get()) { + // if driver type is wddm (windows) always use zesInit path for sysman + L0::Sysman::init(ZE_INIT_FLAG_GPU_ONLY); + } } device->resourcesReleased = false; diff --git a/level_zero/core/source/driver/driver_handle_imp.cpp b/level_zero/core/source/driver/driver_handle_imp.cpp index bde49cab20..0ae4554097 100644 --- a/level_zero/core/source/driver/driver_handle_imp.cpp +++ b/level_zero/core/source/driver/driver_handle_imp.cpp @@ -42,6 +42,7 @@ #include "level_zero/core/source/image/image.h" #include "level_zero/core/source/semaphore/external_semaphore_imp.h" #include "level_zero/driver_experimental/zex_common.h" +#include "level_zero/sysman/source/driver/sysman_driver.h" #include "driver_version.h" @@ -281,6 +282,8 @@ DriverHandleImp::~DriverHandleImp() { delete this->svmAllocsManager; this->svmAllocsManager = nullptr; } + + L0::Sysman::globalSysmanDriverCleanup(); } void DriverHandleImp::updateRootDeviceBitFields(std::unique_ptr &neoDevice) { diff --git a/level_zero/core/source/global_teardown.cpp b/level_zero/core/source/global_teardown.cpp index 759bd6cd5d..a22898fb26 100644 --- a/level_zero/core/source/global_teardown.cpp +++ b/level_zero/core/source/global_teardown.cpp @@ -12,7 +12,7 @@ #include "level_zero/core/source/driver/driver.h" #include "level_zero/core/source/driver/driver_handle_imp.h" #include "level_zero/ddi/ze_ddi_tables.h" -#include "level_zero/sysman/source/driver/sysman_driver_handle_imp.h" +#include "level_zero/sysman/source/driver/sysman_driver.h" namespace L0 { @@ -60,12 +60,9 @@ void globalDriverTeardown() { delete globalDriverHandles; globalDriverHandles = nullptr; } - if (Sysman::globalSysmanDriver != nullptr) { - delete Sysman::globalSysmanDriver; - Sysman::globalSysmanDriver = nullptr; - } globalDriverDispatch.core.isValidFlag = false; globalDriverDispatch.tools.isValidFlag = false; globalDriverDispatch.sysman.isValidFlag = false; + L0::Sysman::globalSysmanDriverCleanup(); } } // namespace L0 diff --git a/level_zero/sysman/source/driver/sysman_driver.cpp b/level_zero/sysman/source/driver/sysman_driver.cpp index 11a9b9baf2..8e783502d3 100644 --- a/level_zero/sysman/source/driver/sysman_driver.cpp +++ b/level_zero/sysman/source/driver/sysman_driver.cpp @@ -122,5 +122,12 @@ ze_result_t init(zes_init_flags_t flags) { } } +void globalSysmanDriverCleanup() { + if (Sysman::globalSysmanDriver != nullptr) { + delete Sysman::globalSysmanDriver; + Sysman::globalSysmanDriver = nullptr; + } +} + } // namespace Sysman } // namespace L0 diff --git a/level_zero/sysman/source/driver/sysman_driver.h b/level_zero/sysman/source/driver/sysman_driver.h index be965e7a0a..85244b7951 100644 --- a/level_zero/sysman/source/driver/sysman_driver.h +++ b/level_zero/sysman/source/driver/sysman_driver.h @@ -24,6 +24,7 @@ struct SysmanDriver { ze_result_t init(zes_init_flags_t); ze_result_t driverHandleGet(uint32_t *pCount, ze_driver_handle_t *phDrivers); +void globalSysmanDriverCleanup(); extern uint32_t driverCount; extern _ze_driver_handle_t *globalSysmanDriverHandle; diff --git a/level_zero/sysman/test/unit_tests/sources/linux/test_sysman.cpp b/level_zero/sysman/test/unit_tests/sources/linux/test_sysman.cpp index eaacc56356..44387eb7f6 100644 --- a/level_zero/sysman/test/unit_tests/sources/linux/test_sysman.cpp +++ b/level_zero/sysman/test/unit_tests/sources/linux/test_sysman.cpp @@ -631,6 +631,14 @@ TEST_F(SysmanDeviceFixture, GivenValidDeviceWhenRetrievingUuidThenValidFdIsVerif std::swap(rootDeviceEnvironment.productHelper, mockProductHelper); } +TEST(SysmanInitTest, GivenGlobalSysmanDriverPointerIsSetDuringSysmanInitThenWhenCallingGlobalSysmanDriverCleanupPointerIsNull) { + auto sysmanDriverHandle = new L0::Sysman::SysmanDriverHandleImp(); + L0::Sysman::globalSysmanDriver = sysmanDriverHandle; + EXPECT_NE(L0::Sysman::globalSysmanDriver, nullptr); + L0::Sysman::globalSysmanDriverCleanup(); + EXPECT_EQ(L0::Sysman::globalSysmanDriver, nullptr); +} + } // namespace ult } // namespace Sysman } // namespace L0 diff --git a/level_zero/sysman/test/unit_tests/sources/linux/test_sysman_core_handle_support.cpp b/level_zero/sysman/test/unit_tests/sources/linux/test_sysman_core_handle_support.cpp index c854c128d3..1f2cd29b65 100644 --- a/level_zero/sysman/test/unit_tests/sources/linux/test_sysman_core_handle_support.cpp +++ b/level_zero/sysman/test/unit_tests/sources/linux/test_sysman_core_handle_support.cpp @@ -16,15 +16,15 @@ namespace L0 { namespace Sysman { namespace ult { -class SysmanDeviceFixtureWithCore : public SysmanDeviceFixture, public L0::ult::DeviceFixture { +class SysmanDeviceFixtureWithCore : public L0::ult::DeviceFixture, public SysmanDeviceFixture { protected: void SetUp() override { - SysmanDeviceFixture::SetUp(); L0::ult::DeviceFixture::setUp(); + SysmanDeviceFixture::SetUp(); } void TearDown() override { - L0::ult::DeviceFixture::tearDown(); SysmanDeviceFixture::TearDown(); + L0::ult::DeviceFixture::tearDown(); } }; diff --git a/level_zero/sysman/test/unit_tests/sources/windows/test_sysman.cpp b/level_zero/sysman/test/unit_tests/sources/windows/test_sysman.cpp index b7222e646e..235c87321c 100644 --- a/level_zero/sysman/test/unit_tests/sources/windows/test_sysman.cpp +++ b/level_zero/sysman/test/unit_tests/sources/windows/test_sysman.cpp @@ -161,6 +161,14 @@ TEST_F(SysmanDeviceFixture, GivenValidWddmSysmanImpWhenRetrievingUuidThenTrueIsR EXPECT_TRUE(result); } +TEST(SysmanInitTest, GivenGlobalSysmanDriverPointerIsSetDuringSysmanInitThenWhenCallingGlobalSysmanDriverCleanupPointerIsNull) { + auto sysmanDriverHandle = new L0::Sysman::SysmanDriverHandleImp(); + L0::Sysman::globalSysmanDriver = sysmanDriverHandle; + EXPECT_NE(L0::Sysman::globalSysmanDriver, nullptr); + L0::Sysman::globalSysmanDriverCleanup(); + EXPECT_EQ(L0::Sysman::globalSysmanDriver, nullptr); +} + } // namespace ult } // namespace Sysman } // namespace L0 diff --git a/level_zero/sysman/test/unit_tests/sources/windows/test_sysman_core_handle_support.cpp b/level_zero/sysman/test/unit_tests/sources/windows/test_sysman_core_handle_support.cpp index 1569d9d723..0812ae1c56 100644 --- a/level_zero/sysman/test/unit_tests/sources/windows/test_sysman_core_handle_support.cpp +++ b/level_zero/sysman/test/unit_tests/sources/windows/test_sysman_core_handle_support.cpp @@ -16,15 +16,15 @@ namespace L0 { namespace Sysman { namespace ult { -class SysmanDeviceFixtureWithCore : public SysmanDeviceFixture, public L0::ult::DeviceFixture { +class SysmanDeviceFixtureWithCore : public L0::ult::DeviceFixture, public SysmanDeviceFixture { protected: void SetUp() override { - SysmanDeviceFixture::SetUp(); L0::ult::DeviceFixture::setUp(); + SysmanDeviceFixture::SetUp(); } void TearDown() override { - L0::ult::DeviceFixture::tearDown(); SysmanDeviceFixture::TearDown(); + L0::ult::DeviceFixture::tearDown(); } }; diff --git a/level_zero/tools/source/sysman/windows/os_sysman_imp.cpp b/level_zero/tools/source/sysman/windows/os_sysman_imp.cpp index dd10f5a164..78ec2da1f0 100644 --- a/level_zero/tools/source/sysman/windows/os_sysman_imp.cpp +++ b/level_zero/tools/source/sysman/windows/os_sysman_imp.cpp @@ -55,7 +55,8 @@ Device *WddmSysmanImp::getDeviceHandle() { } ze_bool_t WddmSysmanImp::isDriverModelSupported() { - return true; + auto usingZesInit = NEO::debugManager.flags.EnableSysmanLegacyModeUsingZesInit.get(); + return !usingZesInit; } std::vector &WddmSysmanImp::getDeviceHandles() { diff --git a/level_zero/tools/test/unit_tests/sources/sysman/windows/mock_sysman_fixture.cpp b/level_zero/tools/test/unit_tests/sources/sysman/windows/mock_sysman_fixture.cpp index a600f730f3..8a175feaa1 100644 --- a/level_zero/tools/test/unit_tests/sources/sysman/windows/mock_sysman_fixture.cpp +++ b/level_zero/tools/test/unit_tests/sources/sysman/windows/mock_sysman_fixture.cpp @@ -17,6 +17,7 @@ namespace L0 { namespace ult { void SysmanDeviceFixture::SetUp() { + debugManager.flags.EnableSysmanLegacyModeUsingZesInit.set(false); if (!sysmanUltsEnable) { GTEST_SKIP(); } diff --git a/level_zero/tools/test/unit_tests/sources/sysman/windows/mock_sysman_fixture.h b/level_zero/tools/test/unit_tests/sources/sysman/windows/mock_sysman_fixture.h index 78fe00a46e..f9689e86b4 100644 --- a/level_zero/tools/test/unit_tests/sources/sysman/windows/mock_sysman_fixture.h +++ b/level_zero/tools/test/unit_tests/sources/sysman/windows/mock_sysman_fixture.h @@ -37,6 +37,7 @@ class SysmanDeviceFixture : public DeviceFixture, public SysmanEnabledFixture { SysmanDeviceImp *pSysmanDeviceImp = nullptr; OsSysman *pOsSysman = nullptr; PublicWddmSysmanImp *pWddmSysmanImp = nullptr; + DebugManagerStateRestore restorer; }; } // namespace ult diff --git a/level_zero/tools/test/unit_tests/sources/sysman/windows/test_sysman.cpp b/level_zero/tools/test/unit_tests/sources/sysman/windows/test_sysman.cpp index 5c7c221ffc..5df60e009d 100644 --- a/level_zero/tools/test/unit_tests/sources/sysman/windows/test_sysman.cpp +++ b/level_zero/tools/test/unit_tests/sources/sysman/windows/test_sysman.cpp @@ -95,5 +95,12 @@ TEST_F(SysmanDeviceFixture, GivenValidSysmanDeviceImpWhenOsSysmanInitFailsThenUn delete testOsSysman; } +TEST_F(SysmanDeviceFixture, GivenValidWddmSysmanImpWhenExternBooleanUseZesInitOnWddmIsTrueThenFalseIsReturned) { + EXPECT_EQ(true, pWddmSysmanImp->isDriverModelSupported()); + debugManager.flags.EnableSysmanLegacyModeUsingZesInit.set(true); + EXPECT_EQ(false, pWddmSysmanImp->isDriverModelSupported()); + debugManager.flags.EnableSysmanLegacyModeUsingZesInit.set(false); +} + } // namespace ult } // namespace L0 diff --git a/shared/source/debug_settings/debug_variables_base.inl b/shared/source/debug_settings/debug_variables_base.inl index b74f9e2454..096ad4c4d7 100644 --- a/shared/source/debug_settings/debug_variables_base.inl +++ b/shared/source/debug_settings/debug_variables_base.inl @@ -479,6 +479,7 @@ DECLARE_DEBUG_VARIABLE(int32_t, WaitForPagingFenceInController, -1, "Instead of DECLARE_DEBUG_VARIABLE(int32_t, DirectSubmissionControllerIdleDetection, -1, "Terminate direct submission only if CSR is idle. -1: default, 0 - disable, 1 - enable.") DECLARE_DEBUG_VARIABLE(int32_t, DirectSubmissionControllerContextGroupIdleDetection, -1, "Terminate direct submission only if all CSRs in group are idle. -1: default, 0 - disable, 1 - enable.") /*FEATURE FLAGS*/ +DECLARE_DEBUG_VARIABLE(bool, EnableSysmanLegacyModeUsingZesInit, true, "Use zesInit based sysman initialization during zeInit") DECLARE_DEBUG_VARIABLE(bool, RegisterPageFaultHandlerOnMigration, false, "Register handler on migration to GPU when current is not from pagefault manager") DECLARE_DEBUG_VARIABLE(bool, EnableNV12, true, "Enables NV12 extension") DECLARE_DEBUG_VARIABLE(bool, EnablePackedYuv, true, "Enables cl_packed_yuv extension") diff --git a/shared/test/common/test_files/igdrcl.config b/shared/test/common/test_files/igdrcl.config index 8524219259..f44d936b3b 100644 --- a/shared/test/common/test_files/igdrcl.config +++ b/shared/test/common/test_files/igdrcl.config @@ -669,4 +669,5 @@ Disable2MBSizeAlignment = 0 InOrderCopyMiFlushSync = -1 SplitBcsForCopyOffload = -1 LimitIsaPrefetchSize = -1 +EnableSysmanLegacyModeUsingZesInit = 1 # Please don't edit below this line