fuel-dispatch 0.22.4

Dispatch infrastructure for fuel: KernelBindingTable, per-backend registration wrappers, CompiledNode + compile_node, ExecutionPlan + compile_plan + resolve_kernel, FusedKernelRegistry, PipelinedExecutor. The layer that takes a graph and runs it against registered backends. Extracted from fuel-memory 2026-05-31.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
---
fkc_version: 1
provider:
  name: fuel-cpu-backend
  backend: Cpu                       # maps to BackendId::Cpu
  kernel_source: "portable-cpu"      # the BindingEntry.kernel_source tag
  link_registry: fuel_cpu_backend::fkc::ENTRY_POINTS   # §12.6 symbol→KernelRef map
  revision_base: "git:f41137b4"      # provider build id, folded into kernel_revision_hash
---

# fuel-cpu-backend — shape-ops kernel contracts


Portable byte-shaped CPU shape/movement, triangular/mask, and prefix-sum kernels from
`fuel-cpu-backend/src/byte_kernels.rs` (the `CpuStorageBytes` production surface the
`fuel_dispatch::dispatch::cpu_wrappers` path extracts and calls). Family: **shape-ops**.

Cross-cutting facts for this family (from the inventory): with the single exception of
`contiguize_cpu` (the strided→contiguous materializer itself), every kernel here operates on flat
`CpuStorageBytes` slices via `bytes()` / `as_slice()` and validates *byte length* against explicit
`usize` shape parameters — none consult a `Layout`/strides/offset internally. The input-layout
contract for all of them (except `contiguize_cpu`) is therefore **contiguous, offset 0, row-major**;
the pipelined executor's auto-Contiguize pass realizes any strided/broadcast/offset input *before*
these kernels run, so each one declares `awkward_layout_strategy: requires_contiguous` and the
planner prices the inserted `Op::Contiguize` from the `contiguize` contract below (§4.3, §4.4).
The movement/mask/triangular kernels are **dtype-agnostic** (the caller passes `dtype_size` and the
kernel copies that many bytes per element); the cumsum kernels are per-dtype (typed add). Output is
caller-pre-allocated and fully overwritten, except the in-place scatter family
(`write_slice_cpu`, `write_slice_rotating_cpu`) which partially overwrite — and alias — a slab of
`dest`. Validation is `Result`-returning byte-length checks; no panics on the production path.

Cost provenance: every kernel below is marked `provenance: judge_measured` — the Judge bootstraps
the coefficients (FKC stays agnostic to how, §4.4). Where a real bandwidth/FLOPs hint is genuinely
derivable from the op (these are memory-bound byte copies / linear prefix scans), it is recorded in
the expression strings as the honest shape of the cost; the Judge refines the constants.

---

## contiguize  (strided/broadcast/offset → dense row-major materialize)


The only strided/broadcast/offset-capable CPU kernel — the strided→contiguous materializer itself.

`contiguize_cpu` (`byte_kernels.rs:1206`) is the one CPU kernel that consumes a `Layout` and walks
arbitrary strides: it iterates `layout.strided_index()` and copies `dtype_size` bytes per produced
element into a freshly-allocated contiguous output of `layout.shape().elem_count() * dtype_size`
bytes. A stride-0 axis transparently **replicates** the source element (broadcast without a separate
materialize), a non-zero `byte_offset`/view base is honored (the iteration starts at the view base),
and the strided walk handles transpose/slice metadata-only views. It is **dtype-agnostic** — only
`dtype_size` matters. This is the kernel the planner inserts (and prices) whenever a downstream
`requires_contiguous` kernel is fed a non-contiguous operand (§4.3); it is itself an ordinary FKC
kernel so the contiguize-vs-strided comparison is a literal sum of two `CostEstimate`s (§4.4). It
allocates and **returns a new `CpuStorageBytes`** (the only allocating kernel here; the rest fill a
caller-buffer). Numerics: pure byte copy, no arithmetic — bit-exact, deterministic across any
hardware. Overflow on `elem_count * dtype_size` or a layout pointing past the input bytes is a typed
`Result` error, never a panic. Perf: bandwidth-bound; one `dtype_size`-byte `copy_from_slice` per
output element (broadcast replays re-read the same source byte range).

```fkc
kernel: contiguize
registrable: false            # §3.10 describe-only: there is NO OpKind::Contiguize in the as-built
                             # enum / lower_op_kind table; Fuel inserts contiguize as an executor
                             # materialize pass, not via a dispatch OpKind. Never invent an OpKind.
op_kind: Contiguize          # descriptive token; no real dispatch OpKind to key against
blurb: "Materialize a dense row-major buffer from a strided/broadcast/offset input; dtype-agnostic byte copy."
backend: Cpu
kernel_source: "portable-cpu"
entry_point: "fuel_cpu_backend::byte_kernels::contiguize_cpu"
kernel_revision_hash: auto

accept:
  inputs:
    - name: input
      dtypes: [U8, I8, U32, I16, I32, I64, BF16, F16, F32, F64, F8E4M3]
      # The ONLY kernel here that walks a Layout: arbitrary strides, stride-0 broadcast,
      # non-zero start offset are all accepted. Negative strides are NOT walked (no flip path).
      layout: { contiguous: accepted, strided: accepted, broadcast_stride0: accepted, start_offset: accepted, reverse_strides: rejected }
      rank: any
  op_params: { variant: None }      # shape/stride/offset arrive via the Layout argument, not OpParams

return:
  outputs:
    - name: out
      dtype_rule: passthrough(input)        # dtype unchanged; only layout changes
      shape_rule: same_as(input)            # element shape preserved (= layout.shape())
      layout_guarantee: contiguous          # dense row-major, offset 0 (this is the kernel's job)
      aliasing: none                        # freshly allocated CpuStorageBytes (this kernel allocates)

caps:
  awkward_layout_strategy: handles_strided   # it IS the strided handler — walks strides directly, no fixup
  fast_paths:
    - { when: "all_inputs_contiguous", note: "dense source: contiguous span copy, no replication" }
    - { when: "any_input_broadcast", note: "stride-0 axis re-reads the same source element" }
  in_place: false
  alignment_bytes: 64
  access_granularity_bits: 8

cost:
  provenance: judge_measured          # Judge bootstraps; hint: bandwidth-bound, ~2*N*dtype_bytes moved (read src + write dst)
  class: strided_elementwise
  flops: "0"                          # pure byte copy, no arithmetic
  bytes_moved: "2 * n * dtype_bytes"  # read each produced element + write it (broadcast re-reads inflate reads)
  overhead_ns: ~
  memory: { device_bytes: 0, host_bytes: "n * dtype_bytes", disk_bytes: 0 }   # allocates the contiguous output

precision:
  bit_stable_on_same_hardware: true
  max_ulp: ~
  max_relative: ~
  max_absolute: ~
  audited: true
  notes: "Pure byte copy, no arithmetic; bit-exact and hardware-independent for every dtype."

determinism: bitwise
```

