2019-10-09 13:17:21 -05:00
#!/bin/bash
2018-09-04 19:10:19 -05:00
2018-07-01 16:09:23 -05:00
################################################################################
2018-08-19 04:11:04 -05:00
# Copyright (c) 2018 Advanced Micro Devices, Inc. All rights reserved.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
2018-07-01 16:09:23 -05:00
################################################################################
2023-08-12 04:49:49 +00:00
ROCPROF_ARGS = " $* "
2018-07-01 15:31:42 -05:00
time_stamp = ` date +%y%m%d_%H%M%S`
2021-04-21 15:54:34 -07:00
BIN_DIR = $( dirname $( realpath ${ BASH_SOURCE [0] } ) )
2022-02-26 16:31:35 -08:00
ROOT_DIR = $( dirname $BIN_DIR )
2018-07-01 15:31:42 -05:00
RUN_DIR = ` pwd `
TMP_DIR = "/tmp"
DATA_DIR = " rpl_data_ ${ time_stamp } _ $$ "
2022-02-26 16:31:35 -08:00
RPL_PATH = $ROOT_DIR /lib
TLIB_PATH = $RPL_PATH /rocprofiler
2022-05-20 04:18:40 -05:00
TTLIB_PATH = $ROOT_DIR /lib/roctracer
2021-05-24 11:25:08 +05:30
ROCM_LIB_PATH = $ROOT_DIR /lib
2022-02-26 16:31:35 -08:00
PROF_BIN_DIR = $ROOT_DIR /libexec/rocprofiler
2018-07-01 15:31:42 -05:00
2025-01-15 22:59:21 +05:30
# Define color code
GREEN = '\033[0;32m'
GREY = '\033[0;90m'
RED = '\033[0;31m'
RESET = '\033[0m'
# Function to display deprecation warning message
display_warning( ) {
echo -e " \n ${ RED } WARNING: We are phasing out development and support for roctracer/rocprofiler/rocprof/rocprofv2 in favor of \
rocprofiler-sdk/rocprofv3 in upcoming ROCm releases. Going forward, only critical defect fixes will be addressed for \
older versions of profiling tools and libraries. We encourage all users to upgrade to the latest version, \
rocprofiler-sdk library and rocprofv3 tool, to ensure continued support and access to new features. ${ RESET } \n "
}
# Display the warning message
display_warning
2023-10-05 15:09:21 +05:30
# check if rocprof is supportd on this gpu arch
2024-01-22 13:20:43 -03:00
V1_SUPPORTED_GPU_ARCHS = ( "gfx80x" ,"gfx90x" ,"gfx94x" )
2023-10-05 15:09:21 +05:30
IS_SUPPORTED = "false"
2024-06-07 11:14:39 -05:00
if [ -f $BIN_DIR /rocm_agent_enumerator ] ; then
CURRENT_AGENTS_LIST = $( $BIN_DIR /rocm_agent_enumerator)
else
IS_SUPPORTED = "false"
echo -e "Warning: Missing rocm_agent_enumerator binary"
exit 0
fi
2023-10-05 15:09:21 +05:30
2020-01-24 14:22:52 -06:00
if [ -z " $ROCP_PYTHON_VERSION " ] ; then
2020-04-24 14:51:09 -05:00
ROCP_PYTHON_VERSION = python3
2020-01-24 14:22:52 -06:00
fi
2019-01-28 08:47:13 -06:00
# runtime API trace
2019-10-09 23:39:59 -05:00
ROCTX_TRACE = 0
2019-01-17 16:51:56 -06:00
HSA_TRACE = 0
2019-07-18 00:41:49 -05:00
SYS_TRACE = 0
2019-01-28 08:47:13 -06:00
HIP_TRACE = 0
2019-01-17 16:51:56 -06:00
# Generate stats
GEN_STATS = 0
2019-11-08 21:13:44 -06:00
# Quoting profiled cmd line
CMD_QTS = 1
2023-11-09 12:29:49 +00:00
export PATH = .:$PATH
# enable error logging
export HSA_TOOLS_REPORT_LOAD_FAILURE = 1
export HSA_VEN_AMD_AQLPROFILE_LOG = 1
export ROCPROFILER_LOG = 1
unset ROCPROFILER_SESS
# Profiler environment
# Loading of profiler library by HSA runtime
MY_HSA_TOOLS_LIB = " $RPL_PATH /librocprofiler64.so.1 "
2024-03-06 14:31:12 +05:30
# Tool internal Preloads
2025-04-14 08:41:00 -05:00
ROCPROFV1_LD_PRELOAD = $MY_HSA_TOOLS_LIB
2024-03-06 14:31:12 +05:30
ROCPROFV1_TOOL_PRELOAD = $MY_HSA_TOOLS_LIB
2023-11-09 12:29:49 +00:00
# Loading of the test tool by ROC Profiler
export ROCP_TOOL_LIB = $TLIB_PATH /librocprof-tool.so
# ROC Profiler metrics definition
export ROCP_METRICS = $TLIB_PATH /metrics.xml
# Enabling HSA dispatches intercepting by ROC PRofiler
export ROCP_HSA_INTERCEPT = 1
# Disabling internal ROC Profiler proxy queue (simple version supported for testing purposes)
unset ROCP_PROXY_QUEUE
# Disable AQL-profile read API
export AQLPROFILE_READ_API = 0
# ROC Profiler package path
export ROCP_PACKAGE_DIR = $ROOT_DIR
# enabled SPM KFD mode
export ROCP_SPM_KFD_MODE = 1
2018-07-01 15:31:42 -05:00
# error handling
fatal( ) {
echo " $0 : Error: $1 "
echo ""
usage
2019-08-25 05:08:55 -05:00
exit 1
2018-07-01 15:31:42 -05:00
}
error( ) {
echo " $0 : Error: $1 "
echo ""
exit 1
}
2019-10-09 13:17:21 -05:00
error_message = ""
errck( ) {
if [ -n " $error_message " ] ; then
fatal " $1 : $error_message "
fi
}
2018-07-01 15:31:42 -05:00
# usage method
usage( ) {
bin_name = ` basename $0 `
echo "ROCm Profiling Library (RPL) run script, a part of ROCprofiler library package."
echo " Full path: $BIN_DIR / $bin_name "
2022-02-26 16:31:35 -08:00
echo " Metrics definition: $TLIB_PATH /metrics.xml "
2018-07-01 15:31:42 -05:00
echo ""
echo "Usage:"
2018-09-17 13:25:39 -05:00
echo " $bin_name [-h] [--list-basic] [--list-derived] [-i <input .txt/.xml file>] [-o <output CSV file>] <app command line> "
2018-07-01 15:31:42 -05:00
echo ""
echo "Options:"
echo " -h - this help"
2023-08-12 04:49:49 +00:00
echo " --tool-version <1|2> - to use specific version of rocprof tool, by default v1 is used"
echo " 1 - rocprofiler tool v1"
echo " 2 - rocprofiler tool v2"
2018-07-01 15:31:42 -05:00
echo " --verbose - verbose mode, dumping all base counters used in the input metrics"
echo " --list-basic - to print the list of basic HW counters"
echo " --list-derived - to print the list of derived metrics with formulas"
2019-11-08 21:13:44 -06:00
echo " --cmd-qts <on|off> - quoting profiled cmd line [on]"
2018-07-01 15:31:42 -05:00
echo ""
echo " -i <.txt|.xml file> - input file"
2019-10-25 17:43:35 -05:00
echo " Input file .txt format, automatically rerun application for every profiling features line:"
2018-07-01 15:31:42 -05:00
echo ""
echo " # Perf counters group 1"
echo " pmc : Wavefronts VALUInsts SALUInsts SFetchInsts FlatVMemInsts LDSInsts FlatLDSInsts GDSInsts VALUUtilization FetchSize"
echo " # Perf counters group 2"
echo " pmc : WriteSize L2CacheHit"
echo " # Filter by dispatches range, GPU index and kernel names"
echo " # supported range formats: \"3:9\", \"3:\", \"3\""
echo " range: 1 : 4"
echo " gpu: 0 1 2 3"
echo " kernel: simple Pass1 simpleConvolutionPass2"
echo ""
echo " Input file .xml format, for single profiling run:"
echo ""
echo " # Metrics list definition, also the form \"<block-name>:<event-id>\" can be used"
echo " # All defined metrics can be found in the 'metrics.xml'"
echo " # There are basic metrics for raw HW counters and high-level metrics for derived counters"
echo " <metric name=SQ:4,SQ_WAVES,VFetchInsts"
echo " ></metric>"
echo ""
echo " # Filter by dispatches range, GPU index and kernel names"
echo " <metric"
echo " # range formats: \"3:9\", \"3:\", \"3\""
echo " range=\"\""
echo " # list of gpu indexes \"0,1,2,3\""
echo " gpu_index=\"\""
echo " # list of matched sub-strings \"Simple1,Conv1,SimpleConvolution\""
echo " kernel=\"\""
echo " ></metric>"
echo ""
echo " -o <output file> - output CSV file [<input file base>.csv]"
2019-05-16 12:07:07 -05:00
echo " -d <data directory> - directory where profiler store profiling data including traces [/tmp]"
2022-06-29 12:53:51 +00:00
echo " The data directory is automatically removed if it is matching the default temporary directory."
2018-07-01 15:31:42 -05:00
echo " -t <temporary directory> - to change the temporary directory [/tmp]"
echo " By changing the temporary directory you can prevent removing the profiling data from /tmp or enable removing from not '/tmp' directory."
2019-09-26 23:13:14 -05:00
echo " -m <metric file> - file defining custom metrics to use in-place of defaults."
2018-07-01 15:31:42 -05:00
echo ""
echo " --basenames <on|off> - to turn on/off truncating of the kernel full function names till the base ones [off]"
2022-07-07 19:07:39 +00:00
echo " --timestamp <on|off> - to turn on/off the kernel dispatches timestamps, dispatch/begin/end/complete during kernel profiling [off]"
2019-01-17 02:50:57 -06:00
echo " --ctx-wait <on|off> - to wait for outstanding contexts on profiler exit [on]"
2018-07-01 15:31:42 -05:00
echo " --ctx-limit <max number> - maximum number of outstanding contexts [0 - unlimited]"
2018-08-01 10:46:19 -05:00
echo " --heartbeat <rate sec> - to print progress heartbeats [0 - disabled]"
2021-03-24 01:44:19 -05:00
echo " --obj-tracking <on|off> - to turn on/off kernels code objects tracking [on]"
2020-01-27 20:27:24 -06:00
echo " To support V3 code object"
2018-07-01 15:31:42 -05:00
echo ""
2019-04-04 21:03:15 -05:00
echo " --stats - generating kernel execution stats, file <output name>.stats.csv"
2020-01-27 20:27:24 -06:00
echo ""
echo " --roctx-trace - to enable rocTX application code annotation trace, \"Markers and Ranges\" JSON trace section."
2019-04-04 21:03:15 -05:00
echo " --hip-trace - to trace HIP, generates API execution stats and JSON file chrome-tracing compatible"
2020-01-07 12:15:29 -06:00
echo " --hsa-trace - to trace HSA, generates API execution stats and JSON file chrome-tracing compatible"
2020-02-25 20:09:45 -06:00
echo " --sys-trace - to trace HIP/HSA APIs and GPU activity, generates stats and JSON trace chrome-tracing compatible"
echo " '--hsa-trace' can be used in addition to select activity tracing from HSA (ROCr runtime) level"
2020-01-07 12:15:29 -06:00
echo " Generated files: <output name>.<domain>_stats.txt <output name>.json"
2019-03-12 18:19:17 -05:00
echo " Traced API list can be set by input .txt or .xml files."
echo " Input .txt:"
echo " hsa: hsa_queue_create hsa_amd_memory_pool_allocate"
echo " Input .xml:"
echo " <trace name=\"HSA\">"
echo " <parameters list=\"hsa_queue_create, hsa_amd_memory_pool_allocate\">"
echo " </parameters>"
echo " </trace>"
2019-01-17 16:51:56 -06:00
echo ""
2022-04-04 22:38:35 -07:00
echo " --roctx-rename - to rename kernels with their enclosing rocTX range's message."
echo ""
2019-12-11 14:41:51 -06:00
echo " --trace-start <on|off> - to enable tracing on start [on]"
2019-10-10 19:04:30 -05:00
echo " --trace-period <dealy:length:rate> - to enable trace with initial delay, with periodic sample length and rate"
2019-10-09 13:17:21 -05:00
echo " Supported time formats: <number(m|s|ms|us)>"
2020-01-27 20:27:24 -06:00
echo " --flush-rate <rate> - to enable trace flush rate (time period)"
echo " Supported time formats: <number(m|s|ms|us)>"
2022-06-29 12:53:51 +00:00
echo " --parallel-kernels - to enable concurrent kernels"
2019-10-09 13:17:21 -05:00
echo ""
2018-07-01 15:31:42 -05:00
echo "Configuration file:"
2022-06-29 12:53:51 +00:00
echo " You can set your parameters defaults preferences in the configuration file 'rpl_rc.xml'. The search path sequence: .: ${ HOME } :<installation directory> "
echo " First the configuration file is searched in the current directory, then in the current user's home directory, and then in the installation directory."
2020-01-07 12:15:29 -06:00
echo " Configurable options: 'basenames', 'timestamp', 'ctx-limit', 'heartbeat', 'obj-tracking'."
2018-07-01 15:31:42 -05:00
echo " An example of 'rpl_rc.xml':"
echo " <defaults"
echo " basenames=off"
echo " timestamp=off"
echo " ctx-limit=0"
echo " heartbeat=0"
2020-01-07 12:15:29 -06:00
echo " obj-tracking=off"
2018-07-01 15:31:42 -05:00
echo " ></defaults>"
echo ""
2023-10-30 23:13:53 +05:30
echo " --merge-traces - Script for aggregating results from multiple rocprofiler out directries."
echo " Usage: if running with rocprof"
echo " rocprof --merge-traces -o <outputdir> [<inputdir>...]"
echo ""
2018-07-01 15:31:42 -05:00
exit 1
}
2020-06-03 01:00:48 -05:00
# checking for availability of rocminfo utility
2021-05-24 11:25:08 +05:30
if !command -v rocminfo > /dev/null 2>& 1 ; then
error "'rocminfo' utility is not found: please add ROCM bin path to PATH env var." ;
fi
# setting ROCM_LIB_PATH
set_rocm_lib_path( ) {
for ROCM_LIB_PATH in " $ROOT_DIR /lib " " $ROOT_DIR /lib64 " ; do
2021-08-09 22:56:00 -04:00
if [ -d " $ROCM_LIB_PATH " ] ; then
2021-05-24 11:25:08 +05:30
return 0
fi
done
#error
2021-08-09 22:56:00 -04:00
return 255
2021-05-24 11:25:08 +05:30
}
2020-05-26 21:56:07 -05:00
2018-07-01 15:31:42 -05:00
# profiling run method
OUTPUT_LIST = ""
run( ) {
2021-05-24 11:25:08 +05:30
if ! set_rocm_lib_path ; then
2021-08-09 22:56:00 -04:00
echo " Fatal could not find ROCm lib directory "
2021-05-24 11:25:08 +05:30
fatal
fi
2023-11-03 14:46:39 +00:00
# split the CURRENT_AGENTS_LIST array into individual elements.
current_gpus = ( ${ CURRENT_AGENTS_LIST [@] } )
for gpu in " ${ current_gpus [@] } " ; do
# Check first 5 characters of gpu strings.
if [ [ " ${ V1_SUPPORTED_GPU_ARCHS [@] : 0 : 5 } " = ~ " ${ gpu : 0 : 5 } " ] ] ; then
IS_SUPPORTED = "true"
fi
done
if [ [ $IS_SUPPORTED = = "false" ] ] ; then
2024-01-22 13:20:43 -03:00
echo ""
echo "------------ ------------ ------------"
echo "WARNING: rocprof(v1) is not supported on this device. Recommended use: rocprofv2"
echo "Please refer project's README for a list of supported architecures."
echo "------------ ------------ ------------"
echo ""
2023-11-03 14:46:39 +00:00
fi
2018-07-01 15:31:42 -05:00
export ROCP_INPUT = " $1 "
OUTPUT_DIR = " $2 "
shift
shift
APP_CMD = $*
if [ " $OUTPUT_DIR " = "-" ] ; then
input_tag = ` echo $ROCP_INPUT | sed "s/\.xml//" `
export ROCP_OUTPUT_DIR = ${ input_tag } _results_${ time_stamp }
elif [ " $OUTPUT_DIR " = "--" ] ; then
unset ROCP_OUTPUT_DIR
else
export ROCP_OUTPUT_DIR = $OUTPUT_DIR
fi
echo " RPL: result dir ' $ROCP_OUTPUT_DIR ' "
2018-08-19 04:11:04 -05:00
2018-07-01 15:31:42 -05:00
if [ ! -e " $ROCP_INPUT " ] ; then
error " Input file ' $ROCP_INPUT ' not found "
fi
2018-08-19 04:11:04 -05:00
2018-07-01 15:31:42 -05:00
if [ -n " $ROCP_OUTPUT_DIR " ] ; then
if [ " $OUTPUT_DIR " = "-" ] ; then
if [ -e " $ROCP_OUTPUT_DIR " ] ; then
error " generated dir ' $ROCP_OUTPUT_DIR ' exists "
fi
fi
mkdir -p " $ROCP_OUTPUT_DIR "
2019-06-21 03:15:12 -05:00
OUTPUT_LIST = " $OUTPUT_LIST $ROCP_OUTPUT_DIR /results.txt "
2018-07-01 15:31:42 -05:00
fi
2018-08-19 04:11:04 -05:00
2019-02-01 22:37:59 -06:00
API_TRACE = ""
2020-04-22 22:26:16 -05:00
MY_LD_PRELOAD = ""
2019-10-09 23:39:59 -05:00
if [ " $ROCTX_TRACE " = 1 ] ; then
API_TRACE = ${ API_TRACE } ":roctx"
2023-09-07 13:09:15 +05:30
MY_LD_PRELOAD = " $ROCM_LIB_PATH /libroctx64.so "
2019-02-01 22:37:59 -06:00
fi
if [ " $HIP_TRACE " = 1 ] ; then
2019-10-09 23:39:59 -05:00
API_TRACE = ${ API_TRACE } ":hip"
2019-02-01 22:37:59 -06:00
fi
2019-10-09 23:39:59 -05:00
if [ " $SYS_TRACE " = 1 ] ; then
API_TRACE = ${ API_TRACE } ":sys"
fi
2019-10-25 17:43:35 -05:00
if [ " $HSA_TRACE " = 1 ] ; then
export ROCTRACER_DOMAIN = $API_TRACE ":hsa"
2024-03-06 14:31:12 +05:30
ROCPROFV1_TOOL_PRELOAD = " $MY_LD_PRELOAD $TTLIB_PATH /libroctracer_tool.so "
ROCPROFV1_LD_PRELOAD = " $MY_HSA_TOOLS_LIB : $ROCM_LIB_PATH /libroctracer64.so.4 "
2019-10-25 17:43:35 -05:00
elif [ -n " $API_TRACE " ] ; then
2019-10-09 23:39:59 -05:00
export ROCTRACER_DOMAIN = $API_TRACE
2019-10-25 17:43:35 -05:00
OUTPUT_LIST = " $ROCP_OUTPUT_DIR / "
2024-03-06 14:31:12 +05:30
ROCPROFV1_TOOL_PRELOAD = " $MY_LD_PRELOAD $TTLIB_PATH /libroctracer_tool.so "
ROCPROFV1_LD_PRELOAD = " $ROCM_LIB_PATH /libroctracer64.so.4 "
2019-01-17 16:51:56 -06:00
fi
2022-06-20 17:53:25 -05:00
if [ " $ROCP_STATS_OPT " = 1 ] ; then
if [ " $ROCTRACER_DOMAIN " = ":hip" ] ; then
2024-03-06 14:31:12 +05:30
ROCPROFV1_LD_PRELOAD = " $ROCM_LIB_PATH /libroctracer64.so.4 "
ROCPROFV1_TOOL_PRELOAD = " $MY_LD_PRELOAD $TTLIB_PATH /libhip_stats.so "
2022-06-20 17:53:25 -05:00
else
error_message = "ROCP_STATS_OPT is only available with --hip-trace option"
echo $error_message
exit 1
fi
fi
2020-04-24 01:32:40 -05:00
retval = 1
2018-07-01 15:31:42 -05:00
if [ -n " $ROCP_OUTPUT_DIR " ] ; then
2020-04-24 01:32:40 -05:00
log_file = " $ROCP_OUTPUT_DIR /log.txt "
exit_file = " $ROCP_OUTPUT_DIR /exit.txt "
{
2024-03-06 14:31:12 +05:30
HSA_TOOLS_LIB = " $ROCPROFV1_TOOL_PRELOAD " LD_PRELOAD = $LD_PRELOAD :" $ROCPROFV1_LD_PRELOAD " eval " $APP_CMD "
2020-04-24 01:32:40 -05:00
retval = $?
echo " exit( $retval ) " > $exit_file
} 2>& 1 | tee " $log_file "
exitval = ` cat " $exit_file " | sed -n " s/^.*exit(\([0-9]*\)).* $/\1/p " `
if [ -n " $exitval " ] ; then retval = $exitval ; fi
else
2024-03-06 14:31:12 +05:30
HSA_TOOLS_LIB = " $ROCPROFV1_TOOL_PRELOAD " LD_PRELOAD = $LD_PRELOAD :" $ROCPROFV1_LD_PRELOAD " eval " $APP_CMD "
2020-04-24 01:32:40 -05:00
retval = $?
2018-07-01 15:31:42 -05:00
fi
2020-04-24 13:56:08 -05:00
return $retval
2018-07-01 15:31:42 -05:00
}
2019-08-21 11:53:27 -05:00
merge_output( ) {
2020-06-15 01:13:19 -05:00
while [ -n " $1 " ] ; do
output_dir = $( echo " $1 " | sed " s/\/[^\/]* $// " )
for file_name in ` ls $output_dir ` ; do
output_name = $( echo $file_name | sed -n " /\.txt $/ s/^[0-9]*_//p " )
if [ -n " $output_name " ] ; then
trace_file = $output_dir /$file_name
output_file = $output_dir /$output_name
touch $output_file
cat $trace_file >> $output_file
fi
done
shift
2019-08-21 11:53:27 -05:00
done
}
2019-10-09 23:39:59 -05:00
convert_time_val( ) {
local time_maxumim_us = $(( 0 xffffffff))
local __resultvar = $1
eval " local val= $" $__resultvar
val_m = ` echo $val | sed -n " s/^\([0-9]*\)m $/\1/p " `
val_s = ` echo $val | sed -n " s/^\([0-9]*\)s $/\1/p " `
val_ms = ` echo $val | sed -n " s/^\([0-9]*\)ms $/\1/p " `
val_us = ` echo $val | sed -n " s/^\([0-9]*\)us $/\1/p " `
if [ -n " $val_m " ] ; then val_us = $(( val_m*60000000))
elif [ -n " $val_s " ] ; then val_us = $(( val_s*1000000))
elif [ -n " $val_ms " ] ; then val_us = $(( val_ms*1000))
fi
if [ -z " $val_us " ] ; then
error_message = " invalid time value format ( $val ) "
elif [ " $val_us " -gt " $time_maxumim_us " ] ; then
error_message = " time value exceeds maximum supported ( $val > ${ time_maxumim_us } us) "
else
eval $__resultvar = " ' $val_us ' "
fi
}
2023-11-09 12:29:49 +00:00
unset_v1_envs( ) {
# enable error logging
unset HSA_TOOLS_REPORT_LOAD_FAILURE
unset HSA_VEN_AMD_AQLPROFILE_LOG
unset ROCPROFILER_LOG
unset ROCPROFILER_SESS
unset MY_HSA_TOOLS_LIB
unset ROCP_TOOL_LIB
unset ROCP_METRICS
unset ROCP_HSA_INTERCEPT
unset ROCP_PROXY_QUEUE
unset AQLPROFILE_READ_API
unset ROCP_PACKAGE_DIR
unset ROCP_SPM_KFD_MODE
}
2019-10-09 23:39:59 -05:00
################################################################################################
2018-07-01 15:31:42 -05:00
# main
2022-02-26 16:31:35 -08:00
echo " RPL: on ' $time_stamp ' from ' $ROOT_DIR ' in ' $RUN_DIR ' "
2018-07-01 15:31:42 -05:00
# Parsing arguments
if [ -z " $1 " ] ; then
usage
fi
INPUT_FILE = ""
2018-11-08 03:54:09 -06:00
DATA_PATH = "-"
2018-07-01 15:31:42 -05:00
OUTPUT_DIR = "-"
output = ""
csv_output = ""
ARG_IN = ""
while [ 1 ] ; do
ARG_IN = $1
ARG_VAL = 1
2023-08-12 04:49:49 +00:00
if [ " $1 " = "--tool-version" ] ; then
if [ $2 = 1 ] ; then
:
elif [ $2 = 2 ] ; then
2023-11-09 12:29:49 +00:00
# unset all v1 variables
unset_v1_envs
2023-08-12 04:49:49 +00:00
eval $BIN_DIR /rocprofv2 $ROCPROF_ARGS
exit 0
else
echo " Wrong option ' $1 $2 ' "
usage
fi
2023-10-19 23:12:04 +00:00
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
2023-08-12 04:49:49 +00:00
elif [ " $1 " = "-h" ] ; then
2018-07-01 15:31:42 -05:00
usage
elif [ " $1 " = "-i" ] ; then
INPUT_FILE = " $2 "
elif [ " $1 " = "-o" ] ; then
output = " $2 "
2021-10-19 09:53:34 -07:00
if [ [ $output != *.csv ] ] ; then
echo "error: file name must have .CSV extension"
exit 1
fi
2018-07-01 15:31:42 -05:00
elif [ " $1 " = "-d" ] ; then
2018-11-08 03:54:09 -06:00
DATA_PATH = $2
2018-07-01 15:31:42 -05:00
elif [ " $1 " = "-t" ] ; then
TMP_DIR = " $2 "
if [ " $OUTPUT_DIR " = "-" ] ; then
DATA_PATH = $TMP_DIR
fi
2019-09-26 23:13:14 -05:00
elif [ " $1 " = "-m" ] ; then
unset ROCP_METRICS
export ROCP_METRICS = " $2 "
2018-07-01 15:31:42 -05:00
elif [ " $1 " = "--list-basic" ] ; then
export ROCP_INFO = b
2022-02-26 16:31:35 -08:00
HSA_TOOLS_LIB = " $MY_HSA_TOOLS_LIB " eval " $TLIB_PATH /rocprof-ctrl "
2018-07-01 15:31:42 -05:00
exit 1
elif [ " $1 " = "--list-derived" ] ; then
export ROCP_INFO = d
2022-02-26 16:31:35 -08:00
HSA_TOOLS_LIB = " $MY_HSA_TOOLS_LIB " eval " $TLIB_PATH /rocprof-ctrl "
2018-07-01 15:31:42 -05:00
exit 1
elif [ " $1 " = "--basenames" ] ; then
if [ " $2 " = "on" ] ; then
export ROCP_TRUNCATE_NAMES = 1
else
export ROCP_TRUNCATE_NAMES = 0
fi
elif [ " $1 " = "--timestamp" ] ; then
if [ " $2 " = "on" ] ; then
export ROCP_TIMESTAMP_ON = 1
else
export ROCP_TIMESTAMP_ON = 0
fi
2019-01-17 02:25:08 -06:00
elif [ " $1 " = "--ctx-wait" ] ; then
if [ " $2 " = "on" ] ; then
export ROCP_OUTSTANDING_WAIT = 1
else
export ROCP_OUTSTANDING_WAIT = 0
fi
2018-07-01 15:31:42 -05:00
elif [ " $1 " = "--ctx-limit" ] ; then
export ROCP_OUTSTANDING_MAX = " $2 "
elif [ " $1 " = "--heartbeat" ] ; then
export ROCP_OUTSTANDING_MON = " $2 "
2019-02-01 22:37:59 -06:00
elif [ " $1 " = "--stats" ] ; then
ARG_VAL = 0
export ROCP_TIMESTAMP_ON = 1
GEN_STATS = 1
2019-10-09 23:39:59 -05:00
elif [ " $1 " = "--roctx-trace" ] ; then
ARG_VAL = 0
2020-01-10 12:39:07 -06:00
GEN_STATS = 1
2019-10-09 23:39:59 -05:00
ROCTX_TRACE = 1
2019-01-17 19:51:02 -06:00
elif [ " $1 " = "--hsa-trace" ] ; then
ARG_VAL = 0
2019-02-01 22:37:59 -06:00
export ROCP_TIMESTAMP_ON = 1
GEN_STATS = 1
2019-01-17 19:51:02 -06:00
HSA_TRACE = 1
2019-07-18 00:41:49 -05:00
elif [ " $1 " = "--sys-trace" ] ; then
ARG_VAL = 0
export ROCP_TIMESTAMP_ON = 1
GEN_STATS = 1
SYS_TRACE = 1
2019-02-04 18:36:40 -06:00
elif [ " $1 " = "--hip-trace" ] ; then
ARG_VAL = 0
2019-03-07 23:55:30 -06:00
export ROCP_TIMESTAMP_ON = 1
2019-02-04 18:36:40 -06:00
GEN_STATS = 1
HIP_TRACE = 1
2022-04-04 22:38:35 -07:00
elif [ " $1 " = "--roctx-rename" ] ; then
ARG_VAL = 0
export ROCP_RENAME_KERNEL = 1
2019-12-11 14:41:51 -06:00
elif [ " $1 " = "--trace-start" ] ; then
if [ " $2 " = "off" ] ; then
2021-08-06 17:41:36 -04:00
export ROCP_CTRL_RATE = "-1:0:0"
2019-12-11 14:41:51 -06:00
fi
2019-10-09 13:17:21 -05:00
elif [ " $1 " = "--trace-period" ] ; then
period_expr = " ^\([^:]*\):\([^:]*\):\([^:]*\) $"
period_ck = ` echo " $2 " | sed -n "s/" ${ period_expr } "/ok/p" `
if [ -z " $period_ck " ] ; then
2019-10-10 19:04:30 -05:00
fatal " Wrong option ' $1 $2 ' "
2019-10-09 13:17:21 -05:00
fi
period_delay = ` echo " $2 " | sed -n "s/" ${ period_expr } "/\1/p" `
2019-10-10 19:04:30 -05:00
period_len = ` echo " $2 " | sed -n "s/" ${ period_expr } "/\2/p" `
period_rate = ` echo " $2 " | sed -n "s/" ${ period_expr } "/\3/p" `
2019-10-09 23:39:59 -05:00
convert_time_val period_delay
2019-10-09 13:17:21 -05:00
errck " Option ' $ARG_IN ', delay value "
2019-10-09 23:39:59 -05:00
convert_time_val period_len
2019-10-09 13:17:21 -05:00
errck " Option ' $ARG_IN ', length value "
2019-10-10 19:04:30 -05:00
convert_time_val period_rate
errck " Option ' $ARG_IN ', rate value "
export ROCP_CTRL_RATE = " $period_delay : $period_len : $period_rate "
2020-01-27 20:27:24 -06:00
elif [ " $1 " = "--flush-rate" ] ; then
period_rate = $2
convert_time_val period_rate
errck " Option ' $ARG_IN ', rate value "
export ROCP_FLUSH_RATE = " $period_rate "
2019-11-19 20:18:09 -06:00
elif [ " $1 " = "--obj-tracking" ] ; then
2020-05-28 03:43:12 -05:00
if [ " $2 " = "off" ] ; then
export ROCP_OBJ_TRACKING = 0
2019-11-19 20:18:09 -06:00
fi
2020-07-07 15:39:08 -04:00
elif [ " $1 " = "--parallel-kernels" ] ; then
ARG_VAL = 0
export ROCP_K_CONCURRENT = 1
2020-08-26 15:15:19 -04:00
export AQLPROFILE_READ_API = 1
2018-07-01 15:31:42 -05:00
elif [ " $1 " = "--verbose" ] ; then
ARG_VAL = 0
export ROCP_VERBOSE_MODE = 1
2019-11-08 21:13:44 -06:00
elif [ " $1 " = "--cmd-qts" ] ; then
if [ " $2 " = "off" ] ; then
CMD_QTS = 0
fi
2023-10-30 23:13:53 +05:30
elif [ " $1 " = "--merge-traces" ] ; then
shift
echo " merging traces with $PROF_BIN_DIR /merge_traces.sh "
$PROF_BIN_DIR /merge_traces.sh $@
exit 0
2018-07-01 15:31:42 -05:00
else
break
fi
shift
if [ " $ARG_VAL " = 1 ] ; then shift; fi
done
ARG_CK = ` echo $ARG_IN | sed " s/^-.* $/-/ " `
if [ " $ARG_CK " = "-" ] ; then
fatal " Wrong option ' $ARG_IN ' "
fi
2020-12-03 05:30:27 -05:00
if [ " $GEN_STATS " = "1" -a " $ROCP_TIMESTAMP_ON " = "0" ] ; then
fatal "Wrong options, stats enabled with disabled timestamps"
fi
2018-07-01 15:31:42 -05:00
if [ -z " $INPUT_FILE " ] ; then
2018-10-30 14:19:45 -05:00
input_base = "results"
input_type = "none"
else
input_base = ` echo " $INPUT_FILE " | sed " s/^\(.*\)\.\([^\.]*\) $/\1/ " `
input_type = ` echo " $INPUT_FILE " | sed " s/^\(.*\)\.\([^\.]*\) $/\2/ " `
if [ -z " ${ input_base } " -o -z " ${ input_type } " ] ; then
fatal " Bad input file ' $INPUT_FILE ' "
fi
input_base = ` basename $input_base `
2018-07-01 15:31:42 -05:00
fi
2018-11-08 03:54:09 -06:00
if [ " $DATA_PATH " = "-" ] ; then
DATA_PATH = $TMP_DIR
2018-07-01 15:31:42 -05:00
fi
if [ -n " $output " ] ; then
if [ " $output " = "--" ] ; then
OUTPUT_DIR = "--"
else
csv_output = $output
fi
else
csv_output = $RUN_DIR /${ input_base } .csv
fi
2019-11-08 21:13:44 -06:00
# Profiled cmd line string
APP_CMD = $*
if [ " $CMD_QTS " = 1 ] ; then
APP_CMD = ""
for i in ` seq 1 $# ` ; do
if [ -n " $APP_CMD " ] ; then
APP_CMD = $APP_CMD " "
fi
eval " arg=\${ $i } "
APP_CMD = $APP_CMD \" $arg \"
done
fi
2018-07-01 15:31:42 -05:00
echo " RPL: profiling ' $APP_CMD ' "
echo " RPL: input file ' $INPUT_FILE ' "
input_list = ""
RES_DIR = ""
if [ " $input_type " = "xml" ] ; then
2018-11-08 03:54:09 -06:00
OUTPUT_DIR = $DATA_PATH
2018-07-01 15:31:42 -05:00
input_list = $INPUT_FILE
2018-10-30 14:19:45 -05:00
elif [ " $input_type " = "txt" -o " $input_type " = "none" ] ; then
2018-07-01 15:31:42 -05:00
RES_DIR = $DATA_PATH /$DATA_DIR
if [ -e $RES_DIR ] ; then
error " Rundir ' $RES_DIR ' exists "
fi
mkdir -p $RES_DIR
echo " RPL: output dir ' $RES_DIR ' "
2018-10-30 14:19:45 -05:00
if [ " $input_type " = "txt" ] ; then
2022-02-26 16:31:35 -08:00
$PROF_BIN_DIR /txt2xml.sh $INPUT_FILE $RES_DIR
2018-10-30 14:19:45 -05:00
else
echo "<metric></metric>" > $RES_DIR /input.xml
fi
2018-07-01 15:31:42 -05:00
input_list = ` /bin/ls $RES_DIR /input*.xml`
2018-07-10 17:59:17 -05:00
export ROCPROFILER_SESS = $RES_DIR
2018-07-01 15:31:42 -05:00
else
fatal " Bad input file type ' $INPUT_FILE ' "
fi
2018-07-10 17:59:17 -05:00
if [ -n " $csv_output " ] ; then
rm -f $csv_output
fi
2020-04-24 01:32:40 -05:00
RET = 1
2022-03-25 04:51:17 +00:00
export ROCP_MERGE_PIDS = 1
2018-07-01 15:31:42 -05:00
for name in $input_list ; do
run $name $OUTPUT_DIR $APP_CMD
2020-04-24 13:56:08 -05:00
RET = $?
2018-07-10 17:59:17 -05:00
if [ -n " $ROCPROFILER_SESS " -a -e " $ROCPROFILER_SESS /error " ] ; then
2020-04-24 01:32:40 -05:00
error_string = ` cat $ROCPROFILER_SESS /error`
echo " Profiling error found: ' $error_string ' "
2018-07-10 17:59:17 -05:00
csv_output = ""
2019-08-25 05:08:55 -05:00
RET = 1
2018-07-10 17:59:17 -05:00
break
fi
2018-07-01 15:31:42 -05:00
done
if [ -n " $csv_output " ] ; then
2020-05-05 05:35:32 -05:00
merge_output $OUTPUT_LIST
2019-01-17 16:51:56 -06:00
if [ " $GEN_STATS " = "1" ] ; then
db_output = $( echo $csv_output | sed "s/\.csv/.db/" )
2022-02-26 16:31:35 -08:00
$ROCP_PYTHON_VERSION $PROF_BIN_DIR /tblextr.py $db_output $OUTPUT_LIST
2019-01-17 16:51:56 -06:00
else
2022-02-26 16:31:35 -08:00
$ROCP_PYTHON_VERSION $PROF_BIN_DIR /tblextr.py $csv_output $OUTPUT_LIST
2019-01-17 16:51:56 -06:00
fi
2019-10-25 17:43:35 -05:00
if [ " $? " -ne 0 ] ; then
2020-04-24 01:32:40 -05:00
echo " Profiling data corrupted: ' $OUTPUT_LIST ' " | tee " $ROCPROFILER_SESS /error "
RET = 1
2018-07-01 15:31:42 -05:00
fi
fi
if [ " $DATA_PATH " = " $TMP_DIR " ] ; then
if [ -e " $RES_DIR " ] ; then
rm -rf $RES_DIR
fi
fi
2019-08-25 05:08:55 -05:00
exit $RET