Skip to content

Commit e71fa03

Browse files
authored
Add stories ci for qnn
Differential Revision: D61141050 Pull Request resolved: #4662
1 parent 56f843b commit e71fa03

File tree

9 files changed

+124
-3
lines changed

9 files changed

+124
-3
lines changed

.ci/docker/build.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ case "${IMAGE_NAME}" in
3737
ARM_SDK=yes
3838
CLANG_VERSION=12
3939
;;
40+
executorch-ubuntu-22.04-qnn-sdk)
41+
QNN_SDK=yes
42+
CLANG_VERSION=12
43+
;;
4044
executorch-ubuntu-22.04-clang12-android)
4145
LINTRUNNER=""
4246
CLANG_VERSION=12
@@ -59,6 +63,9 @@ cp ../../requirements-lintrunner.txt ./
5963
# with a new image hash when the content here is updated
6064
cp -r ../../examples/arm/ ./arm
6165

66+
# Copy qnn setup script from root to here
67+
cp -r ../../backends/qualcomm/ ./qualcomm
68+
6269
docker build \
6370
--no-cache \
6471
--progress=plain \
@@ -72,6 +79,7 @@ docker build \
7279
--build-arg "LINTRUNNER=${LINTRUNNER:-}" \
7380
--build-arg "BUILD_DOCS=${BUILD_DOCS}" \
7481
--build-arg "ARM_SDK=${ARM_SDK:-}" \
82+
--build-arg "QNN_SDK=${QNN_SDK:-}" \
7583
--build-arg "ANDROID_NDK_VERSION=${ANDROID_NDK_VERSION:-}" \
7684
-f "${OS}"/Dockerfile \
7785
"$@" \

.ci/docker/ubuntu/Dockerfile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,5 +82,10 @@ COPY --chown=ci-user:ci-user ./arm /opt/arm
8282
# Set up ARM SDK if needed
8383
RUN if [ -n "${ARM_SDK}" ]; then git config --global user.email "[email protected]"; git config --global user.name "OSS CI"; bash /opt/arm/setup.sh --i-agree-to-the-contained-eula /opt/arm-sdk; chown -R ci-user:ci-user /opt/arm-sdk; fi
8484

85+
ARG QNN_SDK
86+
COPY --chown=ci-user:ci-user ./qualcomm /opt/qualcomm
87+
# Set up QNN SDK if needed
88+
RUN if [ -n "${QNN_SDK}" ]; then git config --global user.email "[email protected]"; git config --global user.name "OSS CI"; fi
89+
8590
USER ci-user
8691
CMD ["bash"]

.ci/scripts/build-qnn-sdk.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
# Copyright (c) Meta Platforms, Inc. and affiliates.
3+
# All rights reserved.
4+
#
5+
# This source code is licensed under the BSD-style license found in the
6+
# LICENSE file in the root directory of this source tree.
7+
8+
set -ex
9+
10+
build_qnn_backend() {
11+
echo "Start building qnn backend."
12+
export ANDROID_NDK_ROOT=/opt/ndk
13+
export QNN_SDK_ROOT=/tmp/qnn/2.23.0.240531
14+
export EXECUTORCH_ROOT="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.." && pwd)"
15+
16+
bash backends/qualcomm/scripts/build.sh --skip_aarch64 --job_number 2 --release
17+
}
18+
19+
build_qnn_backend

