ArchLinux에서 AMD NPU 설정하기

Posted by Dongho's DevLog on July 23, 2025

NPU Device Driver 설치

패키지 관리자 활용

1
paru -S amdxdna-driver-bin

직접 설치

https://github.com/amd/xdna-driver

정상적으로 설치 되었는지 체크

커널 모듈 로드 확인

1
lsmod | grep amdxdna

결과에 amdxdna가 나오면 드라이버가 로드된 상태입니다. 만약 안 보이면:

1
2
sudo modprobe amdxdna
dmesg | grep amdxdna

로 수동 로드하고 로그 확인.



XDNA SDK 설치

패키지 관리자 활용하기

  1. AUR에서 PKGBUILD 가져오기:

    1
    2
    
    git clone https://aur.archlinux.org/xrt-npu-git.git
    cd xrt-npu-git
    
  2. PKGBUILD 수정:

    1
    
    nano PKGBUILD
    
    • cmake 실행하는 부분을 찾아 -Werror 제거.
    • 또는 경고만 무시하도록 플래그 추가:

      1
      
      -DCMAKE_CXX_FLAGS="-Wno-overloaded-virtual"
      

    예를 들어, 원래 줄이:

    1
    
    cmake -B build -S . -DCMAKE_BUILD_TYPE=Release
    

    라면 이렇게 바꿀 수 있음:

    1
    
    cmake -B build -S . -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS="-Wno-overloaded-virtual"
    

    수정된 PKGBUILD

    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
    
     # Maintainer: Kainoa Kanter <kainoa@t1c.dev>
     # Maintainer: Gökçe Aydos <aur2024@aydos.de>
    	
     _name=xrt
     pkgbase=$_name-npu-git
     pkgver=r8337.9c6d4f3794
     pkgrel=1
     pkgdesc="Xilinx runtime configured for AMD NPUs"
     arch=(x86_64)
     url='https://xilinx.github.io/XRT/master/html'
     license=(Apache)
     depends=(
     # Based on src/runtime_src/tools/scripts/xrtdeps.sh
         lsb-release  # Used in tests
         boost
         libtiff
         linux-headers  #TODO only makedepends for dkms?
         elfutils
         gcc
         gdb
         gnuplot
         gnutls
         gtest
         json-glib
         libdrm
         libjpeg-turbo
         util-linux-libs  # for libuuid
         libyaml
         lm_sensors
         ncurses
         ocl-icd
         opencl-clhpp
         openssl
         pciutils
         perl
         protobuf  # includes protobuf-compiler
         python
         python-pip
         rapidjson
         strace
         unzip
         zlib
         pybind11
         xilinx-u280-gen3x16-xdma-base  # create_xsabin.sh in post_install, otherwise platform file empty
     )
     makedepends=(
         cmake
         git
     )
     optdepends=(
         'linux-mainline-um5606: Linux kernel that can use the XDNA drivers'
         'amdxdna-driver: Driver that coencides with these libraries'
     )
     provides=($_name)
     conflicts=($_name)
     options=(!debug)
    	
     source=(
         $_name::git+https://github.com/xilinx/XRT
         git+https://github.com/Xilinx/dma_ip_drivers
         git+https://github.com/serge1/ELFIO
         xrt-precompiled::https://packages.xilinx.com/artifactory/debian-packages-cache/pool/xrt_202320.2.16.204_22.04-amd64-xrt.deb
         xsabin.install
     )
    	
     sha256sums=(
         SKIP
         #SKIP
         SKIP
         SKIP
         SKIP
         '042778107e71a7f3304b15e9bfa3b11677569205f7fe9baa392834aa11b24709'
     )
    	
     pkgver() {
         cd $_name
         printf "r%s.%s" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)"
     }
    	
     prepare() {
         # Submodule integration based on
         # https://wiki.archlinux.org/title/VCS_package_guidelines#Git_submodules
         git -C $_name config \
             submodule.src/runtime_src/core/pcie/driver/linux/xocl/lib/libqdma.url \
             ../dma_ip_drivers
         git -C $_name config \
             submodule.src/runtime_src/core/common/elf.url \
             ../ELFIO
         git -C $_name \
             -c protocol.file.allow=always \
             submodule update --recursive --init # Kainoa: added this here!
         mkdir -p microblaze-fw
         tar xf data.tar.gz -C microblaze-fw ./lib/firmware/xilinx
     }
    	
     build() {
         cd $_name
         mkdir -p build && cd build
         local cmake_flags+=" -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS="-Wno-overloaded-virtual" -DCMAKE_INSTALL_PREFIX=/opt/xilinx -DXRT_INSTALL_PREFIX=/opt/xilinx -DXRT_DKMS_ALVEO=OFF -DXDP_CLIENT_BUILD_CMAKE=yes -DNPU=1"
         XRT_FIRMWARE_DIR="$srcdir"/microblaze-fw/lib/firmware/xilinx cmake $cmake_flags ../src
         make
     }
    	
     #TODO
     # somehow test 8 fails, even it does not seem like a fail.
     #check() {
     #	# Tests require the package to be installed in the build directory. 
     #	DESTDIR=$srcdir/$_name/clean-build \
     #		make -C $_name/clean-build install
     #
     #	cd $srcdir/$_name/clean-build
     #	ctest --output-on-failure
     #}
    	
     pkgname=($pkgbase xrt-xocl-dkms-npu-git)
     package_xrt-npu-git() {
         depends+=(xrt-xocl-dkms-npu-git)
         install=xsabin.install
         DESTDIR=$pkgdir make -C $_name/build install
         # Move /lib to /usr/lib, otherwise: `failed to commit transaction (conflicting files)`
         # mv $pkgdir/lib $pkgdir/usr
    	
         # Drivers belong to the DKMS package, move them to a temporary dir.
         mv $pkgdir/usr/src $pkgdir/..
    	
         # Moving systemd services
         local dest=$pkgdir/usr/lib/systemd/system
         mkdir -p $dest
         mv $pkgdir/opt/xilinx/xrt/etc/*service $dest
    	
         # Moving binaries
         # local dest=$pkgdir/usr/bin
         # mkdir -p $dest
         # mv $pkgdir/usr/local/bin/* $dest
         # rm -r $pkgdir/usr/local/bin
    	
         # Moving appdebug
         # mv $pkgdir/opt/xilinx/xrt/share/appdebug $pkgdir/usr/local/xrt/python
         #rmdir $pkgdir/opt/xilinx{/xrt/share,/xrt,}
    	
         # The following lines are adapted from postinst of control.tar.gz of the debian package
         # ln -s 283bab8f654d8674968f4da57f7fa5d7 "$pkgdir"/usr/lib/firmware/xilinx/fb2b2c5a19ed63593fea95f51fbc8eb9
         mkdir -p "$pkgdir"/opt/xilinx/firmware/u280/gen3x16-xdma/base/firmware
         ln -s /lib/firmware/xilinx/283bab8f654d8674968f4da57f7fa5d7/partition_metadata.json "$pkgdir"/opt/xilinx/firmware/u280/gen3x16-xdma/base/partition_metadata.json
         ln -s /lib/firmware/xilinx/283bab8f654d8674968f4da57f7fa5d7/partition.xsabin "$pkgdir"/opt/xilinx/firmware/u280/gen3x16-xdma/base/partition.xsabin
         ## Gökçe says: "I changed  /opt/xilinx/xrt/share/fw to /lib/firmware/xilinx/ because XRTFW_FILES is somehow not defined in:"
         # https://github.com/Xilinx/XRT/blob/50f17b1d5a29b7af9a9abbc88815883958efdb35/src/runtime_src/ert/CMakeLists.txt#L29
         ln -s /lib/firmware/xilinx "$pkgdir"/opt/xilinx/firmware/u280/gen3x16-xdma/base/firmware/ert-v30
         ln -s /opt/xilinx/firmware/cmc/u280 "$pkgdir"/opt/xilinx/firmware/u280/gen3x16-xdma/base/firmware/cmc-u280
         ln -s /opt/xilinx/firmware/sc-fw/u280 "$pkgdir"/opt/xilinx/firmware/u280/gen3x16-xdma/base/firmware/sc-fw-u280
     }
     package_xrt-xocl-dkms-npu-git() {
         pkgdesc="Drivers for Xilinx runtime (XRT) (configured for AMD NPUs)"
         provides=(xrt-xocl-dkms)
         conflicts=(xrt-xocl-dkms)
    	
         # Collect drivers
         local dest=$pkgdir/usr
         mkdir -p "$dest/src"
    	
         # 복사할 xocl 소스 경로 지정 (기존 PKGBUILD의 src 위치 확인)
         cp -r "$srcdir/$_name/src/runtime_src/core/pcie/driver/linux/xocl" \
               "$dest/src/xrt-xocl-$pkgver"
    	
         # DKMS에 필요한 dkms.conf 추가 (필요하면 경로 조정)
         cp "$srcdir/$_name/src/runtime_src/core/pcie/driver/linux/xocl/dkms.conf" \
            "$dest/src/xrt-xocl-$pkgver/"
     }
    
  3. 패키지 빌드 & 설치:

    1
    
    makepkg -si
    

직접 설치

정상적으로 설치 되었는지 확인하기

디바이스 노드 확인

1
ls /dev/ | grep xdna

또는

1
ls /dev/dri/
  • /dev/xdna0 또는 renderD* 형태로 NPU 디바이스가 표시돼야 합니다.
  • /dev/dri/card*만 보이고 xdna0이 없으면 펌웨어나 XRT 설정이 안 된 상태.

XRT (런타임)로 NPU 인식 확인

먼저 XRT 환경 설정:

1
source /opt/xilinx/xrt/setup.sh

그다음:

1
xrt-smi examine

출력에 XDNA 장치, 메모리 크기, 상태가 나와야 정상.


##

##