Skip to content

Commit

Permalink
Simplify Linux install scripts so it is easier to try new kernels (#50)
Browse files Browse the repository at this point in the history
* Simplify kernel versioning

* Do not build for Alveo

* Add more intructions

* Fix instructions
  • Loading branch information
mariodruiz authored Aug 7, 2024
1 parent fb9762c commit a2b7df2
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 50 deletions.
46 changes: 37 additions & 9 deletions scripts/linux/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,37 @@

Currently there is support for bringing up Riallto on Ubuntu 24.04 with docker.
To use Riallto on Linux requires the use of the [xdna-driver](https://github.com/amd/xdna-driver) which is installed as part of the setup.
This driver requires version 6.10+ of the linux kernel, these scripts will upgrade a standard Ubuntu 24.04 installation to this kernel version. __Using this kernel version will require disabling secure boot on your device.__
This driver requires version 6.10+ of the Linux kernel, these scripts will upgrade a standard Ubuntu 24.04 installation to this kernel version. __Using this kernel version will require disabling secure boot on your device.__

## Install steps

On an NPU enabled laptop running Ubuntu 24.04.

1. __Setup Docker.__
1. __Setup Docker.__

You can follow the steps [here](https://docs.docker.com/engine/install/ubuntu/).

2. __Add your user to the docker user group and then relogin.__
```
sudo usermod -aG docker $USER ; exit
```
2. __Add your user to the docker user group and then relogin.__

```sh
sudo usermod -aG docker $USER ; exit
```

3. __Obtain a license file for Riallto.__

Please follow the [guide here](https://riallto.ai/prerequisites-aie-license.html#prerequisites-aie-license)

4. __Disable secure boot from your BIOS settings.__ For now we are using an unsigned kernel version requiring that secure boot is disabled before it can be used. To disable secure boot there is a [guide](https://learn.microsoft.com/en-us/windows-hardware/manufacture/desktop/disabling-secure-boot?view=windows-11) from Microsoft here, but often the steps depend on your hardware manufacturer.

5. __Run `./setup_riallto_linux.sh <your license file>`.__
5. Clone this the Riallto repository and then navigate to the installation script `git clone https://github.com/AMDResearch/Riallto.git && cd Riallto/scripts/linux/`.

6. __Run `./setup_riallto_linux.sh <your license file>`.__
This command will check the kernel version and if the xdna-driver has been installed. If the kernel is not 6.10 or the NPU device drivers are missing it will build them within a docker and install them on the host machine. This takes about 10 minutes to run and after completing successfully the user will be asked to restart.

6. __Reboot the machine.__
7. __Reboot the machine.__
To finish upgrading the kernel to `6.10`.

7. __Re run the `./setup_riallto_linux.sh <your license file>` script.__
8. __Re run the `./setup_riallto_linux.sh <your license file>` script.__
This will build the Riallto docker and will take about 20 minutes.

## Running Riallto / Running Tests
Expand All @@ -36,3 +41,26 @@ Inside this directory there are a few scripts.
* `launch_jupyter.sh <notebooks directory>` - will launch a jupyterlab server from a docker container allowing you to use Riallto notebooks in the directory provided (usually Riallto/notebooks).
* `run_pytest.sh` - will run a suit of pytests to test the operation of your NPU device and the Riallto installation.

### FAQ

### If you get the following error on boot, `error: bad shim signature`

This means that secure boot has not been disabled from the machine and it cannot run the necessary kernel version.

### If the Docker container does not start with `launch_jupyter.sh` or `run_pytest.sh` because of the `/dev/accel/accel0` does not exist

Check `dmesg`

```sh
sudo dmesg | grep "xdna"
```

If you see `loading /lib/firmware/amdnpu/1502_00/npu.sbin failed with error -22`, it means that the driver did not install properly.

Delete the NPU firmware:

```sh
sudo rm -rf /lib/firmware/amdnpu/1502_00/npu.sbin
```

Then, start the installation from scratch.
72 changes: 40 additions & 32 deletions scripts/linux/setup_riallto_linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,28 @@

set -e

KERNEL_VERSION="6.10-rc2"
KERNEL_VERSION_FULL="6.10.0-061000rc2"
BUILD_DATE="202406022333"

DRIVER_TARBALL=ubuntu24.04_npu_drivers.tar.gz
REQUIRED_KERNEL_VERSION="6.10.0-061000rc2-generic"
REQUIRED_KERNEL_VERSION="${KERNEL_VERSION_FULL}-generic"
NPU_FIRMWARE="/lib/firmware/amdnpu/1502_00/npu.sbin"
KERNEL_HEADERS=linux-headers-6.10.0-061000rc2_6.10.0-061000rc2.202406022333_all.deb
KERNEL_HEADERS_GENERIC=linux-headers-6.10.0-061000rc2-generic_6.10.0-061000rc2.202406022333_amd64.deb
KERNEL_MODULES=linux-modules-6.10.0-061000rc2-generic_6.10.0-061000rc2.202406022333_amd64.deb
KERNEL_IMAGE=linux-image-unsigned-6.10.0-061000rc2-generic_6.10.0-061000rc2.202406022333_amd64.deb
KERNEL_HEADERS="linux-headers-${KERNEL_VERSION_FULL}_${KERNEL_VERSION_FULL}.${BUILD_DATE}_all.deb"
KERNEL_HEADERS_GENERIC="linux-headers-${KERNEL_VERSION_FULL}-generic_${KERNEL_VERSION_FULL}.${BUILD_DATE}_amd64.deb"
KERNEL_MODULES="linux-modules-${KERNEL_VERSION_FULL}-generic_${KERNEL_VERSION_FULL}.${BUILD_DATE}_amd64.deb"
KERNEL_IMAGE="linux-image-unsigned-${KERNEL_VERSION_FULL}-generic_${KERNEL_VERSION_FULL}.${BUILD_DATE}_amd64.deb"

MLIR_FILE="https://www.xilinx.com/bin/public/openDownload?filename=pynqMLIR_AIE_py312_v0.9.tar.gz"
RIALLTO_FILE="https://www.xilinx.com/bin/public/openDownload?filename=Riallto-v1.1.zip"


############# CHECKS ##################################
# Check to ensure key URLs are accessible
URLS=(
"https://kernel.ubuntu.com/mainline/v6.10-rc2/amd64/"
"https://www.xilinx.com/bin/public/openDownload?filename=pynqMLIR_AIE_py312_v0.9.tar.gz"
"https://www.amd.com/bin/public/amdOpenDownload?filename=Riallto-v1.1.zip"
"https://kernel.ubuntu.com/mainline/v$KERNEL_VERSION/amd64/"
$MLIR_FILE
$RIALLTO_FILE
"https://github.com/amd/xdna-driver.git"
"https://github.com/AMDResearch/Riallto.git"
"https://docker.io/library/ubuntu"
Expand Down Expand Up @@ -57,12 +65,12 @@ else
echo "Unable to continue the installation."
echo "Please configure docker using the instructions found here:"
echo "https://docs.docker.com/engine/install/ubuntu/"
echo "And then rerun the script"
echo "And then rerun the script"
exit 1
fi

############### License file check ###################
# Check to make sure that a license file has been provided and that
# Check to make sure that a license file has been provided and that
# a MAC address can be extracted from it for adding into the docker
# image
if [ "$#" -ne 1 ]; then
Expand All @@ -88,7 +96,7 @@ build_xrt=0
kernel_version=$(uname -r)

if [[ "$kernel_version" == "$REQUIRED_KERNEL_VERSION" ]]; then
echo "Kernel version is okay, is NPU available?"
echo "Kernel version is okay, is NPU available?"
else
echo "To install Riallto requires upgrading your kernel to ${REQUIRED_KERNEL_VERSION}"
echo "WARNING: This can be quite disruptive to your system configuration."
Expand All @@ -101,44 +109,44 @@ else
* ) echo "Please chose Y or N.";;
esac
done

# First check to make sure that secure boot is disabled.
if mokutil --sb-state | grep -q "enabled"; then
echo "Secure boot is currently enabled."
echo "To install Riallto on Linux currently requires a"
echo "To install Riallto on Linux currently requires a"
echo "non-mainline kernel version ${REQUIRED_KERNEL_VERSION}."
echo "If you would like to continue with the installation "
echo "please disable secure boot in your bios settings and rerun this script."
exit 1
exit 1
fi

_kbump_dir=$(mktemp -d)

wget -P ${_kbump_dir} https://kernel.ubuntu.com/mainline/v6.10-rc2/amd64/$KERNEL_HEADERS_GENERIC
wget -P ${_kbump_dir} https://kernel.ubuntu.com/mainline/v6.10-rc2/amd64/$KERNEL_HEADERS
wget -P ${_kbump_dir} https://kernel.ubuntu.com/mainline/v6.10-rc2/amd64/$KERNEL_IMAGE
wget -P ${_kbump_dir} https://kernel.ubuntu.com/mainline/v6.10-rc2/amd64/$KERNEL_MODULES
wget -P ${_kbump_dir} https://kernel.ubuntu.com/mainline/v$KERNEL_VERSION/amd64/$KERNEL_HEADERS_GENERIC
wget -P ${_kbump_dir} https://kernel.ubuntu.com/mainline/v$KERNEL_VERSION/amd64/$KERNEL_HEADERS
wget -P ${_kbump_dir} https://kernel.ubuntu.com/mainline/v$KERNEL_VERSION/amd64/$KERNEL_IMAGE
wget -P ${_kbump_dir} https://kernel.ubuntu.com/mainline/v$KERNEL_VERSION/amd64/$KERNEL_MODULES

pushd $_kbump_dir/
sudo dpkg -i $KERNEL_HEADERS
sudo dpkg -i $KERNEL_HEADERS_GENERIC
sudo dpkg -i $KERNEL_MODULES
sudo dpkg -i $KERNEL_IMAGE
sudo dpkg -i $KERNEL_HEADERS_GENERIC
sudo dpkg -i $KERNEL_MODULES
sudo dpkg -i $KERNEL_IMAGE
popd
echo -e "\033[31mPlease now restart your machine and rerun the script.\033[0m"
exit 1
fi

if [ -f "./xdna-driver-builder/${DRIVER_TARBALL}" ]; then
if [ -f "./xdna-driver-builder/${DRIVER_TARBALL}" ]; then
echo "NPU driver is available, just setting up Riallto"
build_xrt=0;
build_xrt=0;
else
build_xrt=1
fi

if [ $build_xrt -eq 1 ]; then
# Building the NPU driver version and installing it

if [ ! -f "./xdna-driver-builder/${DRIVER_TARBALL}" ]; then
echo "xdna-driver-builder/${DRIVER_TARBALL} is missing, building it from scratch"
pushd xdna-driver-builder
Expand All @@ -151,19 +159,19 @@ if [ $build_xrt -eq 1 ]; then
fi

# Build the NPU drivers (xdna-driver)
if [ ! -f "${NPU_FIRMWARE}" ]; then
if [ ! -f "${NPU_FIRMWARE}" ]; then
npu_install_tmp_dir=$(mktemp -d)
tar -xzvf "./xdna-driver-builder/${DRIVER_TARBALL}" -C "${npu_install_tmp_dir}"
pushd $npu_install_tmp_dir/root/debs
sudo -E dpkg -i xrt_*-amd64-xrt.deb || true
sudo -E dpkg -i xrt_plugin*-amdxdna.deb || true
sudo apt -y --fix-broken install
sudo -E dpkg -i xrt_plugin*-amdxdna.deb || true
sudo apt -y --fix-broken install
popd
fi
#########################################################

########### Riallto Docker image construction ###########
echo "Building Riallto docker image"
echo "Building Riallto docker image"
build_tmp=./_work
rm -rf $build_tmp
mkdir -p $build_tmp
Expand All @@ -172,20 +180,20 @@ USER_ID=`id -u`
GROUP_ID=`id -g`
GROUP_NAME=`id -g -n`

## Checks to make sure that all the required tarballs and license are in the directory
## Checks to make sure that all the required tarballs and license are in the directory
if [ ! -f "./pynqMLIR-AIE.tar.gz" ]; then
echo "Error! pynqMLIR-AIE.tar.gz is missing, downloading from opendownloads..."
wget -O $build_tmp/pynqMLIR-AIE.tar.gz https://www.xilinx.com/bin/public/openDownload?filename=pynqMLIR_AIE_py312_v0.9.tar.gz
wget -O $build_tmp/pynqMLIR-AIE.tar.gz $MLIR_FILE
else
cp pynqMLIR-AIE.tar.gz $build_tmp
fi

if [ ! -f "./xilinx_tools.tar.gz" ]; then
echo "xilinx_tools.tar.gz is missing, downloading it from opendownloads..."
wget -O $build_tmp/riallto_installer.zip https://www.amd.com/bin/public/amdOpenDownload?filename=Riallto-v1.1.zip
wget -O $build_tmp/riallto_installer.zip $RIALLTO_FILE
pushd $build_tmp
unzip riallto_installer.zip
mv Riallto-v1.1/Riallto/downloads/xilinx_tools_latest.tar.gz ./xilinx_tools.tar.gz
mv Riallto-v1.1/Riallto/downloads/xilinx_tools_latest.tar.gz ./xilinx_tools.tar.gz
popd
cp $build_tmp/Riallto-v1.1/eula.txt ./
else
Expand Down
2 changes: 1 addition & 1 deletion scripts/linux/xdna-driver-builder/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ RUN mkdir /root/debs
RUN cd /root/xdna-driver/build && ./build.sh -release
RUN cd /root/xdna-driver/build && ./build.sh -package

RUN cd /root/xdna-driver/xrt/build && ./build.sh -noert
RUN cd /root/xdna-driver/xrt/build && ./build.sh -noert -noalveo

RUN cp /root/xdna-driver/build/Release/xrt_plugin*.deb /root/debs/
RUN cp /root/xdna-driver/xrt/build/Release/xrt*xrt.deb /root/debs/
21 changes: 13 additions & 8 deletions scripts/linux/xdna-driver-builder/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,22 @@
# Copyright (C) 2023 Advanced Micro Devices, Inc. All rights reserved.
# SPDX-License-Identifier: MIT

KERNEL_HEADERS=linux-headers-6.10.0-061000rc2_6.10.0-061000rc2.202406022333_all.deb
KERNEL_HEADERS_GENERIC=linux-headers-6.10.0-061000rc2-generic_6.10.0-061000rc2.202406022333_amd64.deb
KERNEL_MODULES=linux-modules-6.10.0-061000rc2-generic_6.10.0-061000rc2.202406022333_amd64.deb
KERNEL_IMAGE=linux-image-unsigned-6.10.0-061000rc2-generic_6.10.0-061000rc2.202406022333_amd64.deb

KERNEL_VERSION="6.10-rc2"
KERNEL_VERSION_FULL="6.10.0-061000rc2"
BUILD_DATE="202406022333"

KERNEL_HEADERS="linux-headers-${KERNEL_VERSION_FULL}_${KERNEL_VERSION_FULL}.${BUILD_DATE}_all.deb"
KERNEL_HEADERS_GENERIC="linux-headers-${KERNEL_VERSION_FULL}-generic_${KERNEL_VERSION_FULL}.${BUILD_DATE}_amd64.deb"
KERNEL_MODULES="linux-modules-${KERNEL_VERSION_FULL}-generic_${KERNEL_VERSION_FULL}.${BUILD_DATE}_amd64.deb"
KERNEL_IMAGE="linux-image-unsigned-${KERNEL_VERSION_FULL}-generic_${KERNEL_VERSION_FULL}.${BUILD_DATE}_amd64.deb"

rm -rf _work
mkdir -p _work
wget -P _work https://kernel.ubuntu.com/mainline/v6.10-rc2/amd64/$KERNEL_HEADERS_GENERIC
wget -P _work https://kernel.ubuntu.com/mainline/v6.10-rc2/amd64/$KERNEL_HEADERS
wget -P _work https://kernel.ubuntu.com/mainline/v6.10-rc2/amd64/$KERNEL_IMAGE
wget -P _work https://kernel.ubuntu.com/mainline/v6.10-rc2/amd64/$KERNEL_MODULES
wget -P _work https://kernel.ubuntu.com/mainline/v$KERNEL_VERSION/amd64/$KERNEL_HEADERS_GENERIC
wget -P _work https://kernel.ubuntu.com/mainline/v$KERNEL_VERSION/amd64/$KERNEL_HEADERS
wget -P _work https://kernel.ubuntu.com/mainline/v$KERNEL_VERSION/amd64/$KERNEL_IMAGE
wget -P _work https://kernel.ubuntu.com/mainline/v$KERNEL_VERSION/amd64/$KERNEL_MODULES

# Build a container that creates the appropriate linux kernel version
docker build \
Expand Down

0 comments on commit a2b7df2

Please sign in to comment.