-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathsetup_riallto_linux.sh
executable file
·234 lines (196 loc) · 7.63 KB
/
setup_riallto_linux.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
#!/bin/bash
# Copyright (C) 2023 Advanced Micro Devices, Inc. All rights reserved.
# SPDX-License-Identifier: MIT
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="${KERNEL_VERSION_FULL}-generic"
NPU_FIRMWARE="/lib/firmware/amdnpu/1502_00/npu.sbin"
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/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"
)
for URL in "${URLS[@]}"; do
if curl --output /dev/null --silent --head --fail "$URL"; then
echo "[CHECK OK] URL is reachable: $URL"
else
echo "WARNING: [CHECK FAILED] URL is not reachable: $URL"
echo "Some parts of the installation might not work correctly."
while true; do
read -p "Are you happy to continue? [Y/N] " answer
case $answer in
[Yy]* ) echo "Continuing..."; break;;
[Nn]* ) echo "Exiting"; exit 1;;
* ) echo "Please chose Y or N.";;
esac
done
fi
done
# Check that we are on Ubuntu24.04
distro_info=$(lsb_release -d)
if [[ $distro_info != *"Ubuntu 24.04"* ]]; then
echo "Riallto is only currently supported on Ubuntu 24.04"
exit 1
fi
# Check that docker is installed
if command -v docker >/dev/null 2>&1; then
echo "Docker has been found."
else
echo "Docker could not be found on this system."
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"
exit 1
fi
############### License file check ###################
# 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 [ "$#" -lt 1 ]; then
echo "Usage $0 <Xilinx license file> <username (optional)>"
exit 1
fi
LIC_FILE="$1"
# Check to make sure that the license file exists
if [ ! -f "$LIC_FILE" ]; then
echo "Unable to open the license file $LIC_FILE"
exit 1
fi
MAC=$(grep -oP 'HOSTID=\K[^;]+' $1 | head -n1 | sed 's/\(..\)/\1:/g; s/:$//')
echo "Found a License file associated with MAC address $MAC"
####################################################
######### Kernel and NPU driver check / install ###########
# Check to see if the kernel version and NPU driver is already installed
build_xrt=0
kernel_version=$(uname -r)
if [[ "$kernel_version" == "$REQUIRED_KERNEL_VERSION" ]]; then
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."
echo "After upgrading you will have to restart your machine and rerun this script"
while true; do
read -p "Are you happy to continue? [Y/N] " answer
case $answer in
[Yy]* ) echo "You chose yes, attempting to update kernel"; break;;
[Nn]* ) echo "Exiting"; exit 1;;
* ) 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 "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
fi
_kbump_dir=$(mktemp -d)
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
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
echo "NPU driver is available, just setting up Riallto"
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
./build.sh
popd
else
echo "Driver tarball already exists."
fi
fi
# Build the NPU drivers (xdna-driver)
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
popd
fi
#########################################################
########### Riallto Docker image construction ###########
echo "Building Riallto docker image"
build_tmp=./_work
rm -rf $build_tmp
mkdir -p $build_tmp
USER_NAME="$USER"
if [ $# -eq 2 ]; then
USER_NAME="$2"
fi
USER_ID=`id -u $USER_NAME`
GROUP_ID=`id -g $USER_NAME`
GROUP_NAME=`id -g -n $USER_NAME`
## 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 $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 $RIALLTO_FILE
pushd $build_tmp
unzip riallto_installer.zip
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
cp xilinx_tools.tar.gz $build_tmp
fi
while true; do
read -p "Do you agree to the terms in ./eula.txt and wish to proceed [y/n]? " answer
case $answer in
[Yy]* ) echo "Terms accepted"; break;;
[Nn]* ) echo "Exiting"; exit 1;;
* ) echo "Please chose Y or N.";;
esac
done
cp $LIC_FILE $build_tmp/Xilinx.lic
tar -xzvf ./xdna-driver-builder/${DRIVER_TARBALL} -C $build_tmp/
docker build \
--build-arg BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ') \
--build-arg LIC_MAC=$MAC \
--build-arg USER_ID=${USER_ID} \
--build-arg GROUP_ID=${GROUP_ID} \
--build-arg GROUP_NAME=${GROUP_NAME} \
--build-arg BUILD_TEMPDIR=$build_tmp \
-t riallto:latest \
./
rm -rf $build_tmp
#####################################################