Skip to content

Commit 56ec2df

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: 291963669 Differential Revision: [D77048745](https://our.internmc.facebook.com/intern/diff/D77048745/)
1 parent 496cb05 commit 56ec2df

File tree

3 files changed

+146
-42
lines changed

3 files changed

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