Extending LLDB to Debug Applications That Span CPUs and GPUs
本文为原文前 6,000 字符的节选翻译,完整内容请查看原文。
Extending LLDB to Debug Applications That Span CPUs and GPUs
By Greg Clayton, Satyanarayana Janga, Jeffrey Tan, Janet Yang, Bar Soloveychik, Chen Li, Vipul Bansal We built a vendor-neutral accelerator plugin architecture in lldb-server for debugging applications that span CPUs and GPUs. It separates shared debugger infrastructure from hardware-specific device control. The design represents the CPU and GPU as separate debugger processes while presenting them in one debugging session.
Greg Clayton、Satyanarayana Janga、Jeffrey Tan、Janet Yang、Bar Soloveychik、Chen Li 和 Vipul Bansal 等人共同构建了一个用于 lldb-server 的供应商中立型加速器插件架构,旨在调试跨 CPU 和 GPU 的应用程序。该架构将共享的调试器基础设施与特定于硬件的设备控制分离开来。其设计将 CPU 和 GPU 表示为独立的调试器进程,同时在同一个调试会话中呈现它们。
Modern AI applications rarely execute in one place. A workload can begin in a high-level framework and move back and forth between native CPU code and kernels running on a GPU. When a bug crosses those boundaries, developers need to understand the host application and the device together. That is harder than attaching a conventional debugger to another process.
现代 AI 应用程序很少只在一个地方执行。工作负载可能始于高级框架,并在原生 CPU 代码与运行在 GPU 上的内核之间来回切换。当错误跨越这些边界时,开发人员需要同时理解宿主应用程序和设备。这比将传统调试器附加到另一个进程要困难得多。
The CPU and GPU may use different instruction sets, registers, memory spaces, and execution models. The GPU is also controlled through a runtime and driver inside the host process, so debugging the device often requires careful coordination with the CPU. Historically, GPU vendors built device-specific debuggers, including AMD’s ROCgdb and NVIDIA’s CUDA-GDB. These tools provide deep support for their respective platforms, but common debugger capabilities must often be implemented and maintained separately.
CPU 和 GPU 可能使用不同的指令集、寄存器、内存空间和执行模型。此外,GPU 通过宿主进程内的运行时和驱动程序进行控制,因此调试设备通常需要与 CPU 进行仔细的协调。从历史上看,GPU 供应商构建了特定于设备的调试器,包括 AMD 的 ROCgdb 和 NVIDIA 的 CUDA-GDB。这些工具为其各自的平台提供了深度支持,但通用的调试器功能往往需要分别实现和维护。
At Meta, we have been developing a different approach for LLDB: a common accelerator plugin architecture in lldb-server. In this post, “GPU” refers to the concrete devices and examples, while “accelerator” refers to LLDB’s broader, vendor-neutral plugin abstraction. The architecture has evolved through contributions from engineers at Meta and across the accelerator ecosystem. It keeps the shared debugger independent of any one GPU while giving hardware vendors a focused place to implement device-specific behavior.
在 Meta,我们一直在为 LLDB 开发一种不同的方法:即 lldb-server 中的通用加速器插件架构。在本文中,“GPU”指的是具体的设备和示例,而“加速器”指的是 LLDB 更广泛的、供应商中立的插件抽象。该架构通过 Meta 及整个加速器生态系统中工程师的贡献不断演进。它使共享调试器独立于任何特定的 GPU,同时为硬件供应商提供了一个专门的场所来实现特定于设备的行为。
Why GPU Debugging Challenges Traditional Debugger Models A traditional debugger generally assumes that one process has one architecture and a consistent view of threads, registers, and memory. GPU programs challenge each of those assumptions. A host process might run on x86-64 while its kernels use a completely different instruction set. A CPU thread has a familiar register context, while a GPU may execute groups of lanes in lockstep. Host and device pointers can refer to different address spaces.
为什么 GPU 调试会挑战传统的调试器模型?传统的调试器通常假设一个进程具有一种架构,并对线程、寄存器和内存有一致的视图。GPU 程序挑战了这些假设中的每一项。宿主进程可能运行在 x86-64 上,而其内核使用完全不同的指令集。CPU 线程具有熟悉的寄存器上下文,而 GPU 可能以锁步方式执行一组通道。宿主指针和设备指针可能指向不同的地址空间。
A GPU can expose thousands of execution lanes, which do not map cleanly onto the thread model that most command-line and graphical debuggers present. Combining all of this state into one artificial process model makes the debugger more complicated. Every operation must first determine whether it applies to the CPU or the GPU. Register handling, memory reads, breakpoints, stepping, and stop events all become conditional on the selected hardware.
GPU 可以公开数千个执行通道,这些通道无法清晰地映射到大多数命令行和图形调试器所呈现的线程模型上。将所有这些状态合并到一个人工进程模型中会使调试器变得更加复杂。每个操作都必须首先确定它是应用于 CPU 还是 GPU。寄存器处理、内存读取、断点、单步执行和停止事件都变得取决于所选的硬件。
A single process model also forces the CPU and GPU into one unified memory map, even though their address spaces can be independent: The same address, such as 0x1000, can refer to different locations in the CPU and GPU processes. Instead of hiding those differences, the LLDB accelerator architecture gives them a clear boundary.
单一进程模型还强制将 CPU 和 GPU 放入一个统一的内存映射中,即使它们的地址空间可能是独立的:同一个地址(例如 0x1000)在 CPU 和 GPU 进程中可能指向不同的位置。LLDB 加速器架构没有隐藏这些差异,而是为它们提供了清晰的界限。
Plugin Support in lldb-server for GPU Debugging LLDB uses a companion process called lldb-server to launch or attach to a program and perform low-level debugging operations. The LLDB client communicates with the server through the GDB remote protocol, a command protocol for operations such as reading memory, inspecting registers, controlling execution, and setting breakpoints. Because lldb-server already controls the native process, it is also the right place to coordinate with an accelerator runtime.
lldb-server 中用于 GPU 调试的插件支持:LLDB 使用一个名为 lldb-server 的配套进程来启动或附加到程序并执行底层调试操作。LLDB 客户端通过 GDB 远程协议与服务器通信,这是一种用于读取内存、检查寄存器、控制执行和设置断点等操作的命令协议。由于 lldb-server 已经控制了原生进程,它也是与加速器运行时进行协调的合适场所。
The new plugin interface lets a hardware-specific backend work alongside the normal CPU debugger. The backend translates a vendor’s device debugging API into concepts LLDB already understands, such as processes, threads, registers, memory, modules, and stop reasons. This separation keeps the LLDB client vendor-neutral. Common improvements to the command line, remote protocol, symbol handling, and IDE integration can benefit every accelerator. At the same time, each vendor remains responsible for the details that are unique to its hardware and driver stack.
新的插件接口允许特定于硬件的后端与常规 CPU 调试器协同工作。后端将供应商的设备调试 API 转换为 LLDB 已经理解的概念,例如进程、线程、寄存器、内存、模块和停止原因。这种分离使 LLDB 客户端保持供应商中立。对命令行、远程协议、符号处理和 IDE 集成的常见改进可以使每个加速器受益。同时,每个供应商仍负责其硬件和驱动程序堆栈所特有的细节。
GPU debugging support is activated only when the debugged application uses a supported GPU runtime. For CPU-only applications, LLDB and lldb-server continue through the existing native debugging path without incurring runtime computational overhead.
仅当被调试的应用程序使用受支持的 GPU 运行时,才会激活 GPU 调试支持。对于仅限 CPU 的应用程序,LLDB 和 lldb-server 继续通过现有的原生调试路径运行,而不会产生运行时的计算开销。
Two Targets, One Debugging Experience The architecture represents the CPU and accelerator as separate LLDB targets. Each target has its own architecture and is associated with a debugger process that maintains its threads, registers, address space, and execution state. The CPU continues to use LLDB’s established native debugging path. When the accelerator becomes available, the plugin provides a second connection that LLDB uses to create the device target. To the debugger, the two targets remain technically independent. To the developer, they can appear in one LLDB or IDE session. This avoids forcing incompatible CPU and GPU concepts into a single process while still supporting a unified workflow.
两个目标,一种调试体验:该架构将 CPU 和加速器表示为独立的 LLDB 目标。每个目标都有自己的架构,并与一个维护其线程、寄存器、地址空间和执行状态的调试器进程相关联。CPU 继续使用 LLDB 既有的原生调试路径。当加速器可用时,插件会提供第二个连接,LLDB 使用该连接来创建设备目标。对于调试器而言,这两个目标在技术上保持独立。对于开发人员而言,它们可以出现在同一个 LLDB 或 IDE 会话中。这避免了将不兼容的 CPU 和 GPU 概念强行塞入单个进程,同时仍然支持统一的工作流程。
The CPU and GPU remain separate LLDB targets while a plugin in lldb-server coordinates host and device debugging. Coordinating the Host and Device A typical debugging session follows a small set of steps: LLDB connects to lldb-server and discovers which accelerator plugins are available. A plugin can ask LLDB to set internal breakpoints in the host process. These breakpoints identify important runtime events, such as the point at which a GPU debugging session can begin. When the host reaches one of those points, lldb-server notifies the plugin. The plugin initializes the vendor debugging API and prepares an accelerator debugging endpoint. LLDB creates a second target for the accelerator and connects to it. Device threads, registers, memory, modules, and breakpoints can then use LLDB’s existing abstractions. Structured actions coordinate the two sides. A plu
CPU 和 GPU 保持为独立的 LLDB 目标,而 lldb-server 中的插件负责协调宿主和设备调试。协调宿主和设备:典型的调试会话遵循一小套步骤:LLDB 连接到 lldb-server 并发现哪些加速器插件可用。插件可以要求 LLDB 在宿主进程中设置内部断点。这些断点用于识别重要的运行时事件,例如 GPU 调试会话可以开始的时间点。当宿主到达这些点之一时,lldb-server 会通知插件。插件初始化供应商调试 API 并准备加速器调试端点。LLDB 为加速器创建第二个目标并连接到它。设备线程、寄存器、内存、模块和断点随后可以使用 LLDB 现有的抽象。结构化操作协调双方。A plu