diff --git a/runtime/device/device_caps.cpp b/runtime/device/device_caps.cpp index 1ac09c6542..5ef645d7e0 100644 --- a/runtime/device/device_caps.cpp +++ b/runtime/device/device_caps.cpp @@ -362,9 +362,13 @@ void Device::initializeCaps() { deviceInfo.preferredLocalAtomicAlignment = MemoryConstants::cacheLineSize; deviceInfo.preferredPlatformAtomicAlignment = MemoryConstants::cacheLineSize; - deviceInfo.sourceLevelDebuggerActive = (sourceLevelDebugger) ? sourceLevelDebugger->isDebuggerActive() : false; - if (deviceInfo.sourceLevelDebuggerActive) { - this->preemptionMode = PreemptionMode::Disabled; + if (hwInfo.capabilityTable.sourceLevelDebuggerSupported) { + deviceInfo.sourceLevelDebuggerActive = (sourceLevelDebugger) ? sourceLevelDebugger->isDebuggerActive() : false; + if (deviceInfo.sourceLevelDebuggerActive) { + this->preemptionMode = PreemptionMode::Disabled; + } + } else { + deviceInfo.sourceLevelDebuggerActive = false; } } } // namespace OCLRT diff --git a/runtime/gen8/hw_info_bdw.cpp b/runtime/gen8/hw_info_bdw.cpp index fa46bcbf8c..97d51437dd 100644 --- a/runtime/gen8/hw_info_bdw.cpp +++ b/runtime/gen8/hw_info_bdw.cpp @@ -73,7 +73,8 @@ const RuntimeCapabilityTable BDW::capabilityTable{ false, // ftr64KBpages EngineType::ENGINE_RCS, // defaultEngineType MemoryConstants::pageSize, //requiredPreemptionSurfaceSize - true // isCore + true, // isCore + false // sourceLevelDebuggerSupported }; const HardwareInfo BDW_1x2x6::hwInfo = { diff --git a/runtime/gen9/hw_info_bxt.cpp b/runtime/gen9/hw_info_bxt.cpp index d1415c68b8..cab765bdf8 100644 --- a/runtime/gen9/hw_info_bxt.cpp +++ b/runtime/gen9/hw_info_bxt.cpp @@ -70,7 +70,8 @@ const RuntimeCapabilityTable BXT::capabilityTable{ false, // ftr64KBpages EngineType::ENGINE_RCS, // defaultEngineType MemoryConstants::pageSize, //requiredPreemptionSurfaceSize - false // isCore + false, // isCore + true // sourceLevelDebuggerSupported }; const HardwareInfo BXT_1x2x6::hwInfo = { diff --git a/runtime/gen9/hw_info_cfl.cpp b/runtime/gen9/hw_info_cfl.cpp index 62f2bfbfe8..5e1d785ade 100644 --- a/runtime/gen9/hw_info_cfl.cpp +++ b/runtime/gen9/hw_info_cfl.cpp @@ -65,7 +65,8 @@ const RuntimeCapabilityTable CFL::capabilityTable{ true, // ftr64KBpages EngineType::ENGINE_RCS, // defaultEngineType MemoryConstants::pageSize, //requiredPreemptionSurfaceSize - true // isCore + true, // isCore + true // sourceLevelDebuggerSupported }; const HardwareInfo CFL_1x2x6::hwInfo = { diff --git a/runtime/gen9/hw_info_glk.cpp b/runtime/gen9/hw_info_glk.cpp index 0bc647446a..183d84c9d2 100644 --- a/runtime/gen9/hw_info_glk.cpp +++ b/runtime/gen9/hw_info_glk.cpp @@ -65,7 +65,8 @@ const RuntimeCapabilityTable GLK::capabilityTable{ false, // ftr64KBpages EngineType::ENGINE_RCS, // defaultEngineType MemoryConstants::pageSize, //requiredPreemptionSurfaceSize - false // isCore + false, // isCore + true // sourceLevelDebuggerSupported }; const HardwareInfo GLK_1x3x6::hwInfo = { diff --git a/runtime/gen9/hw_info_kbl.cpp b/runtime/gen9/hw_info_kbl.cpp index f5375d1bcd..d09bef9572 100644 --- a/runtime/gen9/hw_info_kbl.cpp +++ b/runtime/gen9/hw_info_kbl.cpp @@ -65,7 +65,8 @@ const RuntimeCapabilityTable KBL::capabilityTable{ true, // ftr64KBpages EngineType::ENGINE_RCS, // defaultEngineType MemoryConstants::pageSize, //requiredPreemptionSurfaceSize - true // isCore + true, // isCore + true // sourceLevelDebuggerSupported }; const HardwareInfo KBL_1x2x6::hwInfo = { diff --git a/runtime/gen9/hw_info_skl.cpp b/runtime/gen9/hw_info_skl.cpp index d659458ae0..1b992c2969 100644 --- a/runtime/gen9/hw_info_skl.cpp +++ b/runtime/gen9/hw_info_skl.cpp @@ -73,7 +73,8 @@ const RuntimeCapabilityTable SKL::capabilityTable{ true, // ftr64KBpages EngineType::ENGINE_RCS, // defaultEngineType MemoryConstants::pageSize, //requiredPreemptionSurfaceSize - true // isCore + true, // isCore + true // sourceLevelDebuggerSupported }; const HardwareInfo SKL_1x2x6::hwInfo = { diff --git a/runtime/helpers/hw_info.h b/runtime/helpers/hw_info.h index c463c4a7f5..a5db48a4a6 100644 --- a/runtime/helpers/hw_info.h +++ b/runtime/helpers/hw_info.h @@ -73,6 +73,7 @@ struct RuntimeCapabilityTable { size_t requiredPreemptionSurfaceSize; bool isCore; + bool sourceLevelDebuggerSupported; }; struct HardwareCapabilities { diff --git a/unit_tests/device/device_caps_tests.cpp b/unit_tests/device/device_caps_tests.cpp index 036d5d6d2c..aeee5a7bda 100644 --- a/unit_tests/device/device_caps_tests.cpp +++ b/unit_tests/device/device_caps_tests.cpp @@ -29,10 +29,13 @@ #include "runtime/os_interface/32bit_memory.h" #include "runtime/os_interface/debug_settings_manager.h" #include "runtime/os_interface/os_interface.h" +#include "runtime/source_level_debugger/source_level_debugger.h" #include "unit_tests/fixtures/device_fixture.h" #include "unit_tests/helpers/debug_manager_state_restore.h" +#include "unit_tests/helpers/hw_helper_tests.h" #include "unit_tests/mocks/mock_builtins.h" +#include "unit_tests/mocks/mock_device.h" #include "hw_cmds.h" #include "test.h" @@ -742,3 +745,24 @@ TEST(Device_GetCaps, GivenFlagEnabled64kbPagesWhenSetThenReturnCorrectValue) { OSInterface::osEnabled64kbPages = orgOsEnabled64kbPages; hwInfo.capabilityTable.ftr64KBpages = orgftr64KBpages; } + +TEST(Device_GetCaps, givenDeviceWithNullSourceLevelDebuggerWhenCapsAreInitializedThenSourceLevelDebuggerActiveIsSetToFalse) { + std::unique_ptr device(Device::create(platformDevices[0])); + + const auto &caps = device->getDeviceInfo(); + EXPECT_EQ(nullptr, device->getSourceLevelDebugger()); + EXPECT_FALSE(caps.sourceLevelDebuggerActive); +} + +typedef HwHelperTest DeviceCapsWithModifiedHwInfoTest; + +TEST_F(DeviceCapsWithModifiedHwInfoTest, givenPlatformWithSourceLevelDebuggerNotSupportedWhenDeviceIsCreatedThenSourceLevelDebuggerActiveIsSetToFalse) { + + hwInfo.capabilityTable.sourceLevelDebuggerSupported = false; + + std::unique_ptr> device(Device::create>(&hwInfo)); + + const auto &caps = device->getDeviceInfo(); + EXPECT_NE(nullptr, device->getSourceLevelDebugger()); + EXPECT_FALSE(caps.sourceLevelDebuggerActive); +} diff --git a/unit_tests/gen8/device_tests_gen8.cpp b/unit_tests/gen8/device_tests_gen8.cpp index 441f83e860..2e6aed3934 100644 --- a/unit_tests/gen8/device_tests_gen8.cpp +++ b/unit_tests/gen8/device_tests_gen8.cpp @@ -21,6 +21,8 @@ */ #include "unit_tests/fixtures/device_fixture.h" +#include "unit_tests/mocks/mock_device.h" +#include "unit_tests/mocks/mock_source_level_debugger.h" #include "test.h" using namespace OCLRT; @@ -39,3 +41,10 @@ BDWTEST_F(Gen8DeviceTest, givenGen8DeviceWhenAskedForClVersionThenReport21) { auto version = pDevice->getSupportedClVersion(); EXPECT_EQ(21u, version); } + +BDWTEST_F(Gen8DeviceTest, givenSourceLevelDebuggerAvailableWhenDeviceIsCreatedThenSourceLevelDebuggerIsDisabled) { + auto device = std::unique_ptr>(Device::create>(nullptr)); + const auto &caps = device->getDeviceInfo(); + EXPECT_NE(nullptr, device->getSourceLevelDebugger()); + EXPECT_FALSE(caps.sourceLevelDebuggerActive); +} diff --git a/unit_tests/mocks/mock_device.h b/unit_tests/mocks/mock_device.h index 2294d7d4e7..4e13727e3e 100644 --- a/unit_tests/mocks/mock_device.h +++ b/unit_tests/mocks/mock_device.h @@ -216,4 +216,13 @@ class MockAlignedMallocManagerDevice : public MockDevice { MockAlignedMallocManagerDevice(const HardwareInfo &hwInfo, bool isRootDevice = true); }; +template +class MockDeviceWithSourceLevelDebugger : public MockDevice { + public: + MockDeviceWithSourceLevelDebugger(const HardwareInfo &hwInfo, bool isRootDevice = true) : MockDevice(hwInfo, isRootDevice) { + T *sourceLevelDebuggerCreated = new T(nullptr); + sourceLevelDebugger.reset(sourceLevelDebuggerCreated); + } +}; + } // namespace OCLRT diff --git a/unit_tests/source_level_debugger/device_tests.cpp b/unit_tests/source_level_debugger/device_tests.cpp index 065ae25948..4809d8a647 100644 --- a/unit_tests/source_level_debugger/device_tests.cpp +++ b/unit_tests/source_level_debugger/device_tests.cpp @@ -107,7 +107,7 @@ TEST(DeviceCreation, givenDeviceWithDisabledPreemptionAndDebuggingActiveWhenDevi } TEST(DeviceWithSourceLevelDebugger, givenDeviceWithSourceLevelDebuggerActiveWhenDeviceIsDestructedThenSourceLevelDebuggerIsNotified) { - auto device = std::unique_ptr>(Device::create>(nullptr)); + auto device = std::unique_ptr>>(Device::create>>(nullptr)); GMockSourceLevelDebugger *gmock = device->getSourceLevelDebugger(); EXPECT_CALL(*gmock, notifyDeviceDestruction()).Times(1); } diff --git a/unit_tests/source_level_debugger/source_level_debugger_tests.cpp b/unit_tests/source_level_debugger/source_level_debugger_tests.cpp index b560a7e4d6..e253f26c2d 100644 --- a/unit_tests/source_level_debugger/source_level_debugger_tests.cpp +++ b/unit_tests/source_level_debugger/source_level_debugger_tests.cpp @@ -403,35 +403,39 @@ TEST(SourceLevelDebugger, givenKernelDebuggerLibraryActiveWhenDeviceIsConstructe TEST(SourceLevelDebugger, givenKernelDebuggerLibraryActiveWhenDeviceImplIsCreatedThenDebuggerIsNotified) { DebuggerLibraryRestorer restorer; - DebuggerLibraryInterceptor interceptor; - DebuggerLibrary::setLibraryAvailable(true); - DebuggerLibrary::setDebuggerActive(true); - DebuggerLibrary::injectDebuggerLibraryInterceptor(&interceptor); + if (platformDevices[0]->capabilityTable.sourceLevelDebuggerSupported) { + DebuggerLibraryInterceptor interceptor; + DebuggerLibrary::setLibraryAvailable(true); + DebuggerLibrary::setDebuggerActive(true); + DebuggerLibrary::injectDebuggerLibraryInterceptor(&interceptor); - unique_ptr device(new MockDevice(*platformDevices[0])); - MockDevice::createDeviceImpl(platformDevices[0], true, *device.get()); - EXPECT_TRUE(interceptor.newDeviceCalled); - uint32_t deviceHandleExpected = device->getCommandStreamReceiver().getOSInterface() != nullptr ? device->getCommandStreamReceiver().getOSInterface()->getDeviceHandle() : 0; - EXPECT_EQ(reinterpret_cast(static_cast(deviceHandleExpected)), interceptor.newDeviceArgIn.dh); + unique_ptr device(new MockDevice(*platformDevices[0])); + MockDevice::createDeviceImpl(platformDevices[0], true, *device.get()); + EXPECT_TRUE(interceptor.newDeviceCalled); + uint32_t deviceHandleExpected = device->getCommandStreamReceiver().getOSInterface() != nullptr ? device->getCommandStreamReceiver().getOSInterface()->getDeviceHandle() : 0; + EXPECT_EQ(reinterpret_cast(static_cast(deviceHandleExpected)), interceptor.newDeviceArgIn.dh); + } } TEST(SourceLevelDebugger, givenKernelDebuggerLibraryActiveWhenDeviceImplIsCreatedWithOsCsrThenDebuggerIsNotifiedWithCorrectDeviceHandle) { DebuggerLibraryRestorer restorer; - DebuggerLibraryInterceptor interceptor; - DebuggerLibrary::setLibraryAvailable(true); - DebuggerLibrary::setDebuggerActive(true); - DebuggerLibrary::injectDebuggerLibraryInterceptor(&interceptor); + if (platformDevices[0]->capabilityTable.sourceLevelDebuggerSupported) { + DebuggerLibraryInterceptor interceptor; + DebuggerLibrary::setLibraryAvailable(true); + DebuggerLibrary::setDebuggerActive(true); + DebuggerLibrary::injectDebuggerLibraryInterceptor(&interceptor); - overrideCommandStreamReceiverCreation = true; + overrideCommandStreamReceiverCreation = true; - // Device::create must be used to create correct OS memory manager - unique_ptr device(Device::create(platformDevices[0])); - ASSERT_NE(nullptr, device->getCommandStreamReceiver().getOSInterface()); + // Device::create must be used to create correct OS memory manager + unique_ptr device(Device::create(platformDevices[0])); + ASSERT_NE(nullptr, device->getCommandStreamReceiver().getOSInterface()); - EXPECT_TRUE(interceptor.newDeviceCalled); - uint32_t deviceHandleExpected = device->getCommandStreamReceiver().getOSInterface()->getDeviceHandle(); - EXPECT_EQ(reinterpret_cast(static_cast(deviceHandleExpected)), interceptor.newDeviceArgIn.dh); + EXPECT_TRUE(interceptor.newDeviceCalled); + uint32_t deviceHandleExpected = device->getCommandStreamReceiver().getOSInterface()->getDeviceHandle(); + EXPECT_EQ(reinterpret_cast(static_cast(deviceHandleExpected)), interceptor.newDeviceArgIn.dh); + } } TEST(SourceLevelDebugger, givenKernelDebuggerLibraryNotActiveWhenDeviceIsCreatedThenDebuggerIsNotCreatedInitializedAndNotNotified) {