Skip to content

Commit 2e46129

Browse files
Source Level Debugger: initialization & notify new device
- add source level debugger to device - load isDebuggerActive function from library - rename interface to sourceLevelDebuggerInterface in SLD - add DebugData to KernelInfo with kernel debug data Change-Id: I2643ee633f8dc5c97e8bbdc9d4e7977ddcbf440d
1 parent c8c2832 commit 2e46129

File tree

14 files changed

+414
-51
lines changed

14 files changed

+414
-51
lines changed

runtime/device/device.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
#include "hw_cmds.h"
2424
#include "runtime/built_ins/built_ins.h"
25+
#include "runtime/built_ins/sip.h"
2526
#include "runtime/command_stream/command_stream_receiver.h"
2627
#include "runtime/command_stream/device_command_stream.h"
2728
#include "runtime/command_stream/preemption.h"
@@ -33,7 +34,9 @@
3334
#include "runtime/helpers/debug_helpers.h"
3435
#include "runtime/helpers/options.h"
3536
#include "runtime/memory_manager/memory_manager.h"
37+
#include "runtime/os_interface/os_interface.h"
3638
#include "runtime/os_interface/os_time.h"
39+
#include "runtime/source_level_debugger/source_level_debugger.h"
3740
#include <cstring>
3841
#include <map>
3942

@@ -84,6 +87,12 @@ Device::Device(const HardwareInfo &hwInfo,
8487
engineType = DebugManager.flags.NodeOrdinal.get() == -1
8588
? hwInfo.capabilityTable.defaultEngineType
8689
: static_cast<EngineType>(DebugManager.flags.NodeOrdinal.get());
90+
91+
sourceLevelDebugger.reset(SourceLevelDebugger::create());
92+
if (sourceLevelDebugger) {
93+
bool localMemorySipAvailable = (SipKernelType::DbgCsrLocal == SipKernel::getSipKernelType(hwInfo.pPlatform->eRenderCoreFamily, true));
94+
sourceLevelDebugger->initialize(localMemorySipAvailable);
95+
}
8796
}
8897

8998
Device::~Device() {
@@ -163,6 +172,15 @@ bool Device::createDeviceImpl(const HardwareInfo *pHwInfo,
163172
}
164173
}
165174

175+
uint32_t deviceHandle = 0;
176+
if (commandStreamReceiver->getOSInterface()) {
177+
deviceHandle = commandStreamReceiver->getOSInterface()->getDeviceHandle();
178+
}
179+
180+
if (pDevice->deviceInfo.sourceLevelDebuggerActive) {
181+
pDevice->sourceLevelDebugger->notifyNewDevice(deviceHandle);
182+
}
183+
166184
outDevice.memoryManager->setForce32BitAllocations(pDevice->getDeviceInfo().force32BitAddressess);
167185
outDevice.memoryManager->device = pDevice;
168186

runtime/device/device.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class MemoryManager;
3737
class OSTime;
3838
class DriverInfo;
3939
struct HardwareInfo;
40+
class SourceLevelDebugger;
4041

4142
template <>
4243
struct OpenCLObjectMapper<_cl_device_id> {
@@ -169,6 +170,7 @@ class Device : public BaseObject<_cl_device_id> {
169170

170171
PreemptionMode preemptionMode;
171172
EngineType engineType;
173+
std::unique_ptr<SourceLevelDebugger> sourceLevelDebugger;
172174
};
173175

174176
template <cl_device_info Param>

runtime/device/device_caps.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "runtime/os_interface/os_interface.h"
3131
#include "runtime/platform/extensions.h"
3232
#include "runtime/sharings/sharing_factory.h"
33+
#include "runtime/source_level_debugger/source_level_debugger.h"
3334

3435
#include "CL/cl_ext_intel.h"
3536
#include "driver_version.h"
@@ -361,6 +362,6 @@ void Device::initializeCaps() {
361362
deviceInfo.preferredLocalAtomicAlignment = MemoryConstants::cacheLineSize;
362363
deviceInfo.preferredPlatformAtomicAlignment = MemoryConstants::cacheLineSize;
363364

364-
deviceInfo.sourceLevelDebuggerActive = false;
365+
deviceInfo.sourceLevelDebuggerActive = sourceLevelDebugger ? sourceLevelDebugger->isDebuggerActive() : false;
365366
}
366367
} // namespace OCLRT

