Skip to content

Commit 43698ff

Browse files
committed
Made GPUs enabled by default. Added option to disable them and option to display commands run
1 parent cc9de6f commit 43698ff

File tree

1 file changed

+25
-10
lines changed

1 file changed

+25
-10
lines changed

runDocker.sh

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@ SCRIPTPATH="$( cd "$(dirname "$0")" ; pwd -P )"
77
usage () {
88
echo ""
99
echo "$0 [-h] [-d dir] [-c cmd_full_path] [-N] [-X] [-e \"extra docker options\"] [-b] -- cmd_args"
10-
echo " -h this helps text"
10+
echo " -h this usage text"
1111
echo " -d directory mounted in the container as /dmc (default: current directory)"
1212
echo " -c Full path of the command to run (accessible from within container) (default: /bin/bash)"
1313
echo " -N Non-interactive run (default is interactive)"
1414
echo " -X Disable X11 support (default is enabled)"
1515
echo " -e Extra docker command line options"
1616
echo " -b Bypass any provided command and use the container built in one, if any (also disable any cmd_args provided"
17+
echo " -g Disable GPUs command line options (default is to enable the GPUs)"
18+
echo " -s Show commands run (preceded by a +). Useful if you are trying to repeat the steps later within a script, or are trying to debug. Warning: |-ep together lines will be displayed consecutively"
1719
echo ""
1820
echo "Run using: CONTAINER_ID=\"<name:tag>\" <PATH_TO_RUNDOCKER>/runDocker.sh <command_line_options>"
1921
exit 1
@@ -29,7 +31,9 @@ D_ARGS_INT="-it"
2931
D_ARGS_X11=""
3032
D_ARGS_XTRA=""
3133
D_ARGS_BYPASS=""
32-
while getopts ":hd:c:NXe:b" opt; do
34+
D_FORCE_GPUS="yes"
35+
D_SHOW_CMD=""
36+
while getopts ":hd:c:NXe:bgs" opt; do
3337
case "$opt" in
3438
h) usage ;;
3539
d) DMC=${OPTARG} ;;
@@ -38,6 +42,8 @@ while getopts ":hd:c:NXe:b" opt; do
3842
X) D_ARGS_X11="___" ;;
3943
e) D_ARGS_XTRA=${OPTARG} ;;
4044
b) D_ARGS_BYPASS="yes" ;;
45+
g) D_FORCE_GPUS="no" ;;
46+
s) D_SHOW_CMD="set -x" ;;
4147
\?) usage ;;
4248
esac
4349
done
@@ -67,14 +73,20 @@ if [ "A${D_ARGS_X11}" == "A___" ]; then
6773
D_ARGS_X11=""
6874
else
6975
if [ "A${D_ARGS_OS}" == "ALinux" ]; then
70-
xhost +local:docker
76+
${D_SHOW_CMD}
77+
xhost +local:docker
78+
{ set +x; } 2>/dev/null
7179
XSOCK=/tmp/.X11-unix
7280
XAUTH=/tmp/.docker.xauth
7381
USER_UID=$(id -u)
7482
D_ARGS_X11="-e DISPLAY=$DISPLAY -v $XSOCK:$XSOCK -v $XAUTH:$XAUTH -e XAUTHORITY=$XAUTH"
75-
xauth nlist :0 | sed -e 's/^..../ffff/' | xauth -f $XAUTH nmerge -
83+
${D_SHOW_CMD}
84+
xauth nlist :0 | sed -e 's/^..../ffff/' | xauth -f $XAUTH nmerge -
85+
{ set +x; } 2>/dev/null
7686
else # Darwin (macOS)
77-
xhost + 127.0.0.1
87+
${D_SHOW_CMD}
88+
xhost + 127.0.0.1
89+
{ set +x; } 2>/dev/null
7890
D_ARGS_X11="-e DISPLAY=host.docker.internal:0"
7991
fi
8092
fi
@@ -84,18 +96,21 @@ if [ "A${D_ARGS_OS}" == "ALinux" ]; then
8496
fi
8597

8698
DOCKER_RUN="docker run"
87-
if [ "A${D_ARGS_OS}" == "ALinux" ]; then
88-
if [[ ${CONTAINER_ID} =~ ^datamachines/cud.* ]]; then
89-
DOCKER_RUN="docker run ${D_GPUS} --ipc host"
90-
fi
99+
if [ "A$D_FORCE_GPUS" == "Ayes" ]; then
100+
DOCKER_RUN="docker run ${D_GPUS} --ipc host"
91101
fi
92102

103+
${D_SHOW_CMD}
93104
${DOCKER_RUN} ${D_ARGS_INT} --rm \
94105
-v ${DMC}:/dmc ${D_ARGS_X11} ${D_ARGS_XTRA} ${ARGS_ALWAYS} \
95-
${CONTAINER_ID} ${RCMD} ${RCMD_ARGS}
106+
${CONTAINER_ID} ${RCMD} ${RCMD_ARGS}
107+
{ set +x; } 2>/dev/null
108+
96109

97110
if [ "A${D_ARGS_X11}" != "A" ]; then
98111
if [ "A${D_ARGS_OS}" == "ALinux" ]; then
112+
${D_SHOW_CMD}
99113
xhost -local:docker
114+
{ set +x; } 2>/dev/null
100115
fi
101116
fi

0 commit comments

Comments
 (0)