-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Build a docker image to setup the QNN SDK environment #3736
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| FROM ubuntu:22.04 | ||
|
|
||
| ARG QNN_SDK_VERSION=2.40.0.251030 | ||
| ARG QNN_TOOLKIT_URL=https://huggingface.co/csukuangfj/qnn-toolkit/resolve/main/v${QNN_SDK_VERSION}.zip | ||
|
|
||
| ENV DEBIAN_FRONTEND=noninteractive | ||
|
|
||
| # Use bash as default shell (envsetup.sh requires bash syntax) | ||
| SHELL ["/bin/bash", "-c"] | ||
|
|
||
| # Install basic system dependencies (Ubuntu 22.04 ships Python 3.10 natively) | ||
| RUN apt-get update && apt-get install -y --no-install-recommends \ | ||
| ca-certificates \ | ||
| curl \ | ||
| unzip \ | ||
| software-properties-common \ | ||
| lsb-release \ | ||
| adb \ | ||
| clang \ | ||
| libc++-dev \ | ||
| libc++abi-dev \ | ||
| libclang-dev \ | ||
| libsndfile1 \ | ||
| python3 \ | ||
| python3-pip \ | ||
| python3-venv \ | ||
| python3-dev \ | ||
| && rm -rf /var/lib/apt/lists/* | ||
|
|
||
| # Install Android NDK r29 (placed early so failures surface quickly) | ||
| ARG ANDROID_NDK_VERSION=29.0.14206865 | ||
| ARG ANDROID_NDK_REVISION=r29 | ||
| RUN curl -SL -o /tmp/ndk.zip https://dl.google.com/android/repository/android-ndk-${ANDROID_NDK_REVISION}-linux.zip \ | ||
| && unzip -q /tmp/ndk.zip -d /opt \ | ||
| && rm -f /tmp/ndk.zip | ||
| ENV ANDROID_NDK_LATEST_HOME=/opt/android-ndk-${ANDROID_NDK_REVISION} | ||
| ENV PATH=${ANDROID_NDK_LATEST_HOME}:${PATH} | ||
|
|
||
| # Verify NDK is set up correctly | ||
| RUN ndk-build --help | ||
|
|
||
| # Download, install QNN SDK toolkit, then remove the zip in the same layer | ||
| WORKDIR /opt | ||
| RUN curl -SL -O ${QNN_TOOLKIT_URL} \ | ||
| && unzip v${QNN_SDK_VERSION}.zip \ | ||
| && rm -f v${QNN_SDK_VERSION}.zip | ||
|
|
||
| # Set QNN SDK environment variables | ||
| ENV QNN_SDK_ROOT=/opt/qairt/${QNN_SDK_VERSION} | ||
| ENV PATH=${QNN_SDK_ROOT}/bin/x86_64-linux-clang:${QNN_SDK_ROOT}/bin:${PATH} | ||
| ENV LD_LIBRARY_PATH=${QNN_SDK_ROOT}/lib/x86_64-linux-clang:${LD_LIBRARY_PATH} | ||
|
|
||
| # Install linux dependencies required by QNN SDK (source envsetup.sh first, matching workflow) | ||
| RUN cd ${QNN_SDK_ROOT}/bin && . envsetup.sh \ | ||
| && yes | ${QNN_SDK_ROOT}/bin/check-linux-dependency.sh || true \ | ||
| && rm -rf /var/lib/apt/lists/* | ||
|
|
||
| # Create and activate a Python 3.10 virtual environment | ||
| RUN python3 -m venv /opt/py310 | ||
| ENV VIRTUAL_ENV=/opt/py310 | ||
| ENV PATH=/opt/py310/bin:${PATH} | ||
|
|
||
| # Install all Python dependencies in a single layer to minimize image size | ||
| # The virtual environment is already active via ENV PATH above | ||
| RUN . /opt/py310/bin/activate && \ | ||
| pip install --no-cache-dir --upgrade pip && \ | ||
| pip install --no-cache-dir \ | ||
| mock \ | ||
| numpy \ | ||
| opencv-python \ | ||
| optuna \ | ||
| packaging \ | ||
| pandas \ | ||
| paramiko \ | ||
| pathlib2 \ | ||
| pillow \ | ||
| plotly \ | ||
| protobuf \ | ||
| psutil \ | ||
| pydantic \ | ||
| pytest \ | ||
| pyyaml \ | ||
| rich \ | ||
| scikit-optimize \ | ||
| scipy \ | ||
| six \ | ||
| tabulate \ | ||
| typing-extensions \ | ||
| xlsxwriter \ | ||
| && python3 "${QNN_SDK_ROOT}/bin/check-python-dependency" || true \ | ||
| && pip install --no-cache-dir \ | ||
| torch==2.0.0+cpu -f https://download.pytorch.org/whl/torch \ | ||
| kaldi_native_fbank \ | ||
| "numpy<2" \ | ||
| onnx==1.17.0 \ | ||
| onnxruntime \ | ||
| soundfile \ | ||
| librosa \ | ||
| onnxsim \ | ||
| sentencepiece \ | ||
| pyyaml \ | ||
| && pip cache purge 2>/dev/null || true | ||
|
Comment on lines
+65
to
+102
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Silent Installation Failures & Duplicate Dependencies\n\nThere are two main issues in this block:\n1. Silent Failures due to Operator Precedence: In Bash,
|
||
|
|
||
| # Verify QNN tools are accessible (source envsetup.sh first, matching workflow) | ||
| RUN cd ${QNN_SDK_ROOT}/bin && . envsetup.sh \ | ||
| && qnn-onnx-converter --help \ | ||
| && qnn-model-lib-generator --help \ | ||
| && qnn-net-run --help | ||
|
|
||
| WORKDIR /workspace | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| name: Build docker image for qnn SDK | ||
|
|
||
| on: | ||
| push: | ||
| branches: | ||
| - docker-qnn-2 | ||
| workflow_dispatch: | ||
|
|
||
| jobs: | ||
| build: | ||
| runs-on: ubuntu-latest | ||
| strategy: | ||
| fail-fast: false | ||
|
|
||
| permissions: | ||
| contents: read | ||
| packages: write | ||
|
|
||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@v4 | ||
|
|
||
| # Buildx is required for cache + multi-platform correctness | ||
| - name: Set up Docker Buildx | ||
| uses: docker/setup-buildx-action@v3 | ||
|
|
||
| - name: Login to GitHub Container Registry | ||
| uses: docker/login-action@v3 | ||
| with: | ||
| registry: ghcr.io | ||
| username: ${{ github.actor }} | ||
| password: ${{ secrets.GITHUB_TOKEN }} | ||
|
|
||
| - name: Build | ||
| env: | ||
| HF_TOKEN: ${{ secrets.HF_TOKEN }} | ||
| uses: docker/build-push-action@v5 | ||
| with: | ||
| context: ./.github/scripts/export-qnn | ||
| file: ./.github/scripts/export-qnn/Dockerfile-2.40 | ||
| platforms: linux/amd64 | ||
| push: true | ||
| tags: | | ||
| ghcr.io/${{ github.repository_owner }}/qnn-sdk:2.40 | ||
| cache-from: type=gha | ||
| cache-to: type=gha,mode=max |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| name: test-qnn-sdk-docker | ||
|
|
||
| on: | ||
| push: | ||
| branches: | ||
| - docker-qnn | ||
| workflow_dispatch: | ||
|
|
||
| jobs: | ||
| build: | ||
| runs-on: ubuntu-latest | ||
| container: | ||
| image: ghcr.io/${{ github.repository_owner }}/qnn-sdk:2.40 | ||
|
|
||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
|
||
| - name: Show system information | ||
| shell: bash | ||
| run: | | ||
| df -h | ||
|
|
||
| pwd | ||
| id | ||
| cat /etc/*version | ||
| ls -lh | ||
|
|
||
| - name: Show Python version | ||
| shell: bash | ||
| run: | | ||
| python3 --version | ||
| which python3 | ||
|
|
||
| - name: Show environment variables | ||
| shell: bash | ||
| run: | | ||
| echo "ANDROID_NDK_LATEST_HOME: $ANDROID_NDK_LATEST_HOME" | ||
| echo "PATH: $PATH" | ||
| echo "LD_LIBRARY_PATH: $LD_LIBRARY_PATH" | ||
| echo "QNN_SDK_ROOT: $QNN_SDK_ROOT" | ||
|
|
||
| - name: qnn-onnx-converter show help | ||
| shell: bash | ||
| run: | | ||
| pushd $QNN_SDK_ROOT/bin | ||
| source envsetup.sh | ||
| popd | ||
|
|
||
| which qnn-onnx-converter | ||
| qnn-onnx-converter --help | ||
|
|
||
| - name: qnn-model-lib-generator help | ||
| shell: bash | ||
| run: | | ||
| pushd $QNN_SDK_ROOT/bin | ||
| source envsetup.sh | ||
| popd | ||
|
|
||
| which qnn-model-lib-generator | ||
| echo "qnn-model-lib-generator --help" | ||
|
|
||
| - name: qnn-net-run help | ||
| shell: bash | ||
| run: | | ||
| pushd $QNN_SDK_ROOT/bin | ||
| source envsetup.sh | ||
| popd | ||
|
|
||
| which qnn-net-run | ||
| qnn-net-run --help |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bash Operator Precedence & Missing Package Lists\n\nThere are two issues in this step:\n1. Operator Precedence Pitfall: In Bash,
&&and||have equal precedence and are left-associative. The expressionA && B && C || true && Dis evaluated as(((A && B && C) || true) && D). Ifcdorsource envsetup.shfails, the chainA && B && Cfails, but the|| trueevaluates to true, and the shell proceeds to runD(rm -rf ...). This silently ignores failures in sourcingenvsetup.sh.\n2. Missing Package Lists: Thecheck-linux-dependency.shscript runsapt-get installunder the hood. However, since/var/lib/apt/lists/*was deleted in the previous layer,apt-getwill fail to locate packages. Runningapt-get updatebefore the script ensures dependencies can be successfully installed.\n\nTo fix both, wrap the dependency check in{ ... || true; }and runapt-get updatebeforehand.