runtime/program/kernel_info.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,13 @@ struct WorkSizeInfo {
117117
void checkRatio(const size_t workItems[3]);
118118
};
119119

120+
struct DebugData {
121+
uint32_t vIsaSize = 0;
122+
uint32_t genIsaSize = 0;
123+
const char *vIsa = nullptr;
124+
const char *genIsa = nullptr;
125+
};
126+
120127
struct KernelInfo {
121128
public:
122129
static KernelInfo *create();
@@ -243,5 +250,6 @@ struct KernelInfo {
243250
uint64_t kernelId = 0;
244251
bool isKernelHeapSubstituted = false;
245252
GraphicsAllocation *kernelAllocation = nullptr;
253+
DebugData debugData;
246254
};
247255
} // namespace OCLRT

runtime/source_level_debugger/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ else()
2828
set(RUNTIME_SRCS_SOURCE_LEVEL_DEBUGGER
2929
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
3030
${CMAKE_CURRENT_SOURCE_DIR}/source_level_debugger.h
31+
${CMAKE_CURRENT_SOURCE_DIR}/source_level_debugger_stubs.cpp
3132
)
3233
endif()
3334

3435
target_sources(${NEO_STATIC_LIB_NAME} PRIVATE ${RUNTIME_SRCS_SOURCE_LEVEL_DEBUGGER})
36+
set_property(GLOBAL PROPERTY RUNTIME_SRCS_SOURCE_LEVEL_DEBUGGER ${RUNTIME_SRCS_SOURCE_LEVEL_DEBUGGER})

runtime/source_level_debugger/source_level_debugger.cpp

Lines changed: 84 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "igfx_debug_interchange_types.h"
2424

2525
#include "runtime/helpers/debug_helpers.h"
26+
#include "runtime/program/kernel_info.h"
2627
#include "runtime/source_level_debugger/source_level_debugger.h"
2728
#include "runtime/os_interface/os_interface.h"
2829

@@ -32,39 +33,68 @@ const char *SourceLevelDebugger::notifySourceCodeSymbol = "notifySourceCode";
3233
const char *SourceLevelDebugger::getDebuggerOptionSymbol = "getDebuggerOption";
3334
const char *SourceLevelDebugger::notifyKernelDebugDataSymbol = "notifyKernelDebugData";
3435
const char *SourceLevelDebugger::initSymbol = "init";
36+
const char *SourceLevelDebugger::isDebuggerActiveSymbol = "isDebuggerActive";
3537

3638
class SourceLevelDebugger::SourceLevelDebuggerInterface {
3739
public:
3840
SourceLevelDebuggerInterface() = default;
3941
~SourceLevelDebuggerInterface() = default;
4042

41-
typedef int (*pfNotifyNewDevice)(GfxDbgNewDeviceData *data);
42-
typedef int (*pfNotifySourceCode)(GfxDbgSourceCode *data);
43-
typedef int (*pfGetDebuggerOption)(GfxDbgOption *);
44-
typedef int (*pfNotifyKernelDebugData)(GfxDbgKernelDebugData *data);
45-
typedef int (*pfInit)(GfxDbgTargetCaps *data);
46-
47-
pfNotifyNewDevice fNotifyNewDevice = nullptr;
48-
pfNotifySourceCode fNotifySourceCode = nullptr;
49-
pfGetDebuggerOption fGetDebuggerOption = nullptr;
50-
pfNotifyKernelDebugData fNotifyKernelDebugData = nullptr;
51-
pfInit fInit = nullptr;
43+
typedef int (*NotifyNewDeviceFunction)(GfxDbgNewDeviceData *data);
44+
typedef int (*NotifySourceCodeFunction)(GfxDbgSourceCode *data);
45+
typedef int (*GetDebuggerOptionFunction)(GfxDbgOption *);
46+
typedef int (*NotifyKernelDebugDataFunction)(GfxDbgKernelDebugData *data);
47+
typedef int (*InitFunction)(GfxDbgTargetCaps *data);
48+
typedef int (*IsDebuggerActiveFunction)(void);
49+
50+
NotifyNewDeviceFunction notifyNewDeviceFunc = nullptr;
51+
NotifySourceCodeFunction notifySourceCodeFunc = nullptr;
52+
GetDebuggerOptionFunction getDebuggerOptionFunc = nullptr;
53+
NotifyKernelDebugDataFunction notifyKernelDebugDataFunc = nullptr;
54+
InitFunction initFunc = nullptr;
55+
IsDebuggerActiveFunction isDebuggerActive = nullptr;
5256
};
5357