---

## flip  (reverse element order along one dim)


Reverse the order of elements along one dimension; dtype-agnostic byte reorder.

`flip_cpu` (`byte_kernels.rs:408`) computes `out[outer, j, inner] = in[outer, dim_size-1-j, inner]`
over a contiguous, zero-offset buffer factored into `(outer, dim_size, inner)` by the caller. The
flipped axis is `dim_size`; `inner * dtype_size` bytes per row are copied with one `copy_from_slice`,
reversed in the `dim_size` index. Dtype-agnostic (only `dtype_size` matters). It allocates a scratch
`Vec<u8>`, fills it, then copies into the caller-pre-allocated output (so it is *not* a true
allocating return like `contiguize`; the executor still owns the output buffer). Pure permutation of
bytes — bit-exact, deterministic across any hardware. Byte-length mismatch is a typed `Result` error.
Perf: bandwidth-bound, `outer * dim_size` row copies of `inner * dtype_size` bytes each.

```fkc
kernel: flip
op_kind: Flip
blurb: "Reverse element order along one dim (out[..,j,..]=in[..,dim-1-j,..]); dtype-agnostic byte reorder."
backend: Cpu
kernel_source: "portable-cpu"
entry_point: "fuel_cpu_backend::byte_kernels::flip_cpu"
kernel_revision_hash: auto

accept:
  inputs:
    - name: input
      # Byte-dtype-agnostic (only dtype_size matters), but the REGISTRATION covers
      # the 6 dtypes the executor actually materializes flips for — the fan builds
      # one `[T, T]` binding per dtype, ALL resolving `flip_cpu_wrapper`. Trimmed
      # from the kernel's full byte-agnostic set to match production truthfully
      # (byte-for-byte the deleted `table.register(Flip, &unary(t), …)` regs).
      dtypes: [F32, F64, BF16, F16, U32, U8]
      # Contiguous-only: the kernel walks flat bytes, axis factored as (outer,dim,inner) usize params.
      # It does NOT walk a Layout's negative strides — it MATERIALIZES the reversal into the output.
      layout: { contiguous: required, strided: rejected, broadcast_stride0: rejected, start_offset: rejected, reverse_strides: rejected }
      rank: any                       # logical rank folded into outer/dim_size/inner by the caller
  op_params:
    variant: Flip                     # OpParams::Flip — carries the flipped dim (lowered to outer/dim_size/inner)
    fields:
      outer:     { kind: usize }
      dim_size:  { kind: usize }
      inner:     { kind: usize }
      dtype_size: { kind: usize, note: "bytes per element; kernel is dtype-agnostic" }

return:
  outputs:
    - name: out
      dtype_rule: passthrough(input)
      shape_rule: same_as(input)
      layout_guarantee: contiguous
      aliasing: none

caps:
  awkward_layout_strategy: requires_contiguous   # planner inserts Op::Contiguize (priced from `contiguize`) for non-contig input
  fast_paths: []
  in_place: false
  alignment_bytes: 64
  access_granularity_bits: 8

cost:
  provenance: judge_measured          # hint: bandwidth-bound, 2*N*dtype_bytes moved (read each row + write reversed)
  class: strided_elementwise
  flops: "0"                          # pure reorder, no arithmetic
  bytes_moved: "2 * outer * dim_size * inner * dtype_size"
  overhead_ns: ~
  memory: { device_bytes: 0, host_bytes: "outer * dim_size * inner * dtype_size", disk_bytes: 0 }   # internal scratch Vec

precision:
  bit_stable_on_same_hardware: true
  max_ulp: ~
  max_relative: ~
  max_absolute: ~
  audited: true
  notes: "Pure byte permutation; bit-exact, hardware-independent."

determinism: bitwise
```

---

## roll  (cyclic shift along one dim)


Cyclically shift elements along one dimension by `shift` positions (always wraps).

`roll_cpu` (`byte_kernels.rs:444`) computes `out[outer, j, inner] = in[outer, (j-shift) mod dim_size,
inner]` with Python-style modulo (`rem_euclid`), so positive `shift` moves elements to higher indices
and negative the opposite; the shift is normalized into `[0, dim_size)` once. Contiguous, zero-offset
buffer factored into `(outer, dim_size, inner)`; `inner * dtype_size` bytes per row copied. `dim_size
== 0` is a no-op. Dtype-agnostic (byte reorder). Allocates a scratch `Vec<u8>`, fills it, copies into
the caller output. Pure permutation — bit-exact, deterministic across any hardware. Byte-length
mismatch is a typed `Result` error. Perf: bandwidth-bound, `outer * dim_size` row copies.

```fkc
kernel: roll
op_kind: Roll
blurb: "Cyclic shift along one dim (out[..,j,..]=in[..,(j-shift) mod dim,..]); always wraps; dtype-agnostic."
backend: Cpu
kernel_source: "portable-cpu"
entry_point: "fuel_cpu_backend::byte_kernels::roll_cpu"
kernel_revision_hash: auto

accept:
  inputs:
    - name: input
      # Byte-dtype-agnostic; REGISTRATION trimmed to the 6 production dtypes (fan →
      # one `[T, T]` binding per dtype, ALL → `roll_cpu_wrapper`). Matches the
      # deleted `table.register(Roll, &unary(t), …)` regs.
      dtypes: [F32, F64, BF16, F16, U32, U8]
      layout: { contiguous: required, strided: rejected, broadcast_stride0: rejected, start_offset: rejected, reverse_strides: rejected }
      rank: any
  op_params:
    variant: Roll                     # OpParams::Roll — flattened axis + signed shift
    fields:
      outer:     { kind: usize }
      dim_size:  { kind: usize }
      inner:     { kind: usize }
      shift:     { kind: i64, note: "signed; normalized into [0,dim_size) via Python-style modulo" }
      dtype_size: { kind: usize }

return:
  outputs:
    - name: out
      dtype_rule: passthrough(input)
      shape_rule: same_as(input)
      layout_guarantee: contiguous
      aliasing: none

caps:
  awkward_layout_strategy: requires_contiguous
  fast_paths:
    - { when: "dim_size == 0", class: free, note: "empty axis: no-op early return" }
  in_place: false
  alignment_bytes: 64
  access_granularity_bits: 8

cost:
  provenance: judge_measured          # hint: bandwidth-bound, 2*N*dtype_bytes moved
  class: strided_elementwise
  flops: "0"
  bytes_moved: "2 * outer * dim_size * inner * dtype_size"
  overhead_ns: ~
  memory: { device_bytes: 0, host_bytes: "outer * dim_size * inner * dtype_size", disk_bytes: 0 }   # internal scratch Vec

precision:
  bit_stable_on_same_hardware: true
  max_ulp: ~
  max_relative: ~
  max_absolute: ~
  audited: true
  notes: "Pure byte permutation; bit-exact, hardware-independent."

determinism: bitwise
```

