Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-12-05 02:48:10

0001 #!/bin/bash
0002 
0003 ##############################################################################
0004 #
0005 #
0006 # Line Segment Tracking Standalone Code Make Script
0007 #
0008 #
0009 ##############################################################################
0010 
0011 DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
0012 
0013 # Help
0014 usage()
0015 {
0016   echo "ERROR - Usage:"
0017   echo
0018   echo "      sh $(basename $0) OPTIONSTRINGS ..."
0019   echo
0020   echo "Options:"
0021   echo "  -h    Help                      (Display this message)"
0022   echo "  -s    show log                  (Full compilation script to stdout)"
0023   echo "  -m    make clean binaries       (Make clean binaries before remake. e.g. when header files changed in LST/*.h)"
0024   echo "  -d    cut value ntuple          (With extra variables in a debug ntuple file)"
0025   echo "  -p    primitive object ntuple   (With extra variables related to primitive objects)"
0026   echo "  -N    neural networks           (Toggle LST neural networks)"
0027   echo "  -C    CPU serial backend        (Compile for CPU)"
0028   echo "  -G    GPU (CUDA) backend        (Compile for CUDA)"
0029   echo "  -R    ROCm backend              (Compile for ROCm)"
0030   echo "  -A    All backends              (Compile for all backends, including ROCm)"
0031   echo "  -w    Warning mode              (Print extra warning outputs)"
0032   echo
0033   exit
0034 }
0035 
0036 # Parsing command-line opts
0037 while getopts ":cxgsmdp3NCGRA2ehwP:" OPTION; do
0038   case $OPTION in
0039     c) MAKECACHE=true;;
0040     s) SHOWLOG=true;;
0041     m) MAKECLEANBINARIES=true;;
0042     d) MAKECUTVALUES=true;;
0043     p) PRIMITIVE=true;;
0044     G) CUDABACKEND=true;;
0045     C) CPUBACKEND=true;;
0046     R) ROCMBACKEND=true;;
0047     A) ALLBACKENDS=true;;
0048     w) PRINTWARNINGS=true;;
0049     h) usage;;
0050     :) usage;;
0051   esac
0052 done
0053 
0054 # If the command line options are not provided set it to default value of false
0055 if [ -z ${MAKECACHE} ]; then MAKECACHE=false; fi
0056 if [ -z ${SHOWLOG} ]; then SHOWLOG=false; fi
0057 if [ -z ${MAKECLEANBINARIES} ]; then MAKECLEANBINARIES=false; fi
0058 if [ -z ${MAKECUTVALUES} ]; then MAKECUTVALUES=false; fi
0059 if [ -z ${PRIMITIVE} ]; then PRIMITIVE=false; fi
0060 if [ -z ${CPUBACKEND} ]; then CPUBACKEND=false; fi
0061 if [ -z ${CUDABACKEND} ]; then CUDABACKEND=false; fi
0062 if [ -z ${ROCMBACKEND} ]; then ROCMBACKEND=false; fi
0063 if [ -z ${ALLBACKENDS} ]; then ALLBACKENDS=false; fi
0064 if [ -z ${PRINTWARNINGS} ]; then PRINTWARNINGS=false; fi
0065 
0066 # Default to only CPU and CUDA backends
0067 if [ "${CPUBACKEND}" == false ] && [ "${CUDABACKEND}" == false ] && [ "${ROCMBACKEND}" == false ]; then
0068   CPUBACKEND=true
0069   CUDABACKEND=true
0070 fi
0071 if [ "${ALLBACKENDS}" == true ]; then
0072   CPUBACKEND=true
0073   CUDABACKEND=true
0074   ROCMBACKEND=true
0075 fi
0076 
0077 # Shift away the parsed options
0078 shift $(($OPTIND - 1))
0079 
0080 # Move to the TRACKLOOPERDIR
0081 pushd ${TRACKLOOPERDIR}
0082 
0083 # create log file
0084 LOG=${TRACKLOOPERDIR}/.make.log.$(date +%s)
0085 
0086 # Verbose
0087 date | tee -a ${LOG}
0088 echo "====================================================="  | tee -a ${LOG}
0089 echo "Line Segment Tracking Compilation Script             "  | tee -a ${LOG}
0090 echo "====================================================="  | tee -a ${LOG}
0091 echo "Compilation options set to..."                          | tee -a ${LOG}
0092 echo ""                                                       | tee -a ${LOG}
0093 echo "  SHOWLOG           : ${SHOWLOG}"                       | tee -a ${LOG}
0094 echo "  MAKECLEANBINARIES : ${MAKECLEANBINARIES}"             | tee -a ${LOG}
0095 echo "  MAKECUTVALUES     : ${MAKECUTVALUES}"                 | tee -a ${LOG}
0096 echo "  PRIMITIVE         : ${PRIMITIVE}"                     | tee -a ${LOG}
0097 echo "  CPUBACKEND        : ${CPUBACKEND}"                    | tee -a ${LOG}
0098 echo "  CUDABACKEND       : ${CUDABACKEND}"                   | tee -a ${LOG}
0099 echo "  ROCMBACKEND       : ${ROCMBACKEND}"                   | tee -a ${LOG}
0100 echo "  PRINTWARNINGS     : ${PRINTWARNINGS}"                 | tee -a ${LOG}
0101 echo ""                                                       | tee -a ${LOG}
0102 echo "  (cf. Run > sh $(basename $0) -h to see all options)"  | tee -a ${LOG}
0103 echo ""                                                       | tee -a ${LOG}
0104 
0105 
0106 TRACKLOOPERTARGET=
0107 # If make explicit is true then make library with explicit memory on GPU
0108 MAKETARGET=explicit;
0109 
0110 # Show deprecation warning for cache flag
0111 if $MAKECACHE; then echo "Warning: the -c flag is deprecated"; fi
0112 
0113 # If make clean binaries are called then first make clean before making
0114 if $MAKECLEANBINARIES; then
0115     echo "First make cleaning all of TrackLooper objects and liblst*.so" | tee -a ${LOG}
0116     cd LST;make clean >>${LOG} 2>&1;cd -;
0117     make clean >> ${LOG} 2>&1
0118 fi
0119 #if make cut value is called then cut value ntuple making is done
0120 if $MAKECUTVALUES; then
0121     echo " Making cut value ntuple" | tee -a ${LOG}
0122     MAKETARGET=${MAKETARGET}_cutvalue;
0123     TRACKLOOPERTARGET=cutvalue 
0124     echo "debug : MAKETARGET=${MAKETARGET}"
0125 fi
0126 #if make cut value is called then cut value ntuple making is done
0127 if $PRIMITIVE; then
0128     echo " Making cut value ntuple" | tee -a ${LOG}
0129     TRACKLOOPERTARGET=primitive 
0130     echo "debug : MAKETARGET=${MAKETARGET}"
0131 fi
0132 
0133 BACKENDOPT="BACKEND="
0134 EXES=
0135 if [ "${ALLBACKENDS}" == true ]; then
0136   BACKENDOPT="BACKEND=all"
0137   EXES="bin/lst_cpu bin/lst_cuda bin/lst_rocm"
0138 else
0139   if [ "${CPUBACKEND}" == true ]; then
0140     BACKENDOPT=$BACKENDOPT"cpu,"
0141     EXES="$EXES bin/lst_cpu"
0142   fi
0143   if [ "${CUDABACKEND}" == true ]; then
0144     BACKENDOPT=$BACKENDOPT"cuda,"
0145     EXES="$EXES bin/lst_cuda"
0146   fi
0147   if [ "${ROCMBACKEND}" == true ]; then
0148     BACKENDOPT=$BACKENDOPT"rocm,"
0149     EXES="$EXES bin/lst_rocm"
0150   fi
0151 fi
0152 
0153 PRINTWARNINGSOPT=
0154 if $PRINTWARNINGS; then
0155     PRINTWARNINGSOPT="LSTWARNINGSFLAG=-DWARNINGS"
0156 fi
0157 
0158 if [ -z "${MAXMAKETHREADS}" ]; then
0159     MAXMAKETHREADS=32
0160 fi
0161 
0162 ###
0163 ###
0164 ### Making Line Segment Tracking Library
0165 ###
0166 ###
0167 
0168 echo "Line Segment Tracking GPU library with MAKETARGET=${MAKETARGET} is being compiled...." | tee -a ${LOG}
0169 
0170 echo "---------------------------------------------------------------------------------------------" >> ${LOG} 2>&1 
0171 echo "---------------------------------------------------------------------------------------------" >> ${LOG} 2>&1 
0172 echo "---------------------------------------------------------------------------------------------" >> ${LOG} 2>&1 
0173 if $SHOWLOG; then
0174     (cd LST && make clean && make ${BACKENDOPT} ${PRINTWARNINGSOPT} -j ${MAXMAKETHREADS} ${MAKETARGET} && cd -) 2>&1 | tee -a ${LOG}
0175 else
0176     (cd LST && make clean && make ${BACKENDOPT} ${PRINTWARNINGSOPT} -j ${MAXMAKETHREADS} ${MAKETARGET} && cd -) >> ${LOG} 2>&1
0177 fi
0178 
0179 if ([[ "$BACKENDOPT" == *"all"* ]] || [[ "$BACKENDOPT" == *"cpu"* ]]) && [ ! -f LST/liblst_cpu.so ]; then
0180   echo "ERROR: liblst_cpu.so failed to compile!" | tee -a ${LOG}
0181   echo "See ${LOG} file for more detail..." | tee -a ${LOG}
0182   exit 1
0183 elif ([[ "$BACKENDOPT" == *"all"* ]] || [[ "$BACKENDOPT" == *"cuda"* ]]) && [ ! -f LST/liblst_cuda.so ]; then
0184   echo "ERROR: liblst_cuda.so failed to compile!" | tee -a ${LOG}
0185   echo "See ${LOG} file for more detail..." | tee -a ${LOG}
0186   exit 1
0187 elif ([[ "$BACKENDOPT" == *"all"* ]] || [[ "$BACKENDOPT" == *"rocm"* ]]) && [ ! -f LST/liblst_rocm.so ]; then
0188   echo "ERROR: liblst_rocm.so failed to compile!" | tee -a ${LOG}
0189   echo "See ${LOG} file for more detail..." | tee -a ${LOG}
0190   exit 1
0191 fi
0192 
0193 echo "" >> ${LOG}
0194 echo "" >> ${LOG}
0195 echo "" >> ${LOG}
0196 echo "Line Segment Tracking GPU library compilation with MAKETARGET=${MAKETARGET} successful!" | tee -a ${LOG}
0197 echo "" | tee -a ${LOG}
0198 
0199 ###
0200 ###
0201 ### Making Line Segment Tracking Binaries
0202 ###
0203 ###
0204 
0205 echo "Line Segment Tracking binaries are being compiled...." | tee -a ${LOG}
0206 
0207 echo "---------------------------------------------------------------------------------------------" >> ${LOG} 2>&1 
0208 echo "---------------------------------------------------------------------------------------------" >> ${LOG} 2>&1 
0209 echo "---------------------------------------------------------------------------------------------" >> ${LOG} 2>&1 
0210 if $SHOWLOG; then
0211     make EXES="${EXES}" ${TRACKLOOPERTARGET} -j ${MAXMAKETHREADS} 2>&1 | tee -a ${LOG}
0212 else
0213     make EXES="${EXES}" ${TRACKLOOPERTARGET} -j ${MAXMAKETHREADS} >> ${LOG} 2>&1
0214 fi
0215 
0216 if ([[ "$BACKENDOPT" == *"all"* ]] || [[ "$BACKENDOPT" == *"cpu"* ]]) && [ ! -f bin/lst_cpu ]; then
0217   echo "ERROR: bin/lst_cpu failed to compile!" | tee -a ${LOG}
0218   echo "See ${LOG} file for more detail..." | tee -a ${LOG}
0219   exit 1
0220 elif ([[ "$BACKENDOPT" == *"all"* ]] || [[ "$BACKENDOPT" == *"cuda"* ]]) && [ ! -f bin/lst_cuda ]; then
0221   echo "ERROR: bin/lst_cuda failed to compile!" | tee -a ${LOG}
0222   echo "See ${LOG} file for more detail..." | tee -a ${LOG}
0223   exit 1
0224 elif ([[ "$BACKENDOPT" == *"all"* ]] || [[ "$BACKENDOPT" == *"rocm"* ]]) && [ ! -f bin/lst_rocm ]; then
0225   echo "ERROR: bin/lst_rocm failed to compile!" | tee -a ${LOG}
0226   echo "See ${LOG} file for more detail..." | tee -a ${LOG}
0227   exit 1
0228 fi
0229 
0230 # Make a symlink with priority CUDA > CPU > ROCM
0231 if [ "${CUDABACKEND}" == true ]; then
0232     ln -sfr bin/lst_cuda bin/lst
0233 elif [ "${CPUBACKEND}" == true ]; then
0234     ln -sfr bin/lst_cpu bin/lst
0235 elif [ "${ROCMBACKEND}" == true ]; then
0236     ln -sfr bin/lst_rocm bin/lst
0237 fi
0238 
0239 echo "" >> ${LOG}
0240 echo "" >> ${LOG}
0241 echo "" >> ${LOG}
0242 echo "Line Segment Tracking binaries compilation successful!" | tee -a ${LOG}
0243 echo "" | tee -a ${LOG}
0244 
0245 echo "Compilation is logged at .make.log" | tee -a ${LOG}
0246 echo "Compilation log is backed up at ${LOG}" | tee -a ${LOG}
0247 cp ${LOG} .make.log
0248 
0249 # Go back to where I was
0250 popd