forked from Xilinx/Vitis-AI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
docker_run.sh
executable file
·146 lines (118 loc) · 3.09 KB
/
docker_run.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/bin/bash
# Copyright 2022 Xilinx Inc.
confirm() {
echo -en "\n\nDo you agree to the terms and wish to proceed [y/n]? "
read REPLY
case $REPLY in
[Yy]) ;;
[Nn]) exit 0 ;;
*) confirm ;;
esac
REPLY=''
}
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
echo "Usage: $0 <image>"
exit 2
fi
if [ -z "$1" ]; then
echo "Usage: $0 <Vitis_AI_DOCKER_NAME>"
exit 2
fi
HERE=$(pwd -P) # Absolute path of current directory
user=`whoami`
uid=`id -u`
gid=`id -g`
DOCKER_REPO="xilinx/"
BRAND=vitis-ai
VERSION=latest
CPU_IMAGE_TAG=${DOCKER_REPO}${BRAND}-cpu:${VERSION}
GPU_IMAGE_TAG=${DOCKER_REPO}${BRAND}-gpu:${VERSION}
IMAGE_NAME="$1"
DEFAULT_COMMAND="bash"
if [[ $# -gt 0 ]]; then
shift 1;
DEFAULT_COMMAND="$@"
if [[ -z "$1" ]]; then
DEFAULT_COMMAND="bash"
fi
fi
DETACHED="-it"
xclmgmt_driver="$(find /dev -name xclmgmt\*)"
docker_devices=""
for i in ${xclmgmt_driver} ;
do
docker_devices+="--device=$i "
done
render_driver="$(find /dev/dri -name renderD\*)"
for i in ${render_driver} ;
do
docker_devices+="--device=$i "
done
kfd_driver="$(find /dev -name kfd\*)"
for i in ${kfd_driver} ;
do
docker_devices+="--device=$i "
done
DOCKER_RUN_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
if [ "$HERE" != "$DOCKER_RUN_DIR" ]; then
echo "WARNING: Please start 'docker_run.sh' from the Vitis-AI/ source directory";
fi
docker_run_params=$(cat <<-END
-v /dev/shm:/dev/shm \
-v /opt/xilinx/dsa:/opt/xilinx/dsa \
-v /opt/xilinx/overlaybins:/opt/xilinx/overlaybins \
-e USER=$user -e UID=$uid -e GID=$gid \
-v $DOCKER_RUN_DIR:/vitis_ai_home \
-v $HERE:/workspace \
-w /workspace \
--rm \
--network=host \
${DETACHED} \
${RUN_MODE} \
$IMAGE_NAME \
$DEFAULT_COMMAND
END
)
##############################
if [[ ! -f ".confirm" ]]; then
if [[ $IMAGE_NAME == *"gpu"* ]]; then
arch="gpu"
elif [[ $IMAGE_NAME == *"rocm"* ]]; then
arch='rocm'
else
arch='cpu'
fi
prompt_file="./docker/dockerfiles/PROMPT/PROMPT_${arch}.txt"
sed -n '1, 5p' $prompt_file
read -n 1 -s -r -p "Press any key to continue..." key
sed -n '5, 15p' $prompt_file
read -n 1 -s -r -p "Press any key to continue..." key
sed -n '15, 28p' $prompt_file
read -n 1 -s -r -p "Press any key to continue..." key
sed -n '28, 61p' $prompt_file
read -n 1 -s -r -p "Press any key to continue..." key
sed -n '62, 224p' $prompt_file
read -n 1 -s -r -p "Press any key to continue..." key
sed -n '224, 308p' $prompt_file
read -n 1 -s -r -p "Press any key to continue..." key
sed -n '309, 520p' $prompt_file
read -n 1 -s -r -p "Press any key to continue..." key
confirm
fi
touch .confirm
docker pull $IMAGE_NAME
if [[ $IMAGE_NAME == *"gpu"* ]]; then
docker run \
$docker_devices \
--gpus all \
$docker_run_params
elif [[ $IMAGE_NAME == *"rocm"* ]]; then
docker run \
$docker_devices \
--group-add=render --group-add video --ipc=host --cap-add=SYS_PTRACE --security-opt seccomp=unconfined \
$docker_run_params
else
docker run \
$docker_devices \
$docker_run_params
fi