---

## concat  (join N inputs along one dim)


Concatenate N contiguous inputs along one dimension into a single contiguous output.

`concat_cpu` (`byte_kernels.rs:2711`; `concat_f32` shim at 2777 pins `dtype_size = size_of::<f32>()`)
joins `inputs.len()` operands along one axis whose per-input sizes are `input_dim_sizes[i]`; the
output axis size is their sum. Every operand and the output share the same `(outer_count, inner_count)`
factoring and `dtype_size`; the kernel copies, per input, each `(outer, dim_pos)` row of `inner_count
* dtype_size` bytes into its destination slot at the running `dim_offset`. Dtype-agnostic. Requires
≥1 input; rejects `dtype_size == 0`; validates each input's byte length and the output's against the
declared factoring. Pure byte copy — bit-exact, deterministic. **Variadic input count** (the dispatch
key's operand list is the N joined inputs, all same dtype). Perf: bandwidth-bound, total bytes moved
= the output's byte size (each input byte copied once).

```fkc
kernel: concat
op_kind: Concat
blurb: "Join N contiguous inputs along one dim into one contiguous buffer; dtype-agnostic byte copy."
backend: Cpu
kernel_source: "portable-cpu"
entry_point: "fuel_cpu_backend::byte_kernels::concat_cpu"
kernel_revision_hash: auto

accept:
  inputs:
    # Variadic: N>=1 operands, all the same dtype; per-input axis size = input_dim_sizes[i].
    - name: inputs
      # Byte-dtype-agnostic; REGISTRATION trimmed to the 9 production dtypes. The
      # importer treats the variadic list as ONE representative input, so the fan
      # builds the `[T, T]` shorthand key per dtype (the lookup site collapses the
      # actual N+1 dtype list to it), ALL → `concat_cpu_wrapper`. Matches the
      # deleted `table.register(Concat, &unary(dt), …)` loop.
      dtypes: [F32, F64, BF16, F16, U32, U8, I16, I32, I64]
      layout: { contiguous: required, strided: rejected, broadcast_stride0: rejected, start_offset: rejected, reverse_strides: rejected }
      rank: any
      shape_constraint: "same_rank=out; all inputs agree on every axis except the concatenated dim"
      variadic: true                  # the operand list is N inputs (>=1); each is a distinct key dtype slot
  op_params:
    variant: Concat                   # OpParams::Concat — flattened (outer,inner) + per-input dim sizes
    fields:
      outer_count:    { kind: usize }
      input_dim_sizes: { kind: "Vec<usize>", constraint: "len == inputs.len(); >=1 entry" }
      inner_count:    { kind: usize }
      dtype_size:     { kind: usize, constraint: "> 0" }

return:
  outputs:
    - name: out
      dtype_rule: passthrough(inputs)        # all inputs share one dtype; output is that dtype
      shape_rule: "from_params(concat: outer × sum(input_dim_sizes) × inner)"
      layout_guarantee: contiguous
      aliasing: none

caps:
  awkward_layout_strategy: requires_contiguous
  fast_paths: []
  in_place: false
  alignment_bytes: 64
  access_granularity_bits: 8

cost:
  provenance: judge_measured          # hint: bandwidth-bound, 2*out_bytes moved (read all inputs + write output)
  class: strided_elementwise
  flops: "0"
  bytes_moved: "2 * outer_count * sum(input_dim_sizes) * inner_count * dtype_size"
  overhead_ns: ~
  memory: { device_bytes: 0, host_bytes: 0, disk_bytes: 0 }   # output is caller-preallocated; no internal scratch

precision:
  bit_stable_on_same_hardware: true
  max_ulp: ~
  max_relative: ~
  max_absolute: ~
  audited: true
  notes: "Pure byte copy; bit-exact, hardware-independent."

determinism: bitwise
```

---

## write_slice  (in-place rectangular scatter into a dest slab)


In-place rectangular scatter: copy `source` into a per-axis half-open slab of `dest`; only the slab
bytes are touched.

`write_slice_cpu` (`byte_kernels.rs:8300`) writes `source`'s bytes into a rectangular slab of `dest`
defined by `ranges[i] = (start, end)` (half-open) per axis; the slab's size along axis `i` is `end -
start`, and `source`'s element count must equal the slab's. It walks the slab's non-innermost
coordinates in row-major order, copying the innermost (last-axis) run of `slab_inner * dtype_size`
bytes per outer tuple with one `copy_from_slice` at the dest offset shifted by `ranges[i].0` on each
axis. **Partial overwrite that aliases `dest`** (bytes outside the slab are untouched), so the
return-contract aliasing is `in_place(dest)` and the op requires `caps.in_place: true`. Dtype-agnostic.
Validates `dtype_size > 0`, rank ≥ 1, `ranges.len() == rank`, each range `start ≤ end ≤ dest_shape[i]`,
and dest/source byte sizes; empty slab is a no-op. Pure byte copy — bit-exact, deterministic. Perf:
bandwidth-bound in the slab volume (`slab_elems * dtype_size` bytes written; dest is read-modify only
in that no other bytes change — no read of dest content occurs).

**Key modeling (re-author 2026-07-03).** `dest` is the OUTPUT slot, not a key input: the executor's
`Op::WriteSlice` arm adopts `dest`'s Storage Arc as the kernel's output and passes only `source` as a
kernel input, so `build_lookup_dtypes` canonicalizes the binding key to `[T_source, T_out]` = `[T, T]`
(`pipelined.rs`). This section therefore models `source` as the SINGLE input and `dest` as the `out`
output (`aliasing: in_place(dest)`) — exactly the in-place template — so the importer keys `[T, T]`
byte-for-byte the deleted `table.register(WriteSlice, &unary(t), …)` regs. (The earlier deferral
mis-assumed the importer would key `[source, dest, out]`; the aliased `dest` is the output, never a
second key operand.)

```fkc
kernel: write_slice
op_kind: WriteSlice
blurb: "In-place rectangular scatter of source into a per-axis half-open slab of dest; dtype-agnostic; dest is the in-place output slot."
backend: Cpu
kernel_source: "portable-cpu"
entry_point: "fuel_cpu_backend::byte_kernels::write_slice_cpu"   # base; §3.4 fans write_slice_cpu_{f32,f64,bf16,f16,u32,u8}; §12.6
kernel_revision_hash: auto

accept:
  inputs:
    - name: source
      # Byte-dtype-agnostic (only dtype_size matters); REGISTRATION trimmed to the
      # 6 production dtypes — the fan builds one `[T, T]` binding per dtype, ALL
      # resolving `write_slice_cpu_wrapper`. `dest` is NOT a key input: it is the
      # OUTPUT slot (the executor adopts its Arc in place), so a faithful contract
      # models `source` as the SINGLE input + `dest` as the `out` output, keying
      # `[T_source, T_out]` = `[T, T]` byte-for-byte the deleted hand-written regs.
      dtypes: [F32, F64, BF16, F16, U32, U8]
      layout: { contiguous: required, strided: rejected, broadcast_stride0: rejected, start_offset: rejected, reverse_strides: rejected }
      rank: "1..=8"                   # source rank == dest rank; slab dim i = ranges[i].end-ranges[i].start
      shape_constraint: "dim[i] == ranges[i].end - ranges[i].start"
  op_params:
    variant: WriteSlice               # OpParams::WriteSlice — dest_shape + per-axis ranges
    fields:
      dest_shape: { kind: "Vec<usize>", constraint: "rank >= 1" }
      ranges:     { kind: "Vec<(usize,usize)>", constraint: "len == rank; 0 <= start <= end <= dest_shape[i]" }
      dtype_size: { kind: usize, constraint: "> 0", note: "read from the dest output Storage's dtype tag at dispatch, not a serialized OpParams field" }

return:
  outputs:
    - name: out
      dtype_rule: passthrough(source)        # out IS dest's buffer; dest's dtype == source's (T in, T out)
      shape_rule: "from_params(write_slice: dest_shape)"   # out adopts dest's shape (== dest_shape)
      layout_guarantee: contiguous           # dest's contiguous layout preserved; only slab bytes change
      aliasing: in_place(dest)               # output IS dest's buffer (executor adopts dest's Arc); partial (slab-only) overwrite

caps:
  awkward_layout_strategy: requires_contiguous
  fast_paths:
    - { when: "dim[0] == 0", class: free, note: "empty slab: no-op early return" }
    - { note: "rank==1: single contiguous span copy" }
  in_place: true                      # writes into dest's buffer (§4.6)
  alignment_bytes: 64
  access_granularity_bits: 8

cost:
  provenance: judge_measured          # hint: bandwidth-bound in slab volume; 2*slab_bytes moved (read source + write slab)
  class: strided_elementwise
  flops: "0"
  bytes_moved: "2 * source.n * dtype_size"   # source.n = slab element count; dest bytes outside the slab untouched
  overhead_ns: ~
  memory: { device_bytes: 0, host_bytes: 0, disk_bytes: 0 }   # in-place; no allocation

precision:
  bit_stable_on_same_hardware: true
  max_ulp: ~
  max_relative: ~
  max_absolute: ~
  audited: true
  notes: "Pure byte copy into a dest slab; bit-exact, hardware-independent. Bytes outside the slab are preserved."

determinism: bitwise
```

---

## write_slice_rotating  (in-place ring-buffer scatter)


In-place ring-buffer scatter: write `source` into a slab of `dest` whose `axis` wraps modulo
`modulus`, with the dynamic start read from a `position` operand.

`write_slice_rotating_cpu` (`byte_kernels.rs:8453`) is the sliding-window-KV-cache write. The dynamic
write start on `axis` is `wrapped_start = position % modulus`, where `position` is the first `u32` of
the `position_bytes` operand read host-side (native-endian). With `slab_axis_len = ranges[axis].end -
ranges[axis].start`, it writes rows whose `axis` coord is `(wrapped_start + r) % modulus`; when
`wrapped_start + slab_axis_len > modulus` the write splits across the ring boundary into two
`write_slice_cpu`-style copies (a prefix to `[wrapped_start, modulus)` and a suffix to `[0,
second_len)`), gathering each source half via `extract_strided_chunk`. **v1 constraint (per
inventory): the rotating `axis` is the leading dim (`axis == 0`)** — the documented sliding-window
layout `[seq, n_kv_heads, head_dim]` puts `seq` at axis 0, which makes the source split a flat
prefix/suffix; the param is read generally but axis-0 is the supported/tested case. Dtype-agnostic.
Validates `dtype_size > 0`, rank ≥ 1, `ranges.len() == rank`, `axis < rank`, `0 < modulus ≤
dest_shape[axis]`, `position_bytes.len ≥ 4`, rotating-axis slab ≤ `modulus`, off-axis ranges within
bounds, and dest/source byte sizes. **In-place, aliases `dest`** (`caps.in_place: true`); partial
overwrite. The `position` is a **runtime dynamic scalar** (the write offset is data-determined per
token) read from its operand, not a compile-time param. Pure byte copy — bit-exact, deterministic.
Perf: bandwidth-bound in the slab volume (one or two slab copies).

**Key modeling (re-author 2026-07-03).** Like `write_slice`, `dest` is the OUTPUT slot (the executor
adopts its Arc in place). The `position` operand is a **non-key runtime input**: the executor's
`Op::WriteSliceRotating` arm reads it as a separate kernel input, but `build_lookup_dtypes`
canonicalizes the binding key to `[T_source, T_out]` = `[T, T]` (position is EXCLUDED, `pipelined.rs`).
So this section models `source` as the SINGLE key input and `dest` as the `out` output — position is
documented in the `op_params` note, NOT an `accept.inputs` key slot — so the importer keys `[T, T]`
byte-for-byte the deleted `table.register(WriteSliceRotating, &unary(t), …)` regs. (The earlier
deferral mis-assumed the importer would key `[source, U32, dest, out]`; neither the aliased `dest` nor
the non-key `position` is a key operand.)

```fkc
kernel: write_slice_rotating
op_kind: WriteSliceRotating
blurb: "In-place ring-buffer scatter: write source into a dest slab whose axis wraps mod modulus; dest is the in-place output slot; dynamic start from a non-key position operand."
backend: Cpu
kernel_source: "portable-cpu"
entry_point: "fuel_cpu_backend::byte_kernels::write_slice_rotating_cpu"   # base; §3.4 fans write_slice_rotating_cpu_{f32,f64,bf16,f16,u32,u8}; §12.6
kernel_revision_hash: auto

accept:
  inputs:
    - name: source
      # Byte-dtype-agnostic (only dtype_size matters); REGISTRATION trimmed to the
      # 6 production dtypes — the fan builds one `[T, T]` binding per dtype, ALL
      # resolving `write_slice_rotating_cpu_wrapper`. `dest` is the OUTPUT slot
      # (in-place adoption) and `position` is a NON-KEY runtime U32 operand (read
      # by the kernel, excluded from the key by build_lookup_dtypes), so a faithful
      # contract models `source` as the SINGLE key input, keying `[T_source, T_out]`
      # = `[T, T]` byte-for-byte the deleted hand-written regs.
      dtypes: [F32, F64, BF16, F16, U32, U8]
      layout: { contiguous: required, strided: rejected, broadcast_stride0: rejected, start_offset: rejected, reverse_strides: rejected }
      rank: "1..=8"
      shape_constraint: "dim[i] == ranges[i].end - ranges[i].start; dim[axis] <= modulus"
  op_params:
    variant: WriteSliceRotating       # OpParams::WriteSliceRotating — dest_shape + axis + modulus + ranges
    fields:
      dest_shape: { kind: "Vec<usize>", constraint: "rank >= 1" }
      axis:       { kind: usize, constraint: "< rank; v1 supports axis == 0 (leading dim)" }
      modulus:    { kind: usize, constraint: "0 < modulus <= dest_shape[axis]" }
      ranges:     { kind: "Vec<(usize,usize)>", constraint: "len == rank; rotating-axis slab <= modulus; off-axis end <= dest_shape[i]" }
      dtype_size: { kind: usize, constraint: "> 0", note: "read from the dest output Storage's dtype tag at dispatch, not a serialized OpParams field" }
      position:   { kind: DynScalar, note: "the dynamic write offset — read host-side from a SEPARATE runtime rank-1 U32 `position` operand (the executor passes it as a second kernel input; it is NOT part of the binding key, NOT an OpParams field). Data-determined per token." }

return:
  outputs:
    - name: out
      dtype_rule: passthrough(source)        # out IS dest's buffer; dest's dtype == source's (T in, T out)
      shape_rule: "from_params(write_slice_rotating: dest_shape)"   # out adopts dest's shape (== dest_shape)
      layout_guarantee: contiguous           # dest's contiguous layout preserved; only ring-slab bytes change
      aliasing: in_place(dest)               # output IS dest's buffer (executor adopts dest's Arc); partial (ring-slab) overwrite

caps:
  awkward_layout_strategy: requires_contiguous
  fast_paths:
    - { when: "dim[0] == 0", class: free, note: "empty slab: no-op early return" }
    - { note: "wrapped_start + slab_axis_len <= modulus: single (non-split) slab write" }
  in_place: true
  alignment_bytes: 64
  access_granularity_bits: 8

cost:
  provenance: judge_measured          # hint: bandwidth-bound in slab volume; up to 2 slab copies (ring split) + a small source-gather scratch
  class: strided_elementwise
  flops: "0"
  bytes_moved: "2 * source.n * dtype_size"   # source.n = slab element count; ring split adds a same-volume scratch gather
  overhead_ns: ~
  memory: { device_bytes: 0, host_bytes: "source.n * dtype_size", disk_bytes: 0 }   # extract_strided_chunk scratch on a boundary split

precision:
  bit_stable_on_same_hardware: true
  max_ulp: ~
  max_relative: ~
  max_absolute: ~
  audited: true
  notes: "Pure byte copy into a ring slab; bit-exact, hardware-independent. Bytes outside the written rows are preserved."

determinism: bitwise
```

---

## write_slice_doff  (in-place scatter with a device-resident axis start)


In-place scatter: write `source` into a slab of `dest` whose start on `axis` is read from a rank-0
`I64` `offset` operand, with NO modulo wrap (unlike `write_slice_rotating`).

`write_slice_doff_cpu` (`byte_kernels.rs`) is the CUDA-graph-capturable KV-cache append. The write
start on `axis` is the first `i64` of the `offset` operand (read host-side here on CPU; the CUDA
`_doff` kernel reads it device-side so a captured graph replays at the host-updated position). With
`width = ranges[axis].end - ranges[axis].start`, it overrides `ranges[axis]` to `(offset,
offset + width)` and delegates to `write_slice_cpu`. Dtype-agnostic. Validates `dtype_size > 0`,
rank ≥ 1, `ranges.len() == rank`, `axis < rank`, `offset` ≥ 0, `offset_bytes.len ≥ 8`, and — because
the CPU path reads the start host-side, unlike the non-clamping device kernel — `offset + width ≤
dest_shape[axis]`, returning a typed error on overflow rather than corrupting memory. **In-place,
aliases `dest`** (`caps.in_place: true`); partial overwrite. The `offset` is a **runtime dynamic
scalar** (the append position is per-token) read from its operand, not a compile-time param. Pure
byte copy — bit-exact, deterministic. Perf: bandwidth-bound in the slab volume (one slab copy).

**Key modeling.** Like `write_slice`/`write_slice_rotating`, `dest` is the OUTPUT slot (the executor
adopts its Arc in place). The `offset` operand is a **non-key runtime input**: the executor's
`Op::WriteSliceDoff` arm reads it as a separate kernel input, but `build_lookup_dtypes` canonicalizes
the binding key to `[T_source, T_out]` = `[T, T]` (offset is EXCLUDED, `pipelined.rs`). So this section
models `source` as the SINGLE key input and `dest` as the `out` output — offset is documented in the
`op_params` note, NOT an `accept.inputs` key slot — so the importer keys `[T, T]`.

```fkc
kernel: write_slice_doff
op_kind: WriteSliceDoff
blurb: "In-place scatter: write source into a dest slab whose axis start is a device-resident I64 (no wrap); dest is the in-place output slot; dynamic start from a non-key offset operand."
backend: Cpu
kernel_source: "portable-cpu"
entry_point: "fuel_cpu_backend::byte_kernels::write_slice_doff_cpu"   # base; §3.4 fans write_slice_doff_cpu_{f32,f64,bf16,f16,u32,u8}; §12.6
kernel_revision_hash: auto

accept:
  inputs:
    - name: source
      # Byte-dtype-agnostic (only dtype_size matters); REGISTRATION trimmed to the
      # 6 production dtypes — the fan builds one `[T, T]` binding per dtype, ALL
      # resolving `write_slice_doff_cpu_wrapper`. `dest` is the OUTPUT slot
      # (in-place adoption) and `offset` is a NON-KEY runtime I64 operand (read
      # by the kernel, excluded from the key by build_lookup_dtypes), so a faithful
      # contract models `source` as the SINGLE key input, keying `[T_source, T_out]`
      # = `[T, T]`.
      dtypes: [F32, F64, BF16, F16, U32, U8]
      layout: { contiguous: required, strided: rejected, broadcast_stride0: rejected, start_offset: rejected, reverse_strides: rejected }
      rank: "1..=8"
      shape_constraint: "dim[i] == ranges[i].end - ranges[i].start"
  op_params:
    variant: WriteSliceDoff       # OpParams::WriteSliceDoff — dest_shape + axis + ranges
    fields:
      dest_shape: { kind: "Vec<usize>", constraint: "rank >= 1" }
      axis:       { kind: usize, constraint: "< rank" }
      ranges:     { kind: "Vec<(usize,usize)>", constraint: "len == rank; off-axis end <= dest_shape[i]; axis width <= dest_shape[axis]" }
      dtype_size: { kind: usize, constraint: "> 0", note: "read from the dest output Storage's dtype tag at dispatch, not a serialized OpParams field" }
      offset:     { kind: DynScalar, note: "the dynamic write start on `axis` — read from a SEPARATE runtime rank-0 I64 `offset` operand (the executor passes it as a second kernel input; it is NOT part of the binding key, NOT an OpParams field). Device-resident under CUDA; per-token." }

return:
  outputs:
    - name: out
      dtype_rule: passthrough(source)        # out IS dest's buffer; dest's dtype == source's (T in, T out)
      shape_rule: "from_params(write_slice_doff: dest_shape)"   # out adopts dest's shape (== dest_shape)
      layout_guarantee: contiguous           # dest's contiguous layout preserved; only slab bytes change
      aliasing: in_place(dest)               # output IS dest's buffer (executor adopts dest's Arc); partial (slab) overwrite

caps:
  awkward_layout_strategy: requires_contiguous
  fast_paths:
    - { when: "dim[0] == 0", class: free, note: "empty slab: no-op early return" }
  in_place: true
  alignment_bytes: 64
  access_granularity_bits: 8

cost:
  provenance: judge_measured          # hint: bandwidth-bound in slab volume; single slab copy
  class: strided_elementwise
  flops: "0"
  bytes_moved: "2 * source.n * dtype_size"   # source.n = slab element count
  overhead_ns: ~
  memory: { device_bytes: 0, host_bytes: 0, disk_bytes: 0 }

precision:
  bit_stable_on_same_hardware: true
  max_ulp: ~
  max_relative: ~
  max_absolute: ~
  audited: true
  notes: "Pure byte copy into a slab; bit-exact, hardware-independent. Bytes outside the written rows are preserved."

determinism: bitwise
```

---

## triangular  (Triu / Tril mask)


Upper/lower triangular mask: keep `x[..., i, j]` on one side of a `diagonal` offset, zero elsewhere.

`triangular_cpu` (`byte_kernels.rs:905`) zeros the output, then copies the kept positions from the
input. With `keep_upper`, it keeps `j >= i + diagonal` (Triu); otherwise `j <= i + diagonal` (Tril).
A batch of `batch_count` `rows × cols` matrices is processed; `dtype_size` bytes per kept element are
copied with `copy_from_slice`, dropped elements are left as the all-zero fill. **Dtype-agnostic** —
all-zero bytes are the correct zero for every IEEE-754 / integer dtype Fuel supports, so the kernel
zeros the whole output (`fill(0)`) and then overlays kept positions. Validates input/output byte
length against `batch_count * rows * cols * dtype_size`. Pure mask-and-copy — bit-exact,
deterministic. Perf: bandwidth-bound, output fully written once (`batch*rows*cols*dtype_size` bytes).

```fkc
kernel: triangular
registrable: false            # §3.10 describe-only: chassis umbrella backing Triu+Tril (keep_upper
                             # selects); no single OpKind to key against (Triu/Tril are the real
                             # OpKinds, dispatch.rs:278/280). `Triangular` is the OpParams variant
                             # (kernel.rs:512), NOT an OpKind. Not a typo for one variant → describe-only.
op_kind: Triangular          # descriptive umbrella token; the registrable arms are Triu / Tril
blurb: "Triu/Tril mask: keep one side of a diagonal offset (keep_upper flag), zero elsewhere; dtype-agnostic."
backend: Cpu
kernel_source: "portable-cpu"
entry_point: "fuel_cpu_backend::byte_kernels::triangular_cpu"
kernel_revision_hash: auto

accept:
  inputs:
    - name: input
      dtypes: [U8, I8, U32, I16, I32, I64, BF16, F16, F32, F64, F8E4M3]
      layout: { contiguous: required, strided: rejected, broadcast_stride0: rejected, start_offset: rejected, reverse_strides: rejected }
      rank: "2..=8"                   # last two dims are rows×cols; leading dims fold into batch_count
  op_params:
    variant: Triangular               # OpParams::Triangular
    fields:
      batch_count: { kind: usize }
      rows:       { kind: usize }
      cols:       { kind: usize }
      diagonal:   { kind: i64, note: "diagonal offset; keep boundary is j vs i+diagonal" }
      keep_upper: { kind: bool, note: "true=Triu (j>=i+diag), false=Tril (j<=i+diag)" }
      dtype_size: { kind: usize }

return:
  outputs:
    - name: out
      dtype_rule: passthrough(input)
      shape_rule: same_as(input)
      layout_guarantee: contiguous
      aliasing: none

caps:
  awkward_layout_strategy: requires_contiguous
  fast_paths: []
  in_place: false
  alignment_bytes: 64
  access_granularity_bits: 8

cost:
  provenance: judge_measured          # hint: bandwidth-bound, output fully written once (~N*dtype_size) + kept-element reads
  class: strided_elementwise
  flops: "0"                          # comparison + copy; no FP arithmetic
  bytes_moved: "2 * batch_count * rows * cols * dtype_size"   # zero-fill output + copy kept inputs
  overhead_ns: ~
  memory: { device_bytes: 0, host_bytes: 0, disk_bytes: 0 }

precision:
  bit_stable_on_same_hardware: true
  max_ulp: ~
  max_relative: ~
  max_absolute: ~
  audited: true
  notes: "Mask-and-copy with all-zero fill (valid zero for every Fuel dtype); bit-exact, hardware-independent."

determinism: bitwise
```

---

## masked_fill  (write a fill value where a Bool mask is set)


Where the mask is non-zero, write a fixed `fill` value; elsewhere copy the input.

`masked_fill_cpu` (`byte_kernels.rs:1148`) walks `count = input.len_bytes() / dtype_size` elements:
where `mask[i] != 0` it writes `fill_bytes` (one element's worth of dtype bytes), else it copies the
input element. The **mask is `Bool` (GAP-168(c)), one byte per element** (validated `mask.len == count`, i.e. element
count, not byte count); `fill_bytes.len()` must equal `dtype_size`; input and output byte lengths must
match. **Dtype-agnostic** for the data (the fill value arrives pre-encoded as `dtype_size` bytes).
Pure select-and-copy — bit-exact, deterministic. No broadcasting (mask, input, output all have the
same element count). Perf: bandwidth-bound, output fully written once.

```fkc
kernel: masked_fill
op_kind: MaskedFill
blurb: "Write a fixed fill value where a Bool mask is set, else copy input; dtype-agnostic data, Bool mask."
backend: Cpu
kernel_source: "portable-cpu"
entry_point: "fuel_cpu_backend::byte_kernels::masked_fill_cpu"
kernel_revision_hash: auto

accept:
  inputs:
    - name: input
      # Byte-dtype-agnostic data; REGISTRATION trimmed to the 6 production dtypes.
      # `input` is the sole varying operand, so it drives the fan; `mask` stays the
      # fixed Bool slot (GAP-168(c); byte-identical to the former U8) and `out` is
      # passthrough(input) — key `[T, Bool, T]` per dtype,
      # ALL → `masked_fill_cpu_wrapper`. Matches the deleted
      # `table.register(MaskedFill, &masked_dtypes(t), …)` regs.
      dtypes: [F32, F64, BF16, F16, U32, U8]
      layout: { contiguous: required, strided: rejected, broadcast_stride0: rejected, start_offset: rejected, reverse_strides: rejected }
      rank: any
      shape_constraint: same_as=out
    - name: mask
      dtypes: [BOOL]                  # GAP-168(c): 1 byte per element; non-zero ⇒ write fill
      layout: { contiguous: required, strided: rejected, broadcast_stride0: rejected, start_offset: rejected, reverse_strides: rejected }
      rank: any
      shape_constraint: "element count == input element count (no broadcasting)"
  op_params:
    variant: MaskedFill               # OpParams::MaskedFill — pre-encoded fill bytes + dtype_size
    fields:
      fill_bytes: { kind: "Vec<u8>", constraint: "len == dtype_size; one element's worth of the data dtype" }
      dtype_size: { kind: usize, constraint: "> 0" }

return:
  outputs:
    - name: out
      dtype_rule: passthrough(input)
      shape_rule: same_as(input)
      layout_guarantee: contiguous
      aliasing: none

caps:
  awkward_layout_strategy: requires_contiguous
  fast_paths: []
  in_place: false
  alignment_bytes: 64
  access_granularity_bits: 8

cost:
  provenance: judge_measured          # hint: bandwidth-bound, ~ (input + mask read + output write) ≈ 2*N*dtype_size + N mask bytes
  class: cheap_elementwise
  flops: "0"                          # branch + copy; no arithmetic
  bytes_moved: "2 * n * dtype_size + n"     # read input + write output (n elems) + read n mask bytes
  overhead_ns: ~
  memory: { device_bytes: 0, host_bytes: 0, disk_bytes: 0 }

precision:
  bit_stable_on_same_hardware: true
  max_ulp: ~
  max_relative: ~
  max_absolute: ~
  audited: true
  notes: "Select-and-copy; the fill value is byte-identical to its input encoding; bit-exact, hardware-independent."

determinism: bitwise
```

---

## cumsum_f32  (running prefix sum along one dim, f32)


Running prefix sum along one dimension, computed in native f32.

`cumsum_f32` (`cumsum_kernel!` at `byte_kernels.rs:801`, instantiated 836) computes, for each
`(outer, inner)` lane, `out[..,j,..] = Σ_{t<=j} in[..,t,..]` along `dim_size` with a native **f32**
accumulator seeded at 0. Buffer factored as `(outer, dim_size, inner)`; element count validated
against `outer * dim_size * inner`. This is a typed (not byte-agnostic) kernel — `in`/`out` are
`&[f32]`. Sequential add along the scanned axis ⇒ a fixed, deterministic summation order, so it is
bit-stable on the same hardware (the f32 add order is fixed by the loop). Numerics: standard IEEE-754
f32 accumulation (rounding error accumulates with `dim_size`, the inherent prefix-sum behavior).
Perf: bandwidth-bound, `n` reads + `n` writes, one FLOP (add) per element.

```fkc
kernel: cumsum_f32
op_kind: CumSum
blurb: "Running prefix sum along one dim; native f32 accumulator; bit-stable on same hardware."
backend: Cpu
kernel_source: "portable-cpu"
entry_point: "fuel_cpu_backend::byte_kernels::cumsum_f32"
kernel_revision_hash: auto

accept:
  inputs:
    - name: input
      dtypes: [F32]
      layout: { contiguous: required, strided: rejected, broadcast_stride0: rejected, start_offset: rejected, reverse_strides: rejected }
      rank: any                       # scanned axis folded into outer/dim_size/inner
  op_params:
    variant: CumSum                   # OpParams::CumSum — flattened (outer,dim_size,inner)
    fields:
      outer:    { kind: usize }
      dim_size: { kind: usize }
      inner:    { kind: usize }

return:
  outputs:
    - name: out
      dtype_rule: passthrough(input)        # F32 in, F32 out
      shape_rule: same_as(input)
      layout_guarantee: contiguous
      aliasing: none

caps:
  awkward_layout_strategy: requires_contiguous
  fast_paths: []
  in_place: false
  alignment_bytes: 64
  access_granularity_bits: 32

cost:
  provenance: judge_measured          # hint: bandwidth-bound; n = outer*dim_size*inner; ~1 add/elem
  class: reduction
  flops: "outer * dim_size * inner"   # one add per element along the scan
  bytes_moved: "2 * outer * dim_size * inner * 4"   # read input + write output, 4 bytes/f32
  overhead_ns: ~
  memory: { device_bytes: 0, host_bytes: 0, disk_bytes: 0 }

precision:
  bit_stable_on_same_hardware: true   # fixed sequential f32 add order along the scan
  max_ulp: ~
  max_relative: ~
  max_absolute: ~
  audited: true
  notes: "Native f32 accumulator, fixed sequential summation order; IEEE-754 rounding accumulates with dim_size (inherent prefix-sum)."

determinism: same_hardware_bitwise
```

---

## cumsum_f64  (running prefix sum along one dim, f64)


Running prefix sum along one dimension, computed in native f64.

`cumsum_f64` (`cumsum_kernel!` at `byte_kernels.rs:801`, instantiated 837) is the f64 instantiation of
the shared `cumsum_kernel!` macro: `out[..,j,..] = Σ_{t<=j} in[..,t,..]` with a native **f64**
accumulator seeded at 0, over a `(outer, dim_size, inner)` factoring. `in`/`out` are `&[f64]`; element
count validated against `outer * dim_size * inner`. Fixed sequential add order ⇒ bit-stable on the
same hardware. Standard IEEE-754 f64 accumulation. Perf: bandwidth-bound, `n` reads + `n` writes (8
bytes/element), one add per element.

```fkc
kernel: cumsum_f64
op_kind: CumSum
blurb: "Running prefix sum along one dim; native f64 accumulator; bit-stable on same hardware."
backend: Cpu
kernel_source: "portable-cpu"
entry_point: "fuel_cpu_backend::byte_kernels::cumsum_f64"
kernel_revision_hash: auto

accept:
  inputs:
    - name: input
      dtypes: [F64]
      layout: { contiguous: required, strided: rejected, broadcast_stride0: rejected, start_offset: rejected, reverse_strides: rejected }
      rank: any
  op_params:
    variant: CumSum
    fields:
      outer:    { kind: usize }
      dim_size: { kind: usize }
      inner:    { kind: usize }

return:
  outputs:
    - name: out
      dtype_rule: passthrough(input)        # F64 in, F64 out
      shape_rule: same_as(input)
      layout_guarantee: contiguous
      aliasing: none

caps:
  awkward_layout_strategy: requires_contiguous
  fast_paths: []
  in_place: false
  alignment_bytes: 64
  access_granularity_bits: 64

cost:
  provenance: judge_measured          # hint: bandwidth-bound; n = outer*dim_size*inner; ~1 add/elem
  class: reduction
  flops: "outer * dim_size * inner"
  bytes_moved: "2 * outer * dim_size * inner * 8"   # 8 bytes/f64
  overhead_ns: ~
  memory: { device_bytes: 0, host_bytes: 0, disk_bytes: 0 }

precision:
  bit_stable_on_same_hardware: true
  max_ulp: ~
  max_relative: ~
  max_absolute: ~
  audited: true
  notes: "Native f64 accumulator, fixed sequential summation order; IEEE-754 rounding accumulates with dim_size."

determinism: same_hardware_bitwise
```

---

## cumsum_bf16  (running prefix sum along one dim, bf16 I/O with f32 accumulator)


Running prefix sum along one dim; bf16 input/output, **f32 accumulator** (load-bearing precision
invariant).

`cumsum_bf16` (`byte_kernels.rs:840`) scans `out[..,j,..] = Σ_{t<=j} in[..,t,..]` along `dim_size`
with an **f32 accumulator**: each step widens the bf16 input to f32, adds, and narrows the running
sum back to bf16 on store (`half::bf16::from_f32(acc)`). The f32-accumulator widening is the precision
invariant the chassis encodes — accumulating directly in bf16 over a long axis would lose precision.
I/O dtype is bf16; element count validated against `outer * dim_size * inner`. Fixed sequential add
order ⇒ bit-stable on the same hardware. Perf: bandwidth-bound (2 bytes/element I/O), one
widen-add-narrow per element.

```fkc
kernel: cumsum_bf16
op_kind: CumSum
blurb: "Running prefix sum along one dim; bf16 I/O with f32 accumulator (narrow on store); bit-stable on same hardware."
backend: Cpu
kernel_source: "portable-cpu"
entry_point: "fuel_cpu_backend::byte_kernels::cumsum_bf16"
kernel_revision_hash: auto

accept:
  inputs:
    - name: input
      dtypes: [BF16]
      layout: { contiguous: required, strided: rejected, broadcast_stride0: rejected, start_offset: rejected, reverse_strides: rejected }
      rank: any
  op_params:
    variant: CumSum
    fields:
      outer:    { kind: usize }
      dim_size: { kind: usize }
      inner:    { kind: usize }

return:
  outputs:
    - name: out
      dtype_rule: passthrough(input)        # BF16 in, BF16 out
      shape_rule: same_as(input)
      layout_guarantee: contiguous
      aliasing: none

caps:
  awkward_layout_strategy: requires_contiguous
  fast_paths: []
  in_place: false
  alignment_bytes: 64
  access_granularity_bits: 16

cost:
  provenance: judge_measured          # hint: bandwidth-bound; n = outer*dim_size*inner; widen-add-narrow per elem
  class: reduction
  flops: "outer * dim_size * inner"
  bytes_moved: "2 * outer * dim_size * inner * 2"   # 2 bytes/bf16
  overhead_ns: ~
  memory: { device_bytes: 0, host_bytes: 0, disk_bytes: 0 }

precision:
  bit_stable_on_same_hardware: true   # fixed sequential f32 add order; narrow to bf16 on store
  max_ulp: ~
  max_relative: ~
  max_absolute: ~
  audited: true
  notes: "f32 accumulator (precision invariant): widen bf16→f32, add, narrow→bf16 on store; fixed summation order."

determinism: same_hardware_bitwise
```

---

## cumsum_f16  (running prefix sum along one dim, f16 I/O with f32 accumulator)


Running prefix sum along one dim; f16 input/output, **f32 accumulator** (load-bearing precision
invariant).

`cumsum_f16` (`byte_kernels.rs:868`) is the f16 sibling of `cumsum_bf16`: it scans `out[..,j,..] =
Σ_{t<=j} in[..,t,..]` along `dim_size` with an **f32 accumulator**, widening each f16 input to f32,
adding, and narrowing on store (`half::f16::from_f32(acc)`). The f32 accumulator is the precision
invariant. I/O dtype is f16; element count validated against `outer * dim_size * inner`. Fixed
sequential add order ⇒ bit-stable on the same hardware. Perf: bandwidth-bound (2 bytes/element I/O),
one widen-add-narrow per element.

```fkc
kernel: cumsum_f16
op_kind: CumSum
blurb: "Running prefix sum along one dim; f16 I/O with f32 accumulator (narrow on store); bit-stable on same hardware."
backend: Cpu
kernel_source: "portable-cpu"
entry_point: "fuel_cpu_backend::byte_kernels::cumsum_f16"
kernel_revision_hash: auto

accept:
  inputs:
    - name: input
      dtypes: [F16]
      layout: { contiguous: required, strided: rejected, broadcast_stride0: rejected, start_offset: rejected, reverse_strides: rejected }
      rank: any
  op_params:
    variant: CumSum
    fields:
      outer:    { kind: usize }
      dim_size: { kind: usize }
      inner:    { kind: usize }

return:
  outputs:
    - name: out
      dtype_rule: passthrough(input)        # F16 in, F16 out
      shape_rule: same_as(input)
      layout_guarantee: contiguous
      aliasing: none

caps:
  awkward_layout_strategy: requires_contiguous
  fast_paths: []
  in_place: false
  alignment_bytes: 64
  access_granularity_bits: 16

cost:
  provenance: judge_measured          # hint: bandwidth-bound; n = outer*dim_size*inner; widen-add-narrow per elem
  class: reduction
  flops: "outer * dim_size * inner"
  bytes_moved: "2 * outer * dim_size * inner * 2"   # 2 bytes/f16
  overhead_ns: ~
  memory: { device_bytes: 0, host_bytes: 0, disk_bytes: 0 }

precision:
  bit_stable_on_same_hardware: true   # fixed sequential f32 add order; narrow to f16 on store
  max_ulp: ~
  max_relative: ~
  max_absolute: ~
  audited: true
  notes: "f32 accumulator (precision invariant): widen f16→f32, add, narrow→f16 on store; fixed summation order."

determinism: same_hardware_bitwise
```