File: debugger_l0_linux.cpp

package info (click to toggle)
intel-compute-runtime 25.44.36015.8-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 79,632 kB
  • sloc: cpp: 931,547; lisp: 2,074; sh: 719; makefile: 162; python: 21
file content (175 lines) | stat: -rw-r--r-- 7,640 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
/*
 * Copyright (C) 2020-2025 Intel Corporation
 *
 * SPDX-License-Identifier: MIT
 *
 */

#include "shared/source/debug_settings/debug_settings_manager.h"
#include "shared/source/debugger/debugger_l0.h"
#include "shared/source/device/sub_device.h"
#include "shared/source/execution_environment/execution_environment.h"
#include "shared/source/execution_environment/root_device_environment.h"
#include "shared/source/helpers/basic_math.h"
#include "shared/source/helpers/compiler_product_helper.h"
#include "shared/source/helpers/gfx_core_helper.h"
#include "shared/source/kernel/debug_data.h"
#include "shared/source/os_interface/linux/drm_allocation.h"
#include "shared/source/os_interface/linux/drm_neo.h"
#include "shared/source/os_interface/os_interface.h"

namespace NEO {
bool DebuggerL0::initDebuggingInOs(NEO::OSInterface *osInterface) {
    if (osInterface != nullptr) {
        auto drm = osInterface->getDriverModel()->as<NEO::Drm>();

        const bool vmBindAvailable = drm->isVmBindAvailable();
        const bool perContextVms = drm->isPerContextVMRequired();
        auto &hwInfo = *drm->getHardwareInfo();
        bool allowDebug = false;

        if (drm->getRootDeviceEnvironment().executionEnvironment.getDebuggingMode() == DebuggingMode::online) {
            allowDebug = drm->getRootDeviceEnvironment().getHelper<CompilerProductHelper>().isHeaplessModeEnabled(hwInfo) ? true : perContextVms;
        } else if (drm->getRootDeviceEnvironment().executionEnvironment.getDebuggingMode() == DebuggingMode::offline) {
            allowDebug = true;
        }

        if (vmBindAvailable && allowDebug) {
            drm->registerResourceClasses();
            return true;
        } else {
            printDebugString(debugManager.flags.PrintDebugMessages.get(), stderr,
                             "Debugging not enabled. VmBind: %d, per-context VMs: %d\n", vmBindAvailable ? 1 : 0, perContextVms ? 1 : 0);
        }
    }
    return false;
}

void DebuggerL0::initSbaTrackingMode() {
    if (device->getExecutionEnvironment()->getDebuggingMode() == DebuggingMode::offline) {
        singleAddressSpaceSbaTracking = true;
    } else {
        singleAddressSpaceSbaTracking = false;
    }
}

void DebuggerL0::registerAllocationType(GraphicsAllocation *allocation) {}

void DebuggerL0::registerElfAndLinkWithAllocation(NEO::DebugData *debugData, NEO::GraphicsAllocation *isaAllocation) {
    auto handle = registerElf(debugData);
    if (handle != 0) {
        static_cast<NEO::DrmAllocation *>(isaAllocation)->linkWithRegisteredHandle(handle);
    }
}

uint32_t DebuggerL0::registerElf(NEO::DebugData *debugData) {
    uint32_t handle = 0;
    if (device->getRootDeviceEnvironment().osInterface.get() != nullptr) {
        auto drm = device->getRootDeviceEnvironment().osInterface->getDriverModel()->as<NEO::Drm>();
        handle = drm->registerResource(NEO::DrmResourceClass::elf, debugData->vIsa, debugData->vIsaSize);
    }
    return handle;
}

bool DebuggerL0::attachZebinModuleToSegmentAllocations(const StackVec<NEO::GraphicsAllocation *, 32> &allocs, uint32_t &moduleHandle, uint32_t elfHandle) {
    if (device->getRootDeviceEnvironment().osInterface == nullptr) {
        return false;
    }
    auto drm = device->getRootDeviceEnvironment().osInterface->getDriverModel()->as<NEO::Drm>();
    uint32_t segmentCount = static_cast<uint32_t>(allocs.size());
    moduleHandle = drm->registerResource(NEO::DrmResourceClass::l0ZebinModule, &segmentCount, sizeof(uint32_t));

    for (auto &allocation : allocs) {
        auto drmAllocation = static_cast<NEO::DrmAllocation *>(allocation);

        DEBUG_BREAK_IF(allocation->getAllocationType() == AllocationType::kernelIsaInternal);
        drmAllocation->linkWithRegisteredHandle(elfHandle);
        drmAllocation->linkWithRegisteredHandle(moduleHandle);
    }

    return true;
}

bool DebuggerL0::removeZebinModule(uint32_t moduleHandle) {
    if (device->getRootDeviceEnvironment().osInterface == nullptr || moduleHandle == 0) {
        return false;
    }
    auto drm = device->getRootDeviceEnvironment().osInterface->getDriverModel()->as<NEO::Drm>();

    drm->unregisterResource(moduleHandle);
    return true;
}

void DebuggerL0::notifyModuleDestroy(uint64_t moduleLoadAddress) {}

void DebuggerL0::notifyCommandQueueCreated(NEO::Device *device) {
    if (this->device->getRootDeviceEnvironment().osInterface.get() != nullptr) {
        std::unique_lock<std::mutex> commandQueueCountLock(debuggerL0Mutex);

        if (!device->isSubDevice() && device->getDeviceBitfield().count() > 1) {
            UNRECOVERABLE_IF(this->device->getNumSubDevices() != device->getDeviceBitfield().count());

            for (size_t i = 0; i < device->getDeviceBitfield().size(); i++) {
                if (device->getDeviceBitfield().test(i)) {
                    if (++commandQueueCount[i] == 1) {
                        auto drm = this->device->getRootDeviceEnvironment().osInterface->getDriverModel()->as<NEO::Drm>();

                        CommandQueueNotification notification = {static_cast<uint32_t>(i), this->device->getNumSubDevices()};
                        uuidL0CommandQueueHandle[i] = drm->notifyFirstCommandQueueCreated(&notification, sizeof(CommandQueueNotification));
                    }
                }
            }
            return;
        }

        auto index = 0u;
        auto deviceIndex = 0u;

        if (device->isSubDevice()) {
            index = static_cast<NEO::SubDevice *>(device)->getSubDeviceIndex();
            deviceIndex = index;
        } else if (device->getDeviceBitfield().count() == 1) {
            deviceIndex = Math::log2(static_cast<uint32_t>(device->getDeviceBitfield().to_ulong()));
        }

        if (++commandQueueCount[index] == 1) {
            auto drm = this->device->getRootDeviceEnvironment().osInterface->getDriverModel()->as<NEO::Drm>();

            CommandQueueNotification notification = {deviceIndex, this->device->getNumSubDevices()};
            uuidL0CommandQueueHandle[index] = drm->notifyFirstCommandQueueCreated(&notification, sizeof(CommandQueueNotification));
        }
    }
}

void DebuggerL0::notifyCommandQueueDestroyed(NEO::Device *device) {
    if (this->device->getRootDeviceEnvironment().osInterface.get() != nullptr) {
        std::unique_lock<std::mutex> commandQueueCountLock(debuggerL0Mutex);

        if (!device->isSubDevice() && device->getDeviceBitfield().count() > 1) {
            UNRECOVERABLE_IF(this->device->getNumSubDevices() != device->getDeviceBitfield().count());

            for (size_t i = 0; i < device->getDeviceBitfield().size(); i++) {
                if (device->getDeviceBitfield().test(i)) {
                    if (--commandQueueCount[i] == 0) {
                        auto drm = this->device->getRootDeviceEnvironment().osInterface->getDriverModel()->as<NEO::Drm>();
                        drm->notifyLastCommandQueueDestroyed(uuidL0CommandQueueHandle[i]);
                        uuidL0CommandQueueHandle[i] = 0;
                    }
                }
            }
            return;
        }

        auto index = device->isSubDevice() ? static_cast<NEO::SubDevice *>(device)->getSubDeviceIndex() : 0;

        if (--commandQueueCount[index] == 0) {
            auto drm = this->device->getRootDeviceEnvironment().osInterface->getDriverModel()->as<NEO::Drm>();
            drm->notifyLastCommandQueueDestroyed(uuidL0CommandQueueHandle[index]);
            uuidL0CommandQueueHandle[index] = 0;
        }
    }
}

void DebuggerL0::notifyModuleCreate(void *module, uint32_t moduleSize, uint64_t moduleLoadAddress) {}

} // namespace NEO