diff --git a/lldb/docs/use/gpu-support.rst b/lldb/docs/use/gpu-support.rst new file mode 100644 index 0000000000000..d56526617aa53 --- /dev/null +++ b/lldb/docs/use/gpu-support.rst @@ -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. \ No newline at end of file diff --git a/lldb/tools/lldb-server/CMakeLists.txt b/lldb/tools/lldb-server/CMakeLists.txt index 3248063f0e8e6..8cdf5411dbd53 100644 --- a/lldb/tools/lldb-server/CMakeLists.txt +++ b/lldb/tools/lldb-server/CMakeLists.txt @@ -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 @@ -71,7 +93,6 @@ add_lldb_tool(lldb-server lldbPluginInstructionMIPS64 lldbPluginInstructionRISCV ${LLDB_SYSTEM_LIBS} - lldbServerPluginMockGPU ) set_target_properties(lldb-server PROPERTIES ENABLE_EXPORTS 1) diff --git a/lldb/tools/lldb-server/Plugins/AMDGPU/CMakeLists.txt b/lldb/tools/lldb-server/Plugins/AMDGPU/CMakeLists.txt index 99493a3b03fb6..9a0c2eeac699d 100644 --- a/lldb/tools/lldb-server/Plugins/AMDGPU/CMakeLists.txt +++ b/lldb/tools/lldb-server/Plugins/AMDGPU/CMakeLists.txt @@ -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) diff --git a/lldb/tools/lldb-server/Plugins/CMakeLists.txt b/lldb/tools/lldb-server/Plugins/CMakeLists.txt index e1431e20265f6..18e5f9af4b26d 100644 --- a/lldb/tools/lldb-server/Plugins/CMakeLists.txt +++ b/lldb/tools/lldb-server/Plugins/CMakeLists.txt @@ -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() diff --git a/lldb/tools/lldb-server/lldb-gdbserver.cpp b/lldb/tools/lldb-server/lldb-gdbserver.cpp index 4f818c15dbe5b..572282b823d34 100644 --- a/lldb/tools/lldb-server/lldb-gdbserver.cpp +++ b/lldb/tools/lldb-server/lldb-gdbserver.cpp @@ -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" @@ -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 #ifndef LLGS_PROGRAM_NAME @@ -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(gdb_server, mainloop)); + } #endif - // Install GPU plugin. +#if defined(LLDB_ENABLE_MOCKGPU_PLUGIN) + MainLoop &gpu_mainloop = mainloop; gdb_server.InstallPlugin( - std::make_unique(gdb_server, gpu_mainloop)); + std::make_unique(gdb_server, gpu_mainloop)); #endif llvm::StringRef host_and_port;