Skip to content
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[submodule "xrt"]
path = xrt
url = https://github.com/Xilinx/XRT.git
url = https://github.com/kashif/XRT.git
branch = arch
Copy link

Copilot AI Nov 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The XRT submodule is now pointing to a personal fork instead of the official Xilinx/XRT repository. This should be temporary until the changes are merged upstream. Consider documenting this dependency in the PR description or adding a comment explaining when this will be reverted to the official repository.

Copilot uses AI. Check for mistakes.
17 changes: 14 additions & 3 deletions CMake/pkg.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -134,16 +134,27 @@ if("${XDNA_CPACK_LINUX_PKG_FLAVOR}" MATCHES "debian")
set(CPACK_DEB_COMPONENT_INSTALL ON)
set(CPACK_DEBIAN_PACKAGE_DEPENDS "xrt-base (>= ${XDNA_CPACK_XRT_BASE_VERSION}), xrt-base (<< ${XDNA_CPACK_XRT_BASE_NEXT_VERSION})")
if(NOT SKIP_KMOD)
set(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA "${CMAKE_CURRENT_BINARY_DIR}/package/postinst"
set(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA "${CMAKE_CURRENT_BINARY_DIR}/package/postinst"
"${CMAKE_CURRENT_BINARY_DIR}/package/prerm")
endif()
elseif("${XDNA_CPACK_LINUX_PKG_FLAVOR}" MATCHES "fedora")
set(CPACK_GENERATOR "RPM")
set(CPACK_RPM_COMPONENT_INSTALL ON)
set(CPACK_RPM_PACKAGE_REQUIRES "xrt-base >= ${XDNA_CPACK_XRT_BASE_VERSION}, xrt-base < ${XDNA_CPACK_XRT_BASE_NEXT_VERSION}")
if(NOT SKIP_KMOD)
set(CPACK_RPM_POST_INSTALL_SCRIPT_FILE "${CMAKE_CURRENT_BINARY_DIR}/package/postinst")
set(CPACK_RPM_PRE_UNINSTALL_SCRIPT_FILE "${CMAKE_CURRENT_BINARY_DIR}/package/prerm")
set(CPACK_RPM_POST_INSTALL_SCRIPT_FILE "${CMAKE_CURRENT_BINARY_DIR}/package/postinst")
set(CPACK_RPM_PRE_UNINSTALL_SCRIPT_FILE "${CMAKE_CURRENT_BINARY_DIR}/package/prerm")
endif()
elseif("${XDNA_CPACK_LINUX_PKG_FLAVOR}" MATCHES "arch")
set(CPACK_GENERATOR "TGZ")
# For Arch Linux, we generate a tarball that can be used for manual installation
# or to create a PKGBUILD. Post-install scripts need to be run manually.
Copy link

Copilot AI Nov 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment states 'Post-install scripts need to be run manually', but the PKGBUILD-xrt-plugin file and xrt-plugin-amdxdna.install show that install scripts are automatically executed by pacman. This documentation is misleading and should clarify that when using the provided PKGBUILD, the install hooks handle this automatically.

Suggested change
# or to create a PKGBUILD. Post-install scripts need to be run manually.
# or to create a PKGBUILD. When using the provided PKGBUILD, post-install scripts are executed automatically by pacman. If installing manually from the TGZ, you need to run the post-install scripts yourself.

Copilot uses AI. Check for mistakes.
set(CPACK_ARCHIVE_COMPONENT_INSTALL ON)
message(STATUS "Arch Linux detected - generating TGZ package")
if(NOT SKIP_KMOD)
message(STATUS "Post-install script: ${CMAKE_CURRENT_BINARY_DIR}/package/postinst")
message(STATUS "Pre-remove script: ${CMAKE_CURRENT_BINARY_DIR}/package/prerm")
message(STATUS "Note: For Arch Linux, you'll need to run these scripts manually or create a PKGBUILD")
endif()
else("${XDNA_CPACK_LINUX_PKG_FLAVOR}" MATCHES "debian")
message(FATAL_ERROR "Unknown Linux package flavor: ${XDNA_CPACK_LINUX_PKG_FLAVOR}")
Copy link

Copilot AI Nov 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error handling for unknown package flavors should include 'arch' in the conditional chain. The final else clause will incorrectly catch Arch Linux as an unknown flavor if the elseif on line 132 doesn't match. Consider changing line 143 to else() without the condition, or ensure the Arch detection pattern is comprehensive.

Copilot uses AI. Check for mistakes.
Expand Down
38 changes: 38 additions & 0 deletions PKGBUILD-xrt-plugin
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Maintainer: Your Name <[email protected]>
pkgname=xrt-plugin-amdxdna
pkgver=2.21.0
pkgrel=1
pkgdesc="AMD XDNA Driver plugin for Xilinx RunTime"
arch=('x86_64')
url="https://github.com/amd/xdna-driver"
license=('Apache-2.0')
depends=('xrt-base' 'xrt-npu' 'dkms' 'linux-headers')
provides=('xrt-plugin-amdxdna')
conflicts=('amdxdna-driver' 'amdxdna-driver-bin')
install=xrt-plugin-amdxdna.install

# Set this to your xdna-driver build directory (relative to PKGBUILD location)
: ${XDNA_BUILD_DIR:="build/Release"}

package() {
cd "$srcdir"

# Extract the tarball directly into the package directory
# The tarball should be at $startdir/$XDNA_BUILD_DIR/xrt_plugin*.tar.gz
local tarball=$(ls $startdir/${XDNA_BUILD_DIR}/xrt_plugin*-amdxdna.tar.gz 2>/dev/null | head -1)
if [ -z "$tarball" ]; then
error "XDNA plugin tarball not found in ${XDNA_BUILD_DIR}"
error "Please build XDNA driver first: cd build && ./build.sh -release"
return 1
fi

msg2 "Extracting $tarball"
tar -xzf "$tarball" -C "$pkgdir"

# Copy the install scripts for reference (they'll be called from .install file)
mkdir -p "$pkgdir/opt/xilinx/xrt/share/amdxdna/package"
install -Dm755 $startdir/${XDNA_BUILD_DIR}/package/postinst \
"$pkgdir/opt/xilinx/xrt/share/amdxdna/package/postinst"
install -Dm755 $startdir/${XDNA_BUILD_DIR}/package/prerm \
"$pkgdir/opt/xilinx/xrt/share/amdxdna/package/prerm"
}
51 changes: 49 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ cd <root-of-source-tree>
exit
```

### Steps to create release build DEB package:
### Steps to create release build DEB package (Ubuntu/Debian):

``` bash
cd <root-of-source-tree>/build
Expand All @@ -121,7 +121,54 @@ cd ../../build
# To adapt according to your OS & version
sudo apt reinstall ./Release/xrt_plugin.2.19.0_ubuntu22.04-x86_64-amdxdna.deb
```
You will find `xrt_plugin\*-amdxdna.deb` in Release/ folder. This package includes:

### Steps to create release build packages (Arch Linux):

``` bash
cd <root-of-source-tree>

# Install dependencies (requires sudo)
sudo ./tools/amdxdna_deps.sh

# Get submodules
git submodule update --init --recursive

# Build XRT
cd xrt/build
./build.sh -npu -opt

# Build and install XRT packages using pacman
# PKGBUILDs are in xrt/build/arch/
cd arch
makepkg -p PKGBUILD-xrt-base
sudo pacman -U xrt-base-*.pkg.tar.zst

makepkg -p PKGBUILD-xrt-npu
sudo pacman -U xrt-npu-*.pkg.tar.zst

# Build XDNA driver
cd ../../../build
./build.sh -release

# Build and install XDNA plugin package
cd ..
makepkg -p PKGBUILD-xrt-plugin
sudo pacman -U xrt-plugin-amdxdna-*.pkg.tar.zst

# Configure memory limits (required for NPU access)
sudo bash -c 'echo "* soft memlock unlimited" >> /etc/security/limits.conf'
sudo bash -c 'echo "* hard memlock unlimited" >> /etc/security/limits.conf'
Comment on lines +158 to +159
Copy link

Copilot AI Dec 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using bash -c with echo and >> redirection is unnecessarily complex and potentially error-prone. A more robust approach would be to use tee -a or create a dedicated script. Additionally, directly appending to /etc/security/limits.conf without checking for existing entries could create duplicates on repeated runs. Consider: echo "* soft memlock unlimited" | sudo tee -a /etc/security/limits.conf or add a check to prevent duplicates.

Suggested change
sudo bash -c 'echo "* soft memlock unlimited" >> /etc/security/limits.conf'
sudo bash -c 'echo "* hard memlock unlimited" >> /etc/security/limits.conf'
grep -qxF '* soft memlock unlimited' /etc/security/limits.conf || echo '* soft memlock unlimited' | sudo tee -a /etc/security/limits.conf
grep -qxF '* hard memlock unlimited' /etc/security/limits.conf || echo '* hard memlock unlimited' | sudo tee -a /etc/security/limits.conf

Copilot uses AI. Check for mistakes.

# Log out and log back in (or reboot) for memory limit changes to take effect
```

**Note for Arch Linux users**: The build system generates `.tar.gz` packages which are repackaged into proper Arch packages (`.pkg.tar.zst`) using the provided PKGBUILDs:
Copy link

Copilot AI Nov 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The note mentions that XRT packages are in xrt/build/arch/, but the instructions in lines 136-147 show building XRT in xrt/build and then moving to a subdirectory arch. It would be clearer to explicitly state that the PKGBUILDs are generated during the XRT build process, or if they're provided by XRT, to mention that upfront.

Suggested change
**Note for Arch Linux users**: The build system generates `.tar.gz` packages which are repackaged into proper Arch packages (`.pkg.tar.zst`) using the provided PKGBUILDs:
**Note for Arch Linux users**: The build system generates `.tar.gz` packages which are repackaged into proper Arch packages (`.pkg.tar.zst`) using PKGBUILDs.
The PKGBUILD files for XRT (`PKGBUILD-xrt-base`, `PKGBUILD-xrt-npu`) and the XDNA driver (`PKGBUILD-xrt-plugin`) are provided by the XRT repository and are available in the following locations after building:

Copilot uses AI. Check for mistakes.
- XRT packages: `xrt/build/arch/` (PKGBUILD-xrt-base, PKGBUILD-xrt-npu)
- XDNA driver: root directory (PKGBUILD-xrt-plugin)

This ensures proper integration with pacman for installation, upgrades, and removal.

You will find `xrt_plugin\*-amdxdna.deb` (Ubuntu/Debian) or `xrt_plugin*.tar.gz` (Arch Linux) in Release/ folder. This package includes:
* The `.so` library files, which will be installed into `/opt/xilinx/xrt/lib` folder
* The XDNA driver and DKMS script, which build, install and load
`amdxdna.ko` driver when installing the .DEB package on target machine
Expand Down
2 changes: 2 additions & 0 deletions tools/amdxdna_deps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ if [ -x "$(command -v apt-get)" ]; then
apt-get install -y jq
elif [ -x "$(command -v dnf)" ]; then
dnf install -y jq
elif [ -x "$(command -v pacman)" ]; then
pacman -Syu --needed --noconfirm jq
Copy link

Copilot AI Nov 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The -Syu flag performs a full system upgrade in addition to installing jq, which is inconsistent with the behavior of apt-get install and dnf install on lines 10 and 12. For consistency, use pacman -S --needed --noconfirm jq instead, which only installs the package without upgrading the entire system.

Suggested change
pacman -Syu --needed --noconfirm jq
pacman -S --needed --noconfirm jq

Copilot uses AI. Check for mistakes.
fi

$SCRIPT_DIR/../xrt/src/runtime_src/tools/scripts/xrtdeps.sh
70 changes: 70 additions & 0 deletions xrt-plugin-amdxdna.install
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
post_install() {
echo "Installing AMD XDNA driver via DKMS..."

install_datadir=/opt/xilinx/xrt/share/amdxdna
udev_rules_d=/etc/udev/rules.d
amdxdna_rules_file=99-amdxdna.rules
dracut_conf_d=/etc/dracut.conf.d
dracut_conf_file=amdxdna.dracut.conf

# On systems with dracut, exclude driver from initram
if [ -e ${dracut_conf_d} ]; then
if [ ! -f ${dracut_conf_d}/${dracut_conf_file} ]; then
touch ${dracut_conf_d}/${dracut_conf_file}
fi
echo "omit_drivers+=\" amdxdna \"" > ${dracut_conf_d}/${dracut_conf_file}
fi

# Install DKMS module
echo "Installing amdxdna Linux kernel module via DKMS..."
$install_datadir/dkms_driver.sh --install

# Setup udev rules
echo "Setting up udev rules..."
if [ ! -f ${udev_rules_d}/${amdxdna_rules_file} ]; then
touch ${udev_rules_d}/${amdxdna_rules_file}
fi
echo 'KERNEL=="accel*",DRIVERS=="amdxdna",MODE="0666"' > ${udev_rules_d}/${amdxdna_rules_file}

# Load the kernel module
echo "Loading amdxdna kernel module..."
rmmod amdxdna > /dev/null 2>&1 || true
modprobe amdxdna

echo "AMD XDNA driver installation complete!"
echo "You can test it with: source /opt/xilinx/xrt/setup.sh && xrt-smi validate"
}

post_upgrade() {
post_install
}

pre_remove() {
echo "Removing AMD XDNA driver..."

install_datadir=/opt/xilinx/xrt/share/amdxdna
udev_rules_d=/etc/udev/rules.d
amdxdna_rules_file=99-amdxdna.rules
dracut_conf_d=/etc/dracut.conf.d
dracut_conf_file=amdxdna.dracut.conf

# Unload kernel module
if lsmod | grep -q "amdxdna "; then
rmmod amdxdna
fi

# Remove dracut config
if [ -f ${dracut_conf_d}/${dracut_conf_file} ]; then
rm -f ${dracut_conf_d}/${dracut_conf_file}
fi

# Remove udev rules
if [ -f ${udev_rules_d}/${amdxdna_rules_file} ]; then
rm -f ${udev_rules_d}/${amdxdna_rules_file}
fi

# Remove DKMS module
$install_datadir/dkms_driver.sh --remove

echo "AMD XDNA driver removed!"
}