diff --git a/level_zero/core/source/device/device_imp.cpp b/level_zero/core/source/device/device_imp.cpp index f51711e3d8..1706477977 100644 --- a/level_zero/core/source/device/device_imp.cpp +++ b/level_zero/core/source/device/device_imp.cpp @@ -1368,9 +1368,6 @@ Device *Device::create(DriverHandle *driverHandle, NEO::Device *neoDevice, bool if (neoDevice->getDebugger() || neoDevice->getPreemptionMode() == NEO::PreemptionMode::MidThread) { if (neoDevice->getCompilerInterface()) { - bool ret = NEO::SipKernel::initSipKernel(NEO::SipKernel::getSipKernelType(*neoDevice), *neoDevice); - UNRECOVERABLE_IF(!ret); - if (rootDeviceEnvironment.executionEnvironment.getDebuggingMode() == NEO::DebuggingMode::offline) { if (NEO::SipKernel::getSipKernel(*neoDevice, nullptr).getCtxOffset() == 0) { NEO::printDebugString(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, diff --git a/level_zero/core/source/driver/driver_handle_imp.cpp b/level_zero/core/source/driver/driver_handle_imp.cpp index 86146f9741..e73ba8cac7 100644 --- a/level_zero/core/source/driver/driver_handle_imp.cpp +++ b/level_zero/core/source/driver/driver_handle_imp.cpp @@ -226,14 +226,6 @@ void DriverHandleImp::updateRootDeviceBitFields(std::unique_ptr &ne entry->second = neoDevice->getDeviceBitfield(); } -void DriverHandleImp::enableRootDeviceDebugger(std::unique_ptr &neoDevice) { - if (enableProgramDebugging != NEO::DebuggingMode::disabled) { - const auto rootDeviceIndex = neoDevice->getRootDeviceIndex(); - auto rootDeviceEnvironment = neoDevice->getExecutionEnvironment()->rootDeviceEnvironments[rootDeviceIndex].get(); - rootDeviceEnvironment->initDebuggerL0(neoDevice.get()); - } -} - ze_result_t DriverHandleImp::initialize(std::vector> neoDevices) { bool multiOsContextDriver = false; for (auto &neoDevice : neoDevices) { @@ -251,15 +243,6 @@ ze_result_t DriverHandleImp::initialize(std::vector const auto rootDeviceIndex = neoDevice->getRootDeviceIndex(); - auto osInterface = neoDevice->getRootDeviceEnvironment().osInterface.get(); - if (osInterface && !osInterface->isDebugAttachAvailable() && enableProgramDebugging != NEO::DebuggingMode::disabled) { - NEO::printDebugString(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, - "Debug mode is not enabled in the system.\n"); - enableProgramDebugging = NEO::DebuggingMode::disabled; - } - - enableRootDeviceDebugger(neoDevice); - this->rootDeviceIndices.pushUnique(rootDeviceIndex); this->deviceBitfields.insert({rootDeviceIndex, neoDevice->getDeviceBitfield()}); diff --git a/level_zero/core/source/driver/driver_handle_imp.h b/level_zero/core/source/driver/driver_handle_imp.h index dc4bd6e5b0..788dd2a6d1 100644 --- a/level_zero/core/source/driver/driver_handle_imp.h +++ b/level_zero/core/source/driver/driver_handle_imp.h @@ -158,7 +158,6 @@ struct DriverHandleImp : public DriverHandle { RootDeviceIndicesContainer rootDeviceIndices; std::map deviceBitfields; void updateRootDeviceBitFields(std::unique_ptr &neoDevice); - void enableRootDeviceDebugger(std::unique_ptr &neoDevice); // Environment Variables NEO::DebuggingMode enableProgramDebugging = NEO::DebuggingMode::disabled; diff --git a/level_zero/core/test/unit_tests/sources/debugger/linux/test_l0_debugger_linux.cpp b/level_zero/core/test/unit_tests/sources/debugger/linux/test_l0_debugger_linux.cpp index b3fc38c10d..39c8b8716d 100644 --- a/level_zero/core/test/unit_tests/sources/debugger/linux/test_l0_debugger_linux.cpp +++ b/level_zero/core/test/unit_tests/sources/debugger/linux/test_l0_debugger_linux.cpp @@ -415,40 +415,6 @@ HWTEST_F(L0DebuggerLinuxTest, givenDebuggingEnabledAndDebugAttachAvailableWhenIn EXPECT_EQ(ZE_RESULT_SUCCESS, result); } -HWTEST_F(L0DebuggerLinuxTest, givenDebuggingEnabledAndDebugAttachNotAvailableWhenInitializingDriverThenErrorIsPrintedButNotReturned) { - DebugManagerStateRestore restorer; - NEO::debugManager.flags.PrintDebugMessages.set(1); - - auto executionEnvironment = new NEO::ExecutionEnvironment(); - executionEnvironment->prepareRootDeviceEnvironments(1); - executionEnvironment->setDebuggingMode(NEO::DebuggingMode::online); - executionEnvironment->rootDeviceEnvironments[0]->setHwInfoAndInitHelpers(defaultHwInfo.get()); - executionEnvironment->initializeMemoryManager(); - auto osInterface = new OSInterface(); - auto drmMock = new DrmMockResources(*executionEnvironment->rootDeviceEnvironments[0]); - executionEnvironment->rootDeviceEnvironments[0]->osInterface.reset(osInterface); - executionEnvironment->rootDeviceEnvironments[0]->osInterface->setDriverModel(std::unique_ptr(drmMock)); - - auto neoDevice = NEO::MockDevice::create(executionEnvironment, 0u); - - NEO::DeviceVector devices; - devices.push_back(std::unique_ptr(neoDevice)); - auto driverHandle = std::make_unique>(); - driverHandle->enableProgramDebugging = NEO::DebuggingMode::online; - - drmMock->allowDebugAttach = false; - - ::testing::internal::CaptureStderr(); - ze_result_t result = driverHandle->initialize(std::move(devices)); - EXPECT_EQ(ZE_RESULT_SUCCESS, result); - - auto output = testing::internal::GetCapturedStderr(); - EXPECT_EQ(std::string("Debug mode is not enabled in the system.\n"), output); - - EXPECT_EQ(NEO::DebuggingMode::disabled, driverHandle->enableProgramDebugging); - EXPECT_EQ(nullptr, neoDevice->getL0Debugger()); -} - HWTEST_F(L0DebuggerLinuxTest, givenDebuggingEnabledWhenImmCommandListsCreatedAndDestroyedThenDebuggerL0IsNotified) { auto debuggerL0Hw = static_cast *>(device->getL0Debugger()); diff --git a/level_zero/core/test/unit_tests/sources/debugger/windows/test_l0_debugger_windows.cpp b/level_zero/core/test/unit_tests/sources/debugger/windows/test_l0_debugger_windows.cpp index 5a0cccad47..bd41d1ea33 100644 --- a/level_zero/core/test/unit_tests/sources/debugger/windows/test_l0_debugger_windows.cpp +++ b/level_zero/core/test/unit_tests/sources/debugger/windows/test_l0_debugger_windows.cpp @@ -35,8 +35,8 @@ struct L0DebuggerWindowsFixture { void setUp() { debugManager.flags.ForcePreferredAllocationMethod.set(static_cast(GfxMemoryAllocationMethod::useUmdSystemPtr)); executionEnvironment = new NEO::ExecutionEnvironment; - executionEnvironment->prepareRootDeviceEnvironments(1); executionEnvironment->setDebuggingMode(NEO::DebuggingMode::online); + executionEnvironment->prepareRootDeviceEnvironments(1); rootDeviceEnvironment = executionEnvironment->rootDeviceEnvironments[0].get(); auto osEnvironment = new OsEnvironmentWin(); gdi = new MockGdi(); @@ -225,47 +225,5 @@ TEST_F(L0DebuggerWindowsTest, givenProgramDebuggingEnabledAndDebugAttachAvailabl EXPECT_EQ(ZE_RESULT_SUCCESS, result); } -TEST_F(L0DebuggerWindowsTest, givenProgramDebuggingEnabledAndDebugAttachNotAvailableWhenInitializingDriverThenErrorIsPrintedButNotReturned) { - DebugManagerStateRestore restorer; - - auto executionEnvironment = new NEO::ExecutionEnvironment(); - executionEnvironment->prepareRootDeviceEnvironments(1); - executionEnvironment->setDebuggingMode(NEO::DebuggingMode::online); - auto hwInfo = *NEO::defaultHwInfo.get(); - executionEnvironment->rootDeviceEnvironments[0]->setHwInfoAndInitHelpers(&hwInfo); - - WddmEuDebugInterfaceMock *wddm = new WddmEuDebugInterfaceMock(*executionEnvironment->rootDeviceEnvironments[0]); - wddm->callBaseDestroyAllocations = false; - wddm->callBaseMapGpuVa = false; - wddm->callBaseWaitFromCpu = false; - - auto osInterface = new OSInterface(); - executionEnvironment->rootDeviceEnvironments[0]->osInterface.reset(osInterface); - executionEnvironment->rootDeviceEnvironments[0]->osInterface->setDriverModel(std::unique_ptr(wddm)); - wddm->init(); - executionEnvironment->memoryManager.reset(new MockWddmMemoryManager(*executionEnvironment)); - - auto neoDevice = NEO::MockDevice::create(executionEnvironment, 0u); - NEO::DeviceVector devices; - devices.push_back(std::unique_ptr(neoDevice)); - auto driverHandle = std::make_unique>(); - - driverHandle->enableProgramDebugging = NEO::DebuggingMode::online; - wddm->debugAttachAvailable = false; - - ::testing::internal::CaptureStderr(); - - NEO::debugManager.flags.PrintDebugMessages.set(1); - ze_result_t result = driverHandle->initialize(std::move(devices)); - EXPECT_EQ(ZE_RESULT_SUCCESS, result); - - NEO::debugManager.flags.PrintDebugMessages.set(0); - auto output = testing::internal::GetCapturedStderr(); - EXPECT_EQ(std::string("Debug mode is not enabled in the system.\n"), output); - - EXPECT_EQ(NEO::DebuggingMode::disabled, driverHandle->enableProgramDebugging); - EXPECT_EQ(nullptr, neoDevice->getL0Debugger()); -} - } // namespace ult } // namespace L0 diff --git a/level_zero/core/test/unit_tests/sources/device/test_l0_device.cpp b/level_zero/core/test/unit_tests/sources/device/test_l0_device.cpp index 7e3dd971c9..f442379d50 100644 --- a/level_zero/core/test/unit_tests/sources/device/test_l0_device.cpp +++ b/level_zero/core/test/unit_tests/sources/device/test_l0_device.cpp @@ -226,7 +226,6 @@ HWTEST2_F(DeviceCopyEngineTests, givenRootOrSubDeviceWhenAskingForCopyOrdinalThe TEST(L0DeviceTest, givenMidThreadPreemptionWhenCreatingDeviceThenSipKernelIsInitialized) { - ze_result_t returnValue = ZE_RESULT_SUCCESS; VariableBackup mockSipCalled(&NEO::MockSipData::called, false); VariableBackup mockSipCalledType(&NEO::MockSipData::calledType, NEO::SipKernelType::count); VariableBackup backupSipInitType(&MockSipData::useMockSip, true); @@ -237,12 +236,6 @@ TEST(L0DeviceTest, givenMidThreadPreemptionWhenCreatingDeviceThenSipKernelIsInit auto neoDevice = std::unique_ptr(NEO::MockDevice::createWithNewExecutionEnvironment(&hwInfo, 0)); - EXPECT_EQ(NEO::SipKernelType::count, NEO::MockSipData::calledType); - EXPECT_FALSE(NEO::MockSipData::called); - - auto device = std::unique_ptr(Device::create(driverHandle.get(), neoDevice.release(), false, &returnValue)); - ASSERT_NE(nullptr, device); - EXPECT_EQ(NEO::SipKernelType::csr, NEO::MockSipData::calledType); EXPECT_TRUE(NEO::MockSipData::called); } @@ -338,15 +331,16 @@ TEST(L0DeviceTest, givenDeviceWithoutAnyCompilerLibraryThenInvalidDependencyIsNo } TEST(L0DeviceTest, givenDeviceWithoutIGCCompilerLibraryAndMidThreadPreemptionThenInvalidDependencyIsReturned) { + DebugManagerStateRestore restore{}; + debugManager.flags.ForcePreemptionMode.set(PreemptionMode::MidThread); ze_result_t returnValue = ZE_RESULT_SUCCESS; std::unique_ptr driverHandle(new DriverHandleImp); auto hwInfo = *NEO::defaultHwInfo; - auto neoDevice = std::unique_ptr(NEO::MockDevice::createWithNewExecutionEnvironment(&hwInfo, 0)); - auto oldIgcDllName = Os::igcDllName; Os::igcDllName = "_invalidIGC"; + auto neoDevice = std::unique_ptr(NEO::MockDevice::createWithNewExecutionEnvironment(&hwInfo, 0)); auto mockDevice = reinterpret_cast(neoDevice.get()); mockDevice->setPreemptionMode(NEO::PreemptionMode::MidThread); @@ -358,17 +352,18 @@ TEST(L0DeviceTest, givenDeviceWithoutIGCCompilerLibraryAndMidThreadPreemptionThe } TEST(L0DeviceTest, givenDeviceWithoutAnyCompilerLibraryAndMidThreadPreemptionThenInvalidDependencyIsReturned) { + DebugManagerStateRestore restore{}; + debugManager.flags.ForcePreemptionMode.set(PreemptionMode::MidThread); ze_result_t returnValue = ZE_RESULT_SUCCESS; std::unique_ptr driverHandle(new DriverHandleImp); auto hwInfo = *NEO::defaultHwInfo; - auto neoDevice = std::unique_ptr(NEO::MockDevice::createWithNewExecutionEnvironment(&hwInfo, 0)); - auto oldFclDllName = Os::frontEndDllName; auto oldIgcDllName = Os::igcDllName; Os::frontEndDllName = "_invalidFCL"; Os::igcDllName = "_invalidIGC"; + auto neoDevice = std::unique_ptr(NEO::MockDevice::createWithNewExecutionEnvironment(&hwInfo, 0)); auto mockDevice = reinterpret_cast(neoDevice.get()); mockDevice->setPreemptionMode(NEO::PreemptionMode::MidThread); 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 89080aaf19..280d4734d8 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 @@ -24,6 +24,7 @@ #include "shared/test/common/mocks/mock_device.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_sip.h" #include "shared/test/common/mocks/ult_device_factory.h" #include "shared/test/common/test_macros/hw_test.h" @@ -868,11 +869,13 @@ TEST(DriverTest, givenBuiltinsAsyncInitEnabledWhenCreatingDriverThenMakeSureBuil } TEST(DriverTest, givenInvalidCompilerEnvironmentThenDependencyUnavailableErrorIsReturned) { + VariableBackup backupUseMockSip{&MockSipData::useMockSip}; NEO::HardwareInfo hwInfo = *NEO::defaultHwInfo.get(); hwInfo.capabilityTable.levelZeroSupported = true; VariableBackup mockGetenvCalledBackup(&IoFunctions::mockGetenvCalled, 0); std::unordered_map mockableEnvs = {{"ZET_ENABLE_PROGRAM_DEBUGGING", "1"}}; VariableBackup *> mockableEnvValuesBackup(&IoFunctions::mockableEnvValues, &mockableEnvs); + backupUseMockSip = true; ze_result_t result = ZE_RESULT_ERROR_UNINITIALIZED; DriverImp driverImp; @@ -890,11 +893,13 @@ TEST(DriverTest, givenInvalidCompilerEnvironmentThenDependencyUnavailableErrorIs } TEST(DriverTest, givenInvalidCompilerEnvironmentAndEnableProgramDebuggingWithValue2ThenDependencyUnavailableErrorIsReturned) { + VariableBackup backupUseMockSip{&MockSipData::useMockSip}; NEO::HardwareInfo hwInfo = *NEO::defaultHwInfo.get(); hwInfo.capabilityTable.levelZeroSupported = true; VariableBackup mockGetenvCalledBackup(&IoFunctions::mockGetenvCalled, 0); std::unordered_map mockableEnvs = {{"ZET_ENABLE_PROGRAM_DEBUGGING", "2"}}; VariableBackup *> mockableEnvValuesBackup(&IoFunctions::mockableEnvValues, &mockableEnvs); + backupUseMockSip = true; ze_result_t result = ZE_RESULT_ERROR_UNINITIALIZED; DriverImp driverImp; diff --git a/level_zero/tools/source/sysman/linux/os_sysman_imp.cpp b/level_zero/tools/source/sysman/linux/os_sysman_imp.cpp index 02a46f9c92..3dcc9720b8 100644 --- a/level_zero/tools/source/sysman/linux/os_sysman_imp.cpp +++ b/level_zero/tools/source/sysman/linux/os_sysman_imp.cpp @@ -385,7 +385,6 @@ ze_result_t LinuxSysmanImp::initDevice() { return ZE_RESULT_ERROR_DEVICE_LOST; } static_cast(device->getDriverHandle())->updateRootDeviceBitFields(neoDevice); - static_cast(device->getDriverHandle())->enableRootDeviceDebugger(neoDevice); Device::deviceReinit(device->getDriverHandle(), device, neoDevice, &result); reInitSysmanDeviceResources(); diff --git a/level_zero/tools/test/unit_tests/sources/sysman/global_operations/linux/test_zes_global_operations.cpp b/level_zero/tools/test/unit_tests/sources/sysman/global_operations/linux/test_zes_global_operations.cpp index 7c9ee045a7..a41c5d7b96 100644 --- a/level_zero/tools/test/unit_tests/sources/sysman/global_operations/linux/test_zes_global_operations.cpp +++ b/level_zero/tools/test/unit_tests/sources/sysman/global_operations/linux/test_zes_global_operations.cpp @@ -1086,21 +1086,21 @@ TEST_F(SysmanGlobalOperationsIntegratedFixture, GivenProcessStartsMidResetWhenCa } TEST(SysmanGlobalOperationsTest, GivenValidDevicePciPathWhenPreparingDeviceEnvironmentThenPrepareDeviceEnvironmentReturnsTrue) { - auto device1 = std::unique_ptr{MockDevice::createWithNewExecutionEnvironment(defaultHwInfo.get())}; + MockExecutionEnvironment executionEnvironment; std::string pciPath1 = "0000:00:02.0"; - EXPECT_TRUE(DeviceFactory::prepareDeviceEnvironment(*device1->getExecutionEnvironment(), pciPath1, 0u)); + EXPECT_TRUE(DeviceFactory::prepareDeviceEnvironment(executionEnvironment, pciPath1, 0u)); } TEST(SysmanGlobalOperationsTest, GivenValidDevicePciPathWhoseFileDescriptorOpenFailedThenPrepareDeviceEnvironmentReturnsFalse) { - auto device2 = std::unique_ptr{MockDevice::createWithNewExecutionEnvironment(defaultHwInfo.get())}; + MockExecutionEnvironment executionEnvironment; std::string pciPath2 = "0000:00:03.0"; - EXPECT_FALSE(DeviceFactory::prepareDeviceEnvironment(*device2->getExecutionEnvironment(), pciPath2, 0u)); + EXPECT_FALSE(DeviceFactory::prepareDeviceEnvironment(executionEnvironment, pciPath2, 0u)); } TEST(SysmanGlobalOperationsTest, GivenNotExisitingPciPathWhenPrepareDeviceEnvironmentIsCalledThenFalseIsReturned) { - auto device3 = std::unique_ptr{MockDevice::createWithNewExecutionEnvironment(defaultHwInfo.get())}; + MockExecutionEnvironment executionEnvironment; std::string pciPath3 = "0000:00:04.0"; - EXPECT_FALSE(DeviceFactory::prepareDeviceEnvironment(*device3->getExecutionEnvironment(), pciPath3, 0u)); + EXPECT_FALSE(DeviceFactory::prepareDeviceEnvironment(executionEnvironment, pciPath3, 0u)); } TEST_F(SysmanDeviceFixture, GivenValidDeviceHandleWhenCallingDeviceGetStateThenSuccessResultIsReturned) { diff --git a/opencl/source/platform/platform.cpp b/opencl/source/platform/platform.cpp index 6693ace238..5e35e4c4d4 100644 --- a/opencl/source/platform/platform.cpp +++ b/opencl/source/platform/platform.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2023 Intel Corporation + * Copyright (C) 2018-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -143,17 +143,6 @@ bool Platform::initialize(std::vector> devices) { UNRECOVERABLE_IF(!pDevice); pClDevice = new ClDevice{*pDevice, this}; this->clDevices.push_back(pClDevice); - - if (pClDevice->getDevice().getExecutionEnvironment()->isDebuggingEnabled()) { - const auto rootDeviceIndex = pClDevice->getDevice().getRootDeviceIndex(); - auto rootDeviceEnvironment = pClDevice->getDevice().getExecutionEnvironment()->rootDeviceEnvironments[rootDeviceIndex].get(); - rootDeviceEnvironment->initDebuggerL0(&pClDevice->getDevice()); - } - - if (pClDevice->getPreemptionMode() == PreemptionMode::MidThread) { - bool ret = SipKernel::initSipKernel(SipKernel::getSipKernelType(*pDevice), *pDevice); - UNRECOVERABLE_IF(!ret); - } } DEBUG_BREAK_IF(this->platformInfo); diff --git a/opencl/test/unit_test/command_stream/command_stream_receiver_flush_task_1_tests.cpp b/opencl/test/unit_test/command_stream/command_stream_receiver_flush_task_1_tests.cpp index 0c3be5ce9e..48f6f77a50 100644 --- a/opencl/test/unit_test/command_stream/command_stream_receiver_flush_task_1_tests.cpp +++ b/opencl/test/unit_test/command_stream/command_stream_receiver_flush_task_1_tests.cpp @@ -177,7 +177,10 @@ HWTEST_F(CommandStreamReceiverFlushTaskTests, givenCsrWhenflushTaskThenDshAndIoh } HWTEST_F(CommandStreamReceiverFlushTaskTests, givenCsrInBatchingModeAndMidThreadPreemptionWhenFlushTaskIsCalledThenSipKernelIsMadeResident) { - auto &mockCsr = pDevice->getUltCommandStreamReceiver(); + DebugManagerStateRestore dbgRestorer; + debugManager.flags.ForcePreemptionMode.set(static_cast(NEO::PreemptionMode::MidThread)); + auto mockDevice = std::unique_ptr(MockDevice::createWithNewExecutionEnvironment(nullptr)); + auto &mockCsr = mockDevice->getUltCommandStreamReceiver(); mockCsr.overrideDispatchPolicy(DispatchMode::batchedDispatch); mockCsr.useNewResourceImplicitFlush = false; mockCsr.useGpuIdleImplicitFlush = false; @@ -187,8 +190,8 @@ HWTEST_F(CommandStreamReceiverFlushTaskTests, givenCsrInBatchingModeAndMidThread DispatchFlags dispatchFlags = DispatchFlagsHelper::createDefaultDispatchFlags(); dispatchFlags.preemptionMode = PreemptionMode::MidThread; - auto sipType = SipKernel::getSipKernelType(*pDevice); - SipKernel::initSipKernel(sipType, *pDevice); + auto sipType = SipKernel::getSipKernelType(*mockDevice); + SipKernel::initSipKernel(sipType, *mockDevice); mockCsr.flushTask(commandStream, 0, @@ -197,10 +200,10 @@ HWTEST_F(CommandStreamReceiverFlushTaskTests, givenCsrInBatchingModeAndMidThread &ssh, taskLevel, dispatchFlags, - *pDevice); + *mockDevice); auto cmdBuffer = mockedSubmissionsAggregator->peekCommandBuffers().peekHead(); - auto sipAllocation = SipKernel::getSipKernel(*pDevice, nullptr).getSipAllocation(); + auto sipAllocation = SipKernel::getSipKernel(*mockDevice, nullptr).getSipAllocation(); bool found = false; for (auto allocation : cmdBuffer->surfaces) { if (allocation == sipAllocation) { @@ -212,16 +215,19 @@ HWTEST_F(CommandStreamReceiverFlushTaskTests, givenCsrInBatchingModeAndMidThread } HWTEST_F(CommandStreamReceiverFlushTaskTests, givenCsrInDefaultModeAndMidThreadPreemptionWhenFlushTaskIsCalledThenSipKernelIsMadeResident) { - auto mockCsr = new MockCsrHw2(*pDevice->executionEnvironment, pDevice->getRootDeviceIndex(), pDevice->getDeviceBitfield()); - pDevice->resetCommandStreamReceiver(mockCsr); + DebugManagerStateRestore dbgRestorer; + debugManager.flags.ForcePreemptionMode.set(static_cast(NEO::PreemptionMode::MidThread)); + auto mockDevice = std::unique_ptr(MockDevice::createWithNewExecutionEnvironment(nullptr)); + auto mockCsr = new MockCsrHw2(*mockDevice->executionEnvironment, mockDevice->getRootDeviceIndex(), mockDevice->getDeviceBitfield()); + mockDevice->resetCommandStreamReceiver(mockCsr); CommandQueueHw commandQueue(nullptr, pClDevice, 0, false); auto &commandStream = commandQueue.getCS(4096u); DispatchFlags dispatchFlags = DispatchFlagsHelper::createDefaultDispatchFlags(); dispatchFlags.preemptionMode = PreemptionMode::MidThread; - auto sipType = SipKernel::getSipKernelType(*pDevice); - SipKernel::initSipKernel(sipType, *pDevice); + auto sipType = SipKernel::getSipKernelType(*mockDevice); + SipKernel::initSipKernel(sipType, *mockDevice); mockCsr->flushTask(commandStream, 0, @@ -230,9 +236,9 @@ HWTEST_F(CommandStreamReceiverFlushTaskTests, givenCsrInDefaultModeAndMidThreadP &ssh, taskLevel, dispatchFlags, - *pDevice); + *mockDevice); - auto sipAllocation = SipKernel::getSipKernel(*pDevice, nullptr).getSipAllocation(); + auto sipAllocation = SipKernel::getSipKernel(*mockDevice, nullptr).getSipAllocation(); bool found = false; for (auto allocation : mockCsr->copyOfAllocations) { if (allocation == sipAllocation) { diff --git a/opencl/test/unit_test/device/sub_device_tests.cpp b/opencl/test/unit_test/device/sub_device_tests.cpp index c443281939..538e7192c6 100644 --- a/opencl/test/unit_test/device/sub_device_tests.cpp +++ b/opencl/test/unit_test/device/sub_device_tests.cpp @@ -17,6 +17,7 @@ #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/mock_sip.h" #include "shared/test/common/mocks/ult_device_factory.h" #include "shared/test/common/test_macros/hw_test.h" @@ -198,12 +199,17 @@ TEST(SubDevicesTest, givenClDeviceWithSubDevicesWhenSubDeviceInternalRefCountsAr } TEST(SubDevicesTest, givenDeviceWithSubDevicesWhenSubDeviceCreationFailThenWholeDeviceIsDestroyed) { + VariableBackup useMockSip(&MockSipData::useMockSip); DebugManagerStateRestore restorer; debugManager.flags.CreateMultipleSubDevices.set(4); MockExecutionEnvironment executionEnvironment; executionEnvironment.prepareRootDeviceEnvironments(1); executionEnvironment.incRefInternal(); executionEnvironment.memoryManager.reset(new FailMemoryManager(4, executionEnvironment)); + auto &gfxCoreHelper = executionEnvironment.rootDeviceEnvironments[0]->getHelper(); + if (gfxCoreHelper.isSipKernelAsHexadecimalArrayPreferred()) { + useMockSip = true; + } auto device = Device::create(&executionEnvironment, 0u); EXPECT_EQ(nullptr, device); } diff --git a/opencl/test/unit_test/mem_obj/buffer_tests.cpp b/opencl/test/unit_test/mem_obj/buffer_tests.cpp index 986630cdc0..c48210002a 100644 --- a/opencl/test/unit_test/mem_obj/buffer_tests.cpp +++ b/opencl/test/unit_test/mem_obj/buffer_tests.cpp @@ -641,6 +641,9 @@ struct CompressedBuffersTests : public ::testing::Test { device = std::make_unique(MockDevice::create(executionEnvironment, 0u)); context = std::make_unique(device.get(), true); context->contextType = ContextType::CONTEXT_TYPE_UNRESTRICTIVE; + + auto memoryManager = static_cast(device->getExecutionEnvironment()->memoryManager.get()); + memoryManager->allocate32BitGraphicsMemoryImplCalled = false; } cl_int retVal = CL_SUCCESS; diff --git a/opencl/test/unit_test/platform/platform_tests.cpp b/opencl/test/unit_test/platform/platform_tests.cpp index 011c5e739c..d4b1934a6a 100644 --- a/opencl/test/unit_test/platform/platform_tests.cpp +++ b/opencl/test/unit_test/platform/platform_tests.cpp @@ -429,16 +429,6 @@ TEST(PlatformInitTest, givenSingleDeviceWithNonZeroRootDeviceIndexInPassedDevice EXPECT_EQ(2u, platform()->getClDevice(0)->getRootDeviceIndex()); } -TEST(PlatformInitTest, GivenDebuggingEnabledWhenPlatformIsInitializedThenL0DebuggerIsCreated) { - std::vector> devices; - auto executionEnvironment = new MockExecutionEnvironment(defaultHwInfo.get(), false, 1); - executionEnvironment->setDebuggingMode(NEO::DebuggingMode::online); - devices.push_back(std::make_unique(executionEnvironment, 0)); - auto status = platform()->initialize(std::move(devices)); - EXPECT_TRUE(status); - EXPECT_NE(nullptr, platform()->getClDevice(0)->getDevice().getL0Debugger()); -} - TEST(PlatformInitTest, GivenPreferredPlatformNameWhenPlatformIsInitializedThenOverridePlatformName) { std::vector> devices; auto executionEnvironment = new MockExecutionEnvironment(defaultHwInfo.get(), false, 1); diff --git a/opencl/test/unit_test/program/kernel_info_tests.cpp b/opencl/test/unit_test/program/kernel_info_tests.cpp index 7f6cd6b524..4886475941 100644 --- a/opencl/test/unit_test/program/kernel_info_tests.cpp +++ b/opencl/test/unit_test/program/kernel_info_tests.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2023 Intel Corporation + * Copyright (C) 2018-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -10,6 +10,7 @@ #include "shared/source/program/kernel_info.h" #include "shared/test/common/mocks/mock_execution_environment.h" #include "shared/test/common/mocks/mock_graphics_allocation.h" +#include "shared/test/common/mocks/mock_sip.h" #include "shared/test/common/mocks/ult_device_factory.h" #include "opencl/test/unit_test/fixtures/multi_root_device_fixture.h" @@ -90,12 +91,17 @@ class MyMemoryManager : public OsAgnosticMemoryManager { }; TEST(KernelInfoTest, givenKernelInfoWhenCreateKernelAllocationAndCannotAllocateMemoryThenReturnsFalse) { + VariableBackup useMockSip(&MockSipData::useMockSip); KernelInfo kernelInfo; auto executionEnvironment = new MockExecutionEnvironment(defaultHwInfo.get()); executionEnvironment->memoryManager.reset(new MyMemoryManager(*executionEnvironment)); if (executionEnvironment->memoryManager->isLimitedGPU(0)) { GTEST_SKIP(); } + auto &gfxCoreHelper = executionEnvironment->rootDeviceEnvironments[0]->getHelper(); + if (gfxCoreHelper.isSipKernelAsHexadecimalArrayPreferred()) { + useMockSip = true; + } auto device = std::unique_ptr(Device::create(executionEnvironment, mockRootDeviceIndex)); auto retVal = kernelInfo.createKernelAllocation(*device, false); EXPECT_FALSE(retVal); diff --git a/shared/source/command_stream/command_stream_receiver_hw.h b/shared/source/command_stream/command_stream_receiver_hw.h index 04e9dbce87..f5dd3388be 100644 --- a/shared/source/command_stream/command_stream_receiver_hw.h +++ b/shared/source/command_stream/command_stream_receiver_hw.h @@ -198,7 +198,7 @@ class CommandStreamReceiverHw : public CommandStreamReceiver { void programHeaplessStateProlog(Device &device, LinearStream &commandStream); void programStateBaseAddressHeapless(Device &device, LinearStream &commandStream); void programComputeModeHeapless(Device &device, LinearStream &commandStream); - void handleAllocationsResidencyForflushTaskStateless(const IndirectHeap *dsh, const IndirectHeap *ioh, const IndirectHeap *ssh); + void handleAllocationsResidencyForflushTaskStateless(const IndirectHeap *dsh, const IndirectHeap *ioh, const IndirectHeap *ssh, Device &device); bool submitDependencyUpdate(TagNodeBase *tag) override; protected: @@ -310,7 +310,8 @@ class CommandStreamReceiverHw : public CommandStreamReceiver { ImmediateFlushData &flushData); void handleImmediateFlushStatelessAllocationsResidency(size_t csrEstimatedSize, - LinearStream &csrStream); + LinearStream &csrStream, + Device &device); inline void handleImmediateFlushAllocationsResidency(Device &device, LinearStream &immediateCommandStream, diff --git a/shared/source/command_stream/command_stream_receiver_hw_base.inl b/shared/source/command_stream/command_stream_receiver_hw_base.inl index f78ef61e72..91f9cfe06f 100644 --- a/shared/source/command_stream/command_stream_receiver_hw_base.inl +++ b/shared/source/command_stream/command_stream_receiver_hw_base.inl @@ -542,8 +542,7 @@ CompletionStamp CommandStreamReceiverHw::flushTask( bool debuggingEnabled = device.getDebugger() != nullptr; - if (dispatchFlags.preemptionMode == PreemptionMode::MidThread || debuggingEnabled) { - + if (device.isStateSipRequired()) { GraphicsAllocation *sipAllocation = SipKernel::getSipKernel(device, this->osContext).getSipAllocation(); makeResident(*sipAllocation); } @@ -2119,7 +2118,6 @@ void CommandStreamReceiverHw::handleImmediateFlushAllocationsResidenc } if (device.isStateSipRequired()) { - GraphicsAllocation *sipAllocation = SipKernel::getSipKernel(device, this->osContext).getSipAllocation(); makeResident(*sipAllocation); } diff --git a/shared/source/command_stream/command_stream_receiver_hw_heap_addressing.inl b/shared/source/command_stream/command_stream_receiver_hw_heap_addressing.inl index 18440cb9a4..432e20764d 100644 --- a/shared/source/command_stream/command_stream_receiver_hw_heap_addressing.inl +++ b/shared/source/command_stream/command_stream_receiver_hw_heap_addressing.inl @@ -36,7 +36,8 @@ CompletionStamp CommandStreamReceiverHw::flushImmediateTaskStateless( template void CommandStreamReceiverHw::handleImmediateFlushStatelessAllocationsResidency(size_t csrEstimatedSize, - LinearStream &csrStream) { + LinearStream &csrStream, + Device &device) { UNRECOVERABLE_IF(true); } @@ -68,7 +69,8 @@ size_t CommandStreamReceiverHw::getCmdSizeForHeaplessPrologue(Device } template -void CommandStreamReceiverHw::handleAllocationsResidencyForflushTaskStateless(const IndirectHeap *dsh, const IndirectHeap *ioh, const IndirectHeap *ssh) { +void CommandStreamReceiverHw::handleAllocationsResidencyForflushTaskStateless(const IndirectHeap *dsh, const IndirectHeap *ioh, + const IndirectHeap *ssh, Device &device) { UNRECOVERABLE_IF(true); } diff --git a/shared/source/device/device.cpp b/shared/source/device/device.cpp index 2583930d06..d66b306bdf 100644 --- a/shared/source/device/device.cpp +++ b/shared/source/device/device.cpp @@ -7,6 +7,7 @@ #include "shared/source/device/device.h" +#include "shared/source/built_ins/sip.h" #include "shared/source/command_stream/command_stream_receiver.h" #include "shared/source/command_stream/preemption.h" #include "shared/source/command_stream/submission_status.h" @@ -229,6 +230,21 @@ bool Device::createDeviceImpl() { return false; } + if (getExecutionEnvironment()->isDebuggingEnabled()) { + const auto rootDeviceIndex = getRootDeviceIndex(); + auto rootDeviceEnvironment = getExecutionEnvironment()->rootDeviceEnvironments[rootDeviceIndex].get(); + rootDeviceEnvironment->initDebuggerL0(this); + if (rootDeviceEnvironment->debugger == nullptr) { + NEO::printDebugString(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, + "Debug mode is not enabled in the system.\n"); + } + } + + if (this->isStateSipRequired()) { + bool ret = SipKernel::initSipKernel(SipKernel::getSipKernelType(*this), *this); + UNRECOVERABLE_IF(!ret); + } + getDefaultEngine().osContext->setDefaultContext(true); for (auto &engine : allEngines) { diff --git a/shared/source/device/device.h b/shared/source/device/device.h index 132e160240..b151bbab3e 100644 --- a/shared/source/device/device.h +++ b/shared/source/device/device.h @@ -187,7 +187,7 @@ class Device : public ReferenceTrackedObject { MOCKABLE_VIRTUAL void stopDirectSubmissionAndWaitForCompletion(); bool isAnyDirectSubmissionEnabled(); bool isStateSipRequired() const { - return getPreemptionMode() == PreemptionMode::MidThread || getDebugger() != nullptr; + return (getPreemptionMode() == PreemptionMode::MidThread || getDebugger() != nullptr) && getCompilerInterface(); } MOCKABLE_VIRTUAL EngineControl *getSecondaryEngineCsr(EngineTypeUsage engineTypeUsage, bool allocateInterrupt); diff --git a/shared/test/common/fixtures/device_fixture.cpp b/shared/test/common/fixtures/device_fixture.cpp index f97189f503..70fa81d7cc 100644 --- a/shared/test/common/fixtures/device_fixture.cpp +++ b/shared/test/common/fixtures/device_fixture.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2023 Intel Corporation + * Copyright (C) 2020-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -8,6 +8,7 @@ #include "shared/test/common/fixtures/device_fixture.h" #include "shared/source/built_ins/sip.h" +#include "shared/source/debug_settings/debug_settings_manager.h" #include "shared/source/execution_environment/root_device_environment.h" #include "shared/test/common/mocks/mock_device.h" @@ -55,4 +56,20 @@ template ProductHelper &DeviceFixture::getHelper() const; template GfxCoreHelper &DeviceFixture::getHelper() const; template CompilerProductHelper &DeviceFixture::getHelper() const; +void DeviceWithoutSipFixture::setUp() { + debugManager.flags.ForcePreemptionMode.set(static_cast(NEO::PreemptionMode::Disabled)); + DeviceFixture::setUp(); + + for (auto &rootDeviceEnvironment : pDevice->executionEnvironment->rootDeviceEnvironments) { + for (auto &sipKernel : rootDeviceEnvironment->sipKernels) { + EXPECT_EQ(nullptr, sipKernel); + } + } + debugManager.flags.ForcePreemptionMode.set(dbgRestorer.debugVarSnapshot.ForcePreemptionMode.get()); +} + +void DeviceWithoutSipFixture::tearDown() { + DeviceFixture::tearDown(); +} + } // namespace NEO diff --git a/shared/test/common/fixtures/device_fixture.h b/shared/test/common/fixtures/device_fixture.h index da5d2c3d01..2d1994ba6a 100644 --- a/shared/test/common/fixtures/device_fixture.h +++ b/shared/test/common/fixtures/device_fixture.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021-2023 Intel Corporation + * Copyright (C) 2021-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -8,6 +8,7 @@ #pragma once #include "shared/source/command_stream/task_count_helper.h" #include "shared/source/helpers/hw_info.h" +#include "shared/test/common/helpers/debug_manager_state_restore.h" namespace NEO { @@ -33,4 +34,10 @@ struct DeviceFixture { const ReleaseHelper *getReleaseHelper(); }; +struct DeviceWithoutSipFixture : DeviceFixture { + void setUp(); + void tearDown(); + DebugManagerStateRestore dbgRestorer; +}; + } // namespace NEO diff --git a/shared/test/common/mocks/debugger_l0_create.cpp b/shared/test/common/mocks/debugger_l0_create.cpp index 37de563596..484b43bc20 100644 --- a/shared/test/common/mocks/debugger_l0_create.cpp +++ b/shared/test/common/mocks/debugger_l0_create.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2023 Intel Corporation + * Copyright (C) 2020-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -11,10 +11,14 @@ #include "shared/test/common/mocks/mock_l0_debugger.h" NEO::DebugerL0CreateFn mockDebuggerL0HwFactory[IGFX_MAX_CORE]; +bool forceCreateNullptrDebugger = false; namespace NEO { std::unique_ptr DebuggerL0::create(NEO::Device *device) { + if (forceCreateNullptrDebugger) { + return nullptr; + } initDebuggingInOs(device->getRootDeviceEnvironment().osInterface.get()); auto debugger = mockDebuggerL0HwFactory[device->getHardwareInfo().platform.eRenderCoreFamily](device); return std::unique_ptr(debugger); diff --git a/shared/test/unit_test/built_ins/sip_tests.cpp b/shared/test/unit_test/built_ins/sip_tests.cpp index 0d8a92c2cf..ea9ab71c10 100644 --- a/shared/test/unit_test/built_ins/sip_tests.cpp +++ b/shared/test/unit_test/built_ins/sip_tests.cpp @@ -33,7 +33,7 @@ namespace NEO { extern std::set virtualFileList; } -struct RawBinarySipFixture : public DeviceFixture { +struct RawBinarySipFixture : public DeviceWithoutSipFixture { void setUp() { debugManager.flags.LoadBinarySipFromFile.set("dummy_file.bin"); @@ -52,11 +52,11 @@ struct RawBinarySipFixture : public DeviceFixture { backupFcloseCalled = std::make_unique>(&IoFunctions::mockFcloseCalled, 0u); backupFailAfterNFopenCount = std::make_unique>(&IoFunctions::failAfterNFopenCount, 0u); - DeviceFixture::setUp(); + DeviceWithoutSipFixture::setUp(); } void tearDown() { - DeviceFixture::tearDown(); + DeviceWithoutSipFixture::tearDown(); } DebugManagerStateRestore dbgRestorer; @@ -326,7 +326,8 @@ struct HexadecimalHeaderSipKernel : public SipKernel { using SipKernel::getSipKernelImpl; using SipKernel::initHexadecimalArraySipKernel; }; -using HexadecimalHeaderSipTest = Test; + +using HexadecimalHeaderSipTest = Test; TEST_F(HexadecimalHeaderSipTest, whenInitHexadecimalArraySipKernelIsCalledThenSipKernelIsCorrect) { VariableBackup backupSipClassType(&SipKernel::classType, SipClassType::hexadecimalHeaderFile); @@ -470,11 +471,11 @@ TEST(DebugBindlessSip, givenBindlessDebugSipIsRequestedThenCorrectSipKernelIsRet } TEST(DebugBindlessSip, givenContextWhenBindlessDebugSipIsRequestedThenCorrectSipKernelIsReturned) { - auto mockDevice = std::unique_ptr(MockDevice::createWithNewExecutionEnvironment(nullptr)); - auto executionEnvironment = mockDevice->getExecutionEnvironment(); + auto executionEnvironment = MockDevice::prepareExecutionEnvironment(defaultHwInfo.get(), 0u); auto builtIns = new NEO::MockBuiltins(); builtIns->callBaseGetSipKernel = true; MockRootDeviceEnvironment::resetBuiltins(executionEnvironment->rootDeviceEnvironments[0].get(), builtIns); + auto mockDevice = std::unique_ptr(MockDevice::createWithExecutionEnvironment(defaultHwInfo.get(), executionEnvironment, 0u)); const uint32_t contextId = 0u; std::unique_ptr osContext(OsContext::create(executionEnvironment->rootDeviceEnvironments[0]->osInterface.get(), @@ -499,12 +500,12 @@ TEST(DebugBindlessSip, givenContextWhenBindlessDebugSipIsRequestedThenCorrectSip } TEST(DebugBindlessSip, givenOfflineDebuggingModeWhenGettingSipForContextThenCorrectSipKernelIsReturned) { - auto mockDevice = std::unique_ptr(MockDevice::createWithNewExecutionEnvironment(nullptr)); - auto executionEnvironment = mockDevice->getExecutionEnvironment(); + auto executionEnvironment = MockDevice::prepareExecutionEnvironment(defaultHwInfo.get(), 0u); + executionEnvironment->setDebuggingMode(DebuggingMode::offline); auto builtIns = new NEO::MockBuiltins(); builtIns->callBaseGetSipKernel = true; MockRootDeviceEnvironment::resetBuiltins(executionEnvironment->rootDeviceEnvironments[0].get(), builtIns); - executionEnvironment->setDebuggingMode(DebuggingMode::offline); + auto mockDevice = std::unique_ptr(MockDevice::createWithExecutionEnvironment(defaultHwInfo.get(), executionEnvironment, 0u)); const uint32_t contextId = 0u; std::unique_ptr osContext(OsContext::create(executionEnvironment->rootDeviceEnvironments[0]->osInterface.get(), @@ -529,11 +530,11 @@ TEST(DebugBindlessSip, givenOfflineDebuggingModeWhenGettingSipForContextThenCorr } TEST(DebugBindlessSip, givenTwoContextsWhenBindlessDebugSipIsRequestedThenEachSipKernelIsAssignedToADifferentContextId) { - auto mockDevice = std::unique_ptr(MockDevice::createWithNewExecutionEnvironment(nullptr)); - auto executionEnvironment = mockDevice->getExecutionEnvironment(); + auto executionEnvironment = MockDevice::prepareExecutionEnvironment(defaultHwInfo.get(), 0u); auto builtIns = new NEO::MockBuiltins(); builtIns->callBaseGetSipKernel = true; MockRootDeviceEnvironment::resetBuiltins(executionEnvironment->rootDeviceEnvironments[0].get(), builtIns); + auto mockDevice = std::unique_ptr(MockDevice::createWithExecutionEnvironment(defaultHwInfo.get(), executionEnvironment, 0u)); const uint32_t context0Id = 0u; std::unique_ptr osContext0(OsContext::create(executionEnvironment->rootDeviceEnvironments[0]->osInterface.get(), @@ -561,18 +562,18 @@ TEST(DebugBindlessSip, givenTwoContextsWhenBindlessDebugSipIsRequestedThenEachSi } TEST(DebugBindlessSip, givenFailingSipAllocationWhenBindlessDebugSipWithContextIsRequestedThenSipAllocationInSipKernelIsNull) { - auto mockDevice = std::unique_ptr(MockDevice::createWithNewExecutionEnvironment(nullptr)); - auto executionEnvironment = mockDevice->getExecutionEnvironment(); + auto executionEnvironment = MockDevice::prepareExecutionEnvironment(defaultHwInfo.get(), 0u); + + auto builtIns = new NEO::MockBuiltins(); + builtIns->callBaseGetSipKernel = true; + MockRootDeviceEnvironment::resetBuiltins(executionEnvironment->rootDeviceEnvironments[0].get(), builtIns); + auto mockDevice = std::unique_ptr(MockDevice::createWithExecutionEnvironment(defaultHwInfo.get(), executionEnvironment, 0u)); auto mockMemoryManager = new MockMemoryManager(); mockMemoryManager->isMockHostMemoryManager = true; mockMemoryManager->forceFailureInPrimaryAllocation = true; executionEnvironment->memoryManager.reset(mockMemoryManager); - auto builtIns = new NEO::MockBuiltins(); - builtIns->callBaseGetSipKernel = true; - MockRootDeviceEnvironment::resetBuiltins(executionEnvironment->rootDeviceEnvironments[0].get(), builtIns); - const uint32_t contextId = 0u; std::unique_ptr osContext(OsContext::create(executionEnvironment->rootDeviceEnvironments[0]->osInterface.get(), mockDevice->getRootDeviceIndex(), contextId, @@ -596,11 +597,11 @@ TEST(DebugBindlessSip, givenFailingSipAllocationWhenBindlessDebugSipWithContextI } TEST(DebugBindlessSip, givenCorrectSipKernelWhenReleasingAllocationManuallyThenFreeGraphicsMemoryIsSkippedOnDestruction) { - auto mockDevice = std::unique_ptr(MockDevice::createWithNewExecutionEnvironment(nullptr)); - auto executionEnvironment = mockDevice->getExecutionEnvironment(); + auto executionEnvironment = MockDevice::prepareExecutionEnvironment(defaultHwInfo.get(), 0u); auto builtIns = new NEO::MockBuiltins(); builtIns->callBaseGetSipKernel = true; MockRootDeviceEnvironment::resetBuiltins(executionEnvironment->rootDeviceEnvironments[0].get(), builtIns); + auto mockDevice = std::unique_ptr(MockDevice::createWithExecutionEnvironment(defaultHwInfo.get(), executionEnvironment, 0u)); const uint32_t contextId = 0u; std::unique_ptr osContext(OsContext::create(executionEnvironment->rootDeviceEnvironments[0]->osInterface.get(), @@ -628,13 +629,12 @@ TEST(DebugBindlessSip, givenOfflineDebuggingModeWhenSipIsInitializedThenBinaryIs igcDebugVars.binaryToReturn = binary; gEnvironment->igcPushDebugVars(igcDebugVars); - auto mockDevice = std::unique_ptr(MockDevice::createWithNewExecutionEnvironment(nullptr)); - - auto executionEnvironment = mockDevice->getExecutionEnvironment(); + auto executionEnvironment = MockDevice::prepareExecutionEnvironment(defaultHwInfo.get(), 0u); auto builtIns = new NEO::MockBuiltins(); builtIns->callBaseGetSipKernel = true; MockRootDeviceEnvironment::resetBuiltins(executionEnvironment->rootDeviceEnvironments[0].get(), builtIns); executionEnvironment->setDebuggingMode(DebuggingMode::offline); + auto mockDevice = std::unique_ptr(MockDevice::createWithExecutionEnvironment(defaultHwInfo.get(), executionEnvironment, 0u)); auto osContext = std::make_unique(0, EngineDescriptorHelper::getDefaultDescriptor({aub_stream::ENGINE_RCS, EngineUsage::regular})); osContext->debuggableContext = true; @@ -665,13 +665,12 @@ TEST(DebugBindlessSip, givenOfflineDebuggingModeAndInvalidSipWhenSipIsInitialize igcDebugVars.binaryToReturn = binary; gEnvironment->igcPushDebugVars(igcDebugVars); - auto mockDevice = std::unique_ptr(MockDevice::createWithNewExecutionEnvironment(nullptr)); - - auto executionEnvironment = mockDevice->getExecutionEnvironment(); + auto executionEnvironment = MockDevice::prepareExecutionEnvironment(defaultHwInfo.get(), 0u); auto builtIns = new NEO::MockBuiltins(); builtIns->callBaseGetSipKernel = true; MockRootDeviceEnvironment::resetBuiltins(executionEnvironment->rootDeviceEnvironments[0].get(), builtIns); executionEnvironment->setDebuggingMode(DebuggingMode::offline); + auto mockDevice = std::unique_ptr(MockDevice::createWithExecutionEnvironment(defaultHwInfo.get(), executionEnvironment, 0u)); auto osContext = std::make_unique(0, EngineDescriptorHelper::getDefaultDescriptor({aub_stream::ENGINE_RCS, EngineUsage::regular})); osContext->debuggableContext = true; @@ -703,12 +702,12 @@ TEST(DebugBindlessSip, givenOfflineDebuggingModeWhenDebugSipForContextIsCreatedT igcDebugVars.binaryToReturn = binary; gEnvironment->igcPushDebugVars(igcDebugVars); - auto mockDevice = std::unique_ptr(MockDevice::createWithNewExecutionEnvironment(nullptr)); - auto executionEnvironment = mockDevice->getExecutionEnvironment(); + auto executionEnvironment = MockDevice::prepareExecutionEnvironment(defaultHwInfo.get(), 0u); auto builtIns = new NEO::MockBuiltins(); builtIns->callBaseGetSipKernel = true; MockRootDeviceEnvironment::resetBuiltins(executionEnvironment->rootDeviceEnvironments[0].get(), builtIns); executionEnvironment->setDebuggingMode(DebuggingMode::offline); + auto mockDevice = std::unique_ptr(MockDevice::createWithExecutionEnvironment(defaultHwInfo.get(), executionEnvironment, 0u)); auto osContext = std::make_unique(0, EngineDescriptorHelper::getDefaultDescriptor({aub_stream::ENGINE_RCS, EngineUsage::regular})); osContext->debuggableContext = true; diff --git a/shared/test/unit_test/command_stream/command_stream_receiver_tests.cpp b/shared/test/unit_test/command_stream/command_stream_receiver_tests.cpp index 4474db4162..85eb69452e 100644 --- a/shared/test/unit_test/command_stream/command_stream_receiver_tests.cpp +++ b/shared/test/unit_test/command_stream/command_stream_receiver_tests.cpp @@ -5296,11 +5296,11 @@ HWTEST_F(CommandStreamReceiverHwHeaplessTest, whenHeaplessCommandStreamReceiverF EXPECT_ANY_THROW(csr->getCmdSizeForHeaplessPrologue(*pDevice)); EXPECT_ANY_THROW(csr->handleAllocationsResidencyForHeaplessProlog(commandStream, *pDevice)); EXPECT_ANY_THROW(csr->programHeaplessStateProlog(*pDevice, commandStream)); - EXPECT_ANY_THROW(csr->handleAllocationsResidencyForflushTaskStateless(nullptr, nullptr, nullptr)); + EXPECT_ANY_THROW(csr->handleAllocationsResidencyForflushTaskStateless(nullptr, nullptr, nullptr, *pDevice)); EXPECT_ANY_THROW(csr->getRequiredCmdStreamHeaplessSize(csr->recordedDispatchFlags, *pDevice)); EXPECT_ANY_THROW(csr->getRequiredCmdStreamHeaplessSizeAligned(csr->recordedDispatchFlags, *pDevice)); EXPECT_ANY_THROW(csr->flushImmediateTaskStateless(commandStream, 0, csr->recordedImmediateDispatchFlags, *pDevice)); - EXPECT_ANY_THROW(csr->handleImmediateFlushStatelessAllocationsResidency(0, commandStream)); + EXPECT_ANY_THROW(csr->handleImmediateFlushStatelessAllocationsResidency(0, commandStream, *pDevice)); EXPECT_FALSE(csr->heaplessStateInitialized); } diff --git a/shared/test/unit_test/device/neo_device_tests.cpp b/shared/test/unit_test/device/neo_device_tests.cpp index efea0a1cc0..1f32e672dc 100644 --- a/shared/test/unit_test/device/neo_device_tests.cpp +++ b/shared/test/unit_test/device/neo_device_tests.cpp @@ -1033,6 +1033,46 @@ TEST_F(DeviceTests, givenDeviceThreadGroupPreemptionWhenDebuggerDisabledThenStat EXPECT_FALSE(device->isStateSipRequired()); } +TEST_F(DeviceTests, WhenIsStateSipRequiredIsCalledThenCorrectValueIsReturned) { + struct MockRootDeviceEnvironment : RootDeviceEnvironment { + using RootDeviceEnvironment::RootDeviceEnvironment; + CompilerInterface *getCompilerInterface() override { + return compilerInterfaceReturnValue; + } + CompilerInterface *compilerInterfaceReturnValue = nullptr; + }; + auto device = std::unique_ptr(MockDevice::createWithNewExecutionEnvironment(defaultHwInfo.get())); + auto mockRootDeviceEnvironment = new MockRootDeviceEnvironment{*device->executionEnvironment}; + auto backupenv = device->executionEnvironment->rootDeviceEnvironments[0].release(); + device->executionEnvironment->rootDeviceEnvironments[0].reset(mockRootDeviceEnvironment); + device->executionEnvironment->rootDeviceEnvironments[0]->compilerInterface.release(); + device->executionEnvironment->rootDeviceEnvironments[0]->debugger.release(); + + std::array, 8> testParameters = { + {{PreemptionMode::Disabled, nullptr, nullptr, false}, + {PreemptionMode::MidThread, nullptr, nullptr, false}, + {PreemptionMode::Disabled, (Debugger *)0x1234, nullptr, false}, + {PreemptionMode::MidThread, (Debugger *)0x1234, nullptr, false}, + + {PreemptionMode::Disabled, nullptr, (CompilerInterface *)0x1234, false}, + {PreemptionMode::MidThread, nullptr, (CompilerInterface *)0x1234, true}, + {PreemptionMode::Disabled, (Debugger *)0x1234, (CompilerInterface *)0x1234, true}, + {PreemptionMode::MidThread, (Debugger *)0x1234, (CompilerInterface *)0x1234, true}}}; + + for (const auto &[preemptionMode, debugger, compilerInterface, expectedResult] : testParameters) { + device->setPreemptionMode(preemptionMode); + device->executionEnvironment->rootDeviceEnvironments[0]->debugger.release(); + device->executionEnvironment->rootDeviceEnvironments[0]->debugger.reset(debugger); + mockRootDeviceEnvironment->compilerInterfaceReturnValue = compilerInterface; + + EXPECT_EQ(expectedResult, device->isStateSipRequired()); + } + device->executionEnvironment->rootDeviceEnvironments[0]->debugger.release(); + mockRootDeviceEnvironment->compilerInterfaceReturnValue = nullptr; + delete device->executionEnvironment->rootDeviceEnvironments[0].release(); + device->executionEnvironment->rootDeviceEnvironments[0].reset(backupenv); +} + HWTEST2_F(DeviceTests, GivenXeHpAndLaterThenDefaultPreemptionModeIsThreadGroup, IsWithinXeGfxFamily) { EXPECT_EQ(PreemptionMode::ThreadGroup, defaultHwInfo->capabilityTable.defaultPreemptionMode); } @@ -1452,4 +1492,29 @@ HWTEST_F(DeviceTests, givenDebugFlagSetWhenCreatingSecondaryEnginesThenSkipSelec EXPECT_EQ(device->secondaryEngines.end(), device->secondaryEngines.find(aub_stream::ENGINE_CCS)); executionEnvironment->decRefInternal(); -} \ No newline at end of file +} + +TEST_F(DeviceTests, GivenDebuggingEnabledWhenDeviceIsInitializedThenL0DebuggerIsCreated) { + auto executionEnvironment = MockDevice::prepareExecutionEnvironment(defaultHwInfo.get(), 0u); + executionEnvironment->setDebuggingMode(NEO::DebuggingMode::online); + auto device = std::unique_ptr(MockDevice::createWithExecutionEnvironment(defaultHwInfo.get(), executionEnvironment, 0u)); + EXPECT_NE(nullptr, device->getL0Debugger()); +} + +extern bool forceCreateNullptrDebugger; + +TEST_F(DeviceTests, givenDebuggerRequestedByUserAndNotAvailableWhenDeviceIsInitializedThenErrorIsPrintedButNotReturned) { + VariableBackup backupForceCreateNullptrDebugger{&forceCreateNullptrDebugger, true}; + DebugManagerStateRestore restorer; + + auto executionEnvironment = MockDevice::prepareExecutionEnvironment(defaultHwInfo.get(), 0u); + executionEnvironment->setDebuggingMode(NEO::DebuggingMode::online); + + NEO::debugManager.flags.PrintDebugMessages.set(1); + ::testing::internal::CaptureStderr(); + auto device = std::unique_ptr(MockDevice::createWithExecutionEnvironment(defaultHwInfo.get(), executionEnvironment, 0u)); + auto output = testing::internal::GetCapturedStderr(); + + EXPECT_EQ(std::string("Debug mode is not enabled in the system.\n"), output); + EXPECT_EQ(nullptr, device->getL0Debugger()); +} 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 e86c255747..284aea0af5 100644 --- a/shared/test/unit_test/execution_environment/execution_environment_tests.cpp +++ b/shared/test/unit_test/execution_environment/execution_environment_tests.cpp @@ -532,6 +532,15 @@ TEST(ExecutionEnvironment, givenIncorrectZeAffinityMaskWhenExposeSubDevicesAsApi EXPECT_TRUE(executionEnvironment.mapOfSubDeviceIndices.empty()); } +TEST(ExecutionEnvironment, givenBuiltinsSetWhenRootDeviceEnvironmentIsReleasedThenBuiltinsIsReset) { + auto hwInfo = *defaultHwInfo; + MockExecutionEnvironment executionEnvironment(&hwInfo); + executionEnvironment.prepareRootDeviceEnvironments(1); + executionEnvironment.rootDeviceEnvironments[0]->builtins.reset(new BuiltIns); + executionEnvironment.releaseRootDeviceEnvironmentResources(executionEnvironment.rootDeviceEnvironments[0].get()); + EXPECT_EQ(nullptr, executionEnvironment.rootDeviceEnvironments[0]->builtins); +} + TEST(ExecutionEnvironmentWithAILTests, whenAILConfigurationIsNullptrAndEnableAILFlagIsTrueWhenInitializingAILThenReturnFalse) { DebugManagerStateRestore restore; debugManager.flags.EnableAIL.set(true); diff --git a/shared/test/unit_test/memory_manager/deferrable_allocation_deletion_tests.cpp b/shared/test/unit_test/memory_manager/deferrable_allocation_deletion_tests.cpp index 6d96a1fe97..0fa702e801 100644 --- a/shared/test/unit_test/memory_manager/deferrable_allocation_deletion_tests.cpp +++ b/shared/test/unit_test/memory_manager/deferrable_allocation_deletion_tests.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2023 Intel Corporation + * Copyright (C) 2018-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -223,6 +223,9 @@ TEST_F(DeferrableAllocationDeletionTest, givenAllocationUsedByUnregisteredEngine DeferrableAllocationDeletion deletion{*memoryManager, *allocation}; device.reset(); + for (const auto &rootDeviceEnvironment : executionEnvironment->rootDeviceEnvironments) { + executionEnvironment->releaseRootDeviceEnvironmentResources(rootDeviceEnvironment.get()); + } executionEnvironment->rootDeviceEnvironments.clear(); EXPECT_EQ(0u, memoryManager->getRegisteredEngines(rootDeviceIndex).size()); EXPECT_TRUE(allocation->isUsed()); diff --git a/shared/test/unit_test/os_interface/linux/drm_command_stream_tests_1.cpp b/shared/test/unit_test/os_interface/linux/drm_command_stream_tests_1.cpp index d610010802..6b1c70a2a5 100644 --- a/shared/test/unit_test/os_interface/linux/drm_command_stream_tests_1.cpp +++ b/shared/test/unit_test/os_interface/linux/drm_command_stream_tests_1.cpp @@ -62,17 +62,16 @@ HWTEST_TEMPLATED_F(DrmCommandStreamTest, givenDebugFlagSetWhenSubmittingThenCall uint32_t expectedExitCounter = 13; debugManager.flags.ExitOnSubmissionNumber.set(expectedExitCounter); + debugManager.flags.ForcePreemptionMode.set(PreemptionMode::Disabled); csr->initializeTagAllocation(); auto &cs = csr->getCS(); IndirectHeap ih(cs.getGraphicsAllocation()); DispatchFlags dispatchFlags = DispatchFlagsHelper::createDefaultDispatchFlags(); - dispatchFlags.preemptionMode = PreemptionMode::Disabled; executionEnvironment.incRefInternal(); std::unique_ptr device(MockDevice::create(&executionEnvironment, 0)); - device->setPreemptionMode(PreemptionMode::Disabled); bool bcsSupported = false; for (auto &engine : csr->getGfxCoreHelper().getGpgpuEngineInstances(device->getRootDeviceEnvironment())) { @@ -582,7 +581,7 @@ HWTEST_TEMPLATED_F(DrmCommandStreamBatchingTests, givenCsrWhenDispatchPolicyIsSe EXPECT_EQ(testedCsr->commandStream.getGraphicsAllocation(), recordedCmdBuffer->batchBuffer.commandBufferAllocation); - int ioctlUserPtrCnt = (device->getPreemptionMode() == PreemptionMode::MidThread) ? 4 : 3; + int ioctlUserPtrCnt = 3; ioctlUserPtrCnt += testedCsr->clearColorAllocation ? 1 : 0; EXPECT_EQ(ioctlUserPtrCnt, this->mock->ioctlCnt.total); @@ -662,7 +661,7 @@ HWTEST_TEMPLATED_F(DrmCommandStreamBatchingTests, givenRecordedCommandBufferWhen } int ioctlExecCnt = 1; - int ioctlUserPtrCnt = (device->getPreemptionMode() == PreemptionMode::MidThread) ? 3 : 2; + int ioctlUserPtrCnt = 2; ioctlUserPtrCnt += testedCsr->clearColorAllocation ? 1 : 0; EXPECT_EQ(ioctlExecCnt, this->mock->ioctlCnt.execbuffer2); EXPECT_EQ(ioctlUserPtrCnt, this->mock->ioctlCnt.gemUserptr);