.ci/scripts/setup-qnn-deps.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/bin/bash
2+
# Copyright (c) Meta Platforms, Inc. and affiliates.
3+
# All rights reserved.
4+
#
5+
# This source code is licensed under the BSD-style license found in the
6+
# LICENSE file in the root directory of this source tree.
7+
8+
set -ex
9+
10+
install_qnn() {
11+
echo "Start installing qnn."
12+
QNN_INSTALLATION_DIR=/tmp/qnn
13+
mkdir -p "${QNN_INSTALLATION_DIR}"
14+
15+
curl -Lo /tmp/v2.23.0.24.06.24.zip "https://softwarecenter.qualcomm.com/api/download/software/qualcomm_neural_processing_sdk/v2.23.0.24.06.24.zip"
16+
echo "Finishing downloading qnn sdk."
17+
unzip -qo /tmp/v2.23.0.24.06.24.zip -d /tmp
18+
echo "Finishing unzip qnn sdk."
19+
20+
21+
# Print the content for manual verification
22+
ls -lah "/tmp/qairt"
23+
mv "/tmp/qairt"/* "${QNN_INSTALLATION_DIR}"
24+
echo "Finishing installing qnn '${QNN_INSTALLATION_DIR}' ."
25+
26+
ls -lah "${QNN_INSTALLATION_DIR}"
27+
}
28+
29+
install_qnn

.ci/scripts/test_llama.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,25 @@ fi
7272

7373
echo "COREML option ${COREML}"
7474

75+
if [[ "${MODE}" =~ .*qnn.* ]]; then
76+
QNN=ON
77+
export EXECUTORCH_ROOT="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.." && pwd)"
78+
export QNN_SDK_ROOT=/tmp/qnn/2.23.0.240531
79+
export LD_LIBRARY_PATH="${QNN_SDK_ROOT}/lib/x86_64-linux-clang"
80+
export PYTHONPATH=".."
81+
cp schema/program.fbs exir/_serialize/program.fbs
82+
cp schema/scalar_type.fbs exir/_serialize/scalar_type.fbs
83+
cp -f build-x86/backends/qualcomm/PyQnnManagerAdaptor.cpython-310-x86_64-linux-gnu.so backends/qualcomm/python
84+
cp -f build-x86/backends/qualcomm/PyQnnWrapperAdaptor.cpython-310-x86_64-linux-gnu.so backends/qualcomm/python
85+
86+
else
87+
QNN=OFF
88+
QNN_SDK_ROOT=""
89+
fi
90+
91+
echo "QNN option ${QNN}"
92+
echo "QNN_SDK_ROOT: ${QNN_SDK_ROOT}"
93+
7594
if [[ -z "${BUCK:-}" ]]; then
7695
BUCK=buck2
7796
fi
@@ -96,6 +115,8 @@ cmake_install_executorch_libraries() {
96115
-DEXECUTORCH_BUILD_XNNPACK="$XNNPACK" \
97116
-DEXECUTORCH_BUILD_MPS="$MPS" \
98117
-DEXECUTORCH_BUILD_COREML="$COREML" \
118+
-DEXECUTORCH_BUILD_QNN="$QNN" \
119+
-DQNN_SDK_ROOT="$QNN_SDK_ROOT" \
99120
-DPYTHON_EXECUTABLE="$PYTHON_EXECUTABLE" \
100121
-Bcmake-out .
101122
cmake --build cmake-out -j9 --target install --config Debug
@@ -176,6 +197,9 @@ fi
176197
if [[ "${COREML}" == "ON" ]]; then
177198
EXPORT_ARGS="${EXPORT_ARGS} -kv -v --coreml --disable_dynamic_shape"
178199
fi
200+
if [[ "${QNN}" == "ON" ]]; then
201+
EXPORT_ARGS="${EXPORT_ARGS} -kv -v --qnn --disable_dynamic_shape"
202+
fi
179203
# Add dynamically linked library location
180204
$PYTHON_EXECUTABLE -m examples.models.llama2.export_llama ${EXPORT_ARGS}
181205

.github/workflows/docker-builds.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ jobs:
3838
- docker-image-name: executorch-ubuntu-22.04-clang12
3939
- docker-image-name: executorch-ubuntu-22.04-linter
4040
- docker-image-name: executorch-ubuntu-22.04-arm-sdk
41+
- docker-image-name: executorch-ubuntu-22.04-qnn-sdk
4142
- docker-image-name: executorch-ubuntu-22.04-clang12-android
4243
env:
4344
DOCKER_IMAGE: 308535385114.dkr.ecr.us-east-1.amazonaws.com/executorch/${{ matrix.docker-image-name }}

.github/workflows/trunk.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,3 +270,38 @@ jobs:
270270
PYTHON_EXECUTABLE=python ${CONDA_RUN} bash examples/models/llama2/install_requirements.sh
271271
# Test llama2
272272
PYTHON_EXECUTABLE=python ${CONDA_RUN} bash .ci/scripts/test_llama.sh stories110M.pt "${BUILD_TOOL}" "${DTYPE}" "${MODE}"
273+
274+
275+
test-llama-runner-qnn-linux:
276+
name: test-llama-runner-qnn-linux
277+
uses: pytorch/test-infra/.github/workflows/linux_job.yml@main
278+
strategy:
279+
matrix:
280+
dtype: [fp32]
281+
build-tool: [cmake]
282+
mode: [qnn]
283+
fail-fast: false
284+
with:
285+
runner: linux.2xlarge
286+
docker-image: executorch-ubuntu-22.04-qnn-sdk
287+
submodules: 'true'
288+
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
289+
timeout: 900
290+
script: |
291+
# The generic Linux job chooses to use base env, not the one setup by the image
292+
CONDA_ENV=$(conda env list --json | jq -r ".envs | .[-1]")
293+
conda activate "${CONDA_ENV}"
294+
295+
DTYPE=${{ matrix.dtype }}
296+
BUILD_TOOL=${{ matrix.build-tool }}
297+
MODE=${{ matrix.mode }}
298+
299+
PYTHON_EXECUTABLE=python bash .ci/scripts/setup-qnn-deps.sh
300+
PYTHON_EXECUTABLE=python bash .ci/scripts/build-qnn-sdk.sh
301+
302+
# Setup executorch
303+
PYTHON_EXECUTABLE=python bash .ci/scripts/setup-linux.sh buck2
304+
# Install requirements for export_llama
305+
PYTHON_EXECUTABLE=python bash examples/models/llama2/install_requirements.sh
306+
# Test llama2
307+
PYTHON_EXECUTABLE=python bash .ci/scripts/test_llama.sh stories110M.pt "${BUILD_TOOL}" "${DTYPE}" "${MODE}"

backends/qualcomm/aot/python/PyQnnWrapperAdaptor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ class PyQnnOpWrapper {
8686
break;
8787
default:
8888
QNN_EXECUTORCH_LOG_ERROR(
89-
"%s has invalid data type: %d", name, data_type);
89+
"%s has invalid data type: %d", name.c_str(), data_type);
9090
break;
9191
}
9292
}

backends/qualcomm/scripts/build.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ usage() {
2525
[ "$1" = -h ] && usage
2626

2727
BUILD_X86_64="true"
28-
CMAKE_X86_64="cmake-out"
28+
CMAKE_X86_64="build-x86"
2929
BUILD_AARCH64="true"
30-
CMAKE_AARCH64="cmake-out-android"
30+
CMAKE_AARCH64="build-android"
3131
CLEAN="true"
3232
BUILD_TYPE="Debug"
3333
BUILD_JOB_NUMBER="16"

0 commit comments

Comments
 (0)