From 49a2797e5f222e4e7c3c3bcbb3389803ecdb8b55 Mon Sep 17 00:00:00 2001 From: Ranjith Ramakrishnan Date: Fri, 4 Mar 2022 11:17:11 -0800 Subject: [PATCH 1/4] File Reorganization changes Header file path updated to amd-dbgapi/amd-dbgapi.h based on dbgapi changes Depends-On: I74367e6961b8658511bd1225e1725182308f0a01 Depends-On: I446c3edd0a20eafc47aaac084e6ff9216870400c Change-Id: I472b5194127cacd9e31f2d9ca4f8ca066d7153d3 --- src/code_object.h | 4 ++-- src/debug_agent.cpp | 2 +- src/logging.cpp | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/code_object.h b/src/code_object.h index 566723f..44c10a1 100644 --- a/src/code_object.h +++ b/src/code_object.h @@ -31,7 +31,7 @@ #ifndef _ROCM_DEBUG_AGENT_CODE_OBJECT_H #define _ROCM_DEBUG_AGENT_CODE_OBJECT_H 1 -#include +#include #include #include @@ -98,4 +98,4 @@ class code_object_t } /* namespace amd::debug_agent */ -#endif /* _ROCM_DEBUG_AGENT_CODE_OBJECT_H */ \ No newline at end of file +#endif /* _ROCM_DEBUG_AGENT_CODE_OBJECT_H */ diff --git a/src/debug_agent.cpp b/src/debug_agent.cpp index 67f5c63..846a4cd 100644 --- a/src/debug_agent.cpp +++ b/src/debug_agent.cpp @@ -32,7 +32,7 @@ #include "debug.h" #include "logging.h" -#include +#include #include #include #include diff --git a/src/logging.cpp b/src/logging.cpp index d2396d0..2111475 100644 --- a/src/logging.cpp +++ b/src/logging.cpp @@ -30,7 +30,7 @@ #include "logging.h" -#include +#include #include #include From 0d7def50400b2a0bbc2ad34eb2b57d7f2ca3a745 Mon Sep 17 00:00:00 2001 From: Laurent Morichetti Date: Fri, 18 Mar 2022 13:41:56 -0700 Subject: [PATCH 2/4] Fix printing all wavefronts When printing all wavefronts is requested, the debug agent must stop running waves before inspecting their state. The stop_all_wavefronts function iterates all wavefronts, and stops the wavefronts that are still running. stop_all_wavefronts was failing to detect already stopped wavefronts. Added a check before sending the stop request as it is illegal to send a stop request to an already stopped wavefront. Also noticed that the stopped events were not reported as processed, and resuming wavefronts with stop events was returning an error. A wave is only trully stopped when the stop event is processed. Added amd_dbgapi_event_processed to both event loops. Change-Id: I0eb09d61253e1682488eb6b3c389854f195fdab1 --- src/debug_agent.cpp | 72 ++++++++++++++++++++++++++++++++++++++------- 1 file changed, 62 insertions(+), 10 deletions(-) diff --git a/src/debug_agent.cpp b/src/debug_agent.cpp index 846a4cd..d2761fe 100644 --- a/src/debug_agent.cpp +++ b/src/debug_agent.cpp @@ -365,19 +365,35 @@ stop_all_wavefronts (amd_dbgapi_process_id_t process_id) if (event_id.handle == AMD_DBGAPI_EVENT_NONE.handle) break; - if (kind == AMD_DBGAPI_EVENT_KIND_WAVE_STOP) + if (kind == AMD_DBGAPI_EVENT_KIND_WAVE_STOP + || kind == AMD_DBGAPI_EVENT_KIND_WAVE_COMMAND_TERMINATED) { amd_dbgapi_wave_id_t wave_id; DBGAPI_CHECK (amd_dbgapi_event_get_info ( event_id, AMD_DBGAPI_EVENT_INFO_WAVE, sizeof (wave_id), &wave_id)); + agent_assert (waiting_to_stop.find (wave_id.handle) + != waiting_to_stop.end ()); + waiting_to_stop.erase (wave_id.handle); - already_stopped.emplace (wave_id.handle); - agent_log (log_level_t::info, "wave_%ld is stopped", - wave_id.handle); + if (kind == AMD_DBGAPI_EVENT_KIND_WAVE_STOP) + { + already_stopped.emplace (wave_id.handle); + + agent_log (log_level_t::info, "wave_%ld is stopped", + wave_id.handle); + } + else /* kind == AMD_DBGAPI_EVENT_KIND_COMMAND_TERMINATED */ + { + agent_log (log_level_t::info, + "wave_%ld terminated while stopping", + wave_id.handle); + } } + + DBGAPI_CHECK (amd_dbgapi_event_processed (event_id)); } amd_dbgapi_wave_id_t *wave_ids; @@ -401,13 +417,47 @@ stop_all_wavefronts (amd_dbgapi_process_id_t process_id) continue; } - agent_log (log_level_t::info, - "wave_%ld is running, sending stop request", - wave_id.handle); + amd_dbgapi_wave_state_t state; + if (amd_dbgapi_status_t status = amd_dbgapi_wave_get_info ( + wave_id, AMD_DBGAPI_WAVE_INFO_STATE, sizeof (state), &state); + status == AMD_DBGAPI_STATUS_ERROR_INVALID_WAVE_ID) + { + /* The wave could have terminated since it was reported in the + last wave list. Skip it. */ + continue; + } + else if (status != AMD_DBGAPI_STATUS_SUCCESS) + agent_error ("amd_dbgapi_wave_get_info failed (rc=%d)", status); + + if (state == AMD_DBGAPI_WAVE_STATE_STOP) + { + already_stopped.emplace (wave_ids[i].handle); - /* FIXME: The wave could be single-stepping, how are we going to - restore the state? */ - DBGAPI_CHECK (amd_dbgapi_wave_stop (wave_id)); + agent_log (log_level_t::info, "wave_%ld is already stopped", + wave_id.handle); + continue; + } + if (state == AMD_DBGAPI_WAVE_STATE_SINGLE_STEP) + { + /* The wave is single-stepping, it will stop and report an event + once the instruction execution is complete. */ + agent_log (log_level_t::info, "wave_%ld is single-stepping", + wave_id.handle); + continue; + } + + if (amd_dbgapi_status_t status = amd_dbgapi_wave_stop (wave_id); + status == AMD_DBGAPI_STATUS_ERROR_INVALID_WAVE_ID) + { + /* The wave could have terminated since it was reported in the + last wave list. Skip it. */ + continue; + } + else if (status != AMD_DBGAPI_STATUS_SUCCESS) + agent_error ("amd_dbgapi_wave_stop failed (rc=%d)", status); + + agent_log (log_level_t::info, + "wave_%ld is running, sent stop request", wave_id.handle); waiting_to_stop.emplace (wave_id.handle); } @@ -473,6 +523,8 @@ print_wavefronts (bool all_wavefronts) /* No more events. */ if (event_kind == AMD_DBGAPI_EVENT_KIND_NONE) break; + + DBGAPI_CHECK (amd_dbgapi_event_processed (event_id)); } std::map code_object_map; From aa0a1a6a0548abf690e8c976c6f1fc5655743df2 Mon Sep 17 00:00:00 2001 From: Laurent Morichetti Date: Wed, 22 Jun 2022 13:30:32 -0700 Subject: [PATCH 3/4] Use rocm-debug-agent instead of ROCM_DEBUG_AGENT as the project name GNUInstallDirs sets CMAKE_INSTALL_DOCDIR using the project name (DATAROOTDIR/doc/PROJECT_NAME). Since we want to use rocm-debug-agent for directory names, change the project name to rocm-debug-agent. Change-Id: I78427fc299b81baadc92ad1a5e77ab9c7052562b --- CMakeLists.txt | 12 ++++-------- test/CMakeLists.txt | 2 +- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5bcb7cd..ad51f0c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -34,11 +34,7 @@ cmake_minimum_required(VERSION 3.8.0) -project(ROCM_DEBUG_AGENT VERSION 2.0.3) - -# The project command does not set the _NAME variable so must set -# it explicitly. -set(ROCM_DEBUG_AGENT_NAME "${PROJECT_NAME}") +project(rocm-debug-agent VERSION 2.0.3) file(GLOB SOURCES "src/*.cpp") add_library(rocm-debug-agent SHARED ${SOURCES}) @@ -47,8 +43,8 @@ set_target_properties(rocm-debug-agent PROPERTIES CXX_STANDARD 17 CXX_STANDARD_REQUIRED ON CXX_EXTENSIONS OFF - VERSION ${ROCM_DEBUG_AGENT_VERSION} - SOVERSION ${ROCM_DEBUG_AGENT_VERSION_MAJOR} + VERSION ${PROJECT_VERSION} + SOVERSION ${PROJECT_VERSION_MAJOR} NO_SYSTEM_FROM_IMPORTED ON) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/modules/") @@ -137,7 +133,7 @@ set(CPACK_PACKAGE_NAME rocm-debug-agent) set(CPACK_PACKAGE_VENDOR "Advanced Micro Devices, Inc") set(CPACK_PACKAGE_CONTACT "ROCm Debugger Support ") set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Radeon Open Compute Debug Agent (ROCdebug-agent)") -set(CPACK_PACKAGE_VERSION ${ROCM_DEBUG_AGENT_VERSION}) +set(CPACK_PACKAGE_VERSION ${PROJECT_VERSION}) set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE.txt") if(DEFINED ENV{ROCM_LIBPATCH_VERSION}) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index eed1d02..a0c3d01 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -34,7 +34,7 @@ cmake_minimum_required(VERSION 3.8.0) -project(ROCM_DEBUG_AGENT_TEST VERSION ${ROCM_DEBUG_AGENT_VERSION}) +project(rocm-debug-agent-test) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "/opt/rocm/hip/cmake") find_package(HIP REQUIRED MODULE) From 3d715192e4c6d2177452b758a84b4727bf1b0358 Mon Sep 17 00:00:00 2001 From: Ranjith Ramakrishnan Date: Fri, 20 May 2022 08:35:38 -0700 Subject: [PATCH 4/4] SWDEV-321112: Use GNUInstallDirs Use GNUInstallDirs variables to determine the location of BINDIR, LIBDIR, INCLUDEDIR, DOCDIR, LIBEXECDIR and DATADIR. Change-Id: I5e9a78d094a15d5c96465df48e8fc12237991aaf --- CMakeLists.txt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ad51f0c..e5a68a5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -36,6 +36,8 @@ cmake_minimum_required(VERSION 3.8.0) project(rocm-debug-agent VERSION 2.0.3) +include(GNUInstallDirs) + file(GLOB SOURCES "src/*.cpp") add_library(rocm-debug-agent SHARED ${SOURCES}) @@ -118,11 +120,11 @@ target_compile_definitions(rocm-debug-agent install(TARGETS rocm-debug-agent LIBRARY NAMELINK_SKIP - DESTINATION lib + DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT runtime) install(FILES LICENSE.txt README.md - DESTINATION share/doc/rocm-debug-agent + DESTINATION ${CMAKE_INSTALL_DOCDIR} COMPONENT runtime) enable_testing()