-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDockerfile
More file actions
280 lines (220 loc) · 11.1 KB
/
Dockerfile
File metadata and controls
280 lines (220 loc) · 11.1 KB
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
FROM debian:trixie-slim AS build
RUN mkdir ~/build
# Add deb-src for everything
RUN sed -Ei 's/^Types: deb$/Types: deb deb-src/' /etc/apt/sources.list.d/debian.sources
# Update
RUN DEBIAN_FRONTEND=noninteractive apt-get update
# Install build tools
RUN DEBIAN_FRONTEND=noninteractive apt -y install git meson wget curl unzip
# Pull modified packages builds from Qartifactory repo
RUN wget https://github.com/qualcomm-linux/qcom-deb-images/raw/refs/heads/main/debos-recipes/overlays/qsc-deb-releases/etc/apt/keyrings/qsc-deb-releases.asc -O /etc/apt/keyrings/qsc-deb-releases.asc
COPY <<EOF /etc/apt/sources.list.d/qsc-deb-releases.sources
# QArtifactory qsc-deb-releases repository
# NB: publishing Sources indices for deb-src isn't supported by Artifactory,
# but sources are published with other packages files
Types: deb
URIs: https://qartifactory-edge.qualcomm.com/artifactory/qsc-deb-releases
Suites: trixie-overlay
Components: main
Signed-By: /etc/apt/keyrings/qsc-deb-releases.asc
Enabled: no
EOF
# Enable Backports repo, grab mesa from there
COPY <<EOF /etc/apt/sources.list.d/trixie-backports.sources
Types: deb deb-src
URIs: http://deb.debian.org/debian
Suites: trixie-backports
Components: main
Enabled: yes
Signed-By: /usr/share/keyrings/debian-archive-keyring.gpg
EOF
COPY <<EOF /etc/apt/preferences.d/debian-backports.pref
# for binary packages built from these source packages, score the version from
# Debian backports higher as to get hardware enabled or better hardware support
Package: src:alsa-ucm-conf:any src:firmware-free:any src:firmware-nonfree:any src:linux:any src:linux-signed-arm64:any src:mesa:any
Pin: release n=trixie-backports
Pin-Priority: 900
EOF
# Update again
RUN DEBIAN_FRONTEND=noninteractive apt-get update
# Install the basic mesa dependencies to make our build work
RUN DEBIAN_FRONTEND=noninteractive apt -y install mesa-common-dev libegl-dev libgles-dev cmake ninja-build
RUN git config --global user.email "container@nohardware.com"
RUN git config --global user.name "Container Entity"
# Fetch & patch tflite
RUN cd ~/build ; \
git clone https://github.com/tensorflow/tensorflow.git --single-branch -b r2.20
COPY patches/0001-OpenCL-wrapper-try-loading-libOpenCL.so.1-if-libOpen.patch /root/build/tensorflow/
COPY patches/0002-PATCH-tensorflow-c-library-enable-delegates.patch /root/build/tensorflow/
RUN cd ~/build/tensorflow ; \
git remote add robclark https://github.com/robclark/tensorflow.git ; \
git fetch robclark rusticl-fixes ; \
git merge robclark/rusticl-fixes && git rebase origin/r2.20 ; \
git am 0001-OpenCL-wrapper-try-loading-libOpenCL.so.1-if-libOpen.patch 0002-PATCH-tensorflow-c-library-enable-delegates.patch
RUN cd ~/build/tensorflow ; \
mkdir -p /usr/src ; \
git archive --format=tar.gz --output=/usr/src/tensorflow-lite-2.20.tar.gz --prefix=tensorflow-2.20/ HEAD -v
# Grab bazel binaries and start the build.
RUN wget -O /usr/local/bin/bazel https://github.com/bazelbuild/bazel/releases/download/7.4.1/bazel-7.4.1-linux-arm64
RUN chmod +x /usr/local/bin/bazel
RUN cd ~/build/tensorflow && bazel build --copt -DCL_DELEGATE_NO_GL //tensorflow/lite:libtensorflowlite.so ; \
bazel build --copt -DCL_DELEGATE_NO_GL //tensorflow/lite/c:libtensorflowlite_c.so ; \
bazel build --copt -DCL_DELEGATE_NO_GL //tensorflow/lite/delegates/gpu:libtensorflowlite_gpu_delegate.so ; \
bazel build --copt -DCL_DELEGATE_NO_GL //tensorflow/lite/examples/label_image:label_image ; \
bazel build --copt -DCL_DELEGATE_NO_GL //tensorflow/lite/tools/benchmark:benchmark_model
RUN cd ~/build/tensorflow && bazel build --copt -DCL_DELEGATE_NO_GL //tensorflow/lite/delegates/gpu:libtensorflowlite_gpu_delegate.so
# This likely needs a new place so we can delete ~/build/tensorflow
RUN cd ~/build/tensorflow ; \
cp tensorflow/lite/examples/label_image/testdata/grace_hopper.bmp bazel-bin/tensorflow/lite/examples/label_image/ ; \
cd bazel-bin/tensorflow/lite/examples/label_image ; \
wget https://storage.googleapis.com/download.tensorflow.org/models/tflite/mobilenet_v1_224_android_quant_2017_11_08.zip ; \
unzip mobilenet_v1_224_android_quant_2017_11_08.zip ; \
rm *.zip
RUN mv ~/build/tensorflow/bazel-bin/tensorflow ~
# Remove build folder
RUN rm -rf ~/build
# Remove cached files
RUN rm ~/.cache -rf
RUN apt clean
#######################################################################
FROM debian:trixie-slim AS fastrpc-build
# Update
RUN DEBIAN_FRONTEND=noninteractive apt-get update
# Install build tools
RUN DEBIAN_FRONTEND=noninteractive apt -y install git wget unzip
# Install QNN
RUN mkdir -p ~/build /usr/lib/dsp/cdsp /usr/local/lib
RUN cd ~/build ; \
wget https://softwarecenter.qualcomm.com/api/download/software/sdks/Qualcomm_AI_Runtime_Community/All/2.36.0.250627/v2.36.0.250627.zip; \
unzip v2.36.0.250627.zip ; \
rm ~/build/v2.36.0.250627.zip ; \
cp -v ~/build/qairt/2.36.0.250627/lib/aarch64-oe-linux-gcc11.2/* /usr/local/lib/ ; \
cp -v ~/build/qairt/2.36.0.250627/lib/hexagon-v68/unsigned/* /usr/lib/dsp/cdsp/ ; \
rm /usr/local/lib/libSNPE* -rf ; \
rm /usr/local/lib/libSnpe* -rf ; \
rm ~/build/qairt -rf
# Install hexagon binaries and copy binaries for RB3Gen2 : TODO add for others
RUN cd ~/build; \
mkdir -p /usr/lib/dsp/cdsp ; \
git clone https://github.com/linux-msm/hexagon-dsp-binaries.git ; \
cp -v hexagon-dsp-binaries/qcm6490/Thundercomm/RB3gen2/CDSP.HT.2.5.c3-00077-KODIAK-1/* /usr/lib/dsp/cdsp/ ; \
rm ~/build/hexagon-dsp-binaries -rf
# Remove build folder
RUN rm -rf ~/build
# Remove cached files
RUN rm ~/.cache -rf
RUN apt clean
#######################################################################
FROM debian:bookworm-slim AS models
RUN mkdir /build
# Update
RUN DEBIAN_FRONTEND=noninteractive apt-get update
RUN DEBIAN_FRONTEND=noninteractive apt -y upgrade
RUN DEBIAN_FRONTEND=noninteractive apt -y --no-install-recommends install wget curl unzip ca-certificates
# Install pip to fetch qai_hub, and do the pip thing where you need to break the system
RUN DEBIAN_FRONTEND=noninteractive apt -y install python3-pip python3-backoff python3-deprecation python3-numpy python3-protobuf python3-requests python3-requests-toolbelt python3-wcwidth python3-idna python3-urllib3 python3-certifi python3-jmespath
# Install extra build deps
RUN DEBIAN_FRONTEND=noninteractive apt -y install gcc libc++-dev
# Install Qualcomm AI hub infrastructure - You CANNOT have 'git' installed, the mmcv install will hang.
RUN pip install --break-system-packages qai-hub mmcv ultralytics
# Install the basic mesa dependencies to make the model export work
RUN DEBIAN_FRONTEND=noninteractive apt -y --no-install-recommends install git libgl1 libglib2.0-0 libgl1-mesa-dri mesa-opencl-icd
# Install Yolov6" model
RUN pip install --break-system-packages "torch>=2.1,<2.9.0" "setuptools>=77.0.3"
RUN pip install --break-system-packages "qai-hub-models[yolov6]"
RUN pip install --break-system-packages "pyarrow==20.0.0"
RUN python3 -m qai_hub_models.models.yolov6.export --target-runtime tflite --precision float
RUN ls /build -la --color
RUN mkdir -p /root/models
#RUN mv /build/yolov6_float/ /root/models/
# Uninstall qai-hub-models, then reinstall it, yay python!
RUN pip uninstall --break-system-package --no-input -y "qai-hub-models"
RUN pip install --break-system-packages "qai-hub-models[hrnet_pose]"
#RUN python3 -m qai_hub_models.models.hrnet_pose.export --target-runtime tflite --precision float
#######################################################################
FROM debian:trixie-slim AS deploy
# Update
RUN DEBIAN_FRONTEND=noninteractive apt-get update
RUN DEBIAN_FRONTEND=noninteractive apt -y upgrade
RUN DEBIAN_FRONTEND=noninteractive apt -y --no-install-recommends install wget curl unzip ca-certificates
# Pull modified packages builds from Qartifactory repo
RUN wget https://github.com/qualcomm-linux/qcom-deb-images/raw/refs/heads/main/debos-recipes/overlays/qsc-deb-releases/etc/apt/keyrings/qsc-deb-releases.asc -O /etc/apt/keyrings/qsc-deb-releases.asc
COPY <<EOF /etc/apt/sources.list.d/qsc-deb-releases.sources
# QArtifactory qsc-deb-releases repository
# NB: publishing Sources indices for deb-src isn't supported by Artifactory,
# but sources are published with other packages files
Types: deb
URIs: https://qartifactory-edge.qualcomm.com/artifactory/qsc-deb-releases
Suites: trixie-overlay
Components: main
Signed-By: /etc/apt/keyrings/qsc-deb-releases.asc
Enabled: no
EOF
# Enable Backports repo, grab mesa from there
COPY <<EOF /etc/apt/sources.list.d/trixie-backports.sources
Types: deb deb-src
URIs: http://deb.debian.org/debian
Suites: trixie-backports
Components: main
Enabled: yes
Signed-By: /usr/share/keyrings/debian-archive-keyring.gpg
EOF
COPY <<EOF /etc/apt/preferences.d/debian-backports.pref
# for binary packages built from these source packages, score the version from
# Debian backports higher as to get hardware enabled or better hardware support
Package: src:alsa-ucm-conf:any src:firmware-free:any src:firmware-nonfree:any src:linux:any src:linux-signed-arm64:any src:mesa:any
Pin: release n=trixie-backports
Pin-Priority: 900
EOF
# Update
RUN DEBIAN_FRONTEND=noninteractive apt-get update
# Install the basic mesa dependencies to make our build work
RUN DEBIAN_FRONTEND=noninteractive apt -y --no-install-recommends install libgl1-mesa-dri libgles2 mesa-opencl-icd clpeak
# Copy models from models container
COPY --from=models /root/models /root/models
# Install tensorflow build, no proper debian package
COPY --from=build /root/tensorflow /root/tensorflow
COPY run-tflite.sh /
COPY benchmark-tflite.sh /
COPY install-gstreamer.sh /
RUN chmod +x /*.sh
# Remove cached files
RUN rm ~/.cache -rf
RUN apt clean
# Test tensorflow
RUN cd ~/tensorflow/lite/examples/label_image ; \
./label_image --image=grace_hopper.bmp
ENTRYPOINT ["/bin/bash"]
#######################################################################
FROM deploy AS fastrpc-deploy
# Add repo containing fastrpc, dsp binaries and tflite
COPY <<EOF /etc/apt/sources.list.d/debusine.sources
Types: deb deb-src
URIs: https://deb.debusine.debian.net/debian/r-rbasak-qcom-hexagon-stack-2
Suites: sid
Components: main non-free-firmware
Signed-By:
-----BEGIN PGP PUBLIC KEY BLOCK-----
.
mDMEaWpOVhYJKwYBBAHaRw8BAQdA6gdtyg0BKTS9EA9CAbbY3gk7bOYKY74Clfak
3FjWn220PEFyY2hpdmUgc2lnbmluZyBrZXkgZm9yIGRlYmlhbi9yLXJiYXNhay1x
Y29tLWhleGFnb24tc3RhY2stMoiQBBMWCgA4FiEEWi95OlWxjLyNwWscPETQboDo
XeEFAmlqTlYCGwMFCwkIBwIGFQoJCAsCBBYCAwECHgECF4AACgkQPETQboDoXeFL
AQD+Pm5ERzQPJRdxcqekaUVbqKrbyo1i7NPztV0j0YnyDFUA/24Ms1ZS8eV1um+R
pqm6Uf5gvyZjJrjMGZWx/hqvriED
=P90u
-----END PGP PUBLIC KEY BLOCK-----
EOF
# Update
RUN DEBIAN_FRONTEND=noninteractive apt-get update
# Install libyaml, fastrpc depends on it. Once we use proper debian packages, this workaround can go away
RUN DEBIAN_FRONTEND=noninteractive apt -y --no-install-recommends install fastrpc-tests
# Copy QNN host side libraries and DSP side libraries from the fastrpc-build layer
COPY --from=fastrpc-build /usr/local/lib /usr/local/lib
RUN find /usr/local/lib
# Copy over DSP libraries
COPY --from=fastrpc-build /usr/lib/dsp /usr/lib/dsp
RUN find /usr/lib/dsp
# Remove cached files
RUN rm ~/.cache -rf
RUN apt clean