Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-09 07:49:16

0001 #!/bin/bash
0002 usage(){ cat << EOU
0003 sdevice_test.sh
0004 =================
0005 
0006 This assumes that the ordinal is the index when all GPUs are visible
0007 and it finds this by arranging to persist the query when
0008 CUDA_VISIBLE_DEVICES is not defined and use that to provide something
0009 to match against when the envvar is defined.
0010 
0011 The purpose is for reference running, especially performance
0012 scanning : so its acceptable to require running a metadata
0013 capturing executable prior to scanning.
0014 That initial executable can be this one and the
0015 ones with CUDA_VISIBLE_DEVICES can be embedded opticks
0016 running.
0017 
0018 The typical usage would be to write GPU description
0019 into run/event metadata. Or could access the sdevice.h struct
0020 to put more details such as the VRAM into run/event metadata.
0021 
0022 
0023 Initial run without CUDA_VISIBLE_DEVICES envvar defined
0024 writes info about all connected GPUs to "$HOME/.opticks/runcache"::
0025 
0026     ~/opticks/sysrap/tests/sdevice_test.sh build_run
0027 
0028 Subsequent runs with CUDA_VISIBLE_DEVICES match the currently
0029 visible GPUs against all of them without restriction, so
0030 original ordinal can be discerned even when running with
0031 a subset of the GPUs::
0032 
0033     CUDA_VISIBLE_DEVICES=1   ~/opticks/sysrap/tests/sdevice_test.sh run
0034     CUDA_VISIBLE_DEVICES=0   ~/opticks/sysrap/tests/sdevice_test.sh run
0035     CUDA_VISIBLE_DEVICES=0,1 ~/opticks/sysrap/tests/sdevice_test.sh run
0036     CUDA_VISIBLE_DEVICES=1,0 ~/opticks/sysrap/tests/sdevice_test.sh run
0037 
0038 
0039 HMM : WHAT ABOUT IDENTICAL GPUs ?
0040 a hidden uuid is used in the matching so should work.
0041 
0042 
0043 Examples::
0044 
0045     [blyth@localhost ~]$ ~/opticks/sysrap/tests/sdevice_test.sh
0046     [0:NVIDIA_RTX_5000_Ada_Generation]
0047     idx/ord/mpc/cc:0/0/100/89  31.592 GB  NVIDIA RTX 5000 Ada Generation
0048 
0049     N[blyth@localhost ~]$ ~/opticks/sysrap/tests/sdevice_test.sh build_run
0050     [0:TITAN_V 1:TITAN_RTX]
0051     idx/ord/mpc/cc:0/0/80/70  11.784 GB  TITAN V
0052     idx/ord/mpc/cc:1/1/72/75  23.652 GB  TITAN RTX
0053 
0054     N[blyth@localhost ~]$ CUDA_VISIBLE_DEVICES=0 ~/opticks/sysrap/tests/sdevice_test.sh run
0055     [0:TITAN_V]
0056     idx/ord/mpc/cc:0/0/80/70  11.784 GB  TITAN V
0057 
0058     N[blyth@localhost ~]$ CUDA_VISIBLE_DEVICES=1 ~/opticks/sysrap/tests/sdevice_test.sh run
0059     [1:TITAN_RTX]
0060     idx/ord/mpc/cc:0/1/72/75  23.652 GB  TITAN RTX
0061 
0062     N[blyth@localhost ~]$ CUDA_VISIBLE_DEVICES=1,0 ~/opticks/sysrap/tests/sdevice_test.sh run
0063     [1:TITAN_RTX 0:TITAN_V]
0064     idx/ord/mpc/cc:0/1/72/75  23.652 GB  TITAN RTX
0065     idx/ord/mpc/cc:1/0/80/70  11.784 GB  TITAN V
0066 
0067     N[blyth@localhost ~]$ CUDA_VISIBLE_DEVICES=0,1 ~/opticks/sysrap/tests/sdevice_test.sh run
0068     [0:TITAN_V 1:TITAN_RTX]
0069     idx/ord/mpc/cc:0/0/80/70  11.784 GB  TITAN V
0070     idx/ord/mpc/cc:1/1/72/75  23.652 GB  TITAN RTX
0071 
0072 
0073 EOU
0074 }
0075 
0076 cd $(dirname $(realpath $BASH_SOURCE))
0077 name=sdevice_test
0078 
0079 tmp=/tmp/$USER/opticks
0080 TMP=${TMP:-$tmp}
0081 mkdir -p $TMP
0082 
0083 bin=$TMP/$name
0084 
0085 defarg="build_run"
0086 arg=${1:-$defarg}
0087 
0088 cuda_prefix=/usr/local/cuda
0089 CUDA_PREFIX=${CUDA_PREFIX:-$cuda_prefix}
0090 
0091 CUDA_LIBDIR=$CUDA_PREFIX/lib
0092 [ ! -d "$CUDA_LIBDIR" ] && CUDA_LIBDIR=$CUDA_PREFIX/lib64
0093 
0094 
0095 vv="BASH_SOURCE PWD name tmp TMP bin defarg arg cuda_prefix CUDA_PREFIX CUDA_LIBDIR"
0096 
0097 if [ "${arg/info}" != "$arg" ]; then
0098    for v in $vv ; do printf "%30s : %s\n" "$v" "${!v}" ; done
0099 fi
0100 
0101 if [ "${arg/build}" != "$arg" ]; then
0102    gcc $name.cc  \
0103        -std=c++17 -lstdc++ \
0104        -I.. \
0105        -I$CUDA_PREFIX/include \
0106        -L$CUDA_LIBDIR \
0107        -lcudart \
0108        -o $bin
0109 
0110    [ $? -ne 0 ] && echo $BASH_SOURCE : build error && exit 1
0111 fi
0112 
0113 if [ "${arg/run}" != "$arg" ]; then
0114    $bin
0115    [ $? -ne 0 ] && echo $BASH_SOURCE : run error && exit 2
0116 fi
0117 
0118 if [ "${arg/dbg}" != "$arg" ]; then
0119    source dbg__.sh
0120    dbg__ $bin
0121    [ $? -ne 0 ] && echo $BASH_SOURCE : dbg error && exit 3
0122 fi
0123 
0124 exit 0
0125