54-
SourceLevelDebugger::SourceLevelDebugger() {
55-
debuggerLibrary.reset(SourceLevelDebugger::loadDebugger());
58+
SourceLevelDebugger *SourceLevelDebugger::create() {
59+
auto library = SourceLevelDebugger::loadDebugger();
60+
if (library) {
61+
auto isActiveFunc = reinterpret_cast<SourceLevelDebuggerInterface::IsDebuggerActiveFunction>(library->getProcAddress(isDebuggerActiveSymbol));
62+
int result = isActiveFunc();
63+
if (result == 1) {
64+
// pass library ownership to Source Level Debugger
65+
return new SourceLevelDebugger(library);
66+
}
67+
delete library;
68+
}
69+
return nullptr;
70+
}
71+
SourceLevelDebugger::SourceLevelDebugger(OsLibrary *library) {
72+
debuggerLibrary.reset(library);
5673

5774
if (debuggerLibrary.get() == nullptr) {
5875
return;
5976
}
60-
interface = new SourceLevelDebuggerInterface;
77+
sourceLevelDebuggerInterface = new SourceLevelDebuggerInterface;
6178
getFunctions();
62-
isActive = true;
79+
80+
if (sourceLevelDebuggerInterface->isDebuggerActive == nullptr) {
81+
return;
82+
}
83+
84+
int result = sourceLevelDebuggerInterface->isDebuggerActive();
85+
if (result == 1) {
86+
UNRECOVERABLE_IF(sourceLevelDebuggerInterface->getDebuggerOptionFunc == nullptr);
87+
UNRECOVERABLE_IF(sourceLevelDebuggerInterface->initFunc == nullptr);
88+
UNRECOVERABLE_IF(sourceLevelDebuggerInterface->notifyKernelDebugDataFunc == nullptr);
89+
UNRECOVERABLE_IF(sourceLevelDebuggerInterface->notifyNewDeviceFunc == nullptr);
90+
UNRECOVERABLE_IF(sourceLevelDebuggerInterface->notifySourceCodeFunc == nullptr);
91+
isActive = true;
92+
}
6393
}
6494

6595
SourceLevelDebugger::~SourceLevelDebugger() {
66-
if (interface) {
67-
delete interface;
96+
if (sourceLevelDebuggerInterface) {
97+
delete sourceLevelDebuggerInterface;
6898
}
6999
}
70100

@@ -75,11 +105,12 @@ bool SourceLevelDebugger::isDebuggerActive() {
75105
void SourceLevelDebugger::getFunctions() {
76106
UNRECOVERABLE_IF(debuggerLibrary.get() == nullptr);
77107

78-
interface->fNotifyNewDevice = reinterpret_cast<SourceLevelDebuggerInterface::pfNotifyNewDevice>(debuggerLibrary->getProcAddress(notifyNewDeviceSymbol));
79-
interface->fNotifySourceCode = reinterpret_cast<SourceLevelDebuggerInterface::pfNotifySourceCode>(debuggerLibrary->getProcAddress(notifySourceCodeSymbol));
80-
interface->fGetDebuggerOption = reinterpret_cast<SourceLevelDebuggerInterface::pfGetDebuggerOption>(debuggerLibrary->getProcAddress(getDebuggerOptionSymbol));
81-
interface->fNotifyKernelDebugData = reinterpret_cast<SourceLevelDebuggerInterface::pfNotifyKernelDebugData>(debuggerLibrary->getProcAddress(notifyKernelDebugDataSymbol));
82-
interface->fInit = reinterpret_cast<SourceLevelDebuggerInterface::pfInit>(debuggerLibrary->getProcAddress(initSymbol));
108+
sourceLevelDebuggerInterface->notifyNewDeviceFunc = reinterpret_cast<SourceLevelDebuggerInterface::NotifyNewDeviceFunction>(debuggerLibrary->getProcAddress(notifyNewDeviceSymbol));
109+
sourceLevelDebuggerInterface->notifySourceCodeFunc = reinterpret_cast<SourceLevelDebuggerInterface::NotifySourceCodeFunction>(debuggerLibrary->getProcAddress(notifySourceCodeSymbol));
110+
sourceLevelDebuggerInterface->getDebuggerOptionFunc = reinterpret_cast<SourceLevelDebuggerInterface::GetDebuggerOptionFunction>(debuggerLibrary->getProcAddress(getDebuggerOptionSymbol));
111+
sourceLevelDebuggerInterface->notifyKernelDebugDataFunc = reinterpret_cast<SourceLevelDebuggerInterface::NotifyKernelDebugDataFunction>(debuggerLibrary->getProcAddress(notifyKernelDebugDataSymbol));
112+
sourceLevelDebuggerInterface->initFunc = reinterpret_cast<SourceLevelDebuggerInterface::InitFunction>(debuggerLibrary->getProcAddress(initSymbol));
113+
sourceLevelDebuggerInterface->isDebuggerActive = reinterpret_cast<SourceLevelDebuggerInterface::IsDebuggerActiveFunction>(debuggerLibrary->getProcAddress(isDebuggerActiveSymbol));
83114
}
84115

85116
void SourceLevelDebugger::notifyNewDevice(uint32_t deviceHandle) const {
@@ -88,7 +119,7 @@ void SourceLevelDebugger::notifyNewDevice(uint32_t deviceHandle) const {
88119
newDevice.version = IGFXDBG_CURRENT_VERSION;
89120
newDevice.dh = reinterpret_cast<GfxDeviceHandle>(static_cast<uint64_t>(deviceHandle));
90121
newDevice.udh = GfxDeviceHandle(0);
91-
interface->fNotifyNewDevice(&newDevice);
122+
sourceLevelDebuggerInterface->notifyNewDeviceFunc(&newDevice);
92123
}
93124
}
94125
void SourceLevelDebugger::notifySourceCode(uint32_t deviceHandle, const char *source, size_t sourceSize) const {
@@ -103,7 +134,7 @@ void SourceLevelDebugger::notifySourceCode(uint32_t deviceHandle, const char *so
103134
sourceCode.sourceName = &fileName[0];
104135
sourceCode.sourceNameMaxLen = sizeof(fileName);
105136

106-
interface->fNotifySourceCode(&sourceCode);
137+
sourceLevelDebuggerInterface->notifySourceCodeFunc(&sourceCode);
107138
}
108139
}
109140

@@ -116,7 +147,7 @@ bool SourceLevelDebugger::isOptimizationDisabled() const {
116147
option.valueLen = sizeof(value);
117148
option.value = &value;
118149

119-
int result = interface->fGetDebuggerOption(&option);
150+
int result = sourceLevelDebuggerInterface->getDebuggerOptionFunc(&option);
120151
if (result == 1) {
121152
if (option.value[0] == '1') {
122153
return true;
@@ -126,8 +157,33 @@ bool SourceLevelDebugger::isOptimizationDisabled() const {
126157
return false;
127158
}
128159

129-
void SourceLevelDebugger::notifyKernelDebugData() const {
130-
GfxDbgKernelDebugData kernelDebugData;
131-
interface->fNotifyKernelDebugData(&kernelDebugData);
160+
void SourceLevelDebugger::notifyKernelDebugData(uint32_t deviceHandle, const KernelInfo *kernelInfo) const {
161+
if (isActive) {
162+
GfxDbgKernelDebugData kernelDebugData;
163+
kernelDebugData.hDevice = reinterpret_cast<GfxDeviceHandle>(static_cast<uint64_t>(deviceHandle));
164+
kernelDebugData.version = IGFXDBG_CURRENT_VERSION;
165+
kernelDebugData.hProgram = reinterpret_cast<GenRtProgramHandle>(0);
166+
167+
kernelDebugData.kernelName = kernelInfo->name.c_str();
168+
kernelDebugData.kernelBinBuffer = const_cast<void *>(kernelInfo->heapInfo.pKernelHeap);
169+
kernelDebugData.KernelBinSize = kernelInfo->heapInfo.pKernelHeader->KernelHeapSize;
170+
171+
kernelDebugData.dbgVisaBuffer = kernelInfo->debugData.vIsa;
172+
kernelDebugData.dbgVisaSize = kernelInfo->debugData.vIsaSize;
173+
kernelDebugData.dbgGenIsaBuffer = kernelInfo->debugData.genIsa;
174+
kernelDebugData.dbgGenIsaSize = kernelInfo->debugData.genIsaSize;
175+
176+
sourceLevelDebuggerInterface->notifyKernelDebugDataFunc(&kernelDebugData);
177+
}
178+
}
179+
180+
void SourceLevelDebugger::initialize(bool useLocalMemory) {
181+
if (isActive) {
182+
GfxDbgTargetCaps caps = {IGFXDBG_CURRENT_VERSION, useLocalMemory};
183+
int result = sourceLevelDebuggerInterface->initFunc(&caps);
184+
if (static_cast<IgfxdbgRetVal>(result) != IgfxdbgRetVal::IGFXDBG_SUCCESS) {
185+
isActive = false;
186+
}
187+
}
132188
}
133189
} // namespace OCLRT

runtime/source_level_debugger/source_level_debugger.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,26 @@
2525
#include <memory>
2626

2727
namespace OCLRT {
28+
struct KernelInfo;
29+
2830
class SourceLevelDebugger {
2931
public:
30-
SourceLevelDebugger();
32+
SourceLevelDebugger(OsLibrary *library);
3133
~SourceLevelDebugger();
3234
SourceLevelDebugger(const SourceLevelDebugger &ref) = delete;
3335
SourceLevelDebugger &operator=(const SourceLevelDebugger &) = delete;
36+
static SourceLevelDebugger *create();
3437

3538
bool isDebuggerActive();
3639
void notifyNewDevice(uint32_t deviceHandle) const;
3740
void notifySourceCode(uint32_t deviceHandle, const char *sourceCode, size_t size) const;
3841
bool isOptimizationDisabled() const;
39-
void notifyKernelDebugData() const;
42+
void notifyKernelDebugData(uint32_t deviceHandle, const KernelInfo *kernelInfo) const;
43+
void initialize(bool useLocalMemory);
4044

4145
protected:
4246
class SourceLevelDebuggerInterface;
43-
SourceLevelDebuggerInterface *interface = nullptr;
47+
SourceLevelDebuggerInterface *sourceLevelDebuggerInterface = nullptr;
4448

4549
static OsLibrary *loadDebugger();
4650
void getFunctions();
@@ -53,6 +57,7 @@ class SourceLevelDebugger {
5357
static const char *getDebuggerOptionSymbol;
5458
static const char *notifyKernelDebugDataSymbol;
5559
static const char *initSymbol;
60+
static const char *isDebuggerActiveSymbol;
5661
// OS specific library name
5762
static const char *dllName;
5863
};
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Copyright (c) 2018, Intel Corporation
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a
5+
* copy of this software and associated documentation files (the "Software"),
6+
* to deal in the Software without restriction, including without limitation
7+
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
8+
* and/or sell copies of the Software, and to permit persons to whom the
9+
* Software is furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included
12+
* in all copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15+
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17+
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
18+
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19+
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20+
* OTHER DEALINGS IN THE SOFTWARE.
21+
*/
22+
23+
#include "runtime/source_level_debugger/source_level_debugger.h"
24+
25+
namespace OCLRT {
26+
27+
SourceLevelDebugger::SourceLevelDebugger(OsLibrary *library) {
28+
debuggerLibrary.reset(library);
29+
}
30+
31+
SourceLevelDebugger::~SourceLevelDebugger() {
32+
}
33+
34+
SourceLevelDebugger *SourceLevelDebugger::create() {
35+
return nullptr;
36+
}
37+
38+
bool SourceLevelDebugger::isDebuggerActive() {
39+
return false;
40+
}
41+
42+
void SourceLevelDebugger::notifyNewDevice(uint32_t deviceHandle) const {
43+
}
44+
void SourceLevelDebugger::notifySourceCode(uint32_t deviceHandle, const char *sourceCode, size_t size) const {
45+
}
46+
bool SourceLevelDebugger::isOptimizationDisabled() const {
47+
return false;
48+
}
49+
void SourceLevelDebugger::notifyKernelDebugData(uint32_t deviceHandle, const KernelInfo *kernelInfo) const {
50+
}
51+
void SourceLevelDebugger::initialize(bool useLocalMemory) {
52+
}
53+
54+
} // namespace OCLRT

0 commit comments

Comments
 (0)