Skip to content

Commit e2350e2

Browse files
committed
Update on "Install libcpp from release package other than apt-get"
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 Differential Revision: [D77048745](https://our.internmc.facebook.com/intern/diff/D77048745/) Differential Revision: [D77048745](https://our.internmc.facebook.com/intern/diff/D77048745) [ghstack-poisoned]
1 parent 40f581b commit e2350e2

File tree

3 files changed

+138
-124
lines changed

3 files changed

+138
-124
lines changed

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

Lines changed: 7 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -1,126 +1,13 @@
11
#!/bin/bash
2-
set -ex
3-
4-
# Function to install Android NDK (only if not already set)
5-
setup_android_ndk() {
6-
# Check if ANDROID_NDK_ROOT is already set and valid
7-
if [ -n "${ANDROID_NDK_ROOT}" ] && [ -d "${ANDROID_NDK_ROOT}" ]; then
8-
echo "Android NDK already set to ${ANDROID_NDK_ROOT} - skipping installation"
9-
return
10-
fi
11-
12-
NDK_VERSION="r25c"
13-
NDK_INSTALL_DIR="/tmp/android-ndk"
14-
15-
if [ -d "${NDK_INSTALL_DIR}/ndk" ]; then
16-
echo "Android NDK already installed at ${NDK_INSTALL_DIR}/ndk"
17-
export ANDROID_NDK_ROOT="${NDK_INSTALL_DIR}/ndk"
18-
return
19-
fi
20-
21-
echo "Installing Android NDK ${NDK_VERSION}"
22-
mkdir -p "${NDK_INSTALL_DIR}"
23-
NDK_ZIP="android-ndk-${NDK_VERSION}-linux.zip"
24-
25-
curl -Lo "/tmp/${NDK_ZIP}" "https://dl.google.com/android/repository/${NDK_ZIP}"
26-
unzip -q "/tmp/${NDK_ZIP}" -d "${NDK_INSTALL_DIR}"
27-
mv "${NDK_INSTALL_DIR}/android-ndk-${NDK_VERSION}" "${NDK_INSTALL_DIR}/ndk"
28-
29-
export ANDROID_NDK_ROOT="${NDK_INSTALL_DIR}/ndk"
30-
echo "Android NDK installed to ${ANDROID_NDK_ROOT}"
31-
}
32-
33-
verify_pkg_installed() {
34-
dpkg-query -W --showformat='${Status}\n' "$1" | grep -q "install ok installed"
35-
}
36-
37-
install_qnn() {
38-
# Check if QNN_SDK_ROOT is already set and valid
39-
if [ -n "${QNN_SDK_ROOT}" ] && [ -d "${QNN_SDK_ROOT}" ]; then
40-
echo "QNN SDK already set to ${QNN_SDK_ROOT} - skipping installation"
41-
return
42-
fi
43-
44-
echo "Start installing qnn."
45-
QNN_INSTALLATION_DIR="/tmp/qnn"
46-
47-
# Clean up any previous installation
48-
if [ -d "${QNN_INSTALLATION_DIR}" ]; then
49-
echo "Removing previous QNN installation at ${QNN_INSTALLATION_DIR}"
50-
rm -rf "${QNN_INSTALLATION_DIR}"
51-
fi
52-
53-
mkdir -p "${QNN_INSTALLATION_DIR}"
54-
55-
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"
56-
echo "Finishing downloading qnn sdk."
57-
unzip -qo /tmp/v2.28.0.24.10.29.zip -d /tmp
58-
echo "Finishing unzip qnn sdk."
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.
597

60-
# Print the content for manual verification
61-
echo "Contents of /tmp/qairt:"
62-
ls -lah "/tmp/qairt"
63-
64-
# Check if we're moving a directory or files
65-
if [ -d "/tmp/qairt/2.28.0.241029" ]; then
66-
# Move the specific version directory instead of its contents
67-
mv "/tmp/qairt/2.28.0.241029" "${QNN_INSTALLATION_DIR}"
68-
else
69-
# Move all contents normally
70-
mv "/tmp/qairt"/* "${QNN_INSTALLATION_DIR}"
71-
fi
72-
73-
echo "Finishing installing qnn '${QNN_INSTALLATION_DIR}' ."
74-
echo "Final QNN installation contents:"
75-
ls -lah "${QNN_INSTALLATION_DIR}"
76-
77-
# Set QNN_SDK_ROOT environment variable
78-
export QNN_SDK_ROOT="${QNN_INSTALLATION_DIR}"
79-
echo "Set QNN_SDK_ROOT=${QNN_SDK_ROOT}"
80-
}
81-
82-
setup_libcpp() {
83-
clang_version=$1
84-
LLVM_VERSION="12.0.0"
85-
INSTALL_DIR="/usr/local/libcxx-${LLVM_VERSION}"
86-
87-
echo "Installing libc++-${clang_version}-dev manually from LLVM releases"
88-
89-
# Create temporary directory
90-
TEMP_DIR=$(mktemp -d)
91-
pushd "${TEMP_DIR}"
92-
93-
# Download and extract LLVM binaries
94-
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"
95-
curl -LO "${LLVM_URL}"
96-
tar -xf "clang+llvm-${LLVM_VERSION}-x86_64-linux-gnu-ubuntu-20.04.tar.xz"
97-
98-
# Create necessary directories
99-
sudo mkdir -p "${INSTALL_DIR}/include"
100-
sudo mkdir -p "${INSTALL_DIR}/lib" # FIX: Create lib directory
101-
102-
# Copy libc++ headers and libraries
103-
sudo cp -r clang+llvm*/include/c++/v1/* "${INSTALL_DIR}/include/"
104-
sudo cp -r clang+llvm*/lib/*.so* "${INSTALL_DIR}/lib/"
105-
106-
# Create system symlinks
107-
sudo mkdir -p /usr/include/c++
108-
sudo ln -sf "${INSTALL_DIR}/include" /usr/include/c++/v1
109-
sudo ln -sf "${INSTALL_DIR}/lib/libc++.so.1.0" /usr/lib/libc++.so.1
110-
sudo ln -sf "${INSTALL_DIR}/lib/libc++.so.1" /usr/lib/libc++.so
111-
sudo ln -sf "${INSTALL_DIR}/lib/libc++abi.so.1.0" /usr/lib/libc++abi.so.1
112-
sudo ln -sf "${INSTALL_DIR}/lib/libc++abi.so.1" /usr/lib/libc++abi.so
113-
114-
# Update library cache
115-
sudo ldconfig
116-
117-
# Cleanup
118-
popd
119-
rm -rf "${TEMP_DIR}"
8+
set -ex
1209

121-
echo "libc++-${clang_version}-dev installed to ${INSTALL_DIR}"
122-
}
10+
source "$(dirname "${BASH_SOURCE[0]}")/../../../backends/qualcomm/scripts/install_qnn_sdk.sh"
12311

124-
# Main execution flow
12512
setup_libcpp 12
12613
install_qnn

backends/qualcomm/scripts/install_qnn_sdk.sh

Lines changed: 121 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,129 @@
55
# This source code is licensed under the BSD-style license found in the
66
# LICENSE file in the root directory of this source tree.
77

8-
# Test the end-to-end flow of mps runner.
8+
set -ex
99

10-
set -e
10+
# Source QNN configuration
11+
source "$(dirname "$0")/qnn_config.sh"
1112

12-
# shellcheck source=/dev/null
13-
source "$(dirname "${BASH_SOURCE[0]}")/../../../.ci/scripts/setup-qnn-deps.sh"
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+
}
14131

15132
setup_libcpp 12
16133
setup_android_ndk
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)