Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
40 changes: 15 additions & 25 deletions .github/workflows/bump-xdna.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,22 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Keep third_party/xdna-driver on upstream amd/xdna-driver main (docs/npu.md,
# "The XDNA stack"): when upstream moves, open a PR here moving the submodule.
# It pins XRT too (xdna-driver's own xrt submodule). GitHub-hosted CI has no
# NPU; build with scripts/build-xdna.sh and run the NPU check (docs/npu.md,
# "Checking the NPU") on Strix Halo before merging.
# Move third_party/xdna-driver, the amdxdna kernel driver pin (docs/npu.md, "The
# XDNA driver"), to upstream amd/xdna-driver main: opens a PR moving the
# submodule. Only the kernel driver is pinned here: the engine is XRT-free (its
# NPU runtime is compiled into 1bit), so nothing from the pin is built into the
# release, and XRT (xdna-driver's own xrt submodule) is not tracked.
#
# Run by hand only (workflow_dispatch): a driver move means rebuilding and
# re-signing the out-of-tree module on Strix Halo and running the NPU check
# (docs/npu.md, "Checking the NPU") before merging. GitHub-hosted CI has no NPU.
#
# Uses the secret HRX_BUMP_TOKEN (Contents and Pull requests read/write on
# 1bit-MONSTER/engine): a PR opened with the default GITHUB_TOKEN would not
# start CI.
#
# Behind the runtime switch (docs/npu.md, "XRT or the own runtime"): the engine
# only needs XRT when it builds with ONEBIT_NPU_RUNTIME=xrt. The repository
# variable ONEBIT_NPU_RUNTIME mirrors the build we ship; while it is "own" the
# scheduled bump is skipped and the xdna-driver pin stays where it is (the
# kernel module still comes from the pinned kernel build, docs/npu.md, "The XDNA
# stack"). Set it back to "xrt" (or unset it) to resume the daily bump; a manual
# workflow_dispatch always runs.
name: bump-xdna

on:
schedule:
- cron: "41 6 * * *"
workflow_dispatch:

permissions:
Expand All @@ -46,7 +40,6 @@ concurrency:

jobs:
bump:
if: ${{ github.event_name == 'workflow_dispatch' || vars.ONEBIT_NPU_RUNTIME != 'own' }}
runs-on: ubuntu-latest
steps:
- name: Require the token
Expand All @@ -69,11 +62,10 @@ jobs:
run: |
set -euo pipefail
upstream=$(gh api repos/amd/xdna-driver/commits/main --jq .sha)
upstream_xrt=$(gh api "repos/amd/xdna-driver/contents/xrt?ref=$upstream" --jq .sha)
ours=$(git ls-tree HEAD third_party/xdna-driver | awk '{print $3}')
echo "upstream $upstream (xrt $upstream_xrt), ours $ours"
echo "upstream $upstream, ours $ours"
{
echo "upstream=$upstream"; echo "upstream_xrt=$upstream_xrt"; echo "ours=$ours"
echo "upstream=$upstream"; echo "ours=$ours"
if [ "$upstream" = "$ours" ]; then echo "changed=false"; else echo "changed=true"; fi
} >> "$GITHUB_OUTPUT"

Expand All @@ -82,7 +74,6 @@ jobs:
env:
GH_TOKEN: ${{ secrets.HRX_BUMP_TOKEN }}
UPSTREAM: ${{ steps.pins.outputs.upstream }}
UPSTREAM_XRT: ${{ steps.pins.outputs.upstream_xrt }}
OURS: ${{ steps.pins.outputs.ours }}
run: |
set -euo pipefail
Expand All @@ -96,14 +87,13 @@ jobs:
git config user.email "[email protected]"
git switch -c "$branch"
git update-index --cacheinfo "160000,$UPSTREAM,third_party/xdna-driver"
git commit -q -m "Bump XDNA: amd/xdna-driver ${UPSTREAM:0:12} (XRT ${UPSTREAM_XRT:0:12})"
git commit -q -m "Bump XDNA driver: amd/xdna-driver ${UPSTREAM:0:12}"
git push -q origin "$branch"
gh pr create --base main --head "$branch" \
--title "Bump XDNA: amd/xdna-driver ${UPSTREAM:0:12}" \
--body "Moves third_party/xdna-driver from \`${OURS:0:12}\` to upstream main \`${UPSTREAM:0:12}\` (its XRT submodule: \`${UPSTREAM_XRT:0:12}\`).
--title "Bump XDNA driver: amd/xdna-driver ${UPSTREAM:0:12}" \
--body "Moves third_party/xdna-driver (the amdxdna kernel driver pin) from \`${OURS:0:12}\` to upstream main \`${UPSTREAM:0:12}\`.

Upstream commits (last 30):
${log}

CI here has no NPU. Before merging, on Strix Halo:
\`scripts/build-xdna.sh ~/.cache/xdna-pin/prefix && cmake -B build -G Ninja -DONEBIT_NPU=ON -DONEBIT_XRT_ROOT=\$HOME/.cache/xdna-pin/prefix/root/opt/xilinx/xrt && cmake --build build --target onebit\`, then the NPU check (docs/npu.md, \"Checking the NPU\")"
CI here has no NPU. Before merging, on Strix Halo: build the out-of-tree amdxdna module from this commit, sign and load it, and run the NPU check (docs/npu.md, \"Checking the NPU\")."
84 changes: 30 additions & 54 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ endif()

# ── Step 3: NPU engine, full ELFs only (docs/npu.md) ──────────────────────
# Host side (full-ELF generation, model reader, buffer packing): pure C++, no
# XRT. It needs PCRE2 (the tokenizer), and macOS has no NPU, so it is off there
# NPU runtime. It needs PCRE2 (the tokenizer), and macOS has no NPU, so it is off there
# by default; the Lemonade face (including the mlx backend) does not use it.
if(APPLE)
set(_onebit_npu_host_default OFF)
Expand Down Expand Up @@ -349,7 +349,7 @@ target_link_libraries(npu_pack_test PRIVATE onebit_npu)
add_executable(npu_model_bounds_test tests/npu_model_bounds_test.cpp)
target_link_libraries(npu_model_bounds_test PRIVATE onebit_npu)
add_test(NAME npu_model_bounds COMMAND npu_model_bounds_test)
# The forward's Q4NX loader is plain C (no XRT), so its crafted-file checks run in CI too.
# The forward's Q4NX loader is plain C (no NPU runtime), so its crafted-file checks run in CI too.
add_executable(npu_forward_loader_test tests/npu_forward_loader_test.c npu/forward/src/model.c)
target_include_directories(npu_forward_loader_test PRIVATE npu/forward/include)
target_link_libraries(npu_forward_loader_test PRIVATE m)
Expand All @@ -375,69 +375,50 @@ target_link_libraries(npu_private_route_test PRIVATE onebit_npu)
add_test(NAME npu_private_route COMMAND npu_private_route_test)
endif() # ONEBIT_NPU_HOST

# The lane itself: needs an NPU runtime and an XDNA NPU to run.
option(ONEBIT_NPU "Build the NPU fast lane (needs an NPU runtime: XRT by default)" OFF)
set(ONEBIT_XRT_ROOT "/opt/xilinx/xrt" CACHE PATH "XRT install prefix")
# Which runtime the NPU code compiles against (npu/rt.h, docs/npu.md "The runtime"):
# xrt XRT from ONEBIT_XRT_ROOT (the default; unchanged behaviour)
# own the XRT-compatible runtime of a private add-on: ONEBIT_NPU_RT_DIR holds npu_rt.h and
# npu_rt.cpp, built here into onebit_npu_rt. No XRT is needed or linked.
set(ONEBIT_NPU_RUNTIME "xrt" CACHE STRING "NPU runtime: xrt or own")
set_property(CACHE ONEBIT_NPU_RUNTIME PROPERTY STRINGS xrt own)
set(ONEBIT_NPU_RT_DIR "" CACHE PATH "Directory with npu_rt.h and npu_rt.cpp (ONEBIT_NPU_RUNTIME=own)")
if(NOT ONEBIT_NPU_RUNTIME STREQUAL "xrt" AND NOT ONEBIT_NPU_RUNTIME STREQUAL "own")
message(FATAL_ERROR "ONEBIT_NPU_RUNTIME must be xrt or own, not '${ONEBIT_NPU_RUNTIME}'")
# The lane itself: needs the NPU runtime and an XDNA NPU to run.
option(ONEBIT_NPU "Build the NPU lane (needs the private NPU runtime: ONEBIT_NPU_RT_DIR)" OFF)
# The NPU code compiles against one runtime (npu/rt.h, docs/npu.md "The NPU runtime"): our own, an
# XRT-compatible runtime that is not part of this repository. ONEBIT_NPU_RT_DIR holds its npu_rt.h
# and npu_rt.cpp, built here into the static library onebit_npu_rt and linked into 1bit. AMD's XRT
# is not supported: the engine links no XRT library. The release build takes the runtime from the
# pinned private checkout in config/npu-runtime.config (scripts/fetch-private.sh).
set(ONEBIT_NPU_RUNTIME "own" CACHE STRING "NPU runtime: own (the only value)")
set_property(CACHE ONEBIT_NPU_RUNTIME PROPERTY STRINGS own)
set(ONEBIT_NPU_RT_DIR "" CACHE PATH "Directory with the NPU runtime's npu_rt.h and npu_rt.cpp (private)")
if(NOT ONEBIT_NPU_RUNTIME STREQUAL "own")
message(FATAL_ERROR "ONEBIT_NPU_RUNTIME must be own, not '${ONEBIT_NPU_RUNTIME}': the engine builds "
"no XRT NPU lane (docs/npu.md, \"The NPU runtime\")")
endif()
if(ONEBIT_NPU AND NOT ONEBIT_NPU_HOST)
message(FATAL_ERROR "ONEBIT_NPU needs ONEBIT_NPU_HOST=ON")
endif()
# The option's refusals (bad value, own without a runtime directory); needs no XRT, runs in CI.
# The option's refusals (bad value, no runtime directory); needs no NPU runtime, runs in CI.
if(ONEBIT_NPU_HOST AND NOT WIN32)
add_test(NAME npu_runtime_option
COMMAND ${CMAKE_SOURCE_DIR}/tests/npu_runtime_option.sh ${CMAKE_SOURCE_DIR} ${FETCHCONTENT_BASE_DIR})
set_tests_properties(npu_runtime_option PROPERTIES TIMEOUT 300)
endif()
if(ONEBIT_NPU)
if(ONEBIT_NPU_RUNTIME STREQUAL "own")
if(NOT EXISTS "${ONEBIT_NPU_RT_DIR}/npu_rt.h" OR NOT EXISTS "${ONEBIT_NPU_RT_DIR}/npu_rt.cpp")
message(FATAL_ERROR "ONEBIT_NPU_RUNTIME=own needs ONEBIT_NPU_RT_DIR with npu_rt.h and npu_rt.cpp; "
"ONEBIT_NPU_RT_DIR='${ONEBIT_NPU_RT_DIR}'")
endif()
add_library(onebit_npu_rt STATIC ${ONEBIT_NPU_RT_DIR}/npu_rt.cpp)
target_include_directories(onebit_npu_rt SYSTEM PUBLIC ${ONEBIT_NPU_RT_DIR})
target_compile_definitions(onebit_npu_rt PUBLIC ONEBIT_NPU_RUNTIME_OWN)
find_package(Threads REQUIRED)
target_link_libraries(onebit_npu_rt PUBLIC Threads::Threads)
set(_onebit_npu_rt onebit_npu_rt)
set(_onebit_npu_rt_inc "")
set(_onebit_npu_rt_extra "")
else()
if(NOT EXISTS "${ONEBIT_XRT_ROOT}/include/xrt/xrt_device.h")
message(FATAL_ERROR "ONEBIT_NPU needs XRT; none at ONEBIT_XRT_ROOT=${ONEBIT_XRT_ROOT}")
endif()
set(_onebit_npu_rt ${ONEBIT_XRT_ROOT}/lib/libxrt_coreutil.so)
set(_onebit_npu_rt_inc ${ONEBIT_XRT_ROOT}/include)
set(_onebit_npu_rt_extra aiebu uuid)
if(NOT EXISTS "${ONEBIT_NPU_RT_DIR}/npu_rt.h" OR NOT EXISTS "${ONEBIT_NPU_RT_DIR}/npu_rt.cpp")
message(FATAL_ERROR "ONEBIT_NPU needs the NPU runtime: ONEBIT_NPU_RT_DIR must hold npu_rt.h and "
"npu_rt.cpp (ONEBIT_NPU_RT_DIR='${ONEBIT_NPU_RT_DIR}'). The runtime is private; "
"without it, build with ONEBIT_NPU=OFF (docs/npu.md, \"The NPU runtime\")")
endif()
add_library(onebit_npu_rt STATIC ${ONEBIT_NPU_RT_DIR}/npu_rt.cpp)
target_include_directories(onebit_npu_rt SYSTEM PUBLIC ${ONEBIT_NPU_RT_DIR})
target_compile_definitions(onebit_npu_rt PUBLIC ONEBIT_NPU_RUNTIME_OWN)
find_package(Threads REQUIRED)
target_link_libraries(onebit_npu_rt PUBLIC Threads::Threads)
add_library(onebit_npu_lane STATIC npu/lane.cpp npu/generate.cpp)
if(_onebit_npu_rt_inc)
target_include_directories(onebit_npu_lane SYSTEM PUBLIC ${_onebit_npu_rt_inc})
endif()
target_link_libraries(onebit_npu_lane PUBLIC onebit_npu ${_onebit_npu_rt})
target_link_libraries(onebit_npu_lane PUBLIC onebit_npu onebit_npu_rt)
target_sources(onebit PRIVATE app/unified.cpp)
target_link_libraries(onebit PRIVATE onebit_npu_lane)
target_compile_definitions(onebit PRIVATE ONEBIT_NPU)
if(ONEBIT_NPU_RUNTIME STREQUAL "xrt")
set_target_properties(onebit PROPERTIES BUILD_RPATH ${ONEBIT_XRT_ROOT}/lib INSTALL_RPATH ${ONEBIT_XRT_ROOT}/lib)
endif()
# The shim compiles against the selected runtime (and runs without an NPU: it only builds
# objects and checks the API surface the engine uses).
# The shim compiles against the runtime (and runs without an NPU: it only builds objects and
# checks the API surface the engine uses).
add_executable(npu_rt_shim_test tests/npu_rt_shim_test.cpp)
target_link_libraries(npu_rt_shim_test PRIVATE onebit_npu_lane)
add_test(NAME npu_rt_shim COMMAND npu_rt_shim_test)
if(ONEBIT_NPU_RUNTIME STREQUAL "xrt")
set_target_properties(npu_rt_shim_test PROPERTIES BUILD_RPATH ${ONEBIT_XRT_ROOT}/lib)
endif()

# The model-generic forward (npu/forward): the GGUF-on-NPU serve route
# (docs/npu.md, "Open"). q4nx_forward.cpp + its Q4NX dequant/pack/semantics
Expand All @@ -462,9 +443,8 @@ if(ONEBIT_NPU)
target_compile_definitions(onebit_npu_forward PRIVATE NPU_INFER_DEBUG_DUMPS)
endif()
target_include_directories(onebit_npu_forward SYSTEM PUBLIC
npu/forward/include npu/forward/engine-src npu ${_onebit_npu_rt_inc})
target_link_libraries(onebit_npu_forward PUBLIC
${_onebit_npu_rt} ${_onebit_npu_rt_extra} dl pthread m)
npu/forward/include npu/forward/engine-src npu)
target_link_libraries(onebit_npu_forward PUBLIC onebit_npu_rt dl pthread m)
target_sources(onebit PRIVATE app/forward_serve.cpp)
target_link_libraries(onebit PRIVATE onebit_npu_forward)
set(ONEBIT_NPU_KERNELS "" CACHE PATH "Kernel directory (layer_ctx{1,2,17}.elf, lmhead.elf, layer.pdi)")
Expand All @@ -485,10 +465,6 @@ if(ONEBIT_NPU_PRIVATE)
if(NOT EXISTS "${ONEBIT_NPU_PRIVATE}/addons/CMakeLists.txt")
message(FATAL_ERROR "ONEBIT_NPU_PRIVATE=${ONEBIT_NPU_PRIVATE} has no addons/CMakeLists.txt")
endif()
if(ONEBIT_NPU_RUNTIME STREQUAL "own")
message(WARNING "ONEBIT_NPU_PRIVATE with ONEBIT_NPU_RUNTIME=own: an add-on that links XRT itself "
"still needs XRT (docs/npu.md, \"XRT or the own runtime\")")
endif()
add_subdirectory(${ONEBIT_NPU_PRIVATE}/addons ${CMAKE_BINARY_DIR}/npu_private)
if(NOT TARGET onebit_npu_private)
message(FATAL_ERROR "${ONEBIT_NPU_PRIVATE}/addons defines no onebit_npu_private target")
Expand Down
27 changes: 22 additions & 5 deletions NOTICE
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,20 @@ Copyright 2026 bong-water-water-bong

This product is licensed under the Apache License, Version 2.0 (see LICENSE).

===============================================================================
Proprietary components compiled into the release binaries
===============================================================================

The source code in this repository is licensed under Apache-2.0. The binaries
published with the engine's releases (the Linux package and 1bit OS) also
contain two proprietary components, compiled in: the 1bit NPU runtime (in
1bit) and the 1bit HIP kernels for HRX (code objects in the HRX llama.cpp
library). They are not part of this repository, their source is not
published, and they are not licensed under Apache-2.0.
Copyright 2026 bong-water-water-bong. All rights reserved.
A build of this repository without them has no NPU lane and runs HRX on the
public kernels only.

===============================================================================
Third-party components
===============================================================================
Expand Down Expand Up @@ -49,17 +63,20 @@ Qwen3.8 Flash DGX UltraFast (https://github.com/dime-online/qwen3.8-Flash-DGX-Ul
Pinned at exact commits (git submodules) and built from source
-------------------------------------------------------------------------------

AMD XDNA driver and XRT shim (third_party/xdna-driver)
AMD XDNA driver (third_party/xdna-driver)
https://github.com/amd/xdna-driver
Copyright (C) 2023-2024 Advanced Micro Devices, Inc.
License: Apache-2.0 (the userspace shim built here). The NPU firmware under
License: GPL-2.0 (the amdxdna kernel driver), Apache-2.0 (userspace). Pinned as
the amdxdna kernel driver the NPU lane is checked against; nothing from it is
built into or shipped with the release binaries. The NPU firmware under
LICENSE.amdnpu is not redistributed by this product.

Xilinx Runtime, XRT (fetched by third_party/xdna-driver)
https://github.com/Xilinx/XRT
Xilinx Runtime, XRT (https://github.com/Xilinx/XRT)
Copyright (C) 2016-2022 Xilinx, Inc.
Copyright (C) 2022-2023 Advanced Micro Devices, Inc.
License: Apache-2.0 (userspace)
License: Apache-2.0 (userspace). No longer built, linked or shipped: the NPU
lane runs on the 1bit NPU runtime (see above), whose classes keep XRT's API names
(xrt::device, xrt::bo, ...) so the engine's NPU sources read the same.

MLIR-AIE, IRON and aiecc (third_party/mlir-aie)
https://github.com/Xilinx/mlir-aie
Expand Down
Loading
Loading