Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-10 07:49:35

0001 #!/bin/bash -l
0002 usage(){ cat << EOU
0003 gxs.sh : G4CXSimulateTest : Opticks CX GPU simulation starting from Geant4 geometry auto-translated to CSG
0004 =============================================================================================================
0005 
0006 ::
0007 
0008     cd ~/opticks/g4cx   # gx
0009     ./gxs.sh
0010     ./gxs.sh info
0011     ./gxs.sh run
0012     ./gxs.sh dbg
0013     ./gxs.sh ana
0014     ./gxs.sh grab
0015     ./gxs.sh ab
0016 
0017 
0018 G4CXSimulateTest invokes "SEvt::save()" writing .npy to '$DefaultOutputDir/ALL' eg::
0019 
0020    /tmp/$USER/opticks/$GEOM/SProc::ExecutableName/ALL
0021    /tmp/blyth/opticks/RaindropRockAirWater/G4CXSimulateTest/ALL
0022 
0023 Also the CSGFoundry geometry is written to '$DefaultOutputDir/CSGFoundry' eg::
0024 
0025    /tmp/$USER/opticks/$GEOM/SProc::ExecutableName/CSGFoundry
0026    /tmp/blyth/opticks/RaindropRockAirWater/G4CXSimulateTest/CSGFoundry
0027 
0028 This assumes CFBASE is not defined. When CFBASE is defined the
0029 geometry is written to "$CFBASE/CSGFoundry"
0030 HMM: but when CFBASE is defined the geometry would have been loaded from there,
0031 hence there would be no save done ? See G4CXOpticks::setGeometry.
0032 
0033 HMM: maybe better to distinguish loading and saving CFBASE as a form
0034 of control of when to save ?
0035 
0036 
0037 grablog/analog timings showing log lines with delta time more than 2% of total
0038 --------------------------------------------------------------------------------
0039 
0040 * initial CUDA access latency stands at 39% so no point working on
0041   other init bottlenecks until that latency can be reduced (which might need driver update)
0042 
0043 * HMM: a frame of pixels that is not being used may be being allocated
0044 
0045 ::
0046 
0047     In [1]: log[2]
0048     Out[1]:
0049                      timestamp :        DTS-prev :        DFS-frst :msg
0050     2022-08-23 23:46:28.359000 :      0.3140[39] :      0.3140[39] : INFO  [57470] [main@33] ] cu first
0051     2022-08-23 23:46:28.571000 :      0.1770[22] :      0.5260[65] : INFO  [57470] [QSim::UploadComponents@111] ] new QRng
0052     2022-08-23 23:46:28.590000 :      0.0180[ 2] :      0.5450[67] : INFO  [57470] [QSim::UploadComponents@128] QBnd src NP  dtype <f4(45, 4, 2, 761, 4, ) size 1095840 uifc f ebyte 4 shape.size 5 data.size 4383360 meta.size 69 names.size 45 tex QTex width 761 height 360 texObj 1 meta 0x3069a00 d_meta 0x7f3e9dc01000 tex 0x3069990
0053     2022-08-23 23:46:28.672000 :      0.0720[ 9] :      0.6270[78] : INFO  [57470] [CSGOptiX::initCtx@322] ]
0054     2022-08-23 23:46:28.696000 :      0.0230[ 3] :      0.6510[81] : INFO  [57470] [CSGOptiX::initPIP@333] ]
0055     2022-08-23 23:46:28.805000 :      0.0350[ 4] :      0.7600[94] : INFO  [57470] [CSGFoundry::getFrame@2880]  fr sframe::desc inst 0 frs -1
0056     2022-08-23 23:46:28.839000 :      0.0200[ 2] :      0.7940[98] : INFO  [57470] [CSGOptiX::launch@794]  (width, height, depth) ( 1920,1080,1) 0.0201
0057 
0058 
0059                              - :                 :                 :G4CXSimulateTest.log
0060     2022-08-23 23:46:28.045000 :                 :                 :start
0061     2022-08-23 23:46:28.853000 :                 :                 :end
0062                              - :                 :      0.8080[100] :total seconds
0063                              - :                 :      2.0000[100] :pc_cut
0064 
0065 
0066 Using single GPU reduces first contact latency a little, total time down to 0.7410 seconds.
0067 
0068 
0069 EOU
0070 }
0071 
0072 
0073 defarg="run"
0074 arg=${1:-$defarg}
0075 
0076 case $arg in
0077   fold) QUIET=1 ;;
0078   analog) QUIET=1 ;;
0079 esac
0080 
0081 
0082 bin=G4CXSimulateTest
0083 log=$bin.log
0084 gxsdir=$(dirname $BASH_SOURCE)
0085 source $gxsdir/../bin/COMMON.sh
0086 
0087 
0088 BASE=$GEOMDIR/$bin
0089 UBASE=${BASE//$HOME\/}    # UBASE is BASE relative to HOME to handle rsync between different HOME
0090 FOLD=$BASE/ALL            # corresponds SEvt::save() with SEvt::SetReldir("ALL")
0091 
0092 notes(){ cat << EON
0093 
0094 * When BASE is not within $HOME eg its in /tmp then UBASE and BASE are the same.
0095 
0096 EON
0097 }
0098 
0099 
0100 # NB FOLD is not used by run, but it is used by ana
0101 
0102 if [ "info" == "$arg" ]; then
0103     vars="BASH_SOURCE gxsdir GEOM GEOMDIR CFBASE BASE UBASE FOLD OPTICKS_INPUT_PHOTON"
0104     for var in $vars ; do printf "%20s : %s \n" $var ${!var} ; done
0105 fi
0106 
0107 if [ "fold" == "$arg" ]; then
0108     echo $FOLD
0109 fi
0110 
0111 
0112 
0113 
0114 loglevels()
0115 {
0116     export Dummy=INFO
0117     #export SGeoConfig=INFO
0118     export SEventConfig=INFO
0119     export SEvt=INFO          # lots of AddGenstep output, messing with timings
0120     #export Ctx=INFO
0121     export QSim=INFO
0122     export QBase=INFO
0123     export SSim=INFO
0124     export SBT=INFO
0125     export IAS_Builder=INFO
0126     #export QEvt=INFO
0127     export CSGOptiX=INFO
0128     export G4CXOpticks=INFO
0129     export CSGFoundry=INFO
0130     #export GInstancer=INFO
0131     #export X4PhysicalVolume=INFO
0132     #export U4VolumeMaker=INFO
0133 }
0134 loglevels
0135 
0136 #export U4VolumeMaker_PVG_WriteNames=1
0137 
0138 
0139 if [ "run" == "$arg" ]; then
0140     echo $msg run $bin log $log
0141     if [ -f "$log" ]; then
0142        rm $log
0143     fi
0144 
0145     $bin
0146     [ $? -ne 0 ] && echo $BASH_SOURCE run $bin error && exit 1
0147 fi
0148 
0149 if [ "dbg" == "$arg" ]; then
0150     case $(uname) in
0151         Linux) gdb_ $bin -ex r  ;;
0152         Darwin) lldb__ $bin ;;
0153     esac
0154     [ $? -ne 0 ] && echo $BASH_SOURCE dbg $bin error && exit 2
0155 fi
0156 
0157 
0158 if [ "grablog" == "$arg" ]; then
0159     scp P:opticks/g4cx/$log .
0160 fi
0161 
0162 if [ "analog" == "$arg" ]; then
0163     echo $msg analog log $log
0164     if [ -f "$log" ]; then
0165         LOG=$log $gxsdir/../bin/log.sh
0166     fi
0167 fi
0168 
0169 
0170 if [ "ana" == "$arg" ]; then
0171     export FOLD
0172     export CFBASE=$BASE/CSGFoundry
0173     ${IPYTHON:-ipython} --pdb -i $gxsdir/tests/$bin.py
0174     [ $? -ne 0 ] && echo $BASH_SOURCE ana $bin error && exit 3
0175 fi
0176 
0177 if [ "grab" == "$arg" ]; then
0178     source $gxsdir/../bin/rsync.sh $UBASE
0179 fi
0180 
0181 if [ "ab" == "$arg" ]; then
0182     cd $gxsdir
0183     ./gxs_ab.sh
0184 fi
0185 
0186 exit 0
0187