Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-11-19 23:20:32

0001 #!/bin/bash
0002 
0003 run_rocm()
0004 {
0005     version=$1
0006     sample=$2
0007     nevents=$3
0008     shift 3
0009     # ROCm backend
0010     lst_make_tracklooper -mR $*
0011     for s_value in 1 2 4 6 8; do
0012         lst -n ${NEVENTS} -o ${OUTDIR}/rocm_${version}_s${s_value}.root -v 1 -w 0 -s ${s_value} -i ${sample} | tee -a timing_temp.txt
0013     done
0014 }
0015 
0016 run_cuda()
0017 {
0018     version=$1
0019     sample=$2
0020     nevents=$3
0021     shift 3
0022     # CUDA backend
0023     lst_make_tracklooper -mG $*
0024     for s_value in 1 2 4 6 8; do
0025         lst -n ${NEVENTS} -o ${OUTDIR}/cuda_${version}_s${s_value}.root -v 1 -w 0 -s ${s_value} -i ${sample} | tee -a timing_temp.txt
0026     done
0027 }
0028 
0029 run_cpu()
0030 {
0031     version=$1
0032     sample=$2
0033     nevents=$3
0034     shift 3
0035     # CPU backend
0036     lst_make_tracklooper -mC $*
0037     for s_value in 1 4 16 32 64; do
0038         lst -n ${NEVENTS} -o ${OUTDIR}/cpu_${version}_s${s_value}.root -v 1 -w 0 -s ${s_value} -i ${sample} | tee -a timing_temp.txt
0039     done
0040 }
0041 
0042 run_timing_test_usage()
0043 {
0044     echo "ERROR - Usage:"
0045     echo
0046     echo "      sh $(basename $0) [-b BACKEND] SAMPLETYPE [SPECIFICGPUVERISON] [NEVENTS]"
0047     echo
0048     echo "Options:"
0049     echo "   -b BACKEND                         cpu, cuda, or rocm (default is cuda)"
0050     echo
0051     echo "Arguments:"
0052     echo "   SAMPLETYPE                         muonGun, PU200, or pionGun"
0053     echo "   SPECIFICGPUVERSION (optional)      Run only one of the cache, etc."
0054     echo "                                      If nothing provided, then it checks all possible tests."
0055     echo "   NEVENTS           (optional)       200, 10000, -1, etc."
0056     echo ""
0057     exit
0058 }
0059 
0060 # Parsing command-line opts
0061 BACKEND="cuda"  # Default to cuda if no backend specified
0062 while getopts ":hb:" OPTION; do
0063   case $OPTION in
0064     h) usage;;
0065     b) BACKEND=$OPTARG;;
0066     :) usage;;
0067   esac
0068 done
0069 
0070 # Shift away the parsed options
0071 shift $(($OPTIND - 1))
0072 
0073 if [ -z ${1} ]; then run_timing_test_usage; fi
0074 
0075 SAMPLE=${1}
0076 if [[ ${SAMPLE} == *"pionGun"* ]]; then
0077     PDGID=211
0078 elif [[ ${SAMPLE} == *"muonGun"* ]]; then
0079     PDGID=13
0080 elif [[ ${SAMPLE} == *"PU200"* ]]; then
0081     PDGID=0
0082 fi
0083 
0084 SPECIFICGPUVERSION=${2}
0085 
0086 if [ -z ${3} ]; then
0087     NEVENTS=200 # If no number of events provided, validate on first 200 events
0088 else
0089     NEVENTS=${3} # If provided set the NEVENTS
0090 fi
0091 
0092 # Decide which function to run
0093 if [ "$BACKEND" == "cuda" ]; then
0094     run_func=run_cuda
0095 elif [ "$BACKEND" == "cpu" ]; then
0096     run_func=run_cpu
0097 elif [ "$BACKEND" == "rocm" ]; then
0098     run_func=run_rocm
0099 else
0100     echo "Invalid backend specified."
0101     exit 1
0102 fi
0103 
0104 # Check if there are any uncommited changes in the repo
0105 pushd ${TRACKLOOPERDIR}
0106 GITHASH=$(git rev-parse --short HEAD)
0107 DIRTY=""
0108 DIFF=$(git diff)
0109 if [ -z "${DIFF}" ]; then
0110     DIRTY=""
0111 else
0112     DIRTY="DIRTY"
0113 fi
0114 popd
0115 GITHASH=${GITHASH}${DIRTY}
0116 
0117 OUTDIR=output/outputs_${GITHASH}_${SAMPLE}
0118 
0119 # Verbose
0120 echo "*****************************************************"
0121 echo ""
0122 echo ""
0123 echo "Run LST Timing Program                               "
0124 echo ""
0125 echo ""
0126 echo "*****************************************************"
0127 echo ""
0128 echo "  GITHASH              : ${GITHASH}"
0129 echo "  SAMPLE               : ${SAMPLE}"
0130 echo "  NEVENTS              : ${NEVENTS}"
0131 if [ -n ${SPECIFICGPUVERSION} ]; then
0132 echo "  SPECIFICGPUVERSION   : ${SPECIFICGPUVERSION}"
0133 else
0134 echo "  SPECIFICGPUVERSION   : all configurations"
0135 fi
0136 echo ""
0137 
0138 # Delete old run
0139 rm -rf ${OUTDIR}
0140 mkdir -p ${OUTDIR}
0141 rm -f timing_temp.txt
0142 
0143 # Run different configurations
0144 if [ -z "${SPECIFICGPUVERSION}" ] || [[ "${SPECIFICGPUVERSION}" == "explicit" ]]; then
0145     $run_func explicit "${SAMPLE}" "${NEVENTS}"
0146 fi
0147 
0148 echo "Total Timing Summary"
0149 grep -h "Time for map " timing_temp.txt | cut -d " " -f 6 | awk '{ SUM += $1} END { print "Average time for map loading =",SUM/5,"ms" }' # 5 is the number of stream values run
0150 grep -h "Time for input " timing_temp.txt | cut -d " " -f 6 | awk '{ SUM += $1} END { print "Average time for input loading =",SUM/5,"ms" }' # 5 is the number of stream values run
0151 grep -h "Time for event " timing_temp.txt | cut -d " " -f 6 | awk '{ SUM += $1} END { print "Average time for lst::Event creation =",SUM/21,"ms"}' # 5 is the number of total streams run (1+2+4+6+8)
0152 echo "   Evt    Hits       MD       LS      T3       T5       pLS       pT5      pT3      TC       Reset    Event     Short             Rate"
0153 grep -hr "avg " timing_temp.txt # space is needed to not get certain bad lines