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§
- Flat
Relation - One candidate relation as the flat COLUMN-MAJOR buffer the kernel reads.
- Nary
Pattern Batch Layout - One pattern batch as the parallel flat arrays the kernel consumes.
Enums§
- Nary
Layout Error - 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.