Skip to content

Commit 6fed46d

Browse files
committed
Install libcpp from release package other than apt-get
Pull Request resolved: #11832 A few changes 1. Use the release package from https://releases.llvm.org/ to install libcpp, so we can install from different linux in addition to Ubuntu 2. Seperate out the qnn version and the url to a seperate file, for better versin management in the future ghstack-source-id: 294996148 Differential Revision: [D77048745](https://our.internmc.facebook.com/intern/diff/D77048745/)
1 parent ba19c75 commit 6fed46d

File tree

3 files changed

+157
-42
lines changed

3 files changed

+157
-42
lines changed

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

Lines changed: 2 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -7,47 +7,7 @@
77

88
set -ex
99

10-
verify_pkg_installed() {
11-
echo $(dpkg-query -W --showformat='${Status}\n' $1|grep "install ok installed")
12-
}
10+
source "$(dirname "${BASH_SOURCE[0]}")/../../backends/qualcomm/scripts/install_qnn_sdk.sh"
1311

14-
install_qnn() {
15-
echo "Start installing qnn."
16-
QNN_INSTALLATION_DIR=/tmp/qnn
17-
mkdir -p "${QNN_INSTALLATION_DIR}"
18-
19-
curl -Lo /tmp/v2.28.0.24.10.29.zip "https://softwarecenter.qualcomm.com/api/download/software/qualcomm_neural_processing_sdk/v2.28.0.241029.zip"
20-
echo "Finishing downloading qnn sdk."
21-
unzip -qo /tmp/v2.28.0.24.10.29.zip -d /tmp
22-
echo "Finishing unzip qnn sdk."
23-
24-
25-
# Print the content for manual verification
26-
ls -lah "/tmp/qairt"
27-
mv "/tmp/qairt"/* "${QNN_INSTALLATION_DIR}"
28-
echo "Finishing installing qnn '${QNN_INSTALLATION_DIR}' ."
29-
30-
ls -lah "${QNN_INSTALLATION_DIR}"
31-
}
32-
33-
setup_libc++() {
34-
clang_version=$1
35-
sudo apt-get update
36-
pkgs_to_check=("libc++-${clang_version}-dev")
37-
j=0
38-
while [ $j -lt ${#pkgs_to_check[*]} ]; do
39-
install_status=$(verify_pkg_installed ${pkgs_to_check[$j]})
40-
if [ "$install_status" == "" ]; then
41-
sudo apt-get install -y ${pkgs_to_check[$j]}
42-
if [[ $? -ne 0 ]]; then
43-
echo "ERROR: Failed to install required packages for libc++"
44-
exit 1
45-
fi
46-
fi
47-
j=$(( $j +1));
48-
done
49-
}
50-
51-
# This needs to match with the clang version from the Docker image
52-
setup_libc++ 12
12+
setup_libcpp 12
5313
install_qnn
Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
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+
# Get the absolute path of this script
11+
SCRIPT_DIR="$( cd -- "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 ; pwd -P )"
12+
13+
# Source QNN configuration from the same directory
14+
source "${SCRIPT_DIR}/qnn_config.sh"
15+
16+
# Function to install Android NDK (only if not already set)
17+
setup_android_ndk() {
18+
# Check if ANDROID_NDK_ROOT is already set and valid
19+
if [ -n "${ANDROID_NDK_ROOT}" ] && [ -d "${ANDROID_NDK_ROOT}" ]; then
20+
echo "Android NDK already set to ${ANDROID_NDK_ROOT} - skipping installation"
21+
return
22+
fi
23+
24+
NDK_VERSION="r25c"
25+
NDK_INSTALL_DIR="/tmp/android-ndk"
26+
27+
if [ -d "${NDK_INSTALL_DIR}/ndk" ]; then
28+
echo "Android NDK already installed at ${NDK_INSTALL_DIR}/ndk"
29+
export ANDROID_NDK_ROOT="${NDK_INSTALL_DIR}/ndk"
30+
return
31+
fi
32+
33+
echo "Installing Android NDK ${NDK_VERSION}"
34+
mkdir -p "${NDK_INSTALL_DIR}"
35+
NDK_ZIP="android-ndk-${NDK_VERSION}-linux.zip"
36+
37+
curl -Lo "/tmp/${NDK_ZIP}" "https://dl.google.com/android/repository/${NDK_ZIP}"
38+
unzip -q "/tmp/${NDK_ZIP}" -d "${NDK_INSTALL_DIR}"
39+
mv "${NDK_INSTALL_DIR}/android-ndk-${NDK_VERSION}" "${NDK_INSTALL_DIR}/ndk"
40+
41+
export ANDROID_NDK_ROOT="${NDK_INSTALL_DIR}/ndk"
42+
echo "Android NDK installed to ${ANDROID_NDK_ROOT}"
43+
}
44+
45+
verify_pkg_installed() {
46+
dpkg-query -W --showformat='${Status}\n' "$1" | grep -q "install ok installed"
47+
}
48+
49+
install_qnn() {
50+
# Check if QNN_SDK_ROOT is already set and valid
51+
if [ -n "${QNN_SDK_ROOT}" ] && [ -d "${QNN_SDK_ROOT}" ]; then
52+
echo "QNN SDK already set to ${QNN_SDK_ROOT} - skipping installation"
53+
return
54+
fi
55+
56+
echo "Start installing qnn v${QNN_VERSION}"
57+
QNN_INSTALLATION_DIR="/tmp/qnn"
58+
59+
# Clean up any previous installation
60+
if [ -d "${QNN_INSTALLATION_DIR}" ]; then
61+
echo "Removing previous QNN installation at ${QNN_INSTALLATION_DIR}"
62+
rm -rf "${QNN_INSTALLATION_DIR}"
63+
fi
64+
65+
mkdir -p "${QNN_INSTALLATION_DIR}"
66+
67+
QNN_ZIP_FILE="v${QNN_VERSION}.zip"
68+
curl -Lo "/tmp/${QNN_ZIP_FILE}" "${QNN_ZIP_URL}"
69+
echo "Finishing downloading qnn sdk."
70+
unzip -qo "/tmp/${QNN_ZIP_FILE}" -d /tmp
71+
echo "Finishing unzip qnn sdk."
72+
73+
# Print the content for manual verification
74+
echo "Contents of /tmp/qairt:"
75+
ls -lah "/tmp/qairt"
76+
77+
# Move the specific version directory
78+
if [ -d "/tmp/qairt/${QNN_VERSION}" ]; then
79+
mv "/tmp/qairt/${QNN_VERSION}" "${QNN_INSTALLATION_DIR}"
80+
else
81+
mv "/tmp/qairt"/* "${QNN_INSTALLATION_DIR}"
82+
fi
83+
84+
echo "Finishing installing qnn '${QNN_INSTALLATION_DIR}' ."
85+
echo "Final QNN installation contents:"
86+
ls -lah "${QNN_INSTALLATION_DIR}"
87+
88+
# Set QNN_SDK_ROOT environment variable
89+
export QNN_SDK_ROOT="${QNN_INSTALLATION_DIR}"
90+
echo "Set QNN_SDK_ROOT=${QNN_SDK_ROOT}"
91+
}
92+
93+
setup_libcpp() {
94+
clang_version=$1
95+
LLVM_VERSION="12.0.0"
96+
INSTALL_DIR="/usr/local/libcxx-${LLVM_VERSION}"
97+
98+
# Check if libc++ is already installed
99+
if [ -d "/usr/include/c++/v1" ] && \
100+
[ -f "/usr/lib/libc++.so.1" ] && \
101+
[ -f "/usr/lib/libc++abi.so.1" ]; then
102+
echo "libc++-${clang_version}-dev is already installed - skipping"
103+
return
104+
fi
105+
106+
echo "Installing libc++-${clang_version}-dev manually from LLVM releases"
107+
108+
# Create temporary directory
109+
TEMP_DIR=$(mktemp -d)
110+
pushd "${TEMP_DIR}"
111+
112+
# Download and extract LLVM binaries
113+
LLVM_URL="https://github.com/llvm/llvm-project/releases/download/llvmorg-${LLVM_VERSION}/clang+llvm-${LLVM_VERSION}-x86_64-linux-gnu-ubuntu-20.04.tar.xz"
114+
curl -LO "${LLVM_URL}"
115+
tar -xf "clang+llvm-${LLVM_VERSION}-x86_64-linux-gnu-ubuntu-20.04.tar.xz"
116+
117+
# Create necessary directories
118+
sudo mkdir -p "${INSTALL_DIR}/include"
119+
sudo mkdir -p "${INSTALL_DIR}/lib" # FIX: Create lib directory
120+
121+
# Copy libc++ headers and libraries
122+
sudo cp -r clang+llvm*/include/c++/v1/* "${INSTALL_DIR}/include/"
123+
sudo cp -r clang+llvm*/lib/*.so* "${INSTALL_DIR}/lib/"
124+
125+
# Create system symlinks
126+
sudo mkdir -p /usr/include/c++
127+
sudo ln -sf "${INSTALL_DIR}/include" /usr/include/c++/v1
128+
sudo ln -sf "${INSTALL_DIR}/lib/libc++.so.1.0" /usr/lib/libc++.so.1
129+
sudo ln -sf "${INSTALL_DIR}/lib/libc++.so.1" /usr/lib/libc++.so
130+
sudo ln -sf "${INSTALL_DIR}/lib/libc++abi.so.1.0" /usr/lib/libc++abi.so.1
131+
sudo ln -sf "${INSTALL_DIR}/lib/libc++abi.so.1" /usr/lib/libc++abi.so
132+
133+
# Update library cache
134+
sudo ldconfig
135+
136+
# Cleanup
137+
popd
138+
rm -rf "${TEMP_DIR}"
139+
140+
echo "libc++-${clang_version}-dev installed to ${INSTALL_DIR}"
141+
}
142+
143+
setup_libcpp 12
144+
setup_android_ndk
145+
install_qnn
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
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+
# QNN SDK Configuration
9+
QNN_VERSION="2.28.0.241029"
10+
QNN_ZIP_URL="https://softwarecenter.qualcomm.com/api/download/software/qualcomm_neural_processing_sdk/v${QNN_VERSION}.zip"

0 commit comments

Comments
 (0)