XArith Example Projects
The xarith-examples package provides standalone projects that demonstrate XArith operations on the device. Each example combines host code and device kernels in one source file and builds with the XCENA SDK’s pxcc++ compiler.
Make sure pxcc / pxcc++ are on your PATH. For details on writing device kernels, 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.3.0.tar.gz
cd xarith-examples-0.3.0
./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 --pxl-device-id 1 vpe knn # run a subset on device id 1
./run.sh knn -- --dim 128 --vectors 4096 --k 10 # forward args to one 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 PXL_DEVICE_ID environment variable to run on another device (e.g. PXL_DEVICE_ID=1).