gizhw:npu
the NPUs of the machine, whatever their driver, and the runs of kernels on them. An NPU is an accel-class device (/dev/accel/accelN) whose driver a backend serves (amdxdna.giz: AMD XDNA). A program uses one Session for device buffers, loaded kernels and their runs; a kernel's firmware image and control code are in its backend's formats (XDNA: an xclbin's PDI and an AIE instruction list, which Amdxdna.Txn writes). The DRM driver's name and version are read the same way for every NPU (drm.giz), and each backend adds its own firmware reads. Adding an NPU vendor is one backend and one case in each function here.
import * as Npu from "gizhw:npu";Types
Npu
type Npu = { node: string; driver: string; }An NPU: its node node (under /dev) and the driver bound to it.
node:stringdriver:string
Info
type Info = { driver: string; version: string; firmware: string; }What an NPU reports: its driver's name and version, and its firmware's version.
driver:stringversion:stringfirmware:string
Session
type Session = { npu: Npu; xdna: Amdxdna.Context; loaded: i64; }An open NPU: the device and its backend's state (XDNA: the hardware context of the first kernel loaded; each other kernel gets its own, as a context holds one firmware image).
npu:M14.Npuxdna:M1.Contextloaded:i64
Buffer
type Buffer = Amdxdna.BoA device buffer: kernels reach it by its device address at.
Kernel
type Kernel = Amdxdna.KernelA kernel to load: its firmware image and its control code.
Program
type Program = Amdxdna.ProgramA loaded kernel, ready to run.
Command
type Command = Amdxdna.CommandA command buffer: one run's packet, from its submit until the run ends.
Functions
supports
function supports(driver: string): boolWhether a backend serves the driver driver.
devices
function devices(sys: System): Vec<Npu> throws IoErrorThe NPUs of the machine: the accel devices a backend serves.
Effects: fail, io.
info
function info(sys: System, npu: Npu): Info throws stringWhat NPU npu reports, read through its node (opened and closed here).
Effects: fail, io.
open
function open(sys: System, which: i64 = 0): Session throws stringOpens NPU number which of the machine (devices).
Effects: fail, io.
recoded
function recoded(p: Program, code: bytes): Program throws stringProgram p with its control code replaced by code.
Effects: fail, io.
variant
function variant(p: Program, code: bytes): Program throws stringAnother program of the firmware of p, with control code code (a kernel whose runs differ only in their control
code, such as each kind of a model's layers).
Effects: fail, io.
submit
function submit(p: Program, cmd: Command, args: Vec<i64>, buffers: Vec<Buffer> = []): u64 throws stringQueues a run of p in cmd with the arguments args (the buffers' device addresses among them) and returns its point
on the timeline of p's firmware: runs of one firmware go in order. The run's buffers stay held until it ends.
Effects: fail, io.
finish
function finish(p: Program, point: u64, commands: Vec<Command>): void throws stringWaits until the firmware of p reaches point (submit), then checks that each of commands completed.
Effects: fail, io.
run
function run(p: Program, args: Vec<i64>, buffers: Vec<Buffer> = []): void throws stringRuns p once (submit and finish in its own command buffer).
Effects: fail, io.
Methods
Session.close
function Session.close(self: Session): voidCloses the session: its buffers and programs go with it.
Effects: fail, io.
Session.buffer
function Session.buffer(self: Session, size: i64): Buffer throws stringA device buffer of size zero bytes.
Effects: fail, io.
Session.upload
function Session.upload(self: Session, b: Buffer, data: bytes, at: i64 = 0): voidCopies data into buffer b at byte at, before the runs that read it.
Effects: fail, io.
Session.download
function Session.download(self: Session, b: Buffer, size: i64, at: i64 = 0): bytesThe size bytes of buffer b from byte at, as the runs before left them.
Effects: fail, io.
Session.downloadInto
function Session.downloadInto(self: Session, b: Buffer, into: mut bytes, at: i64 = 0): voidAs download, the into.length bytes from byte at copied into into, with no allocation.
Effects: fail, io.
Session.load
function Session.load(self: mut Session, kernel: Kernel): Program throws stringLoads kernel, with a command buffer for its run.
Effects: fail, io.
Session.command
function Session.command(self: Session): Command throws stringA command buffer for a run submitted while others are in flight.
Effects: fail, io.