Skip to content

Commit

Permalink
[skip ci] Provide script for installing system dependencies (#14405)
Browse files Browse the repository at this point in the history
INSTALLING.md instructions use pinned version of deps that may go out of
sync and vary across distro.
Avoid the need to document, by introducing a script
The new script can be called from our Dockerfiles as well

### What's changed
Script provided
Documentation updated
  • Loading branch information
blozano-tt authored Nov 14, 2024
1 parent 14a6f6f commit 5f04e31
Show file tree
Hide file tree
Showing 2 changed files with 143 additions and 8 deletions.
10 changes: 2 additions & 8 deletions INSTALLING.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,10 @@ Note the current compatability matrix:
### Step 2. System-level dependencies

```sh
sudo apt update
sudo apt install software-properties-common=0.99.9.12 build-essential=12.8ubuntu1.1 python3.8-venv libhwloc-dev graphviz cmake=3.16.3-1ubuntu1.20.04.1 ninja-build

wget https://apt.llvm.org/llvm.sh
chmod u+x llvm.sh
sudo ./llvm.sh 17
sudo apt install libc++-17-dev libc++abi-17-dev
sudo ./install_dependencies.sh
```
- Note: `CMake 3.16` is the targetted required version of `CMake` as it aligns with the default from `Ubuntu 20.04`. Some advanced build configurations like unity builds require `CMake 3.20`.
- To install `CMake 3.20` see: https://github.com/tenstorrent/tt-metal/blob/4d7730d3e2d22c51d62baa1bfed861b557d9a3c0/dockerfile/ubuntu-20.04-amd64.Dockerfile#L9-L14
- To install `CMake 3.20` see: https://github.com/tenstorrent/tt-metal/blob/4d7730d3e2d22c51d62baa1bfed861b557d9a3c0/dockerfile/ubuntu-20.04-amd64.Dockerfile#L9-L14
---

### Step 3. Hugepages
Expand Down
141 changes: 141 additions & 0 deletions install_dependencies.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
#!/bin/bash

# SPDX-License-Identifier: Apache-2.0
# Copyright (C) 2024 Tenstorrent, Inc. All rights reserved.
#
# This script is based on `xrtdeps.sh` from the Xilinx XRT project.
# Original source: https://github.com/Xilinx/XRT/blob/master/src/runtime_src/tools/scripts/xrtdeps.sh
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

FLAVOR=`grep '^ID=' /etc/os-release | awk -F= '{print $2}' | tr -d '"'`
VERSION=`grep '^VERSION_ID=' /etc/os-release | awk -F= '{print $2}' | tr -d '"'`
MAJOR=${VERSION%.*}
ARCH=`uname -m`

usage()
{
echo "Usage: sudo ./install_dependencies.sh [options]"
echo
echo "[--help, -h] List this help"
echo "[--validate, -v] Validate that required packages are installed"
exit 1
}

validate=0

while [ $# -gt 0 ]; do
case "$1" in
--help|-h)
usage
;;
--validate|-v)
validate=1
shift
;;
*)
echo "Unknown option: $1"
usage
;;
esac
done

ub_package_list()
{
UB_LIST=(\
git \
git-lfs \
build-essential \
cmake \
software-properties-common \
libhwloc-dev \
graphviz \
ninja-build \
libpython3-dev \
libcapstone-dev \
python3-pip \
python3-dev \
python3.8-venv \
libc++-17-dev \
libc++abi-17-dev \
)

}

update_package_list()
{
if [ $FLAVOR == "ubuntu" ]; then
ub_package_list
else
echo "unknown OS flavor $FLAVOR"
exit 1
fi
}

validate_packages()
{
if [ $FLAVOR == "ubuntu" ]; then
dpkg -l "${UB_LIST[@]}"
#dpkg -l "${UB_LIST[@]}" > /dev/null
else
echo "unknown OS flavor $FLAVOR"
exit 1
fi
}

prep_ubuntu()
{
echo "Preparing ubuntu ..."
# Update the list of available packages
apt-get update
}

install_llvm() {
LLVM_VERSION="17"
echo "Checking if LLVM $LLVM_VERSION is already installed..."
if command -v clang-$LLVM_VERSION &> /dev/null; then
echo "LLVM $LLVM_VERSION is already installed. Skipping installation."
else
echo "Installing LLVM $LLVM_VERSION..."
TEMP_DIR=$(mktemp -d)
wget -P $TEMP_DIR https://apt.llvm.org/llvm.sh
chmod u+x $TEMP_DIR/llvm.sh
$TEMP_DIR/llvm.sh $LLVM_VERSION
rm -rf "$TEMP_DIR"
fi
}

install()
{
if [ $FLAVOR == "ubuntu" ]; then
prep_ubuntu

echo "Installing packages..."
apt-get install -y "${UB_LIST[@]}"
fi
}

if [ "$EUID" -ne 0 ]; then
echo "This script must be run as root. Please use sudo."
usage
fi

install_llvm

update_package_list

if [ $validate == 1 ]; then
validate_packages
else
install
fi

0 comments on commit 5f04e31

Please sign in to comment.