From 9a86f86a246694b59ff268745e4da2547a1e535e Mon Sep 17 00:00:00 2001 From: "Hoppe, Mateusz" Date: Fri, 6 Apr 2018 14:25:22 +0200 Subject: [PATCH] Source Level Debugger device debugger active flag - device flag indicating if debugger is active - when active, proper sip kernels must be used Change-Id: I678367cdf8fab5d4b5770e3f471246ff6d6bd112 --- runtime/built_ins/sip.cpp | 6 ++++++ runtime/built_ins/sip.h | 2 ++ runtime/command_stream/command_stream_receiver_hw.inl | 3 ++- runtime/command_stream/preemption.inl | 3 ++- runtime/device/device.cpp | 4 ++++ runtime/device/device.h | 1 + runtime/device/device_caps.cpp | 2 ++ runtime/device/device_info.h | 3 ++- runtime/gen9/hw_helper.cpp | 10 +++++++++- runtime/helpers/hw_helper.h | 4 ++++ runtime/helpers/hw_helper.inl | 7 +++++++ unit_tests/built_ins/sip_tests.cpp | 11 +++++++++++ unit_tests/gen9/hw_helper_tests.cpp | 7 +++++++ unit_tests/gen9/sip_tests.cpp | 5 +++++ unit_tests/helpers/hw_helper_tests.cpp | 8 ++++++++ 15 files changed, 72 insertions(+), 4 deletions(-) diff --git a/runtime/built_ins/sip.cpp b/runtime/built_ins/sip.cpp index 81f8a4f78e..fcdae1a578 100644 --- a/runtime/built_ins/sip.cpp +++ b/runtime/built_ins/sip.cpp @@ -22,6 +22,7 @@ #include "runtime/built_ins/sip.h" #include "runtime/device/device.h" +#include "runtime/helpers/hw_helper.h" #include "runtime/helpers/ptr_math.h" #include "runtime/program/program.h" #include "runtime/helpers/debug_helpers.h" @@ -94,4 +95,9 @@ size_t SipKernel::getBinarySize() const { auto kernelInfo = program->getKernelInfo(size_t{0}); return kernelInfo->heapInfo.pKernelHeader->KernelHeapSize - kernelInfo->systemKernelOffset; } + +SipKernelType SipKernel::getSipKernelType(GFXCORE_FAMILY family, bool debuggingActive) { + auto &hwHelper = HwHelper::get(family); + return hwHelper.getSipKernelType(debuggingActive); +} } diff --git a/runtime/built_ins/sip.h b/runtime/built_ins/sip.h index 01d19d706d..6fc4b904d0 100644 --- a/runtime/built_ins/sip.h +++ b/runtime/built_ins/sip.h @@ -21,6 +21,7 @@ */ #pragma once +#include "runtime/helpers/hw_info.h" #include #include @@ -61,6 +62,7 @@ class SipKernel { static const size_t maxDbgSurfaceSize; GraphicsAllocation *getSipAllocation() const; + static SipKernelType getSipKernelType(GFXCORE_FAMILY family, bool debuggingActive); protected: SipKernelType type = SipKernelType::COUNT; diff --git a/runtime/command_stream/command_stream_receiver_hw.inl b/runtime/command_stream/command_stream_receiver_hw.inl index bbf857ca93..6d5e8599b4 100644 --- a/runtime/command_stream/command_stream_receiver_hw.inl +++ b/runtime/command_stream/command_stream_receiver_hw.inl @@ -313,7 +313,8 @@ CompletionStamp CommandStreamReceiverHw::flushTask( makeResident(*preemptionCsrAllocation); if (dispatchFlags.preemptionMode == PreemptionMode::MidThread) { - makeResident(*BuiltIns::getInstance().getSipKernel(SipKernelType::Csr, *device).getSipAllocation()); + auto sipType = SipKernel::getSipKernelType(device->getHardwareInfo().pPlatform->eRenderCoreFamily, device->isSourceLevelDebuggerActive()); + makeResident(*BuiltIns::getInstance().getSipKernel(sipType, *device).getSipAllocation()); } // If the CSR has work in its CS, flush it before the task diff --git a/runtime/command_stream/preemption.inl b/runtime/command_stream/preemption.inl index 8ed136d2fe..ab4188d1d0 100644 --- a/runtime/command_stream/preemption.inl +++ b/runtime/command_stream/preemption.inl @@ -90,7 +90,8 @@ void PreemptionHelper::programPreamble(LinearStream &preambleCmdStream, Device & auto sip = reinterpret_cast(preambleCmdStream.getSpace(sizeof(STATE_SIP))); sip->init(); - sip->setSystemInstructionPointer(BuiltIns::getInstance().getSipKernel(SipKernelType::Csr, device).getSipAllocation()->getGpuAddressToPatch()); + auto sipType = SipKernel::getSipKernelType(device.getHardwareInfo().pPlatform->eRenderCoreFamily, device.isSourceLevelDebuggerActive()); + sip->setSystemInstructionPointer(BuiltIns::getInstance().getSipKernel(sipType, device).getSipAllocation()->getGpuAddressToPatch()); } template diff --git a/runtime/device/device.cpp b/runtime/device/device.cpp index 4b95b08784..77b64036fe 100644 --- a/runtime/device/device.cpp +++ b/runtime/device/device.cpp @@ -254,4 +254,8 @@ double Device::getPlatformHostTimerResolution() const { GFXCORE_FAMILY Device::getRenderCoreFamily() const { return this->getHardwareInfo().pPlatform->eRenderCoreFamily; } + +bool Device::isSourceLevelDebuggerActive() { + return deviceInfo.sourceLevelDebuggerActive; +} } // namespace OCLRT diff --git a/runtime/device/device.h b/runtime/device/device.h index 8e39feeaa4..924c056b08 100644 --- a/runtime/device/device.h +++ b/runtime/device/device.h @@ -133,6 +133,7 @@ class Device : public BaseObject<_cl_device_id> { std::vector simultaneousInterops; std::string deviceExtensions; bool getEnabled64kbPages(); + bool isSourceLevelDebuggerActive(); protected: Device() = delete; diff --git a/runtime/device/device_caps.cpp b/runtime/device/device_caps.cpp index 3d6219bea3..c85a6fa055 100644 --- a/runtime/device/device_caps.cpp +++ b/runtime/device/device_caps.cpp @@ -352,5 +352,7 @@ void Device::initializeCaps() { deviceInfo.preferredGlobalAtomicAlignment = MemoryConstants::cacheLineSize; deviceInfo.preferredLocalAtomicAlignment = MemoryConstants::cacheLineSize; deviceInfo.preferredPlatformAtomicAlignment = MemoryConstants::cacheLineSize; + + deviceInfo.sourceLevelDebuggerActive = false; } } // namespace OCLRT diff --git a/runtime/device/device_info.h b/runtime/device/device_info.h index 522551c708..32964dc5de 100644 --- a/runtime/device/device_info.h +++ b/runtime/device/device_info.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, Intel Corporation + * Copyright (c) 2017 - 2018, Intel Corporation * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -150,5 +150,6 @@ struct DeviceInfo { bool packedYuvExtension; cl_uint internalDriverVersion; bool enabled64kbPages; + bool sourceLevelDebuggerActive; }; // clang-format on diff --git a/runtime/gen9/hw_helper.cpp b/runtime/gen9/hw_helper.cpp index 62c4efedab..2265ded115 100644 --- a/runtime/gen9/hw_helper.cpp +++ b/runtime/gen9/hw_helper.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, Intel Corporation + * Copyright (c) 2017 - 2018, Intel Corporation * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -37,5 +37,13 @@ bool HwHelperHw::setupPreemptionRegisters(HardwareInfo *pHwInfo, bool en return pHwInfo->capabilityTable.whitelistedRegisters.csChicken1_0x2580; } +template <> +SipKernelType HwHelperHw::getSipKernelType(bool debuggingActive) { + if (!debuggingActive) { + return SipKernelType::Csr; + } + return SipKernelType::DbgCsrLocal; +} + template class HwHelperHw; } // namespace OCLRT diff --git a/runtime/helpers/hw_helper.h b/runtime/helpers/hw_helper.h index 4189aafbb2..a0e9e0000e 100644 --- a/runtime/helpers/hw_helper.h +++ b/runtime/helpers/hw_helper.h @@ -23,6 +23,7 @@ #pragma once #include "runtime/gen_common/hw_cmds.h" #include "runtime/command_stream/linear_stream.h" +#include "runtime/built_ins/sip.h" #include #include @@ -42,6 +43,7 @@ class HwHelper { virtual bool setupPreemptionRegisters(HardwareInfo *pHwInfo, bool enable) = 0; virtual void adjustDefaultEngineType(HardwareInfo *pHwInfo) = 0; virtual void setupHardwareCapabilities(HardwareCapabilities *caps) = 0; + virtual SipKernelType getSipKernelType(bool debuggingActive) = 0; protected: HwHelper(){}; @@ -87,6 +89,8 @@ class HwHelperHw : public HwHelper { void setupHardwareCapabilities(HardwareCapabilities *caps) override; + SipKernelType getSipKernelType(bool debuggingActive) override; + private: HwHelperHw(){}; }; diff --git a/runtime/helpers/hw_helper.inl b/runtime/helpers/hw_helper.inl index 4bf281f34d..c1a10394c3 100644 --- a/runtime/helpers/hw_helper.inl +++ b/runtime/helpers/hw_helper.inl @@ -39,4 +39,11 @@ void HwHelperHw::setupHardwareCapabilities(HardwareCapabilities *caps) { caps->image3DMaxWidth = 16384; } +template +SipKernelType HwHelperHw::getSipKernelType(bool debuggingActive) { + if (!debuggingActive) { + return SipKernelType::Csr; + } + return SipKernelType::DbgCsr; +} } // namespace OCLRT diff --git a/unit_tests/built_ins/sip_tests.cpp b/unit_tests/built_ins/sip_tests.cpp index 3de3d97597..61950305c7 100644 --- a/unit_tests/built_ins/sip_tests.cpp +++ b/unit_tests/built_ins/sip_tests.cpp @@ -25,6 +25,7 @@ #include "runtime/built_ins/built_ins.h" #include "runtime/built_ins/sip.h" +#include "runtime/helpers/options.h" #include "unit_tests/global_environment.h" #include "unit_tests/helpers/test_files.h" #include "unit_tests/mocks/mock_device.h" @@ -114,6 +115,16 @@ TEST(Sip, givenSipKernelClassWhenAskedForMaxDebugSurfaceSizeThenCorrectValueIsRe EXPECT_EQ(0x49c000u, SipKernel::maxDbgSurfaceSize); } +TEST(Sip, givenDebuggingInactiveWhenSipTypeIsQueriedThenCsrSipTypeIsReturned) { + auto sipType = SipKernel::getSipKernelType(renderCoreFamily, false); + EXPECT_EQ(SipKernelType::Csr, sipType); +} + +TEST(DebugSip, givenDebuggingActiveWhenSipTypeIsQueriedThenDbgCsrSipTypeIsReturned) { + auto sipType = SipKernel::getSipKernelType(renderCoreFamily, true); + EXPECT_LE(SipKernelType::DbgCsr, sipType); +} + TEST(DebugSip, WhenRequestingDbgCsrSipKernelThenProperCompilerInternalOptionsAreReturned) { const char *opt = getSipKernelCompilerInternalOptions(SipKernelType::DbgCsr); ASSERT_NE(nullptr, opt); diff --git a/unit_tests/gen9/hw_helper_tests.cpp b/unit_tests/gen9/hw_helper_tests.cpp index 6ffd1d65be..ee0648cf99 100644 --- a/unit_tests/gen9/hw_helper_tests.cpp +++ b/unit_tests/gen9/hw_helper_tests.cpp @@ -64,3 +64,10 @@ GEN9TEST_F(HwHelperTestSkl, givenGen9PlatformWhenSetupHardwareCapabilitiesIsCall // Test default method implementation testDefaultImplementationOfSetupHardwareCapabilities(helper); } + +GEN9TEST_F(HwHelperTestSkl, givenDebuggingActiveWhenSipKernelTypeIsQueriedThenDbgCsrLocalTypeIsReturned) { + auto &helper = HwHelper::get(renderCoreFamily); + + auto sipType = helper.getSipKernelType(true); + EXPECT_EQ(SipKernelType::DbgCsrLocal, sipType); +} diff --git a/unit_tests/gen9/sip_tests.cpp b/unit_tests/gen9/sip_tests.cpp index e0fd98438a..363dd53ed2 100644 --- a/unit_tests/gen9/sip_tests.cpp +++ b/unit_tests/gen9/sip_tests.cpp @@ -58,4 +58,9 @@ GEN9TEST_F(gen9SipTests, DISABLED_givenDebugCsrSipKernelWithLocalMemoryWhenAsked gEnvironment->igcPopDebugVars(); } + +GEN9TEST_F(gen9SipTests, givenDebuggingActiveWhenSipTypeIsQueriedThenDbgCsrLocalIsReturned) { + auto sipType = SipKernel::getSipKernelType(renderCoreFamily, true); + EXPECT_EQ(SipKernelType::DbgCsrLocal, sipType); +} } // namespace SipKernelTests diff --git a/unit_tests/helpers/hw_helper_tests.cpp b/unit_tests/helpers/hw_helper_tests.cpp index e7987c77b1..c8fdfa3f91 100644 --- a/unit_tests/helpers/hw_helper_tests.cpp +++ b/unit_tests/helpers/hw_helper_tests.cpp @@ -75,6 +75,14 @@ HWTEST_F(HwHelperTest, getInterfaceDescriptorDataSizeReturnsCorrectSize) { EXPECT_EQ(sizeof(INTERFACE_DESCRIPTOR_DATA), helper.getInterfaceDescriptorDataSize()); } +HWTEST_F(HwHelperTest, givenDebuggingInactiveWhenSipKernelTypeIsQueriedThenCsrTypeIsReturned) { + auto &helper = HwHelper::get(renderCoreFamily); + EXPECT_NE(nullptr, &helper); + + auto sipType = helper.getSipKernelType(false); + EXPECT_EQ(SipKernelType::Csr, sipType); +} + TEST(DwordBuilderTest, setNonMaskedBits) { uint32_t dword = 0;