diff --git a/CMakeLists.txt b/CMakeLists.txt index 5bcb7cd..e5a68a5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -34,11 +34,9 @@ cmake_minimum_required(VERSION 3.8.0) -project(ROCM_DEBUG_AGENT VERSION 2.0.3) +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}") +include(GNUInstallDirs) file(GLOB SOURCES "src/*.cpp") add_library(rocm-debug-agent SHARED ${SOURCES}) @@ -47,8 +45,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/") @@ -122,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() @@ -137,7 +135,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/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..d2761fe 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 @@ -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; 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 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)