Skip to main content

Module nary_layout

Module nary_layout 

Source
Expand description

Flat device encoding of n-ary rule patterns + the iterative scorer.

The CUDA n-ary scoring kernel cannot walk Vec<BodyAtomPattern> — it consumes the pattern batch as parallel flat arrays. This module owns that encoding AND score_pattern_flat, an iterative backtracking interpreter over the encoding that is the kernel’s algorithm stated in host Rust: same state (row cursors, join values, per-depth bound masks), same order, no recursion. Its tests pin it against the recursive crate::nary_reference scorer, so when the device kernel reproduces this walk, agreement with the reference follows by transitivity — the CUDA leg then only has to witness bit-equality on the pod.

Bounds are part of the device contract: the kernel allocates fixed per-thread state, so flattening REFUSES (typed, host-side) any pattern the kernel could not evaluate. Nothing out of bounds ever reaches a launch.

Binding code layout (u32): bit 31 set => join variable, clear => head position; low 8 bits carry the index. The remaining bits are zero and reserved.

Structs§

FlatRelation
One candidate relation as the flat COLUMN-MAJOR buffer the kernel reads.
NaryPatternBatchLayout
One pattern batch as the parallel flat arrays the kernel consumes.

Enums§

NaryLayoutError
Typed refusal: the pattern batch cannot be represented on device.

Constants§

NARY_MAX_ATOM_ARITY
NARY_MAX_BODY_ATOMS
Device-contract bounds for one pattern evaluation thread.
NARY_MAX_HEAD_ARITY
Head arity the kernel can gather into its fixed per-thread example array. Published HERE with the rest of the device contract: it was previously duplicated as private constants in the launcher and the engine while this module claimed to refuse everything the kernel could not evaluate.
NARY_MAX_JOIN_VARS

Functions§

binding_code
Encode one binding as the device u32 code.
decode_binding
Decode a device binding code (inverse of binding_code).
flatten_patterns
Flatten a validated pattern batch into the device layout.
score_pattern_flat
Score ONE pattern of the batch against one example tuple — the exact iterative walk the device kernel runs, in host Rust.
score_pattern_flat_coverage
Coverage counts for one pattern over example sets, via the flat walk.