Move SourceLevelDebugger ownership to execution environment

Change-Id: I7fc6fd1cde2e450dbd41a164f915373e80a4aaf8
This commit is contained in:
Jobczyk, Lukasz
2018-07-12 15:47:48 +02:00
committed by sys_ocldev
parent 6112ce4e8f
commit eebb919c18
12 changed files with 109 additions and 46 deletions

View File

@@ -88,11 +88,8 @@ Device::Device(const HardwareInfo &hwInfo, ExecutionEnvironment *executionEnviro
engineType = DebugManager.flags.NodeOrdinal.get() == -1
? hwInfo.capabilityTable.defaultEngineType
: static_cast<EngineType>(DebugManager.flags.NodeOrdinal.get());
sourceLevelDebugger.reset(SourceLevelDebugger::create());
if (sourceLevelDebugger) {
bool localMemorySipAvailable = (SipKernelType::DbgCsrLocal == SipKernel::getSipKernelType(hwInfo.pPlatform->eRenderCoreFamily, true));
sourceLevelDebugger->initialize(localMemorySipAvailable);
if (!getSourceLevelDebugger()) {
this->executionEnvironment->initSourceLevelDebugger(hwInfo);
}
this->executionEnvironment->incRefInternal();
}
@@ -109,8 +106,8 @@ Device::~Device() {
executionEnvironment->commandStreamReceiver->flushBatchedSubmissions();
}
if (deviceInfo.sourceLevelDebuggerActive && sourceLevelDebugger) {
sourceLevelDebugger->notifyDeviceDestruction();
if (deviceInfo.sourceLevelDebuggerActive && executionEnvironment->sourceLevelDebugger) {
executionEnvironment->sourceLevelDebugger->notifyDeviceDestruction();
}
if (executionEnvironment->memoryManager) {
@@ -166,7 +163,7 @@ bool Device::createDeviceImpl(const HardwareInfo *pHwInfo, Device &outDevice) {
}
if (pDevice->deviceInfo.sourceLevelDebuggerActive) {
pDevice->sourceLevelDebugger->notifyNewDevice(deviceHandle);
pDevice->executionEnvironment->sourceLevelDebugger->notifyNewDevice(deviceHandle);
}
outDevice.executionEnvironment->memoryManager->setForce32BitAllocations(pDevice->getDeviceInfo().force32BitAddressess);

View File

@@ -129,7 +129,7 @@ class Device : public BaseObject<_cl_device_id> {
std::string name;
bool getEnabled64kbPages();
bool isSourceLevelDebuggerActive() const;
SourceLevelDebugger *getSourceLevelDebugger() { return sourceLevelDebugger.get(); }
SourceLevelDebugger *getSourceLevelDebugger() { return executionEnvironment->sourceLevelDebugger.get(); }
protected:
Device() = delete;
@@ -168,7 +168,6 @@ class Device : public BaseObject<_cl_device_id> {
PreemptionMode preemptionMode;
EngineType engineType;
std::unique_ptr<SourceLevelDebugger> sourceLevelDebugger;
ExecutionEnvironment *executionEnvironment = nullptr;
};

View File

@@ -356,13 +356,9 @@ void Device::initializeCaps() {
deviceInfo.preferredLocalAtomicAlignment = MemoryConstants::cacheLineSize;
deviceInfo.preferredPlatformAtomicAlignment = MemoryConstants::cacheLineSize;
if (hwInfo.capabilityTable.sourceLevelDebuggerSupported) {
deviceInfo.sourceLevelDebuggerActive = (sourceLevelDebugger) ? sourceLevelDebugger->isDebuggerActive() : false;
if (deviceInfo.sourceLevelDebuggerActive) {
this->preemptionMode = PreemptionMode::Disabled;
}
} else {
deviceInfo.sourceLevelDebuggerActive = false;
deviceInfo.sourceLevelDebuggerActive = (executionEnvironment->sourceLevelDebugger) ? executionEnvironment->sourceLevelDebugger->isDebuggerActive() : false;
if (deviceInfo.sourceLevelDebuggerActive) {
this->preemptionMode = PreemptionMode::Disabled;
}
}
} // namespace OCLRT

View File

@@ -22,6 +22,8 @@
#include "runtime/execution_environment/execution_environment.h"
#include "runtime/command_stream/command_stream_receiver.h"
#include "runtime/source_level_debugger/source_level_debugger.h"
#include "runtime/built_ins/sip.h"
#include "runtime/gmm_helper/gmm_helper.h"
#include "runtime/memory_manager/memory_manager.h"
#include "runtime/os_interface/device_factory.h"
@@ -59,4 +61,13 @@ void ExecutionEnvironment::initializeMemoryManager(bool enable64KBpages) {
DEBUG_BREAK_IF(!this->memoryManager);
}
void ExecutionEnvironment::initSourceLevelDebugger(const HardwareInfo &hwInfo) {
if (hwInfo.capabilityTable.sourceLevelDebuggerSupported) {
sourceLevelDebugger.reset(SourceLevelDebugger::create());
}
if (sourceLevelDebugger) {
bool localMemorySipAvailable = (SipKernelType::DbgCsrLocal == SipKernel::getSipKernelType(hwInfo.pPlatform->eRenderCoreFamily, true));
sourceLevelDebugger->initialize(localMemorySipAvailable);
}
}
} // namespace OCLRT

View File

@@ -27,6 +27,7 @@ namespace OCLRT {
class GmmHelper;
class CommandStreamReceiver;
class MemoryManager;
class SourceLevelDebugger;
struct HardwareInfo;
class ExecutionEnvironment : public ReferenceTrackedObject<ExecutionEnvironment> {
private:
@@ -41,7 +42,9 @@ class ExecutionEnvironment : public ReferenceTrackedObject<ExecutionEnvironment>
void initGmm(const HardwareInfo *hwInfo);
bool initializeCommandStreamReceiver(const HardwareInfo *pHwInfo);
void initializeMemoryManager(bool enable64KBpages);
void initSourceLevelDebugger(const HardwareInfo &hwInfo);
std::unique_ptr<MemoryManager> memoryManager;
std::unique_ptr<CommandStreamReceiver> commandStreamReceiver;
std::unique_ptr<SourceLevelDebugger> sourceLevelDebugger;
};
} // namespace OCLRT

View File

@@ -47,7 +47,7 @@ class EnqueueDebugKernelTest : public ProgramSimpleFixture,
constructPlatform();
ProgramSimpleFixture::SetUp();
device = pDevice;
pDevice->sourceLevelDebugger.reset(new SourceLevelDebugger(nullptr));
pDevice->executionEnvironment->sourceLevelDebugger.reset(new SourceLevelDebugger(nullptr));
if (pDevice->getHardwareInfo().pPlatform->eRenderCoreFamily >= IGFX_GEN9_CORE) {
std::string filename;

View File

@@ -28,6 +28,7 @@
#include "runtime/platform/platform.h"
#include "test.h"
#include "unit_tests/mocks/mock_csr.h"
#include "runtime/source_level_debugger/source_level_debugger.h"
using namespace OCLRT;
@@ -111,31 +112,39 @@ TEST(ExecutionEnvironment, givenExecutionEnvironmentWhenInitializeMemoryManagerI
}
auto destructorId = 0u;
static_assert(sizeof(ExecutionEnvironment) == (is64bit ? 48 : 28), "New members detected in ExecutionEnvironment, please ensure that destruction sequence of objects is correct");
static_assert(sizeof(ExecutionEnvironment) == (is64bit ? 56 : 32), "New members detected in ExecutionEnvironment, please ensure that destruction sequence of objects is correct");
TEST(ExecutionEnvironment, givenExecutionEnvironmentWithVariousMembersWhenItIsDestroyedThenDeleteSequenceIsSpecified) {
destructorId = 0u;
struct GmmHelperMock : public GmmHelper {
using GmmHelper::GmmHelper;
~GmmHelperMock() override {
EXPECT_EQ(destructorId, 2u);
EXPECT_EQ(destructorId, 3u);
destructorId++;
}
};
struct MemoryMangerMock : public OsAgnosticMemoryManager {
~MemoryMangerMock() override {
EXPECT_EQ(destructorId, 1u);
EXPECT_EQ(destructorId, 2u);
destructorId++;
}
};
struct CommandStreamReceiverMock : public MockCommandStreamReceiver {
~CommandStreamReceiverMock() override {
EXPECT_EQ(destructorId, 0u);
EXPECT_EQ(destructorId, 1u);
destructorId++;
};
};
struct SourceLevelDebuggerMock : public SourceLevelDebugger {
SourceLevelDebuggerMock() : SourceLevelDebugger(nullptr){};
~SourceLevelDebuggerMock() override {
EXPECT_EQ(destructorId, 0u);
destructorId++;
}
};
struct MockExecutionEnvironment : ExecutionEnvironment {
using ExecutionEnvironment::gmmHelper;
};
@@ -144,9 +153,10 @@ TEST(ExecutionEnvironment, givenExecutionEnvironmentWithVariousMembersWhenItIsDe
executionEnvironment->gmmHelper.reset(new GmmHelperMock(platformDevices[0]));
executionEnvironment->memoryManager.reset(new MemoryMangerMock);
executionEnvironment->commandStreamReceiver.reset(new CommandStreamReceiverMock);
executionEnvironment->sourceLevelDebugger.reset(new SourceLevelDebuggerMock);
executionEnvironment.reset(nullptr);
EXPECT_EQ(3u, destructorId);
EXPECT_EQ(4u, destructorId);
}
TEST(ExecutionEnvironment, givenMultipleDevicesWhenTheyAreCreatedTheyAllReuseTheSameMemoryManagerAndCommandStreamReceiver) {

View File

@@ -41,10 +41,3 @@ BDWTEST_F(BdwDeviceTest, givenBdwDeviceWhenAskedForClVersionThenReport21) {
auto version = pDevice->getSupportedClVersion();
EXPECT_EQ(21u, version);
}
BDWTEST_F(BdwDeviceTest, givenSourceLevelDebuggerAvailableWhenDeviceIsCreatedThenSourceLevelDebuggerIsDisabled) {
auto device = std::unique_ptr<MockDeviceWithSourceLevelDebugger<MockActiveSourceLevelDebugger>>(MockDevice::createWithNewExecutionEnvironment<MockDeviceWithSourceLevelDebugger<MockActiveSourceLevelDebugger>>(nullptr));
const auto &caps = device->getDeviceInfo();
EXPECT_NE(nullptr, device->getSourceLevelDebugger());
EXPECT_FALSE(caps.sourceLevelDebuggerActive);
}

View File

@@ -41,7 +41,6 @@ class MockDevice : public Device {
using Device::createDeviceImpl;
using Device::executionEnvironment;
using Device::initializeCaps;
using Device::sourceLevelDebugger;
void setOSTime(OSTime *osTime);
void setDriverInfo(DriverInfo *driverInfo);
@@ -230,7 +229,7 @@ class MockDeviceWithSourceLevelDebugger : public MockDevice {
public:
MockDeviceWithSourceLevelDebugger(const HardwareInfo &hwInfo, ExecutionEnvironment *executionEnvironment) : MockDevice(hwInfo, executionEnvironment) {
T *sourceLevelDebuggerCreated = new T(nullptr);
sourceLevelDebugger.reset(sourceLevelDebuggerCreated);
executionEnvironment->sourceLevelDebugger.reset(sourceLevelDebuggerCreated);
}
};

View File

@@ -116,7 +116,7 @@ TEST_F(ProgramWithKernelDebuggingTest, givenEnabledKernelDebugAndOptDisabledWhen
MockActiveSourceLevelDebugger *sourceLevelDebugger = new MockActiveSourceLevelDebugger;
sourceLevelDebugger->isOptDisabled = true;
pDevice->sourceLevelDebugger.reset(sourceLevelDebugger);
pDevice->executionEnvironment->sourceLevelDebugger.reset(sourceLevelDebugger);
cl_int retVal = pProgram->compile(1, &device, nullptr,
0, nullptr, nullptr,
@@ -131,7 +131,7 @@ TEST_F(ProgramWithKernelDebuggingTest, givenEnabledKernelDebugWhenProgramIsCompi
if (pDevice->getHardwareInfo().pPlatform->eRenderCoreFamily >= IGFX_GEN9_CORE) {
MockActiveSourceLevelDebugger *sourceLevelDebugger = new MockActiveSourceLevelDebugger;
sourceLevelDebugger->sourceCodeFilename = "debugFileName";
pDevice->sourceLevelDebugger.reset(sourceLevelDebugger);
pDevice->executionEnvironment->sourceLevelDebugger.reset(sourceLevelDebugger);
cl_int retVal = pProgram->compile(1, &device, nullptr,
0, nullptr, nullptr,
@@ -171,7 +171,7 @@ TEST_F(ProgramWithKernelDebuggingTest, givenEnabledKernelDebugAndOptDisabledWhen
MockActiveSourceLevelDebugger *sourceLevelDebugger = new MockActiveSourceLevelDebugger;
sourceLevelDebugger->isOptDisabled = true;
pDevice->sourceLevelDebugger.reset(sourceLevelDebugger);
pDevice->executionEnvironment->sourceLevelDebugger.reset(sourceLevelDebugger);
cl_int retVal = pProgram->build(1, &device, nullptr, nullptr, nullptr, false);
EXPECT_EQ(CL_SUCCESS, retVal);
@@ -184,7 +184,7 @@ TEST_F(ProgramWithKernelDebuggingTest, givenEnabledKernelDebugWhenProgramIsBuilt
MockActiveSourceLevelDebugger *sourceLevelDebugger = new MockActiveSourceLevelDebugger;
sourceLevelDebugger->sourceCodeFilename = "debugFileName";
pDevice->sourceLevelDebugger.reset(sourceLevelDebugger);
pDevice->executionEnvironment->sourceLevelDebugger.reset(sourceLevelDebugger);
cl_int retVal = pProgram->build(1, &device, nullptr, nullptr, nullptr, false);
EXPECT_EQ(CL_SUCCESS, retVal);
@@ -204,7 +204,7 @@ TEST_F(ProgramWithKernelDebuggingTest, givenEnabledKernelDebugWhenProgramIsBuilt
EXPECT_CALL(*sourceLevelDebugger, notifyKernelDebugData(::testing::_)).Times(1);
sourceLevelDebugger->setActive(true);
pDevice->sourceLevelDebugger.reset(sourceLevelDebugger);
pDevice->executionEnvironment->sourceLevelDebugger.reset(sourceLevelDebugger);
cl_int retVal = pProgram->build(1, &device, nullptr, nullptr, nullptr, false);
EXPECT_EQ(CL_SUCCESS, retVal);
@@ -223,7 +223,7 @@ TEST_F(ProgramWithKernelDebuggingTest, givenEnabledKernelDebugWhenProgramIsLinke
EXPECT_CALL(*sourceLevelDebugger, notifyKernelDebugData(::testing::_)).Times(1);
sourceLevelDebugger->setActive(true);
pDevice->sourceLevelDebugger.reset(sourceLevelDebugger);
pDevice->executionEnvironment->sourceLevelDebugger.reset(sourceLevelDebugger);
cl_int retVal = pProgram->compile(1, &device, nullptr,
0, nullptr, nullptr,

View File

@@ -46,7 +46,7 @@ class MockDeviceWithActiveDebugger : public MockDevice {
};
MockDeviceWithActiveDebugger(const HardwareInfo &hwInfo, ExecutionEnvironment *executionEnvironment) : MockDevice(hwInfo, executionEnvironment) {
sourceLevelDebuggerCreated = new T(new MockOsLibrary);
sourceLevelDebugger.reset(sourceLevelDebuggerCreated);
executionEnvironment->sourceLevelDebugger.reset(sourceLevelDebuggerCreated);
}
void initializeCaps() override {

View File

@@ -28,6 +28,7 @@
#include "unit_tests/libult/source_level_debugger_library.h"
#include "unit_tests/libult/create_command_stream.h"
#include "unit_tests/mocks/mock_source_level_debugger.h"
#include "runtime/platform/platform.h"
#include <gtest/gtest.h>
#include <memory>
@@ -52,6 +53,20 @@ class DebuggerLibraryRestorer {
bool restoreAvailableState = false;
};
TEST(SourceLevelDebugger, givenPlatformWhenItIsCreatedThenSourceLevelDebuggerIsCreatedInExecutionEnvironment) {
DebuggerLibraryRestorer restorer;
if (platformDevices[0]->capabilityTable.sourceLevelDebuggerSupported) {
DebuggerLibrary::setLibraryAvailable(true);
DebuggerLibrary::setDebuggerActive(true);
Platform platform;
platform.initialize();
EXPECT_NE(nullptr, platform.peekExecutionEnvironment()->sourceLevelDebugger);
}
}
TEST(SourceLevelDebugger, givenNoKernelDebuggerLibraryWhenSourceLevelDebuggerIsCreatedThenLibraryIsNotLoaded) {
DebuggerLibraryRestorer restorer;
DebuggerLibrary::setLibraryAvailable(false);
@@ -391,13 +406,15 @@ TEST(SourceLevelDebugger, givenKernelDebuggerLibraryNotActiveWhenInitializeIsCal
TEST(SourceLevelDebugger, givenKernelDebuggerLibraryActiveWhenDeviceIsConstructedThenDebuggerIsInitialized) {
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<MockDevice> device(new MockDevice(*platformDevices[0]));
EXPECT_TRUE(interceptor.initCalled);
unique_ptr<MockDevice> device(new MockDevice(*platformDevices[0]));
EXPECT_TRUE(interceptor.initCalled);
}
}
TEST(SourceLevelDebugger, givenKernelDebuggerLibraryActiveWhenDeviceImplIsCreatedThenDebuggerIsNotified) {
@@ -447,7 +464,45 @@ TEST(SourceLevelDebugger, givenKernelDebuggerLibraryNotActiveWhenDeviceIsCreated
unique_ptr<MockDevice> device(DeviceHelper<>::create());
EXPECT_EQ(nullptr, device->sourceLevelDebugger.get());
EXPECT_EQ(nullptr, device->getSourceLevelDebugger());
EXPECT_FALSE(interceptor.initCalled);
EXPECT_FALSE(interceptor.newDeviceCalled);
}
TEST(SourceLevelDebugger, givenTwoDevicesWhenSecondIsCreatedThenNotCreatingNewSourceLevelDebugger) {
DebuggerLibraryRestorer restorer;
if (platformDevices[0]->capabilityTable.sourceLevelDebuggerSupported) {
DebuggerLibraryInterceptor interceptor;
DebuggerLibrary::setLibraryAvailable(true);
DebuggerLibrary::setDebuggerActive(true);
DebuggerLibrary::injectDebuggerLibraryInterceptor(&interceptor);
std::unique_ptr<ExecutionEnvironment> executionEnvironment(new ExecutionEnvironment);
executionEnvironment->incRefInternal();
std::unique_ptr<Device> device1(Device::create<OCLRT::Device>(nullptr, executionEnvironment.get()));
EXPECT_NE(nullptr, executionEnvironment->memoryManager);
EXPECT_TRUE(interceptor.initCalled);
interceptor.initCalled = false;
std::unique_ptr<Device> device2(Device::create<OCLRT::Device>(nullptr, executionEnvironment.get()));
EXPECT_NE(nullptr, executionEnvironment->memoryManager);
EXPECT_FALSE(interceptor.initCalled);
}
}
TEST(SourceLevelDebugger, givenMultipleDevicesWhenTheyAreCreatedTheyAllReuseTheSameSourceLevelDebugger) {
DebuggerLibraryRestorer restorer;
if (platformDevices[0]->capabilityTable.sourceLevelDebuggerSupported) {
DebuggerLibrary::setLibraryAvailable(true);
DebuggerLibrary::setDebuggerActive(true);
auto executionEnvironment = new ExecutionEnvironment;
std::unique_ptr<Device> device1(Device::create<OCLRT::Device>(nullptr, executionEnvironment));
auto sourceLevelDebugger = device1->getSourceLevelDebugger();
std::unique_ptr<Device> device2(Device::create<OCLRT::Device>(nullptr, executionEnvironment));
EXPECT_EQ(sourceLevelDebugger, device2->getSourceLevelDebugger());
}
}