From 9cc4d6fba11b4a56d14790c9eeaee2fe94ff02e4 Mon Sep 17 00:00:00 2001 From: Lukasz Jobczyk Date: Wed, 11 Mar 2020 08:56:55 +0100 Subject: [PATCH] Move debugger to root device environment Resolves: NEO-3857 Change-Id: I216ef0cfc4ed7e1ab67261378905c6c0ec40a17f Signed-off-by: Lukasz Jobczyk --- opencl/source/device/device_caps.cpp | 2 +- .../command_queue/enqueue_debug_kernel_tests.cpp | 2 +- .../execution_environment_tests.cpp | 4 ++-- opencl/test/unit_test/platform/platform_tests.cpp | 4 ++-- .../program/program_with_kernel_debug_tests.cpp | 14 +++++++------- .../source_level_debugger_device_tests.cpp | 5 +++-- .../source_level_debugger_tests.cpp | 10 +++++----- shared/source/device/device.cpp | 2 +- shared/source/device/device.h | 2 +- .../execution_environment.cpp | 13 ------------- .../execution_environment/execution_environment.h | 3 --- .../root_device_environment.cpp | 6 ++++++ .../root_device_environment.h | 11 +++++++---- 13 files changed, 36 insertions(+), 42 deletions(-) diff --git a/opencl/source/device/device_caps.cpp b/opencl/source/device/device_caps.cpp index 1f7e295b66..380be38c6a 100644 --- a/opencl/source/device/device_caps.cpp +++ b/opencl/source/device/device_caps.cpp @@ -168,7 +168,7 @@ void Device::initializeCaps() { deviceInfo.vmeAvcSupportsPreemption = hwInfo.capabilityTable.ftrSupportsVmeAvcPreemption; - deviceInfo.debuggerActive = (executionEnvironment->debugger) ? executionEnvironment->debugger->isDebuggerActive() : false; + deviceInfo.debuggerActive = (getRootDeviceEnvironment().debugger.get()) ? getRootDeviceEnvironment().debugger->isDebuggerActive() : false; if (deviceInfo.debuggerActive) { this->preemptionMode = PreemptionMode::Disabled; } diff --git a/opencl/test/unit_test/command_queue/enqueue_debug_kernel_tests.cpp b/opencl/test/unit_test/command_queue/enqueue_debug_kernel_tests.cpp index fb67bee7ae..8318a1ca39 100644 --- a/opencl/test/unit_test/command_queue/enqueue_debug_kernel_tests.cpp +++ b/opencl/test/unit_test/command_queue/enqueue_debug_kernel_tests.cpp @@ -33,7 +33,7 @@ class EnqueueDebugKernelTest : public ProgramSimpleFixture, void SetUp() override { ProgramSimpleFixture::SetUp(); device = pClDevice; - pDevice->executionEnvironment->debugger.reset(new SourceLevelDebugger(nullptr)); + pDevice->executionEnvironment->rootDeviceEnvironments[pDevice->getRootDeviceIndex()]->debugger.reset(new SourceLevelDebugger(nullptr)); if (pDevice->getHardwareInfo().platform.eRenderCoreFamily >= IGFX_GEN9_CORE) { pDevice->deviceInfo.debuggerActive = true; diff --git a/opencl/test/unit_test/execution_environment/execution_environment_tests.cpp b/opencl/test/unit_test/execution_environment/execution_environment_tests.cpp index 52f033a176..7afb0d5042 100644 --- a/opencl/test/unit_test/execution_environment/execution_environment_tests.cpp +++ b/opencl/test/unit_test/execution_environment/execution_environment_tests.cpp @@ -153,7 +153,7 @@ TEST(ExecutionEnvironment, givenExecutionEnvironmentWhenInitializeMemoryManagerI } static_assert(sizeof(ExecutionEnvironment) == sizeof(std::unique_ptr) + sizeof(std::vector) + - (is64bit ? 24 : 16), + (is64bit ? 16 : 12), "New members detected in ExecutionEnvironment, please ensure that destruction sequence of objects is correct"); TEST(ExecutionEnvironment, givenExecutionEnvironmentWithVariousMembersWhenItIsDestroyedThenDeleteSequenceIsSpecified) { @@ -194,7 +194,7 @@ TEST(ExecutionEnvironment, givenExecutionEnvironmentWithVariousMembersWhenItIsDe executionEnvironment->rootDeviceEnvironments[0]->aubCenter = std::make_unique(destructorId); executionEnvironment->rootDeviceEnvironments[0]->builtins = std::make_unique(destructorId); executionEnvironment->rootDeviceEnvironments[0]->compilerInterface = std::make_unique(destructorId); - executionEnvironment->debugger = std::make_unique(destructorId); + executionEnvironment->rootDeviceEnvironments[0]->debugger = std::make_unique(destructorId); executionEnvironment.reset(nullptr); EXPECT_EQ(8u, destructorId); diff --git a/opencl/test/unit_test/platform/platform_tests.cpp b/opencl/test/unit_test/platform/platform_tests.cpp index 5a454b39eb..89dfa1165c 100644 --- a/opencl/test/unit_test/platform/platform_tests.cpp +++ b/opencl/test/unit_test/platform/platform_tests.cpp @@ -151,7 +151,7 @@ TEST_F(PlatformTest, givenDisabledPreemptionInactiveSourceLevelDebuggerWhenIniti executionEnvironment->rootDeviceEnvironments[0]->builtins.reset(builtIns); auto sourceLevelDebugger = new MockSourceLevelDebugger(); sourceLevelDebugger->setActive(false); - pPlatform->peekExecutionEnvironment()->debugger.reset(sourceLevelDebugger); + executionEnvironment->rootDeviceEnvironments[0]->debugger.reset(sourceLevelDebugger); EXPECT_EQ(SipKernelType::COUNT, MockSipData::calledType); EXPECT_FALSE(MockSipData::called); @@ -168,7 +168,7 @@ TEST_F(PlatformTest, givenDisabledPreemptionActiveSourceLevelDebuggerWhenInitial auto executionEnvironment = pPlatform->peekExecutionEnvironment(); executionEnvironment->prepareRootDeviceEnvironments(1); executionEnvironment->rootDeviceEnvironments[0]->builtins.reset(builtIns); - pPlatform->peekExecutionEnvironment()->debugger.reset(new MockActiveSourceLevelDebugger()); + executionEnvironment->rootDeviceEnvironments[0]->debugger.reset(new MockActiveSourceLevelDebugger()); EXPECT_EQ(SipKernelType::COUNT, MockSipData::calledType); EXPECT_FALSE(MockSipData::called); diff --git a/opencl/test/unit_test/program/program_with_kernel_debug_tests.cpp b/opencl/test/unit_test/program/program_with_kernel_debug_tests.cpp index e21d8a907b..8cd064ccdf 100644 --- a/opencl/test/unit_test/program/program_with_kernel_debug_tests.cpp +++ b/opencl/test/unit_test/program/program_with_kernel_debug_tests.cpp @@ -102,7 +102,7 @@ TEST_F(ProgramWithKernelDebuggingTest, givenEnabledKernelDebugAndOptDisabledWhen MockActiveSourceLevelDebugger *sourceLevelDebugger = new MockActiveSourceLevelDebugger; sourceLevelDebugger->isOptDisabled = true; - pDevice->executionEnvironment->debugger.reset(sourceLevelDebugger); + pDevice->executionEnvironment->rootDeviceEnvironments[pDevice->getRootDeviceIndex()]->debugger.reset(sourceLevelDebugger); cl_int retVal = pProgram->compile(1, &device, nullptr, 0, nullptr, nullptr, @@ -117,7 +117,7 @@ TEST_F(ProgramWithKernelDebuggingTest, givenEnabledKernelDebugWhenProgramIsCompi if (pDevice->getHardwareInfo().platform.eRenderCoreFamily >= IGFX_GEN9_CORE) { MockActiveSourceLevelDebugger *sourceLevelDebugger = new MockActiveSourceLevelDebugger; sourceLevelDebugger->sourceCodeFilename = "debugFileName"; - pDevice->executionEnvironment->debugger.reset(sourceLevelDebugger); + pDevice->executionEnvironment->rootDeviceEnvironments[pDevice->getRootDeviceIndex()]->debugger.reset(sourceLevelDebugger); cl_int retVal = pProgram->compile(1, &device, nullptr, 0, nullptr, nullptr, @@ -157,7 +157,7 @@ TEST_F(ProgramWithKernelDebuggingTest, givenEnabledKernelDebugAndOptDisabledWhen MockActiveSourceLevelDebugger *sourceLevelDebugger = new MockActiveSourceLevelDebugger; sourceLevelDebugger->isOptDisabled = true; - pDevice->executionEnvironment->debugger.reset(sourceLevelDebugger); + pDevice->executionEnvironment->rootDeviceEnvironments[pDevice->getRootDeviceIndex()]->debugger.reset(sourceLevelDebugger); cl_int retVal = pProgram->build(1, &device, nullptr, nullptr, nullptr, false); EXPECT_EQ(CL_SUCCESS, retVal); @@ -170,7 +170,7 @@ TEST_F(ProgramWithKernelDebuggingTest, givenEnabledKernelDebugWhenProgramIsBuilt MockActiveSourceLevelDebugger *sourceLevelDebugger = new MockActiveSourceLevelDebugger; sourceLevelDebugger->sourceCodeFilename = "debugFileName"; - pDevice->executionEnvironment->debugger.reset(sourceLevelDebugger); + pDevice->executionEnvironment->rootDeviceEnvironments[pDevice->getRootDeviceIndex()]->debugger.reset(sourceLevelDebugger); cl_int retVal = pProgram->build(1, &device, nullptr, nullptr, nullptr, false); EXPECT_EQ(CL_SUCCESS, retVal); @@ -182,7 +182,7 @@ TEST_F(ProgramWithKernelDebuggingTest, givenEnabledKernelDebugWhenProgramIsLinke if (pDevice->getHardwareInfo().platform.eRenderCoreFamily >= IGFX_GEN9_CORE) { MockActiveSourceLevelDebugger *sourceLevelDebugger = new MockActiveSourceLevelDebugger; - pDevice->executionEnvironment->debugger.reset(sourceLevelDebugger); + pDevice->executionEnvironment->rootDeviceEnvironments[pDevice->getRootDeviceIndex()]->debugger.reset(sourceLevelDebugger); cl_int retVal = pProgram->compile(1, &device, nullptr, 0, nullptr, nullptr, nullptr, nullptr); EXPECT_EQ(CL_SUCCESS, retVal); @@ -210,7 +210,7 @@ TEST_F(ProgramWithKernelDebuggingTest, givenEnabledKernelDebugWhenProgramIsBuilt EXPECT_CALL(*sourceLevelDebugger, notifyKernelDebugData(::testing::_, ::testing::_, ::testing::_, ::testing::_)).Times(1); sourceLevelDebugger->setActive(true); - pDevice->executionEnvironment->debugger.reset(sourceLevelDebugger); + pDevice->executionEnvironment->rootDeviceEnvironments[pDevice->getRootDeviceIndex()]->debugger.reset(sourceLevelDebugger); cl_int retVal = pProgram->build(1, &device, nullptr, nullptr, nullptr, false); EXPECT_EQ(CL_SUCCESS, retVal); @@ -229,7 +229,7 @@ TEST_F(ProgramWithKernelDebuggingTest, givenEnabledKernelDebugWhenProgramIsLinke EXPECT_CALL(*sourceLevelDebugger, notifyKernelDebugData(::testing::_, ::testing::_, ::testing::_, ::testing::_)).Times(1); sourceLevelDebugger->setActive(true); - pDevice->executionEnvironment->debugger.reset(sourceLevelDebugger); + pDevice->executionEnvironment->rootDeviceEnvironments[pDevice->getRootDeviceIndex()]->debugger.reset(sourceLevelDebugger); cl_int retVal = pProgram->compile(1, &device, nullptr, 0, nullptr, nullptr, diff --git a/opencl/test/unit_test/source_level_debugger/source_level_debugger_device_tests.cpp b/opencl/test/unit_test/source_level_debugger/source_level_debugger_device_tests.cpp index c2e2af0cf4..1d966e5999 100644 --- a/opencl/test/unit_test/source_level_debugger/source_level_debugger_device_tests.cpp +++ b/opencl/test/unit_test/source_level_debugger/source_level_debugger_device_tests.cpp @@ -40,7 +40,8 @@ class MockDeviceWithDebuggerActive : public MockDevice { TEST(DeviceWithSourceLevelDebugger, givenDeviceWithSourceLevelDebuggerActiveWhenDeviceIsDestructedThenSourceLevelDebuggerIsNotified) { ExecutionEnvironment *executionEnvironment = platform()->peekExecutionEnvironment(); auto gmock = new ::testing::NiceMock(new MockOsLibrary); - executionEnvironment->debugger.reset(gmock); + + executionEnvironment->rootDeviceEnvironments[0]->debugger.reset(gmock); auto device = std::make_unique(MockDevice::create(executionEnvironment, 0u)); EXPECT_CALL(*gmock, notifyDeviceDestruction()).Times(1); @@ -48,7 +49,7 @@ TEST(DeviceWithSourceLevelDebugger, givenDeviceWithSourceLevelDebuggerActiveWhen TEST(DeviceWithSourceLevelDebugger, givenDeviceWithSourceLevelDebuggerActiveWhenDeviceIsCreatedThenPreemptionIsDisabled) { ExecutionEnvironment *executionEnvironment = platform()->peekExecutionEnvironment(); - executionEnvironment->debugger.reset(new MockActiveSourceLevelDebugger(new MockOsLibrary)); + executionEnvironment->rootDeviceEnvironments[0]->debugger.reset(new MockActiveSourceLevelDebugger(new MockOsLibrary)); auto device = std::unique_ptr(MockDevice::create(executionEnvironment, 0u)); EXPECT_EQ(PreemptionMode::Disabled, device->getPreemptionMode()); diff --git a/opencl/test/unit_test/source_level_debugger/source_level_debugger_tests.cpp b/opencl/test/unit_test/source_level_debugger/source_level_debugger_tests.cpp index aac0cf85ab..91ab1c4aab 100644 --- a/opencl/test/unit_test/source_level_debugger/source_level_debugger_tests.cpp +++ b/opencl/test/unit_test/source_level_debugger/source_level_debugger_tests.cpp @@ -53,7 +53,7 @@ TEST(SourceLevelDebugger, givenPlatformWhenItIsCreatedThenSourceLevelDebuggerIsC MockPlatform platform(*executionEnvironment); platform.initializeWithNewDevices(); - EXPECT_NE(nullptr, executionEnvironment->debugger); + EXPECT_NE(nullptr, executionEnvironment->rootDeviceEnvironments[0]->debugger); } } @@ -527,7 +527,7 @@ TEST(SourceLevelDebugger, givenKernelDebuggerLibraryNotActiveWhenDeviceIsCreated EXPECT_FALSE(interceptor.newDeviceCalled); } -TEST(SourceLevelDebugger, givenTwoRootDevicesWhenSecondIsCreatedThenNotCreatingNewSourceLevelDebugger) { +TEST(SourceLevelDebugger, givenTwoRootDevicesWhenSecondIsCreatedThenCreatingNewSourceLevelDebugger) { DebuggerLibraryRestorer restorer; if (platformDevices[0]->capabilityTable.debuggerSupported) { @@ -548,11 +548,11 @@ TEST(SourceLevelDebugger, givenTwoRootDevicesWhenSecondIsCreatedThenNotCreatingN interceptor.initCalled = false; auto device2 = std::make_unique(Device::create(executionEnvironment, 1u)); EXPECT_NE(nullptr, executionEnvironment->memoryManager); - EXPECT_FALSE(interceptor.initCalled); + EXPECT_TRUE(interceptor.initCalled); } } -TEST(SourceLevelDebugger, givenMultipleRootDevicesWhenTheyAreCreatedTheyAllReuseTheSameSourceLevelDebugger) { +TEST(SourceLevelDebugger, givenMultipleRootDevicesWhenTheyAreCreatedTheyUseDedicatedSourceLevelDebugger) { DebuggerLibraryRestorer restorer; if (platformDevices[0]->capabilityTable.debuggerSupported) { @@ -567,6 +567,6 @@ TEST(SourceLevelDebugger, givenMultipleRootDevicesWhenTheyAreCreatedTheyAllReuse auto device1 = std::make_unique(Device::create(executionEnvironment, 0u)); auto sourceLevelDebugger = device1->getDebugger(); auto device2 = std::make_unique(Device::create(executionEnvironment, 1u)); - EXPECT_EQ(sourceLevelDebugger, device2->getDebugger()); + EXPECT_NE(sourceLevelDebugger, device2->getDebugger()); } } diff --git a/shared/source/device/device.cpp b/shared/source/device/device.cpp index c658045611..7437028011 100644 --- a/shared/source/device/device.cpp +++ b/shared/source/device/device.cpp @@ -51,7 +51,7 @@ bool Device::createDeviceImpl() { preemptionMode = PreemptionHelper::getDefaultPreemptionMode(hwInfo); if (!getDebugger()) { - this->executionEnvironment->initDebugger(); + this->executionEnvironment->rootDeviceEnvironments[getRootDeviceIndex()]->initDebugger(); } auto &hwHelper = HwHelper::get(hwInfo.platform.eRenderCoreFamily); hwHelper.setupHardwareCapabilities(&this->hardwareCapabilities, hwInfo); diff --git a/shared/source/device/device.h b/shared/source/device/device.h index 20d68e01c8..b3a062380e 100644 --- a/shared/source/device/device.h +++ b/shared/source/device/device.h @@ -51,7 +51,7 @@ class Device : public ReferenceTrackedObject { PerformanceCounters *getPerformanceCounters() { return performanceCounters.get(); } PreemptionMode getPreemptionMode() const { return preemptionMode; } MOCKABLE_VIRTUAL bool isDebuggerActive() const; - Debugger *getDebugger() { return executionEnvironment->debugger.get(); } + Debugger *getDebugger() { return getRootDeviceEnvironment().debugger.get(); } ExecutionEnvironment *getExecutionEnvironment() const { return executionEnvironment; } const RootDeviceEnvironment &getRootDeviceEnvironment() const { return *executionEnvironment->rootDeviceEnvironments[getRootDeviceIndex()]; } const HardwareCapabilities &getHardwareCapabilities() const { return hardwareCapabilities; } diff --git a/shared/source/execution_environment/execution_environment.cpp b/shared/source/execution_environment/execution_environment.cpp index e499217b7e..850754b928 100644 --- a/shared/source/execution_environment/execution_environment.cpp +++ b/shared/source/execution_environment/execution_environment.cpp @@ -7,12 +7,7 @@ #include "shared/source/execution_environment/execution_environment.h" -#include "shared/source/built_ins/built_ins.h" -#include "shared/source/compiler_interface/compiler_interface.h" -#include "shared/source/compiler_interface/default_cache_config.h" -#include "shared/source/debugger/debugger.h" #include "shared/source/execution_environment/root_device_environment.h" -#include "shared/source/gmm_helper/gmm_helper.h" #include "shared/source/helpers/hw_helper.h" #include "opencl/source/memory_manager/os_agnostic_memory_manager.h" @@ -21,10 +16,6 @@ namespace NEO { ExecutionEnvironment::ExecutionEnvironment() = default; ExecutionEnvironment::~ExecutionEnvironment() { - debugger.reset(); - for (auto &rootDeviceEnvironment : rootDeviceEnvironments) { - rootDeviceEnvironment->builtins.reset(); - } if (memoryManager) { memoryManager->commonCleanup(); } @@ -56,10 +47,6 @@ void ExecutionEnvironment::initializeMemoryManager() { DEBUG_BREAK_IF(!this->memoryManager); } -void ExecutionEnvironment::initDebugger() { - debugger = Debugger::create(rootDeviceEnvironments[0]->getMutableHardwareInfo()); -} - void ExecutionEnvironment::calculateMaxOsContextCount() { for (const auto &rootDeviceEnvironment : this->rootDeviceEnvironments) { auto hwInfo = rootDeviceEnvironment->getHardwareInfo(); diff --git a/shared/source/execution_environment/execution_environment.h b/shared/source/execution_environment/execution_environment.h index eab030bf13..37655ae1e8 100644 --- a/shared/source/execution_environment/execution_environment.h +++ b/shared/source/execution_environment/execution_environment.h @@ -12,7 +12,6 @@ namespace NEO { class MemoryManager; -class Debugger; struct RootDeviceEnvironment; class ExecutionEnvironment : public ReferenceTrackedObject { @@ -22,12 +21,10 @@ class ExecutionEnvironment : public ReferenceTrackedObject ~ExecutionEnvironment() override; void initializeMemoryManager(); - void initDebugger(); void calculateMaxOsContextCount(); void prepareRootDeviceEnvironments(uint32_t numRootDevices); std::unique_ptr memoryManager; std::vector> rootDeviceEnvironments; - std::unique_ptr debugger; }; } // namespace NEO diff --git a/shared/source/execution_environment/root_device_environment.cpp b/shared/source/execution_environment/root_device_environment.cpp index e697422902..13fb4db993 100644 --- a/shared/source/execution_environment/root_device_environment.cpp +++ b/shared/source/execution_environment/root_device_environment.cpp @@ -10,6 +10,7 @@ #include "shared/source/built_ins/built_ins.h" #include "shared/source/compiler_interface/compiler_interface.h" #include "shared/source/compiler_interface/default_cache_config.h" +#include "shared/source/debugger/debugger.h" #include "shared/source/execution_environment/execution_environment.h" #include "shared/source/gmm_helper/gmm_helper.h" #include "shared/source/gmm_helper/page_table_mngr.h" @@ -32,6 +33,11 @@ void RootDeviceEnvironment::initAubCenter(bool localMemoryEnabled, const std::st aubCenter.reset(new AubCenter(getHardwareInfo(), localMemoryEnabled, aubFileName, csrType)); } } + +void RootDeviceEnvironment::initDebugger() { + debugger = Debugger::create(hwInfo.get()); +} + const HardwareInfo *RootDeviceEnvironment::getHardwareInfo() const { return hwInfo.get(); } diff --git a/shared/source/execution_environment/root_device_environment.h b/shared/source/execution_environment/root_device_environment.h index ea9343022b..90da721a75 100644 --- a/shared/source/execution_environment/root_device_environment.h +++ b/shared/source/execution_environment/root_device_environment.h @@ -15,17 +15,18 @@ namespace NEO { +class AubCenter; class BuiltIns; class CompilerInterface; -class AubCenter; +class Debugger; +class ExecutionEnvironment; class GmmClientContext; class GmmHelper; -class ExecutionEnvironment; class GmmPageTableMngr; +class HwDeviceId; class MemoryOperationsHandler; class OSInterface; struct HardwareInfo; -class HwDeviceId; struct RootDeviceEnvironment { protected: @@ -44,6 +45,7 @@ struct RootDeviceEnvironment { MOCKABLE_VIRTUAL void initAubCenter(bool localMemoryEnabled, const std::string &aubFileName, CommandStreamReceiverType csrType); bool initOsInterface(std::unique_ptr &&hwDeviceId); void initGmm(); + void initDebugger(); GmmHelper *getGmmHelper() const; GmmClientContext *getGmmClientContext() const; MOCKABLE_VIRTUAL CompilerInterface *getCompilerInterface(); @@ -55,8 +57,9 @@ struct RootDeviceEnvironment { std::unique_ptr memoryOperationsInterface; std::unique_ptr aubCenter; - std::unique_ptr builtins; std::unique_ptr compilerInterface; + std::unique_ptr builtins; + std::unique_ptr debugger; ExecutionEnvironment &executionEnvironment; private: