onwx-dash / setup.sh
ryugyosoft's picture
onwx' (onwx-dash) 0.8.7: Linux NPU's help loads the PC's own XRT (was 'No such library libxrt_core.so.2'); README / setup.sh steps for XRT and the memlock limit (part 2)
3d7e568 verified
Raw History Blame Contribute Delete
4.65 kB
#!/usr/bin/env bash
# onwx' (onwx-dash) - LLMs on the AMD Ryzen AI Radeon GPU + NPU: install the resident top-bar app (Ubuntu 24.04+).
# Installs the system pieces the indicator and the window need (AppIndicator, WebKit; asks for sudo once), creates .venv,
# installs onwx-dash + the tray, adds "onwx-dash" to the application list and starts it in the top bar.
# GNOME shows indicators through the "Ubuntu AppIndicators" extension, which Ubuntu enables by default.
set -e
cd "$(dirname "$0")"
export PYTHONUTF8=1
if ! python3 -c "import sys; sys.exit(0 if sys.version_info >= (3, 10) else 1)" 2>/dev/null; then
echo "Python 3.10 or newer is needed (Ubuntu 22.04 and later ship it): sudo apt install python3"
exit 1
fi
need=""
# the window is a WebKit web view (pywebview): 4.1 on Ubuntu 24.04 and later, 4.0 before
webkit=gir1.2-webkit2-4.1
apt-cache show $webkit >/dev/null 2>&1 || webkit=gir1.2-webkit2-4.0
# wl-clipboard / xclip: "Copy the OpenAI API URL" in the top-bar menu (Wayland / X11)
for p in python3-venv python3-gi gir1.2-ayatanaappindicator3-0.1 $webkit wl-clipboard xclip; do
dpkg -s "$p" >/dev/null 2>&1 || need="$need $p"
done
if [ -n "$need" ]; then
echo "[setup] installing system packages:$need"
sudo apt-get install -y $need
fi
install_onwx() {
# [sec 2026-10] pip >= 26.2.2 first (it downloads with its own certifi; the emSign roots are out after the
# eMudhra CA compromise). 26.2.1 failed on packages with scripts; 26.2.2 is tested. Not fatal.
.venv/bin/python -m pip install "pip>=26.2.2" || true
.venv/bin/python -m pip install -e ".[tray]"
}
# pip ran for this pyproject.toml already (onwx.deps): nothing to install. Otherwise - new packages from an update, an
# update whose pip could not finish, an older install - pip runs again (a running onwx is stopped first, and started
# again at the end).
if [ ! -f .venv/bin/python ] || ! .venv/bin/python -m onwx.deps check >/dev/null 2>&1; then
if [ ! -f .venv/bin/python ]; then
echo "[setup] creating Python environment in .venv ..."
# system site packages: the GObject bindings for the indicator and WebKit come from apt (python3-gi)
python3 -m venv --system-site-packages .venv
fi
.venv/bin/python -m onwx.deps stop || true
if ! install_onwx; then
echo "[setup] installation failed; rebuilding the Python environment once ..."
rm -rf .venv
python3 -m venv --system-site-packages .venv
install_onwx || exit 1
fi
.venv/bin/python -m onwx.deps done
echo ok > .venv/installed.txt
fi
# [dash] the GPU: the engine opens /dev/kfd and /dev/dri/renderD*, which need the render and video groups
if [ ! -r /dev/kfd ] || [ ! -w /dev/kfd ]; then
echo "[setup] the GPU cannot be used yet: add yourself to the render and video groups and log in again:"
echo " sudo usermod -aG render,video \$USER"
fi
# [0.8.7] the NPU's help with prompts (off by default on Linux; the setting turns it on) needs the AMD NPU driver
# (amdxdna), XRT and a locked-memory limit above the default 8 MB. Only said here - all three are system settings.
if [ -e /dev/accel/accel0 ]; then
if ! ls /opt/xilinx/xrt/lib/libxrt_core.so.2 /usr/lib/x86_64-linux-gnu/libxrt_core.so.2 /usr/lib64/libxrt_core.so.2 \
/usr/lib/libxrt_core.so.2 /usr/local/lib/libxrt_core.so.2 /opt/amd/xrt/lib/libxrt_core.so.2 2>/dev/null | grep -q .; then
echo "[setup] for the NPU's help: XRT is not installed. On Ubuntu:"
echo " sudo add-apt-repository ppa:lemonade-team/stable && sudo apt update && sudo apt install libxrt-npu2 python3-xrt"
fi
if [ "$(ulimit -l)" != "unlimited" ]; then
echo "[setup] for the NPU's help: the locked-memory limit is $(ulimit -l) KB; raise it, then restart the PC:"
echo " printf '* - memlock unlimited\\n' | sudo tee /etc/security/limits.d/99-memlock.conf"
echo " sudo mkdir -p /etc/systemd/system.conf.d /etc/systemd/user.conf.d"
echo " printf '[Manager]\\nDefaultLimitMEMLOCK=infinity\\n' | sudo tee /etc/systemd/system.conf.d/memlock.conf /etc/systemd/user.conf.d/memlock.conf"
fi
fi
mkdir -p ~/.local/share/applications
cat > ~/.local/share/applications/onwx-dash.desktop <<EOF
[Desktop Entry]
Type=Application
Name=onwx-dash
Comment=LLMs on the AMD Ryzen AI Radeon GPU + NPU
Exec="$PWD/.venv/bin/onwx" tray
Path=$PWD
Icon=$PWD/onwx/web/icon.png
Terminal=false
Categories=Utility;
StartupWMClass=onwx-dash
EOF
echo "[setup] application list: onwx-dash"
echo "[start] onwx-dash is starting in the top bar ..."
nohup .venv/bin/onwx tray >/dev/null 2>&1 &