XArith Example Projects
The xarith-examples package contains standalone example projects, built with pxcc++ as a single source per example. Each demo is one <name>/main.cpp that holds its device kernels (annotated __pxl_kernel__) next to the host driver that launches them; pxcc++ splits the file into a host (x86-64) and a device (RISC-V) half, compiles each with the right backend, and embeds the device blob into the host executable — so there is no separate .mubin to ship and no device/+host/ split. Kernels are launched by symbol with pxl::Launcher().execute<kernel>(...), and device buffers come from pxl::allocateMemory/releaseMemory — the launcher flushes them to the device before a launch and invalidates the host’s cached copy after it (SDK 1.4.10+), so hosts read results back directly with no manual cache management. This tree requires pxcc / pxcc++ on your PATH. For the kernel programming model these projects build on, see Writing XArith Kernels.
| Example | Demonstrates |
|---|---|
| basic | Fundamental vector operations — L2 distance, inner product, fused dot2, vector add/sub |
| mixed_dim | Per-call dimension — multi-resolution dot and mixed-size buffers in one context |
| matmul | Matrix multiply from dot/dot2 — one context and one allocation serve a whole mixed-size batch; parallel and A-row-tiled variants scale it across 48 VPEs and shift it from memory-bound to compute-bound |
| fp16 | FP16 data type — fp32 ↔ fp16 conversion plus element-wise and dot operations |
| vpe | VPE operation benchmark with GFLOPS measurement — FP32 and FP16 from one binary |
| knn | VPE-accelerated KNN — the device-kernel implementation behind the XVector C API |
Build and Run
The quickest path uses the helper scripts — build.sh configures and builds every example into ./build, run.sh runs the host binaries on a device:
tar -xzf xarith-examples-0.2.2.tar.gz
cd xarith-examples-0.2.2
./build.sh # configure + build all examples into ./build
./build.sh --release # build with CMAKE_BUILD_TYPE=Release
./run.sh # run every example on device 0
./run.sh --device 1 vpe knn # run a subset on device id 1
./run.sh knn -- --foo bar # forward extra args to a single example
Pass -h to either script for the full option list (--clean, --prefix, --build-dir, --release/--debug).
Or, from the same extracted directory, build manually with CMake (the xarith prefix is forwarded to the device chain via -DXARITH_PREFIX):
mkdir build && cd build
cmake -DXARITH_PREFIX=/opt/xarith ..
make -j
Every example is built into build/bin/ as xarith_<name> (a single host executable with the device blob embedded); the per-example pages’ run commands (./bin/xarith_<name>) assume you are in that build/ directory. Binaries run on device 0 by default — set the DEVICEID environment variable to run on another device (e.g. DEVICEID=1).