2023-02-03 12:31:39 -06:00
#!/bin/bash
2023-03-03 12:34:31 +05:30
CURRENT_DIR = " $( dirname -- " $0 " ; ) " ;
2023-02-03 12:31:39 -06:00
ROCPROFV2_DIR = $( dirname -- $( realpath ${ BASH_SOURCE [0] } )) ;
ROCM_DIR = $( dirname -- ${ ROCPROFV2_DIR } )
2023-05-05 07:14:09 +00:00
ROCM_PATH = " ${ ROCM_PATH :=/opt/rocm } "
2023-05-23 15:25:37 +05:30
PLUGIN_LIST =( "ctf" "perfetto" "file" "att" )
2023-02-03 12:31:39 -06:00
RUN_FROM_BUILD = 0
if [[ $ROCPROFV2_DIR == *"/build" * ]] ; then
RUN_FROM_BUILD = 1
2023-06-23 13:49:01 +05:30
export ROCPROFILER_METRICS_PATH = $ROCM_DIR /build/counters/derived_counters.xml
2023-02-03 12:31:39 -06:00
elif [[ $ROCPROFV2_DIR == *"/rocprofiler" * ]] ; then
RUN_FROM_BUILD = 1
ROCM_DIR = $ROCPROFV2_DIR
fi
usage() {
2023-02-07 13:06:02 +05:30
echo -e "ROCProfilerV2 Run Script Usage:"
2023-02-03 12:31:39 -06:00
echo -e "-h | --help For showing this message"
echo -e "--list-counters For showing all available counters for the current GPUs"
if [ $RUN_FROM_BUILD == 1 ] ; then
echo -e "-b | --build For compiling"
echo -e "-cb | --clean-build For full clean build"
echo -e "-t | --test For Running the tests"
echo -e "-ct | --clean-build-test For Running the tests after a clean build"
echo -e "-mt | --mem-test For Running the Memory Leak tests. This run requires building using -acb | --asan-clean-build option"
echo -e "-acb | --asan-clean-build For compiling with ASAN library attached"
2023-02-07 13:06:02 +05:30
echo -e "--install For installing ROCProfilerV2 without clean build in the default installation folder (review build.sh to know more about the default paths)"
echo -e "--clean-install For installing ROCProfilerV2 with new clean build in the default installation folder (review build.sh to know more about the default paths)"
2023-02-03 12:31:39 -06:00
fi
2023-05-15 17:51:37 +00:00
echo -e "--hip-api For Collecting HIP API Traces"
echo -e "--hip-activity | --hip-trace For Collecting HIP API Activities Traces"
echo -e "--hsa-api For Collecting HSA API Traces"
echo -e "--hsa-activity | --hsa-trace For Collecting HSA API Activities Traces"
echo -e "--roctx-trace For Collecting ROCTx Traces"
echo -e "--kernel-trace For Collecting Kernel dispatch Traces"
echo -e "--sys-trace For Collecting HIP and HSA APIs and their Activities Traces along ROCTX and Kernel Dispatch traces"
2023-05-23 00:42:16 +05:30
echo -e "--plugin PLUGIN_NAME For enabling a plugin (file/perfetto/att/ctf)"
2023-05-15 17:51:37 +00:00
echo -e "-i | --input For adding counters file path (every line in the text file represents a counter)"
echo -e "-o | --output-file For the output file name"
echo -e "-d | --output-directory For adding output path where the output files will be saved"
echo -e "-fi | --flush-interval For adding a flush interval in milliseconds, every \"flush interval\" the buffers will be flushed"
2023-06-20 19:16:20 +00:00
echo -e "-tp | --trace-period For adding a trace period in milliseconds, in the following format \"-tp <DELAY_TIME>:<TIME_BETWEEN_START_AND_STOP>\"."
2023-02-03 12:31:39 -06:00
exit 1
}
if [ -z " $1 " ] ; then
usage
exit 1
fi
while [ 1 ] ; do
if [[ " $1 " = "-h" || " $1 " = "--help" ]] ; then
usage
exit 1
elif [[ " $1 " = "-b" || " $1 " = "--build" ]] ; then
if [ $RUN_FROM_BUILD == 1 ] ; then
TO_CLEAN = no ./build.sh
exit 1
fi
elif [[ " $1 " = "-acb" || " $1 " = "--asan-clean-build" ]] ; then
if [ $RUN_FROM_BUILD == 1 ] ; then
ASAN = yes TO_CLEAN = yes ./build.sh
exit 1
fi
elif [[ " $1 " = "-cb" || " $1 " = "--clean-build" ]] ; then
if [ $RUN_FROM_BUILD == 1 ] ; then
TO_CLEAN = yes ./build.sh
exit 1
fi
elif [[ " $1 " = "-t" || " $1 " = "--test" ]] ; then
if [ $RUN_FROM_BUILD == 1 ] ; then
export ROCPROFILER_METRICS_PATH = $ROCM_DIR /build/counters/derived_counters.xml
2023-06-15 20:26:19 +05:30
export LD_LIBRARY_PATH = $ROCPROFV2_DIR :$LD_LIBRARY_PATH
2023-05-31 15:41:49 +00:00
RUN_TEST = yes TO_CLEAN = no $ROCM_DIR /build.sh
2023-03-03 12:34:31 +05:30
if [ " $CURRENT_DIR /build" -ef "./build" ] ; then
./run_tests.sh
else
pushd build
./run_tests.sh
fi
2023-02-03 12:31:39 -06:00
exit 1
fi
elif [[ " $1 " = "-mt" || " $1 " = "--mem-test" ]] ; then
if [ $RUN_FROM_BUILD == 1 ] ; then
2023-06-15 20:26:19 +05:30
export LD_LIBRARY_PATH = $ROCPROFV2_DIR :$LD_LIBRARY_PATH
2023-02-03 12:31:39 -06:00
ASAN = yes TO_CLEAN = yes ./build.sh
2023-06-10 05:51:56 +00:00
./tests-v2/memorytests/run_asan_tests.sh $ROCM_DIR /build/tests-v2/featuretests/profiler/apps/hip_vectoradd $ROCM_DIR /build/memleaks.log
2023-02-03 12:31:39 -06:00
exit 1
fi
elif [[ " $1 " = "-ct" || " $1 " = "--clean-build-test" ]] ; then
if [ $RUN_FROM_BUILD == 1 ] ; then
TO_CLEAN = yes $ROCM_DIR /build.sh
2023-03-03 12:34:31 +05:30
if [ " $CURRENT_DIR /build" -ef "./build" ] ; then
./run_tests.sh
else
pushd build
./run_tests.sh
fi
2023-02-03 12:31:39 -06:00
exit 1
fi
elif [[ " $1 " = "--install" ]] ; then
if [ $RUN_FROM_BUILD == 1 ] ; then
TO_CLEAN = no $ROCM_DIR /build.sh
pushd build
2023-05-31 15:41:49 +00:00
make -j install
2023-02-03 12:31:39 -06:00
exit 1
fi
elif [[ " $1 " = "--clean-install" ]] ; then
if [ $RUN_FROM_BUILD == 1 ] ; then
TO_CLEAN = yes $ROCM_DIR /build.sh
pushd build
make install
exit 1
fi
elif [[ " $1 " = "--list-counters" ]] ; then
if [ $RUN_FROM_BUILD == 1 ] ; then
export ROCPROFILER_METRICS_PATH = $ROCM_DIR /build/counters/derived_counters.xml
2023-06-15 20:26:19 +05:30
export LD_LIBRARY_PATH = $ROCPROFV2_DIR :$LD_LIBRARY_PATH
2023-02-03 12:31:39 -06:00
eval $ROCM_DIR /build/src/tools/ctrl
else
export ROCPROFILER_METRICS_PATH = $ROCPROFV2_DIR /../libexec/rocprofiler/counters/derived_counters.xml
export LD_LIBRARY_PATH = $ROCPROFV2_DIR /../lib:$LD_LIBRARY_PATH
2023-06-21 15:27:21 +05:30
LD_PRELOAD = $LD_PRELOAD :$ROCM_DIR /lib/rocprofiler/librocprofiler_tool.so
2023-02-03 12:31:39 -06:00
eval $ROCPROFV2_DIR /../libexec/rocprofiler/ctrl
fi
exit 1
elif [[ " $1 " = "-i" || " $1 " = "--input" ]] ; then
if [ $2 ] && [ -n $2 ] && [ -r $2 ] ; then
if [ $RUN_FROM_BUILD == 1 ] ; then
export ROCPROFILER_METRICS_PATH = $ROCM_DIR /build/counters/derived_counters.xml
2023-06-15 20:26:19 +05:30
export LD_LIBRARY_PATH = $ROCPROFV2_DIR :$LD_LIBRARY_PATH
2023-02-03 12:31:39 -06:00
else
export ROCPROFILER_METRICS_PATH = $ROCPROFV2_DIR /../libexec/rocprofiler/counters/derived_counters.xml
fi
export COUNTERS_PATH = $2
else
echo -e "Error: \" $2 \" doesn't exist!"
usage
exit 1
fi
shift
shift
elif [[ " $1 " = "-o" || " $1 " = "--output-file-name" ]] ; then
if [ $2 ] ; then
export OUT_FILE_NAME = $2
else
usage
exit 1
fi
shift
shift
elif [[ " $1 " = "-d" || " $1 " = "--output-directory" ]] ; then
if [ $2 ] ; then
mkdir -p $2
export OUTPUT_PATH = $2
OUTPUT_PATH_INTERNAL = $2
else
usage
exit 1
fi
shift
shift
elif [[ " $1 " = "-fi" || " $1 " = "--flush-interval" ]] ; then
if [ $2 ] && [ $2 -gt 0 ] ; then
export ROCPROFILER_FLUSH_INTERVAL = $2
else
echo -e "Wrong input \" $2 \" for flush interval, it needs to be integer greater than zero!"
usage
exit 1
fi
shift
shift
2023-06-20 19:16:20 +00:00
elif [[ " $1 " = "-tp" || " $1 " = "--trace-period" ]] ; then
if [ $2 ] && [[ " $2 " == *":" * ]] ; then
export ROCPROFILER_TRACE_PERIOD = $2
else
echo -e "Wrong input \" $2 \" for trace period!"
usage
exit 1
fi
shift
shift
2023-02-03 12:31:39 -06:00
elif [ " $1 " = "--hip-api" ] ; then
export ROCPROFILER_HIP_API_TRACE = 1
shift
2023-05-15 17:51:37 +00:00
elif [[ " $1 " = "--hip-activity" || " $1 " = "--hip-trace" ]] ; then
2023-02-03 12:31:39 -06:00
export ROCPROFILER_HIP_API_TRACE = 1
export ROCPROFILER_HIP_ACTIVITY_TRACE = 1
shift
elif [ " $1 " = "--hsa-api" ] ; then
export ROCPROFILER_HSA_API_TRACE = 1
shift
2023-05-16 18:44:12 +00:00
elif [[ " $1 " = "--hsa-activity" || " $1 " = "--hsa-trace" ]] ; then
2023-02-03 12:31:39 -06:00
export ROCPROFILER_HSA_API_TRACE = 1
export ROCPROFILER_HSA_ACTIVITY_TRACE = 1
shift
elif [ " $1 " = "--roctx-trace" ] ; then
export ROCPROFILER_ROCTX_TRACE = 1
shift
elif [ " $1 " = "--kernel-trace" ] ; then
export ROCPROFILER_KERNEL_TRACE = 1
shift
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
2023-05-25 04:17:29 +00:00
elif [ " $1 " = "--roc-sys" ] ; then
2023-02-03 12:31:39 -06:00
export ROCPROFILER_ENABLE_AMDSYS = $2
shift
shift
elif [ " $1 " = "--plugin" ] ; then
if [ -n $2 ] ; then
PLUGIN = $2
2023-05-23 15:25:37 +05:30
if [[ ! " ${ PLUGIN_LIST [*] } " = ~ $PLUGIN ]] ; then
echo -e "Wrong input \" $2 \" for plugin!"
usage
exit 1
fi
2023-06-09 04:34:01 +00:00
export ROCPROFILER_PLUGIN_LIB = lib${ PLUGIN } _plugin.so
2023-02-03 12:31:39 -06:00
else
echo -e "Wrong input \" $2 \" for plugin!"
usage
exit 1
fi
2023-02-07 13:06:02 +05:30
if [ " $2 " = "att" ] ; then
2023-02-17 11:12:27 -06:00
if [ $RUN_FROM_BUILD == 1 ] ; then
2023-06-23 21:21:47 +05:30
ATT_PATH = $ROCPROFV2_DIR /plugin/att/att/att.py
2023-05-05 07:14:09 +00:00
export ROCPROFV2_ATT_LIB_PATH = $ROCM_PATH /lib/hsa-amd-aqlprofile/librocprofv2_att.so
2023-06-15 20:26:19 +05:30
export LD_LIBRARY_PATH = $ROCPROFV2_DIR :$LD_LIBRARY_PATH
2023-02-17 11:12:27 -06:00
else
ATT_PATH = $ROCPROFV2_DIR /../libexec/rocprofiler/att/att.py
2023-05-05 07:14:09 +00:00
export ROCPROFV2_ATT_LIB_PATH = $ROCPROFV2_DIR /../lib/hsa-amd-aqlprofile/librocprofv2_att.so
2023-02-17 11:12:27 -06:00
fi
2023-02-07 13:06:02 +05:30
ATT_ARGV = $3
2023-02-18 02:12:05 -03:00
shift
2023-02-07 13:06:02 +05:30
ATT_OPTIONS = "Not done"
while [ " $ATT_OPTIONS " = "Not done" ] ; do
if [[ " $3 " = "--trace_file" ]] ; then
ATT_ARGV = " $ATT_ARGV $3 \" $4 \""
shift
shift
2023-04-24 14:07:22 -03:00
elif [[ " $3 " = "--mode" || " $3 " = "--ports" || " $3 " = "--genasm" || " $3 " == "--att_kernel" ]] ; then
2023-02-07 13:06:02 +05:30
ATT_ARGV = " $ATT_ARGV $3 $4 "
shift
shift
else
ATT_OPTIONS = "Done"
fi
done
fi
2023-02-03 12:31:39 -06:00
shift
shift
elif [[ " $1 " = "-" * || " $1 " = "--" * ]] ; then
echo -e "Wrong option \" $1 \", Please use the following options:\n"
usage
exit 1
else
break
fi
done
PMC_LINES =()
if [ -n " $COUNTERS_PATH " ] ; then
input = $COUNTERS_PATH
while IFS = read -r line || [[ -n " $line " ]] ; do
2023-06-20 19:18:59 +05:30
#skip empty lines
if [[ -z " $line " ]] ; then
continue
fi
2023-02-07 13:06:02 +05:30
# if in att mode, only add the first line
if [[ ! -n " $PMC_LINES " ]] || [[ ! -n " $ATT_ARGV " ]] ; then
2023-02-03 12:31:39 -06:00
PMC_LINES +=( " $line " )
2023-02-07 13:06:02 +05:30
fi
2023-02-03 12:31:39 -06:00
done < $input
fi
2023-04-20 20:23:41 -05:00
COUNTERS_PMC_DIRS = ""
2023-02-03 12:31:39 -06:00
if [ -n " $PMC_LINES " ] ; then
COUNTER = 1
for i in ${ !PMC_LINES[@] } ; do
export ROCPROFILER_COUNTERS = " ${ PMC_LINES [ $i ] } "
2023-06-23 21:21:47 +05:30
#Skipping lines without pmc when not in att mode
if [[ ! ${ PMC_LINES [ $i ] } = ~ "pmc" && ! ${ PMC_LINES [ $i ] } = ~ "att" ]] ; then
continue
fi
2023-02-03 12:31:39 -06:00
if [ -n " $OUTPUT_PATH " ] ; then
2023-02-11 02:33:38 +05:30
if [ ! -n " $ATT_ARGV " ] ; then
FINAL_PATH = " $OUTPUT_PATH_INTERNAL /pmc_ $COUNTER "
2023-04-20 20:23:41 -05:00
COUNTERS_PMC_DIRS = " $COUNTERS_PMC_DIRS $FINAL_PATH "
2023-02-11 02:33:38 +05:30
else
FINAL_PATH = " $OUTPUT_PATH "
fi
2023-02-03 12:31:39 -06:00
echo -e "\nThe output path for the following counters: $FINAL_PATH "
mkdir -p $FINAL_PATH
echo $ROCPROFILER_COUNTERS > $FINAL_PATH /pmc.txt
export OUTPUT_PATH = $FINAL_PATH
let COUNTER = COUNTER+1
fi
if [ $RUN_FROM_BUILD == 1 ] ; then
2023-06-15 20:26:19 +05:30
export LD_LIBRARY_PATH = $ROCPROFV2_DIR :$LD_LIBRARY_PATH
2023-02-03 12:31:39 -06:00
LD_PRELOAD = $LD_PRELOAD :$ROCM_DIR /build/librocprofiler_tool.so $*
else
2023-05-16 18:10:49 +00:00
LD_PRELOAD = $LD_PRELOAD :$ROCM_DIR /lib/rocprofiler/librocprofiler_tool.so $*
2023-02-03 12:31:39 -06:00
fi
done
2023-02-07 13:06:02 +05:30
elif [ ! -n " $ATT_ARGV " ] ; then
2023-02-03 12:31:39 -06:00
if [ $RUN_FROM_BUILD == 1 ] ; then
2023-06-15 20:26:19 +05:30
export LD_LIBRARY_PATH = $ROCPROFV2_DIR :$LD_LIBRARY_PATH
2023-02-03 12:31:39 -06:00
LD_PRELOAD = $LD_PRELOAD :$ROCM_DIR /build/librocprofiler_tool.so $*
else
2023-05-16 18:10:49 +00:00
LD_PRELOAD = $LD_PRELOAD :$ROCM_DIR /lib/rocprofiler/librocprofiler_tool.so $*
2023-02-03 12:31:39 -06:00
fi
fi
2023-04-20 20:23:41 -05:00
get_pmc_results_txt_path(){
for file_name in ` ls $1 ` ; do
if [[ $file_name == *results.txt ]] ; then
echo " $1 / $file_name "
fi
done
}
2023-02-07 13:06:02 +05:30
if [ -n " $ATT_PATH " ] ; then
if [ -n " $ATT_ARGV " ] ; then
eval "python3 $ATT_PATH $ATT_ARGV "
elif [ ! -n " $PMC_LINES " ] ; then
echo "ATT File is required!"
fi
fi