Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions lldb/docs/use/gpu-support.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
GPU Support in LLDB
====================

AMD
------

System requirements
^^^^^^^^^^^^^^^^^^^

Mention how to set up ROMC.

CMake
^^^^^

Mention something about the ROCM_PATH CMake variable and setting LLDB_ENABLE_AMDGPU_PLUGIN = ON.
27 changes: 24 additions & 3 deletions lldb/tools/lldb-server/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,34 @@ if(APPLE_EMBEDDED)
endif()
endif()

if(DEFINED ROCM_PATH)
option(LLDB_ENABLE_AMDGPU_PLUGIN "Enable support for the AMD GPU plugin" OFF)
option(LLDB_ENABLE_MOCK_GPU_PLUGIN "Enable support for the Mock GPU plugin" OFF)

set(GPU_PLUGINS_ENABLED 0)

if(LLDB_ENABLE_AMDGPU_PLUGIN)
if(NOT DEFINED ROCM_PATH)
message(FATAL_ERROR "ROCM_PATH is not defined and LLDB_ENABLE_AMDGPU_PLUGIN expects it. Use -DROCM_PATH=/path/to/rocm")
endif()

if(NOT EXISTS ${ROCM_PATH})
message(FATAL_ERROR "ROCM_PATH does not exist: ${ROCM_PATH}. Use -DROCM_PATH=/path/to/rocm")
endif()
message(STATUS "ROCM_PATH is set to: '${ROCM_PATH}'")

add_definitions(-DLLDB_ENABLE_AMDGPU_PLUGIN=1)
list(APPEND LLDB_PLUGINS lldbServerPluginAMDGPU)
else()
math(EXPR GPU_PLUGINS_ENABLED "${GPU_PLUGINS_ENABLED} + 1")
endif()

if(LLDB_ENABLE_MOCK_GPU_PLUGIN)
add_definitions(-DLLDB_ENABLE_MOCKGPU_PLUGIN=1)
list(APPEND LLDB_PLUGINS lldbServerPluginMockGPU)
math(EXPR GPU_PLUGINS_ENABLED "${GPU_PLUGINS_ENABLED} + 1")
endif()

if(GPU_PLUGINS_ENABLED GREATER 1)
message(FATAL_ERROR "Only one GPU plugin can be enabled at a time")
endif()

add_lldb_tool(lldb-server
Expand All @@ -71,7 +93,6 @@ add_lldb_tool(lldb-server
lldbPluginInstructionMIPS64
lldbPluginInstructionRISCV
${LLDB_SYSTEM_LIBS}
lldbServerPluginMockGPU
)

set_target_properties(lldb-server PROPERTIES ENABLE_EXPORTS 1)
Expand Down
10 changes: 0 additions & 10 deletions lldb/tools/lldb-server/Plugins/AMDGPU/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@

message(STATUS "ROCM_PATH is set to: '${ROCM_PATH}'")
if(NOT ROCM_PATH)
message(FATAL_ERROR "ROCM_PATH must be specified. Use -DROCM_PATH=/path/to/rocm")
endif()

if (NOT EXISTS ${ROCM_PATH})
message(FATAL_ERROR "ROCM_PATH does not exist: '${ROCM_PATH}'")
endif()

# Find AMD-dbgapi package using the provided CMake config
set(amd-dbgapi_DIR "${ROCM_PATH}/lib/cmake/amd-dbgapi" CACHE PATH "Path to amd-dbgapi cmake config")
find_package(amd-dbgapi REQUIRED CONFIG)
Expand Down
7 changes: 5 additions & 2 deletions lldb/tools/lldb-server/Plugins/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
if(DEFINED ROCM_PATH AND EXISTS ${ROCM_PATH})
if(LLDB_ENABLE_AMDGPU_PLUGIN)
add_subdirectory(AMDGPU)
endif()
add_subdirectory(MockGPU)

if(LLDB_ENABLE_MOCK_GPU_PLUGIN)
add_subdirectory(MockGPU)
endif()
27 changes: 14 additions & 13 deletions lldb/tools/lldb-server/lldb-gdbserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include "llvm/Support/Errno.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/WithColor.h"
#include "Plugins/Process/gdb-remote/LLDBServerPlugin.h"

#if defined(__linux__)
#include "Plugins/Process/Linux/NativeProcessLinux.h"
Expand All @@ -49,10 +50,10 @@

#if defined(LLDB_ENABLE_AMDGPU_PLUGIN)
#include "Plugins/AMDGPU/LLDBServerPluginAMDGPU.h"
typedef lldb_private::lldb_server::LLDBServerPluginAMDGPU LLDBServerGPUPlugin;
#elif defined(LLDB_ENABLE_MOCKGPU_PLUGIN)
#endif

#if defined(LLDB_ENABLE_MOCKGPU_PLUGIN)
#include "Plugins/MockGPU/LLDBServerPluginMockGPU.h"
typedef lldb_private::lldb_server::LLDBServerPluginMockGPU LLDBServerGPUPlugin;
#endif
Comment on lines 51 to 57
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if both plug-ins are enabled? It seems this would redefine the LLDBServerGPUPlugin typedef and case a build error:

(lldb) expr
Enter expressions, then terminate with an empty line to evaluate:
  1: typedef int Foo; 
  2: typedef float Foo; 
error: <user expression 0>:2:15: typedef redefinition with different types ('float' vs 'int')
    2 | typedef float Foo;
      |               ^
note: <user expression 0>:1:13: previous definition is here
    1 | typedef int Foo;
      |             ^

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Greg, there are no more typedefs!


#ifndef LLGS_PROGRAM_NAME
Expand Down Expand Up @@ -461,19 +462,19 @@ int main_gdbserver(int argc, char *argv[]) {
NativeProcessManager manager(mainloop);
GDBRemoteCommunicationServerLLGS gdb_server(mainloop, manager, "gdb-server");

#if defined(LLDB_ENABLE_AMDGPU_PLUGIN) || defined(LLDB_ENABLE_MOCKGPU_PLUGIN)
#if defined(LLDB_ENABLE_AMDGPU_PLUGIN)
// AMD GPU plugin requires to use the same mainloop as the native process.
// This is because AMD debug API has to be called from the same thread as the
// ptrace() thread.
MainLoop &gpu_mainloop = mainloop;
#else
// Any GPU plugins can use a separate mainloop.
MainLoop gpu_mainloop;
{
// AMD GPU plugin requires to use the same mainloop as the native process.
// This is because AMD debug API has to be called from the same thread as the
// ptrace() thread.
gdb_server.InstallPlugin(
std::make_unique<lldb_private::lldb_server::LLDBServerPluginAMDGPU>(gdb_server, mainloop));
}
#endif
// Install GPU plugin.
#if defined(LLDB_ENABLE_MOCKGPU_PLUGIN)
MainLoop &gpu_mainloop = mainloop;
gdb_server.InstallPlugin(
std::make_unique<LLDBServerGPUPlugin>(gdb_server, gpu_mainloop));
std::make_unique<lldb_private::lldb_server::LLDBServerPluginMockGPU>(gdb_server, gpu_mainloop));
#endif

llvm::StringRef host_and_port;
Expand Down