API reference

API reference#

hawk’s public Python surface, by subpackage. The authoring names (hawk.kernel, the declarations, hawk.steps) live at the top level and the math vocabulary, including the quaternion helpers and the random distributions, at hawk.math. hawk.raw_device / hawk.RawBlock are the escape hatch: splice a block of device code the vocabulary cannot spell, with its access class declared by hand.

The compiled hawk._core extension and the IR/emitter internals (hawk.ir, hawk.emit) are implementation detail and not documented here. Their __all__ is a small “IR access” surface for a downstream package that builds or renders sink sets by hand (hawk.ir.canonical, hawk.ir.recognize, hawk.emit.render_source, …); everything else in them may change between releases.

hawk

HAWK — Hardware Agnostic Writing of Kernels.

hawk.math

hawk.math — the free-function namespace a kernel body writes math through.

hawk.geometry

A bounding-volume hierarchy over triangles, and the closest hit of a ray against it.

hawk.ext

The extension protocol: the seams a kind DECLARES.

hawk.diff

IR -> IR autodiff, symbolic and in both directions.

hawk.diff.event

A step kernel's stop rule as a DIFFERENTIABLE guard.

hawk.compile

AOT compile drivers + the content-closure cache.

hawk.runtime

The thin Python face over hawk._core — descriptor, bind, launch.

hawk.artifact

Manifest + sidecar + the ABI exports + bundles.

hawk.embedded

The standalone C target: hawk kernels rendered as freestanding MISRA-C instead of aether expression templates.

The authoring names#

The declarations a kernel is written in, and the top-level functions. Each has its own page.

hawk.kernel([fn, kind, steps, time, ...])

Trace fn into a Kernel.

hawk.Kernel

A traced kernel: its sink set, its canonical walk and its declarations.

hawk.raw_device(text, *[, access, reads, ...])

Declare a raw device block (the escape hatch for code the vocabulary cannot spell): text spliced verbatim, with access= required (the walk can't see inside text), reads/writes naming the touched slots, returns the value type and language the language text is written in (a writer refuses one it cannot write).

hawk.RawBlock

One spliceable block of author text plus its declared access.

hawk.steps(kernel, K)

kernel stepping K times per launch, named <name>_x<K>.

hawk.chain(*kernels, name)

Run kernels in sequence as ONE kernel named name.

hawk.scatter(sink[, policy])

hawk.scatter(sink)[key] += v adds v into sink at key, = v stores it there.

hawk.lane_position()

This lane's position t in the launch, as a value: base + flat.

hawk.primitive([name, vjp, jvp])

Register a custom primitive, named name or after the function.

hawk.resolve_dispatch(kernel, policies)

kernel with each "auto" dispatch group lowered as policies[group] ("switch", "segmented" or "predicated"): how a launching runtime applies the policy it chose.

hawk.samples_first(x)

Mark x as sample-major: its FIRST axis holds the samples, (N, w).

hawk.samples_last(x)

Mark x as component-major (native): its LAST axis holds the samples, (w, N).

hawk.Value

One traced IR value: every operator on it mints a node.

hawk.Quantity

A compound quantity declaration (seam).

hawk.Scalar(*args, **kwargs)

(shape, dtype, tag).

hawk.Index(*args, **kwargs)

(shape, dtype, tag).

hawk.Int32(*args, **kwargs)

(shape, dtype, tag).

hawk.UInt32(*args, **kwargs)

(shape, dtype, tag).

hawk.Quat(*args, **kwargs)

(shape, dtype, tag).

hawk.Vector

Vector[W] — a rank-1 payload of static width W.

hawk.Matrix

Matrix[R, C] — a rank-2 payload of static extents.

hawk.Param(*args, **kwargs)

Param — one value shared by every lane, whatever type it wraps.

hawk.Meta

Annotated[Vector[3], Meta(unit="km")] — opaque notes on a plane.

hawk.Mutable

Mutable[...] — the output plane a body assigns (the assign).

hawk.Table

Table[...] — a lookup plane read with at().

hawk.Grid

Grid["channel", "sample":8192] — the shape of the launch: one lane per point, the body is one lane's code.

hawk.Sorted

Sorted[Index] — a per-sample Index plane whose values never decrease along the flat lane (segment ids): a promise the compiler may build on.

hawk.Staged

Staged[Vector[W], count] — a buffer one launch PRODUCES and the next CONSUMES, declared as the producer wrote it.

hawk.Wide

Wide[W] — a per-sample WIDE plane of RUNTIME extent, stride W.

hawk.WideOut

WideOut[...] — the wide OUTPUT plane a body commits to, assigned buf = v for the own column or stored by key with hawk.scatter(buf)[k] = v, for the same reason Wide is here: a role an author cannot write is a hole in the language.

hawk.Terminated(*args, **kwargs)

its form plus the payload type it carries.

hawk.HawkError

The one HAWK refusal type: every structural refusal named by the spec (a total-leaf-merge collision, a mixed sink set, an impossible quantity span, an undeclared reduce op) raises it.