From 32907ff14c47a52c7a5186cbddaee3ad562550c0 Mon Sep 17 00:00:00 2001 From: Ammar ELWazir Date: Thu, 19 Oct 2023 23:12:04 +0000 Subject: [PATCH] Fixing Tool/Plugin Versioning and adding --version and adding proper documentation for those features Change-Id: Icdb0d64e02943e638f183ab31759a37736d2dd61 --- CHANGELOG.md | 3 ++ README.md | 43 ++++++++++++++- bin/rocprofv2 | 84 +++++++++++++++++++---------- bin/rpl_run.sh | 9 ++++ src/tools/CMakeLists.txt | 1 + src/tools/versioning/CMakeLists.txt | 13 +++++ src/tools/versioning/version.cpp | 20 +++++++ 7 files changed, 143 insertions(+), 30 deletions(-) create mode 100644 src/tools/versioning/CMakeLists.txt create mode 100644 src/tools/versioning/version.cpp diff --git a/CHANGELOG.md b/CHANGELOG.md index aa3400c003..3152c5a809 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -303,3 +303,6 @@ Example for file plugin output: - CSV mode for ATT. See README. - Added option to control kernel name truncation. - Limit rocprof(v1) srcipt usage to only supported architectures. +- Added Tool versioning to be able to run rocprofv2 using rocprof. See README for more information. +- Added Plugin Versioning way in rocprofv2. See README for more details. +- Added --version in the rocprof and rocprofv2 to be able to see the current rocprof/v2 version along with ROCm version information. diff --git a/README.md b/README.md index d640e2c39a..32df0c36a6 100644 --- a/README.md +++ b/README.md @@ -220,6 +220,23 @@ A command line utility to control a session (launch/start/stop/exit), with the r rocsys –session session_name exit ``` +### ROCProf Versioning Support + +Currently, rocprof can support both versions, rocprof and rocprofv2, that can be done using `--tool-version` + +```bash +rocprof --tool-version +``` + +- `--tool-version 1` means it will just use rocprof V1. +- `--tool-version 2` means it will just use rocprofv2. + +To know what version you are using right now, along with more information about the rocm version, use the following: + +```bash +rocprof --version +``` + ### Counters and Metric Collection HW counters and derived metrics can be collected using following option: @@ -279,13 +296,31 @@ rocprofiler-plugins_2.0.0-local_amd64.deb rocprofiler-plugins-2.0.0-local.x86_64.rpm ``` -- File plugin: outputs the data in txt files. +Plugins may have multiple versions, the user can specify which version of the plugin to use by running the following command: + +```bash +rocprofv2 --plugin --plugin-version +``` + +- File plugin: outputs the data in txt files. File plugin have two versions, by default version 2 is the current default. Usage: ```bash rocprofv2 --plugin file -i samples/input.txt -d output_dir # -d is optional, but can be used to define the directory output for output results ``` + File plugin version 1 output header will be similar to the legacy rocprof v1 output: + + ```text + Index,KernelName,gpu-id,queue-id,queue-index,pid,tid,grd,wgr,lds,scr,arch_vgpr,accum_vgpr,sgpr,wave_size,sig,obj,DispatchNs,BeginNs,EndNs,CompleteNs,Counters + ``` + + File plugin version 2 output header: + + ```text + Dispatch_ID,GPU_ID,Queue_ID,PID,TID,Grid_Size,Workgroup_Size,LDS_Per_Workgroup,Scratch_Per_Workitem,Arch_VGPR,Accum_VGPR,SGPR,Wave_Size,Kernel_Name,Start_Timestamp,End_Timestamp,Correlation_ID,Counters + ``` + - Perfetto plugin: outputs the data in protobuf format. Protobuf files can be viewed using ui.perfetto.dev or using trace_processor. Usage: @@ -362,7 +397,7 @@ Tool used to collect fine-grained hardware metrics. Provides ISA-level instructi - 1 = capture symbols for file:// and make a copy of memory:// - 2 = Copy file:// and memory:// - By default, kernel names are truncated for ATT.To disable, please see the kernel name truncation section below. - + - Example for vectoradd. ```bash @@ -371,9 +406,11 @@ Tool used to collect fine-grained hardware metrics. Provides ISA-level instructi # "auto" means to use the automatically captured ISA. "csv" dumps result to "vectoradd_float_v0.csv". rocprofv2 -i input.txt --plugin att auto --mode csv ./vectoradd_hip.exe ``` + Instruction latencies will be in vectoradd_float_v0.csv - Example with symbolic ISA (as in ROCm 5.7 or previous). + ```bash hipcc -g --save-temps vectoradd_hip.cpp -o vectoradd_hip.exe # A custom ISA can be used such as vectoradd_hip-hip-amdgcn-amd-amdhsa-gfx1100.s @@ -389,7 +426,9 @@ Tool used to collect fine-grained hardware metrics. Provides ISA-level instructi # Run only data collection, not the parser rocprofv2 -i input.txt --plugin att auto --mode off ./vectoradd_hip.exe ``` + Remove the binary/application from the command line. + ```bash # Only runs the parser on previously collected data. rocprofv2 -i input.txt --plugin att auto --mode csv diff --git a/bin/rocprofv2 b/bin/rocprofv2 index e74ab6f4e9..262ba91bba 100755 --- a/bin/rocprofv2 +++ b/bin/rocprofv2 @@ -8,7 +8,7 @@ if [ -n "${ROCP_PRELOAD}" ]; then LD_PRELOAD="${ROCP_PRELOAD}"; fi CURRENT_DIR="$( dirname -- "$0"; )"; ROCPROFV2_DIR=$(dirname -- $(realpath ${BASH_SOURCE[0]})); ROCM_DIR=$( dirname -- "$ROCPROFV2_DIR"; ) -PLUGIN_LIST=("ctf" "perfetto" "file" "att") +PLUGIN_LIST=("ctf" "perfetto" "file" "att" "cli") RUN_FROM_BUILD=0 if [[ $ROCPROFV2_DIR == *"/build"* ]]; then RUN_FROM_BUILD=1 @@ -41,7 +41,7 @@ usage() { echo -e "${GREEN}--kernel-trace ${RESET} For Collecting Kernel dispatch Traces" echo -e "${GREEN}--sys-trace ${RESET} For Collecting HIP and HSA APIs and their Activities Traces along ROCTX and Kernel Dispatch traces\n" echo -e "\t#${GREY}usage e.g: rocprofv2 --[hip-trace|hsa-trace|roctx-trace|kernel-trace|sys-trace] \n"${RESET} - echo -e "${GREEN}--plugin ${RESET} PLUGIN_NAME For enabling a plugin (file/perfetto/att/ctf)" + echo -e "${GREEN}--plugin ${RESET} PLUGIN_NAME For enabling a plugin (cli/file/perfetto/att/ctf)" echo -e "\t#${GREY} usage(file/perfetto/ctf) e.g: rocprofv2 -i pmc.txt --plugin [file/perfetto/ctf] -d out_dir " echo -e "\t# usage(att): rocprofv2 --plugin att " echo -e "\t# use \"rocprofv2 --plugin att --help\" for ATT-specific parameters help.${RESET}\n" @@ -69,24 +69,24 @@ fi OUTPUT_PATH_INTERNAL="." while [ 1 ]; do - if [[ "$1" = "-h" || "$1" = "--help" ]]; then + if [[ "$1" == "-h" || "$1" == "--help" ]]; then usage exit 1 - elif [[ "$1" = "-t" || "$1" = "--test" ]]; then + elif [[ "$1" == "-t" || "$1" == "--test" ]]; then if [ $RUN_FROM_BUILD == 1 ]; then ./run_tests.sh exit 1 fi - elif [[ "$1" = "-mt" || "$1" = "--mem-test" ]]; then + elif [[ "$1" == "-mt" || "$1" == "--mem-test" ]]; then if [ $RUN_FROM_BUILD == 1 ]; then $ROCM_DIR/tests-v2/memorytests/run_asan_tests.sh $ROCM_DIR/tests-v2/featuretests/profiler/apps/hip_vectoradd $ROCM_DIR/memleaks.log exit 1 fi - elif [[ "$1" = "--list-counters" ]]; then + elif [[ "$1" == "--list-counters" ]]; then export LD_PRELOAD=$LD_PRELOAD:$ROCM_DIR/lib/rocprofiler/librocprofiler_tool.so eval $ROCM_DIR/libexec/rocprofiler/ctrl exit 1 - elif [[ "$1" = "-i" || "$1" = "--input" ]]; then + elif [[ "$1" == "-i" || "$1" == "--input" ]]; then if [ $2 ] && [ -n $2 ] && [ -r $2 ]; then export COUNTERS_PATH=$2 else @@ -96,7 +96,7 @@ while [ 1 ]; do fi shift shift - elif [[ "$1" = "-o" || "$1" = "--output-file-name" ]]; then + elif [[ "$1" == "-o" || "$1" == "--output-file-name" ]]; then if [ $2 ]; then export OUT_FILE_NAME=$2 else @@ -105,7 +105,7 @@ while [ 1 ]; do fi shift shift - elif [[ "$1" = "-d" || "$1" = "--output-directory" ]]; then + elif [[ "$1" == "-d" || "$1" == "--output-directory" ]]; then if [ $2 ]; then OUTPUT_PATH_INTERNAL=$2 export OUTPUT_PATH=$OUTPUT_PATH_INTERNAL @@ -115,7 +115,7 @@ while [ 1 ]; do fi shift shift - elif [[ "$1" = "-fi" || "$1" = "--flush-interval" ]]; then + elif [[ "$1" == "-fi" || "$1" == "--flush-interval" ]]; then if [ $2 ] && [ $2 -gt 0 ]; then export ROCPROFILER_FLUSH_INTERVAL=$2 else @@ -125,7 +125,7 @@ while [ 1 ]; do fi shift shift - elif [[ "$1" = "-tp" || "$1" = "--trace-period" ]]; then + elif [[ "$1" == "-tp" || "$1" == "--trace-period" ]]; then if [ $2 ] && [[ "$2" == *":"* ]]; then export ROCPROFILER_TRACE_PERIOD=$2 else @@ -135,38 +135,38 @@ while [ 1 ]; do fi shift shift - elif [ "$1" = "--hip-api" ]; then + elif [ "$1" == "--hip-api" ]; then export ROCPROFILER_HIP_API_TRACE=1 shift - elif [[ "$1" = "--hip-activity" || "$1" = "--hip-trace" ]]; then + elif [[ "$1" == "--hip-activity" || "$1" == "--hip-trace" ]]; then export ROCPROFILER_HIP_API_TRACE=1 export ROCPROFILER_HIP_ACTIVITY_TRACE=1 shift - elif [ "$1" = "--hsa-api" ]; then + elif [ "$1" == "--hsa-api" ]; then export ROCPROFILER_HSA_API_TRACE=1 shift - elif [[ "$1" = "--hsa-activity" || "$1" = "--hsa-trace" ]]; then + elif [[ "$1" == "--hsa-activity" || "$1" == "--hsa-trace" ]]; then export ROCPROFILER_HSA_API_TRACE=1 export ROCPROFILER_HSA_ACTIVITY_TRACE=1 shift - elif [ "$1" = "--roctx-trace" ]; then + elif [ "$1" == "--roctx-trace" ]; then export ROCPROFILER_ROCTX_TRACE=1 shift - elif [ "$1" = "--kernel-trace" ]; then + elif [ "$1" == "--kernel-trace" ]; then export ROCPROFILER_KERNEL_TRACE=1 shift - elif [ "$1" = "--sys-trace" ]; then + elif [ "$1" == "--sys-trace" ]; then export ROCPROFILER_HIP_API_TRACE=1 export ROCPROFILER_HIP_ACTIVITY_TRACE=1 export ROCPROFILER_HSA_API_TRACE=1 export ROCPROFILER_HSA_ACTIVITY_TRACE=1 export ROCPROFILER_ROCTX_TRACE=1 shift - elif [ "$1" = "--roc-sys" ]; then + elif [ "$1" == "--roc-sys" ]; then export ROCPROFILER_ENABLE_ROCSYS=$2 shift shift - elif [ "$1" = "-m" ]; then + elif [ "$1" == "-m" ]; then if [ $2 ] && [ -n $2 ] && [ -r $2 ]; then export ROCPROFILER_METRICS_PATH=$2 else @@ -176,17 +176,33 @@ while [ 1 ]; do fi shift shift - elif [ "$1" = "--basenames" ]; then + elif [ "$1" == "--version" ]; then + if [ -f "$ROCM_DIR/libexec/rocprofiler/rocprofiler-version" ]; then + ROCPROFILER_LIBRARY_VERSION=2 $ROCM_DIR/libexec/rocprofiler/rocprofiler-version + else + ROCM_VERSION=$(cat $ROCM_DIR/.info/version) + echo -e "ROCm version: $ROCM_VERSION" + echo -e "ROCProfiler version: 2.0" + fi + exit 0 + elif [ "$1" == "--basenames" ]; then export ROCPROFILER_TRUNCATE_KERNEL_PATH=1 - shift - elif [ "$1" = "--version" ]; then + elif [ "$1" == "--tool-version" ]; then shift shift - elif [ "$1" = "--plugin-version" ]; then - export ROCPROFILER_PLUGIN_LIB=$ROCPROFILER_PLUGIN_LIB.$2 + elif [ "$1" == "--plugin-version" ]; then + export ROCPROFILER_PLUGIN_LIB_VERSION=".$2" + if [ ! -z $ROCPROFILER_PLUGIN_LIB ]; then + if [ -f $ROCM_DIR/lib/rocprofiler/$ROCPROFILER_PLUGIN_LIB$ROCPROFILER_PLUGIN_LIB_VERSION ]; then + export ROCPROFILER_PLUGIN_LIB=$ROCPROFILER_PLUGIN_LIB$ROCPROFILER_PLUGIN_LIB_VERSION + else + echo -e "Error: \"$ROCPROFILER_PLUGIN_LIB$ROCPROFILER_PLUGIN_LIB_VERSION\" doesn't exist!" + exit 1 + fi + fi shift shift - elif [ "$1" = "--plugin" ]; then + elif [ "$1" == "--plugin" ]; then if [ -n $2 ]; then PLUGIN=$2 if [[ ! "${PLUGIN_LIST[*]}" =~ $PLUGIN ]]; then @@ -194,7 +210,7 @@ while [ 1 ]; do usage exit 1 fi - export ROCPROFILER_PLUGIN_LIB=lib${PLUGIN}_plugin.so$ROCPROFILER_PLUGIN_LIB + export ROCPROFILER_PLUGIN_LIB=lib${PLUGIN}_plugin.so$ROCPROFILER_PLUGIN_LIB_VERSION else echo -e "Wrong input \"$2\" for plugin!" usage @@ -229,7 +245,7 @@ while [ 1 ]; do fi shift shift - elif [[ "$1" = "-"* || "$1" = "--"* ]]; then + elif [[ "$1" == "-"* || "$1" == "--"* ]]; then echo -e "Wrong option \"$1\", Please use the following options:\n" usage exit 1 @@ -253,6 +269,18 @@ if [ -n "$COUNTERS_PATH" ]; then done <$input fi +if [ -z $ROCPROFILER_PLUGIN_LIB ]; then + PLUGIN_TO_BE_USED=file_plugin + if [ -z $OUTPUT_PATH ]; then + PLUGIN_TO_BE_USED=cli_plugin + fi + if [ -f $ROCM_DIR/lib/rocprofiler/$ROCPROFILER_PLUGIN_LIB$ROCPROFILER_PLUGIN_LIB_VERSION ]; then + export ROCPROFILER_PLUGIN_LIB=lib$PLUGIN_TO_BE_USED.so$ROCPROFILER_PLUGIN_LIB_VERSION + else + export ROCPROFILER_PLUGIN_LIB=lib$PLUGIN_TO_BE_USED.so + fi +fi + if [ -n "$PMC_LINES" ] && [ ! -n "$ATT_ARGV" ]; then COUNTER=1 for i in ${!PMC_LINES[@]}; do diff --git a/bin/rpl_run.sh b/bin/rpl_run.sh index d4ac9c1086..76b85070a9 100755 --- a/bin/rpl_run.sh +++ b/bin/rpl_run.sh @@ -404,6 +404,15 @@ while [ 1 ] ; do echo "Wrong option '$1 $2'" usage fi + elif [ "$1" = "--version" ]; then + if [ -f "$BIN_DIR/../libexec/rocprofiler/rocprofiler-version" ]; then + ROCPROFILER_LIBRARY_VERSION=1 $BIN_DIR/../libexec/rocprofiler/rocprofiler-version + else + ROCM_VERSION=$(cat $BIN_DIR/../.info/version) + echo -e "ROCm version: $ROCM_VERSION" + echo -e "ROCProfiler version: 2.0" + fi + exit 0 elif [ "$1" = "-h" ] ; then usage elif [ "$1" = "-i" ] ; then diff --git a/src/tools/CMakeLists.txt b/src/tools/CMakeLists.txt index e17664c5d6..20b7d07924 100644 --- a/src/tools/CMakeLists.txt +++ b/src/tools/CMakeLists.txt @@ -47,6 +47,7 @@ install(TARGETS rocprofiler_tool LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}/roc add_subdirectory(rocsys) add_subdirectory(rocprofv2) +add_subdirectory(versioning) add_executable(ctrl ctrl.cpp) set_target_properties( diff --git a/src/tools/versioning/CMakeLists.txt b/src/tools/versioning/CMakeLists.txt new file mode 100644 index 0000000000..3b3cc76405 --- /dev/null +++ b/src/tools/versioning/CMakeLists.txt @@ -0,0 +1,13 @@ +# # TODO(aelwazir): To be added later once rocm-core is updated to be rocprofiler dependency + +find_library(ROCM_CORE_LIB rocm-core HINTS ${ROCM_PATH}/lib) + +if(ROCM_CORE_LIB) + add_executable(rocprofiler-version version.cpp) + target_link_libraries(rocprofiler-version PRIVATE ${ROCM_CORE_LIB}) + set_target_properties(rocprofiler-version PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/libexec/rocprofiler) + target_include_directories(rocprofiler-version PRIVATE ${ROCM_PATH}/include) + + install(TARGETS rocprofiler-version + RUNTIME DESTINATION ${CMAKE_INSTALL_LIBEXECDIR}/${PROJECT_NAME}) +endif() \ No newline at end of file diff --git a/src/tools/versioning/version.cpp b/src/tools/versioning/version.cpp new file mode 100644 index 0000000000..11bdd00ed4 --- /dev/null +++ b/src/tools/versioning/version.cpp @@ -0,0 +1,20 @@ +#include +#include +#include + + +int main() { + const char* envvar = getenv("ROCPROFILER_LIBRARY_VERSION"); + uint32_t mj = 0, mn = 0, p = 0; + int ret = 0; + ret = getROCmVersion(&mj, &mn, &p); + if (ret != VerSuccess) { + std::cerr << "Error occured while retreiving rocm version!\n"; + } else { + std::cout << "ROCm version: " << mj << "." << mn << "." << p << "\n"; + if (envvar) std::cout << "ROCProfiler Version: " << envvar << "\n"; + std::cout << "\nFull Build information for ROCm:\t"; + printBuildInfo(); + } + return 1; +} \ No newline at end of file