Skip to content

Commit f8ffa43

Browse files
authored
Build docker image to setup the QNN SDK environment (k2-fsa#3736)
1 parent 6a20463 commit f8ffa43

3 files changed

Lines changed: 226 additions & 0 deletions

File tree

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
FROM ubuntu:22.04
2+
3+
ARG QNN_SDK_VERSION=2.40.0.251030
4+
ARG QNN_TOOLKIT_URL=https://huggingface.co/csukuangfj/qnn-toolkit/resolve/main/v${QNN_SDK_VERSION}.zip
5+
6+
ENV DEBIAN_FRONTEND=noninteractive
7+
8+
# Use bash as default shell (envsetup.sh requires bash syntax)
9+
SHELL ["/bin/bash", "-c"]
10+
11+
# Install basic system dependencies (Ubuntu 22.04 ships Python 3.10 natively)
12+
RUN apt-get update && apt-get install -y --no-install-recommends \
13+
ca-certificates \
14+
curl \
15+
unzip \
16+
software-properties-common \
17+
lsb-release \
18+
adb \
19+
clang \
20+
libc++-dev \
21+
libc++abi-dev \
22+
libclang-dev \
23+
libsndfile1 \
24+
python3 \
25+
python3-pip \
26+
python3-venv \
27+
python3-dev \
28+
&& rm -rf /var/lib/apt/lists/*
29+
30+
# Install Android NDK r29 (placed early so failures surface quickly)
31+
ARG ANDROID_NDK_VERSION=29.0.14206865
32+
ARG ANDROID_NDK_REVISION=r29
33+
RUN curl -SL -o /tmp/ndk.zip https://dl.google.com/android/repository/android-ndk-${ANDROID_NDK_REVISION}-linux.zip \
34+
&& unzip -q /tmp/ndk.zip -d /opt \
35+
&& rm -f /tmp/ndk.zip
36+
ENV ANDROID_NDK_LATEST_HOME=/opt/android-ndk-${ANDROID_NDK_REVISION}
37+
ENV PATH=${ANDROID_NDK_LATEST_HOME}:${PATH}
38+
39+
# Verify NDK is set up correctly
40+
RUN ndk-build --help
41+
42+
# Download, install QNN SDK toolkit, then remove the zip in the same layer
43+
WORKDIR /opt
44+
RUN curl -SL -O ${QNN_TOOLKIT_URL} \
45+
&& unzip v${QNN_SDK_VERSION}.zip \
46+
&& rm -f v${QNN_SDK_VERSION}.zip
47+
48+
# Set QNN SDK environment variables
49+
ENV QNN_SDK_ROOT=/opt/qairt/${QNN_SDK_VERSION}
50+
ENV PATH=${QNN_SDK_ROOT}/bin/x86_64-linux-clang:${QNN_SDK_ROOT}/bin:${PATH}
51+
ENV LD_LIBRARY_PATH=${QNN_SDK_ROOT}/lib/x86_64-linux-clang:${LD_LIBRARY_PATH}
52+
53+
# Install linux dependencies required by QNN SDK (source envsetup.sh first, matching workflow)
54+
RUN cd ${QNN_SDK_ROOT}/bin && . envsetup.sh \
55+
&& yes | ${QNN_SDK_ROOT}/bin/check-linux-dependency.sh || true \
56+
&& rm -rf /var/lib/apt/lists/*
57+
58+
# Create and activate a Python 3.10 virtual environment
59+
RUN python3 -m venv /opt/py310
60+
ENV VIRTUAL_ENV=/opt/py310
61+
ENV PATH=/opt/py310/bin:${PATH}
62+
63+
# Install all Python dependencies in a single layer to minimize image size
64+
# The virtual environment is already active via ENV PATH above
65+
RUN . /opt/py310/bin/activate && \
66+
pip install --no-cache-dir --upgrade pip && \
67+
pip install --no-cache-dir \
68+
mock \
69+
numpy \
70+
opencv-python \
71+
optuna \
72+
packaging \
73+
pandas \
74+
paramiko \
75+
pathlib2 \
76+
pillow \
77+
plotly \
78+
protobuf \
79+
psutil \
80+
pydantic \
81+
pytest \
82+
pyyaml \
83+
rich \
84+
scikit-optimize \
85+
scipy \
86+
six \
87+
tabulate \
88+
typing-extensions \
89+
xlsxwriter \
90+
&& python3 "${QNN_SDK_ROOT}/bin/check-python-dependency" || true \
91+
&& pip install --no-cache-dir \
92+
torch==2.0.0+cpu -f https://download.pytorch.org/whl/torch \
93+
kaldi_native_fbank \
94+
"numpy<2" \
95+
onnx==1.17.0 \
96+
onnxruntime \
97+
soundfile \
98+
librosa \
99+
onnxsim \
100+
sentencepiece \
101+
pyyaml \
102+
&& pip cache purge 2>/dev/null || true
103+
104+
# Verify QNN tools are accessible (source envsetup.sh first, matching workflow)
105+
RUN cd ${QNN_SDK_ROOT}/bin && . envsetup.sh \
106+
&& qnn-onnx-converter --help \
107+
&& qnn-model-lib-generator --help \
108+
&& qnn-net-run --help
109+
110+
WORKDIR /workspace
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: Build docker image for qnn SDK
2+
3+
on:
4+
push:
5+
branches:
6+
- docker-qnn-2
7+
workflow_dispatch:
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
strategy:
13+
fail-fast: false
14+
15+
permissions:
16+
contents: read
17+
packages: write
18+
19+
steps:
20+
- name: Checkout repository
21+
uses: actions/checkout@v4
22+
23+
# Buildx is required for cache + multi-platform correctness
24+
- name: Set up Docker Buildx
25+
uses: docker/setup-buildx-action@v3
26+
27+
- name: Login to GitHub Container Registry
28+
uses: docker/login-action@v3
29+
with:
30+
registry: ghcr.io
31+
username: ${{ github.actor }}
32+
password: ${{ secrets.GITHUB_TOKEN }}
33+
34+
- name: Build
35+
env:
36+
HF_TOKEN: ${{ secrets.HF_TOKEN }}
37+
uses: docker/build-push-action@v5
38+
with:
39+
context: ./.github/scripts/export-qnn
40+
file: ./.github/scripts/export-qnn/Dockerfile-2.40
41+
platforms: linux/amd64
42+
push: true
43+
tags: |
44+
ghcr.io/${{ github.repository_owner }}/qnn-sdk:2.40
45+
cache-from: type=gha
46+
cache-to: type=gha,mode=max
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
name: test-qnn-sdk-docker
2+
3+
on:
4+
push:
5+
branches:
6+
- docker-qnn
7+
workflow_dispatch:
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
container:
13+
image: ghcr.io/${{ github.repository_owner }}/qnn-sdk:2.40
14+
15+
steps:
16+
- uses: actions/checkout@v4
17+
18+
- name: Show system information
19+
shell: bash
20+
run: |
21+
df -h
22+
23+
pwd
24+
id
25+
cat /etc/*version
26+
ls -lh
27+
28+
- name: Show Python version
29+
shell: bash
30+
run: |
31+
python3 --version
32+
which python3
33+
34+
- name: Show environment variables
35+
shell: bash
36+
run: |
37+
echo "ANDROID_NDK_LATEST_HOME: $ANDROID_NDK_LATEST_HOME"
38+
echo "PATH: $PATH"
39+
echo "LD_LIBRARY_PATH: $LD_LIBRARY_PATH"
40+
echo "QNN_SDK_ROOT: $QNN_SDK_ROOT"
41+
42+
- name: qnn-onnx-converter show help
43+
shell: bash
44+
run: |
45+
pushd $QNN_SDK_ROOT/bin
46+
source envsetup.sh
47+
popd
48+
49+
which qnn-onnx-converter
50+
qnn-onnx-converter --help
51+
52+
- name: qnn-model-lib-generator help
53+
shell: bash
54+
run: |
55+
pushd $QNN_SDK_ROOT/bin
56+
source envsetup.sh
57+
popd
58+
59+
which qnn-model-lib-generator
60+
echo "qnn-model-lib-generator --help"
61+
62+
- name: qnn-net-run help
63+
shell: bash
64+
run: |
65+
pushd $QNN_SDK_ROOT/bin
66+
source envsetup.sh
67+
popd
68+
69+
which qnn-net-run
70+
qnn-net-run --help

0 commit comments

Comments
 (0)