fuel-dispatch 0.23.0

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
---
fkc_version: 1
provider:
  name: fuel-reference-backend
  backend: Cpu                        # the reference oracle runs on the host (BackendId::Cpu)
  kernel_source: "reference-oracle"   # the BindingEntry.kernel_source tag
  link_registry: fuel_reference_backend::fkc::ENTRY_POINTS   # §12.6 symbol→KernelRef map
  revision_base: "git:f41137b4"       # provider build id, folded into kernel_revision_hash
---

# fuel-reference-backend — cast kernel contracts


Directional dtype-conversion kernels from `fuel-reference-backend/src/ops.rs` (`// ---------- dtype
casts ----------`, `ops.rs:1132-1241`). One logical `Cast` op (`OpKind::Cast`; `OpParams::Cast`
unit variant) is realized as **distinct concrete-typed directional kernels** — each (src dtype →
dst dtype) pair is its own function, **not** a generic `T`, because the input and output element
widths differ (so the output byte size differs from the input). The executor routes by the target
dtype via `eval_cast` (`exec.rs:1000`, dispatched from `Op::Cast(target)` at `exec.rs:618`); the
per-operand ordered (src, dst) dtype slots make each direction a distinct dispatch key (§12.1).

Implementation shape (all sixteen): each kernel takes a `&RefTensor<Src>`, walks its flat
contiguous slice with `x.as_slice().iter().map(|&v| <convert>(v)).collect()`, and returns a fresh
`RefTensor::from_vec(data, x.shape().clone())` of the target dtype. There is no `Layout`, no
strides, no offset, no in-place path — `RefTensor<T>` (`lib.rs:68`) is *always* a contiguous,
row-major buffer with zero offset (inventory §"Crate-wide layout invariant"). The input-layout
contract is therefore **contiguous, offset 0, row-major** for every kernel; any strided / broadcast
/ offset view must be materialized into a fresh contiguous `RefTensor` by the planner *before* the
kernel runs (the reference crate is an oracle with no internal contiguize). The output is always a
**fresh contiguous buffer**, fully written, with no input/output aliasing. Element count is
preserved across the cast; only the per-element byte width changes.

Three precision regimes appear below:

- **Lossless widening** (`max_ulp: 0`) — the source is a strict subset of the target
  (`f32→f64`, `bf16→f32`, `bf16→f64`, `f16→f32`, `f16→f64`, `u32→f64`).
- **Lossy narrowing** — a single IEEE / `half`-crate round per element
  (`f64→f32`, `f32→bf16`, `f32→f16`, `f64→bf16`, `f64→f16`, and the via-f32 `bf16→f16` / `f16→bf16`,
  whose f32 pivot leg is lossless and whose loss is on the narrowing leg only).
- **Float→uint truncation** (`f32→u32`, `f64→u32`) — `as`-cast truncation toward zero; values
  outside `[0, u32::MAX]` are out-of-range / implementation-defined and must not occur in
  well-formed graphs. `u32→f32` is exact below 2^24 and rounds above.

> **COST PROVENANCE.** Every cost block below is marked `provenance: judge_measured` — the Judge
> bootstraps these by measurement (§4.4). No author cost numbers are fabricated; the only cost
> hints carried are the derivable elementwise-bandwidth `bytes_moved` (read N×src_bytes + write
> N×dst_bytes) and `flops: "0"` (a cast does no arithmetic, only a per-element format conversion).

## cast_f32_to_f64  (f32 → f64)


Convert `f32` → `f64`. **Lossless widening** — every f32 value is exactly representable in f64.

Walks a contiguous, zero-offset, row-major `f32` slice and collects `out[i] = in[i] as f64` into a
fresh contiguous `f64` `RefTensor` (`ops.rs:1135`). Output is 2× the input byte size (8 bytes/elem
vs 4) with the same element count. The Rust `as` widening is the identity embedding f32 ⊂ f64, so it
is exact and bit-stable on the same hardware. Bandwidth-bound elementwise op: read N×4 bytes, write
N×8 bytes. Known limitation: contiguous-only — any strided/broadcast/offset operand must be
materialized first.

```fkc
kernel: cast_f32_to_f64
op_kind: Cast
blurb: "Cast f32 -> f64; contiguous; lossless widening."
backend: Cpu
kernel_source: "reference-oracle"
entry_point: "fuel_reference_backend::ops::cast_f32_to_f64"
kernel_revision_hash: auto

accept:
  inputs:
    - name: src
      dtypes: [F32]
      layout: { contiguous: required, strided: rejected, broadcast_stride0: rejected, start_offset: rejected, reverse_strides: rejected }
      rank: any
  op_params: { variant: Cast }

return:
  outputs:
    - name: out
      dtype_rule: fixed(F64)          # target dtype lives on the output Storage; key-pinned (§5.1)
      shape_rule: same_as(src)        # element count preserved
      layout_guarantee: contiguous
      aliasing: none

caps:
  awkward_layout_strategy: requires_contiguous   # planner inserts Op::Contiguize (an FKC kernel) + sums its cost
  fast_paths:
    - { when: "all_inputs_contiguous", class: cheap_elementwise }
  in_place: false
  alignment_bytes: 64
  access_granularity_bits: 8

cost:
  provenance: judge_measured          # Judge bootstraps; coefficients below are bandwidth hints
  class: cheap_elementwise
  flops: "0"                          # pure widen; no arithmetic
  bytes_moved: "n * (4 + 8)"          # read N*4 (f32) + write N*8 (f64); elementwise = bandwidth-bound
  overhead_ns: ~                      # launch cost not authored — judge_measured
  memory: { device_bytes: 0, host_bytes: "n * 8", disk_bytes: 0 }

precision:
  bit_stable_on_same_hardware: true
  max_ulp: 0                          # exact: f32 is a strict subset of f64
  max_relative: ~
  max_absolute: ~
  audited: true
  notes: "Lossless widening; f32 strictly subset of f64; exact, deterministic widen via Rust `as`."

determinism: bitwise
```

## cast_f32_to_bf16  (f32 → bf16)


Convert `f32` → `bf16`. **Lossy narrowing** — keeps the f32 exponent and the top mantissa bits.

Walks a contiguous `f32` slice and collects `out[i] = half::bf16::from_f32(in[i])` into a fresh
contiguous `bf16` `RefTensor` (`ops.rs:1141`). Output is half the input byte size (2 bytes/elem vs
4). bf16 shares f32's 8-bit exponent, so the conversion is exponent-preserving; the 23-bit f32
mantissa is rounded to bf16's 7 mantissa bits (rounding per the `half` crate's `bf16::from_f32`).
Bandwidth-bound elementwise op. Deterministic on the same hardware (a single round per element).
Contiguous-only.

```fkc
kernel: cast_f32_to_bf16
op_kind: Cast
blurb: "Cast f32 -> bf16; contiguous; lossy narrowing (keeps exponent, top mantissa)."
backend: Cpu
kernel_source: "reference-oracle"
entry_point: "fuel_reference_backend::ops::cast_f32_to_bf16"
kernel_revision_hash: auto

accept:
  inputs:
    - name: src
      dtypes: [F32]
      layout: { contiguous: required, strided: rejected, broadcast_stride0: rejected, start_offset: rejected, reverse_strides: rejected }
      rank: any
  op_params: { variant: Cast }

return:
  outputs:
    - name: out
      dtype_rule: fixed(BF16)
      shape_rule: same_as(src)
      layout_guarantee: contiguous
      aliasing: none

caps:
  awkward_layout_strategy: requires_contiguous
  fast_paths:
    - { when: "all_inputs_contiguous", class: cheap_elementwise }
  in_place: false
  alignment_bytes: 64
  access_granularity_bits: 8

cost:
  provenance: judge_measured
  class: cheap_elementwise
  flops: "0"
  bytes_moved: "n * (4 + 2)"          # read N*4 (f32) + write N*2 (bf16)
  overhead_ns: ~                      # launch cost not authored — judge_measured
  memory: { device_bytes: 0, host_bytes: "n * 2", disk_bytes: 0 }

precision:
  bit_stable_on_same_hardware: true
  max_ulp: ~
  max_relative: ~
  max_absolute: ~
  audited: true
  notes: "Lossy narrowing; preserves f32 exponent, rounds 23-bit mantissa to bf16's 7 bits via half::bf16::from_f32; deterministic per element."

determinism: same_hardware_bitwise
```

## cast_f32_to_f16  (f32 → f16)


Convert `f32` → `f16`. **Lossy narrowing** — clips to f16 range with NaN/inf preserved.

Walks a contiguous `f32` slice and collects `out[i] = half::f16::from_f32(in[i])` into a fresh
contiguous `f16` `RefTensor` (`ops.rs:1147`). Output is half the input byte size (2 bytes/elem vs
4). f16 has a 5-bit exponent and 10-bit mantissa: values exceeding f16's finite range saturate to
±inf, subnormals/zero round per the `half` crate's `f16::from_f32`, NaN is preserved. Bandwidth-bound
elementwise op. Deterministic on the same hardware. Contiguous-only.

```fkc
kernel: cast_f32_to_f16
op_kind: Cast
blurb: "Cast f32 -> f16; contiguous; lossy narrowing (clip to f16 range, NaN/inf preserved)."
backend: Cpu
kernel_source: "reference-oracle"
entry_point: "fuel_reference_backend::ops::cast_f32_to_f16"
kernel_revision_hash: auto

accept:
  inputs:
    - name: src
      dtypes: [F32]
      layout: { contiguous: required, strided: rejected, broadcast_stride0: rejected, start_offset: rejected, reverse_strides: rejected }
      rank: any
  op_params: { variant: Cast }

return:
  outputs:
    - name: out
      dtype_rule: fixed(F16)
      shape_rule: same_as(src)
      layout_guarantee: contiguous
      aliasing: none

caps:
  awkward_layout_strategy: requires_contiguous
  fast_paths:
    - { when: "all_inputs_contiguous", class: cheap_elementwise }
  in_place: false
  alignment_bytes: 64
  access_granularity_bits: 8

cost:
  provenance: judge_measured
  class: cheap_elementwise
  flops: "0"
  bytes_moved: "n * (4 + 2)"          # read N*4 (f32) + write N*2 (f16)
  overhead_ns: ~                      # launch cost not authored — judge_measured
  memory: { device_bytes: 0, host_bytes: "n * 2", disk_bytes: 0 }

precision:
  bit_stable_on_same_hardware: true
  max_ulp: ~
  max_relative: ~
  max_absolute: ~
  audited: true
  notes: "Lossy narrowing; out-of-range saturates to +/-inf, NaN preserved, rounds via half::f16::from_f32; deterministic per element."

determinism: same_hardware_bitwise
```

## cast_f64_to_f32  (f64 → f32)


Convert `f64` → `f32`. **Lossy narrowing** per IEEE-754 round-to-nearest-even.

Walks a contiguous `f64` slice and collects `out[i] = in[i] as f32` into a fresh contiguous `f32`
`RefTensor` (`ops.rs:1153`). Output is half the input byte size (4 bytes/elem vs 8). Rounding follows
the platform IEEE-754 `f64`→`f32` `as` conversion; values outside f32's range saturate to ±inf, NaN
is preserved. Bandwidth-bound elementwise op. Deterministic on the same hardware (a single round per
element). Contiguous-only.

```fkc
kernel: cast_f64_to_f32
op_kind: Cast
blurb: "Cast f64 -> f32; contiguous; lossy IEEE narrowing."
backend: Cpu
kernel_source: "reference-oracle"
entry_point: "fuel_reference_backend::ops::cast_f64_to_f32"
kernel_revision_hash: auto

accept:
  inputs:
    - name: src
      dtypes: [F64]
      layout: { contiguous: required, strided: rejected, broadcast_stride0: rejected, start_offset: rejected, reverse_strides: rejected }
      rank: any
  op_params: { variant: Cast }

return:
  outputs:
    - name: out
      dtype_rule: fixed(F32)
      shape_rule: same_as(src)
      layout_guarantee: contiguous
      aliasing: none

caps:
  awkward_layout_strategy: requires_contiguous
  fast_paths:
    - { when: "all_inputs_contiguous", class: cheap_elementwise }
  in_place: false
  alignment_bytes: 64
  access_granularity_bits: 8

cost:
  provenance: judge_measured
  class: cheap_elementwise
  flops: "0"
  bytes_moved: "n * (8 + 4)"          # read N*8 (f64) + write N*4 (f32)
  overhead_ns: ~                      # launch cost not authored — judge_measured
  memory: { device_bytes: 0, host_bytes: "n * 4", disk_bytes: 0 }

precision:
  bit_stable_on_same_hardware: true
  max_ulp: ~
  max_relative: ~
  max_absolute: ~
  audited: true
  notes: "Lossy narrowing; IEEE-754 round-to-nearest-even; overflow saturates to +/-inf, NaN preserved; deterministic single round per element."

determinism: same_hardware_bitwise
```

## cast_f64_to_bf16  (f64 → bf16)


Convert `f64` → `bf16`. **Lossy narrowing** — double-precision down to bf16's 8-bit exp / 7-bit mantissa.

Walks a contiguous `f64` slice and collects `out[i] = half::bf16::from_f64(in[i])` into a fresh
contiguous `bf16` `RefTensor` (`ops.rs:1159`). Output is one quarter the input byte size (2 bytes/elem
vs 8). The conversion is a single `half::bf16::from_f64` round per element: bf16's exponent range
covers f64's normal range so large magnitudes saturate to ±inf, and the f64 mantissa is rounded to
bf16's 7 bits, NaN preserved. Bandwidth-bound elementwise op. Deterministic on the same hardware.
Contiguous-only.

```fkc
kernel: cast_f64_to_bf16
op_kind: Cast
blurb: "Cast f64 -> bf16; contiguous; lossy narrowing (single round)."
backend: Cpu
kernel_source: "reference-oracle"
entry_point: "fuel_reference_backend::ops::cast_f64_to_bf16"
kernel_revision_hash: auto

accept:
  inputs:
    - name: src
      dtypes: [F64]
      layout: { contiguous: required, strided: rejected, broadcast_stride0: rejected, start_offset: rejected, reverse_strides: rejected }
      rank: any
  op_params: { variant: Cast }

return:
  outputs:
    - name: out
      dtype_rule: fixed(BF16)
      shape_rule: same_as(src)
      layout_guarantee: contiguous
      aliasing: none

caps:
  awkward_layout_strategy: requires_contiguous
  fast_paths:
    - { when: "all_inputs_contiguous", class: cheap_elementwise }
  in_place: false
  alignment_bytes: 64
  access_granularity_bits: 8

cost:
  provenance: judge_measured
  class: cheap_elementwise
  flops: "0"
  bytes_moved: "n * (8 + 2)"          # read N*8 (f64) + write N*2 (bf16)
  overhead_ns: ~                      # launch cost not authored — judge_measured
  memory: { device_bytes: 0, host_bytes: "n * 2", disk_bytes: 0 }

precision:
  bit_stable_on_same_hardware: true
  max_ulp: ~
  max_relative: ~
  max_absolute: ~
  audited: true
  notes: "Lossy narrowing; single half::bf16::from_f64 round per element; overflow saturates to +/-inf, NaN preserved; deterministic."

determinism: same_hardware_bitwise
```

## cast_f64_to_f16  (f64 → f16)


Convert `f64` → `f16`. **Lossy narrowing** — double-precision down to f16's 5-bit exp / 10-bit mantissa.

Walks a contiguous `f64` slice and collects `out[i] = half::f16::from_f64(in[i])` into a fresh
contiguous `f16` `RefTensor` (`ops.rs:1165`). Output is one quarter the input byte size (2 bytes/elem
vs 8). A single `half::f16::from_f64` round per element: f16's narrow finite range means most
large-magnitude f64 values saturate to ±inf, the f64 mantissa rounds to f16's 10 bits, NaN
preserved. Bandwidth-bound elementwise op. Deterministic on the same hardware. Contiguous-only.

```fkc
kernel: cast_f64_to_f16
op_kind: Cast
blurb: "Cast f64 -> f16; contiguous; lossy narrowing (single round)."
backend: Cpu
kernel_source: "reference-oracle"
entry_point: "fuel_reference_backend::ops::cast_f64_to_f16"
kernel_revision_hash: auto

accept:
  inputs:
    - name: src
      dtypes: [F64]
      layout: { contiguous: required, strided: rejected, broadcast_stride0: rejected, start_offset: rejected, reverse_strides: rejected }
      rank: any
  op_params: { variant: Cast }

return:
  outputs:
    - name: out
      dtype_rule: fixed(F16)
      shape_rule: same_as(src)
      layout_guarantee: contiguous
      aliasing: none

caps:
  awkward_layout_strategy: requires_contiguous
  fast_paths:
    - { when: "all_inputs_contiguous", class: cheap_elementwise }
  in_place: false
  alignment_bytes: 64
  access_granularity_bits: 8

cost:
  provenance: judge_measured
  class: cheap_elementwise
  flops: "0"
  bytes_moved: "n * (8 + 2)"          # read N*8 (f64) + write N*2 (f16)
  overhead_ns: ~                      # launch cost not authored — judge_measured
  memory: { device_bytes: 0, host_bytes: "n * 2", disk_bytes: 0 }

precision:
  bit_stable_on_same_hardware: true
  max_ulp: ~
  max_relative: ~
  max_absolute: ~
  audited: true
  notes: "Lossy narrowing; single half::f16::from_f64 round per element; out-of-range saturates to +/-inf, NaN preserved; deterministic."

determinism: same_hardware_bitwise
```

## cast_bf16_to_f32  (bf16 → f32)


Convert `bf16` → `f32`. **Lossless widening** — bf16 is a strict subset of f32.

Walks a contiguous `bf16` slice and collects `out[i] = in[i].to_f32()` into a fresh contiguous `f32`
`RefTensor` (`ops.rs:1171`). Output is 2× the input byte size (4 bytes/elem vs 2). bf16 shares f32's
exponent and is a 16-bit truncation of f32, so every bf16 value is exactly representable in f32 — the
conversion is exact. Bandwidth-bound elementwise op. Bit-stable on the same hardware. Contiguous-only.

```fkc
kernel: cast_bf16_to_f32
op_kind: Cast
blurb: "Cast bf16 -> f32; contiguous; lossless widening."
backend: Cpu
kernel_source: "reference-oracle"
entry_point: "fuel_reference_backend::ops::cast_bf16_to_f32"
kernel_revision_hash: auto

accept:
  inputs:
    - name: src
      dtypes: [BF16]
      layout: { contiguous: required, strided: rejected, broadcast_stride0: rejected, start_offset: rejected, reverse_strides: rejected }
      rank: any
  op_params: { variant: Cast }

return:
  outputs:
    - name: out
      dtype_rule: fixed(F32)
      shape_rule: same_as(src)
      layout_guarantee: contiguous
      aliasing: none

caps:
  awkward_layout_strategy: requires_contiguous
  fast_paths:
    - { when: "all_inputs_contiguous", class: cheap_elementwise }
  in_place: false
  alignment_bytes: 64
  access_granularity_bits: 8

cost:
  provenance: judge_measured
  class: cheap_elementwise
  flops: "0"
  bytes_moved: "n * (2 + 4)"          # read N*2 (bf16) + write N*4 (f32)
  overhead_ns: ~                      # launch cost not authored — judge_measured
  memory: { device_bytes: 0, host_bytes: "n * 4", disk_bytes: 0 }

precision:
  bit_stable_on_same_hardware: true
  max_ulp: 0                          # exact: bf16 strict subset of f32
  max_relative: ~
  max_absolute: ~
  audited: true
  notes: "Lossless widening; bf16 strict subset of f32 (16-bit truncation widened back); exact, deterministic."

determinism: bitwise
```

## cast_bf16_to_f64  (bf16 → f64)


Convert `bf16` → `f64`. **Lossless widening** — bf16 is a strict subset of f64.

Walks a contiguous `bf16` slice and collects `out[i] = in[i].to_f64()` into a fresh contiguous `f64`
`RefTensor` (`ops.rs:1177`). Output is 4× the input byte size (8 bytes/elem vs 2). bf16's exponent
and mantissa both fit within f64, so every bf16 value is exactly representable in f64 — the
conversion is exact. Bandwidth-bound elementwise op. Bit-stable on the same hardware. Contiguous-only.

```fkc
kernel: cast_bf16_to_f64
op_kind: Cast
blurb: "Cast bf16 -> f64; contiguous; lossless widening."
backend: Cpu
kernel_source: "reference-oracle"
entry_point: "fuel_reference_backend::ops::cast_bf16_to_f64"
kernel_revision_hash: auto

accept:
  inputs:
    - name: src
      dtypes: [BF16]
      layout: { contiguous: required, strided: rejected, broadcast_stride0: rejected, start_offset: rejected, reverse_strides: rejected }
      rank: any
  op_params: { variant: Cast }

return:
  outputs:
    - name: out
      dtype_rule: fixed(F64)
      shape_rule: same_as(src)
      layout_guarantee: contiguous
      aliasing: none

caps:
  awkward_layout_strategy: requires_contiguous
  fast_paths:
    - { when: "all_inputs_contiguous", class: cheap_elementwise }
  in_place: false
  alignment_bytes: 64
  access_granularity_bits: 8

cost:
  provenance: judge_measured
  class: cheap_elementwise
  flops: "0"
  bytes_moved: "n * (2 + 8)"          # read N*2 (bf16) + write N*8 (f64)
  overhead_ns: ~                      # launch cost not authored — judge_measured
  memory: { device_bytes: 0, host_bytes: "n * 8", disk_bytes: 0 }

precision:
  bit_stable_on_same_hardware: true
  max_ulp: 0                          # exact: bf16 strict subset of f64
  max_relative: ~
  max_absolute: ~
  audited: true
  notes: "Lossless widening; bf16 exponent+mantissa fit f64; exact, deterministic via half::bf16::to_f64."

determinism: bitwise
```

## cast_bf16_to_f16  (bf16 → f16, via f32)


Convert `bf16` → `f16`. **Lossy** (different mantissa/exponent layouts); routes through f32.

Walks a contiguous `bf16` slice and collects `out[i] = half::f16::from_f32(in[i].to_f32())` into a
fresh contiguous `f16` `RefTensor` (`ops.rs:1184`). Same byte size in and out (2 bytes/elem). The
two-leg pivot first widens bf16→f32 (exact, bf16 ⊂ f32) then narrows f32→f16 (lossy: bf16's wider
8-bit exponent does not fit f16's 5-bit exponent, so large magnitudes saturate to ±inf, and the
mantissa is re-rounded). Only the second leg loses precision; NaN preserved. Bandwidth-bound
elementwise op. Deterministic on the same hardware. Contiguous-only.

```fkc
kernel: cast_bf16_to_f16
op_kind: Cast
blurb: "Cast bf16 -> f16 via f32; contiguous; lossy on the f16 leg (exponent does not fit)."
backend: Cpu
kernel_source: "reference-oracle"
entry_point: "fuel_reference_backend::ops::cast_bf16_to_f16"
kernel_revision_hash: auto

accept:
  inputs:
    - name: src
      dtypes: [BF16]
      layout: { contiguous: required, strided: rejected, broadcast_stride0: rejected, start_offset: rejected, reverse_strides: rejected }
      rank: any
  op_params: { variant: Cast }

return:
  outputs:
    - name: out
      dtype_rule: fixed(F16)
      shape_rule: same_as(src)
      layout_guarantee: contiguous
      aliasing: none

caps:
  awkward_layout_strategy: requires_contiguous
  fast_paths:
    - { when: "all_inputs_contiguous", class: cheap_elementwise }
  in_place: false
  alignment_bytes: 64
  access_granularity_bits: 8

cost:
  provenance: judge_measured
  class: cheap_elementwise
  flops: "0"
  bytes_moved: "n * (2 + 2)"          # read N*2 (bf16) + write N*2 (f16)
  overhead_ns: ~                      # launch cost not authored — judge_measured
  memory: { device_bytes: 0, host_bytes: "n * 2", disk_bytes: 0 }

precision:
  bit_stable_on_same_hardware: true
  max_ulp: ~
  max_relative: ~
  max_absolute: ~
  audited: true
  notes: "Two-leg pivot bf16->f32 (lossless, bf16 subset of f32) then f32->f16 (lossy: bf16's 8-bit exponent does not fit f16's 5-bit; saturates to +/-inf, re-rounds mantissa); NaN preserved; deterministic per element."

determinism: same_hardware_bitwise
```

## cast_f16_to_f32  (f16 → f32)


Convert `f16` → `f32`. **Lossless widening** — f16 is a strict subset of f32.

Walks a contiguous `f16` slice and collects `out[i] = in[i].to_f32()` into a fresh contiguous `f32`
`RefTensor` (`ops.rs:1194`). Output is 2× the input byte size (4 bytes/elem vs 2). Every f16 value
(finite, subnormal, inf, NaN) is exactly representable in f32, so the conversion is exact.
Bandwidth-bound elementwise op. Bit-stable on the same hardware. Contiguous-only.

```fkc
kernel: cast_f16_to_f32
op_kind: Cast
blurb: "Cast f16 -> f32; contiguous; lossless widening."
backend: Cpu
kernel_source: "reference-oracle"
entry_point: "fuel_reference_backend::ops::cast_f16_to_f32"
kernel_revision_hash: auto

accept:
  inputs:
    - name: src
      dtypes: [F16]
      layout: { contiguous: required, strided: rejected, broadcast_stride0: rejected, start_offset: rejected, reverse_strides: rejected }
      rank: any
  op_params: { variant: Cast }

return:
  outputs:
    - name: out
      dtype_rule: fixed(F32)
      shape_rule: same_as(src)
      layout_guarantee: contiguous
      aliasing: none

caps:
  awkward_layout_strategy: requires_contiguous
  fast_paths:
    - { when: "all_inputs_contiguous", class: cheap_elementwise }
  in_place: false
  alignment_bytes: 64
  access_granularity_bits: 8

cost:
  provenance: judge_measured
  class: cheap_elementwise
  flops: "0"
  bytes_moved: "n * (2 + 4)"          # read N*2 (f16) + write N*4 (f32)
  overhead_ns: ~                      # launch cost not authored — judge_measured
  memory: { device_bytes: 0, host_bytes: "n * 4", disk_bytes: 0 }

precision:
  bit_stable_on_same_hardware: true
  max_ulp: 0                          # exact: f16 strict subset of f32
  max_relative: ~
  max_absolute: ~
  audited: true
  notes: "Lossless widening; every f16 value exactly representable in f32; exact, deterministic."

determinism: bitwise
```

## cast_f16_to_f64  (f16 → f64)


Convert `f16` → `f64`. **Lossless widening** — f16 is a strict subset of f64.

Walks a contiguous `f16` slice and collects `out[i] = in[i].to_f64()` into a fresh contiguous `f64`
`RefTensor` (`ops.rs:1200`). Output is 4× the input byte size (8 bytes/elem vs 2). f16's exponent and
mantissa both fit within f64, so every f16 value is exactly representable in f64 — the conversion is
exact. Bandwidth-bound elementwise op. Bit-stable on the same hardware. Contiguous-only.

```fkc
kernel: cast_f16_to_f64
op_kind: Cast
blurb: "Cast f16 -> f64; contiguous; lossless widening."
backend: Cpu
kernel_source: "reference-oracle"
entry_point: "fuel_reference_backend::ops::cast_f16_to_f64"
kernel_revision_hash: auto

accept:
  inputs:
    - name: src
      dtypes: [F16]
      layout: { contiguous: required, strided: rejected, broadcast_stride0: rejected, start_offset: rejected, reverse_strides: rejected }
      rank: any
  op_params: { variant: Cast }

return:
  outputs:
    - name: out
      dtype_rule: fixed(F64)
      shape_rule: same_as(src)
      layout_guarantee: contiguous
      aliasing: none

caps:
  awkward_layout_strategy: requires_contiguous
  fast_paths:
    - { when: "all_inputs_contiguous", class: cheap_elementwise }
  in_place: false
  alignment_bytes: 64
  access_granularity_bits: 8

cost:
  provenance: judge_measured
  class: cheap_elementwise
  flops: "0"
  bytes_moved: "n * (2 + 8)"          # read N*2 (f16) + write N*8 (f64)
  overhead_ns: ~                      # launch cost not authored — judge_measured
  memory: { device_bytes: 0, host_bytes: "n * 8", disk_bytes: 0 }

precision:
  bit_stable_on_same_hardware: true
  max_ulp: 0                          # exact: f16 strict subset of f64
  max_relative: ~
  max_absolute: ~
  audited: true
  notes: "Lossless widening; f16 exponent+mantissa fit f64; exact, deterministic via half::f16::to_f64."

determinism: bitwise
```

## cast_f16_to_bf16  (f16 → bf16, via f32)


Convert `f16` → `bf16`. **Lossy** (different mantissa/exponent layouts); routes through f32.

Walks a contiguous `f16` slice and collects `out[i] = half::bf16::from_f32(in[i].to_f32())` into a
fresh contiguous `bf16` `RefTensor` (`ops.rs:1206`). Same byte size in and out (2 bytes/elem). The
two-leg pivot first widens f16→f32 (exact, f16 ⊂ f32) then narrows f32→bf16 (lossy: bf16's 7-bit
mantissa is narrower than f16's 10-bit, so the mantissa is re-rounded; bf16's wider exponent fully
covers f16's range). Only the second leg loses precision; NaN preserved. Bandwidth-bound elementwise
op. Deterministic on the same hardware. Contiguous-only.

```fkc
kernel: cast_f16_to_bf16
op_kind: Cast
blurb: "Cast f16 -> bf16 via f32; contiguous; lossy on the bf16 leg (mantissa re-rounded)."
backend: Cpu
kernel_source: "reference-oracle"
entry_point: "fuel_reference_backend::ops::cast_f16_to_bf16"
kernel_revision_hash: auto

accept:
  inputs:
    - name: src
      dtypes: [F16]
      layout: { contiguous: required, strided: rejected, broadcast_stride0: rejected, start_offset: rejected, reverse_strides: rejected }
      rank: any
  op_params: { variant: Cast }

return:
  outputs:
    - name: out
      dtype_rule: fixed(BF16)
      shape_rule: same_as(src)
      layout_guarantee: contiguous
      aliasing: none

caps:
  awkward_layout_strategy: requires_contiguous
  fast_paths:
    - { when: "all_inputs_contiguous", class: cheap_elementwise }
  in_place: false
  alignment_bytes: 64
  access_granularity_bits: 8

cost:
  provenance: judge_measured
  class: cheap_elementwise
  flops: "0"
  bytes_moved: "n * (2 + 2)"          # read N*2 (f16) + write N*2 (bf16)
  overhead_ns: ~                      # launch cost not authored — judge_measured
  memory: { device_bytes: 0, host_bytes: "n * 2", disk_bytes: 0 }

precision:
  bit_stable_on_same_hardware: true
  max_ulp: ~
  max_relative: ~
  max_absolute: ~
  audited: true
  notes: "Two-leg pivot f16->f32 (lossless, f16 subset of f32) then f32->bf16 (lossy: bf16's 7-bit mantissa narrower than f16's 10-bit, re-rounds; bf16 exponent covers f16 range); NaN preserved; deterministic per element."

determinism: same_hardware_bitwise
```

## cast_u32_to_f32  (u32 → f32)


Convert `u32` → `f32`. **Exact below 2^24**, rounds above (f32 has a 24-bit mantissa).

Walks a contiguous `u32` slice and collects `out[i] = in[i] as f32` into a fresh contiguous `f32`
`RefTensor` (`ops.rs:1218`). Same byte size in and out (4 bytes/elem). Integers below 2^24 round-trip
exactly (small label indices and counts are always lossless); values at or above 2^24 are rounded to
the nearest representable f32 per IEEE round-to-nearest-even. Bandwidth-bound elementwise op.
Deterministic on the same hardware. Contiguous-only.

```fkc
kernel: cast_u32_to_f32
op_kind: Cast
blurb: "Cast u32 -> f32; contiguous; exact below 2^24, rounds above."
backend: Cpu
kernel_source: "reference-oracle"
entry_point: "fuel_reference_backend::ops::cast_u32_to_f32"
kernel_revision_hash: auto

accept:
  inputs:
    - name: src
      dtypes: [U32]
      layout: { contiguous: required, strided: rejected, broadcast_stride0: rejected, start_offset: rejected, reverse_strides: rejected }
      rank: any
  op_params: { variant: Cast }

return:
  outputs:
    - name: out
      dtype_rule: fixed(F32)
      shape_rule: same_as(src)
      layout_guarantee: contiguous
      aliasing: none

caps:
  awkward_layout_strategy: requires_contiguous
  fast_paths:
    - { when: "all_inputs_contiguous", class: cheap_elementwise }
  in_place: false
  alignment_bytes: 64
  access_granularity_bits: 8

cost:
  provenance: judge_measured
  class: cheap_elementwise
  flops: "0"
  bytes_moved: "n * (4 + 4)"          # read N*4 (u32) + write N*4 (f32)
  overhead_ns: ~                      # launch cost not authored — judge_measured
  memory: { device_bytes: 0, host_bytes: "n * 4", disk_bytes: 0 }

precision:
  bit_stable_on_same_hardware: true
  max_ulp: ~                          # exact below 2^24; >=2^24 rounds (not a strict 0-ULP claim)
  max_relative: ~
  max_absolute: ~
  audited: true
  notes: "Integer->float; exact for u32 values < 2^24 (f32 24-bit mantissa); values >= 2^24 round to nearest representable f32 (IEEE round-to-nearest-even); deterministic."

determinism: same_hardware_bitwise
```

## cast_u32_to_f64  (u32 → f64)


Convert `u32` → `f64`. **Lossless** — f64's 53-bit mantissa covers the full u32 range exactly.

Walks a contiguous `u32` slice and collects `out[i] = in[i] as f64` into a fresh contiguous `f64`
`RefTensor` (`ops.rs:1224`). Output is 2× the input byte size (8 bytes/elem vs 4). Every u32 value
fits within f64's 53-bit mantissa, so the conversion is exact across the entire u32 range.
Bandwidth-bound elementwise op. Bit-stable on the same hardware. Contiguous-only.

```fkc
kernel: cast_u32_to_f64
op_kind: Cast
blurb: "Cast u32 -> f64; contiguous; lossless (full u32 range exact)."
backend: Cpu
kernel_source: "reference-oracle"
entry_point: "fuel_reference_backend::ops::cast_u32_to_f64"
kernel_revision_hash: auto

accept:
  inputs:
    - name: src
      dtypes: [U32]
      layout: { contiguous: required, strided: rejected, broadcast_stride0: rejected, start_offset: rejected, reverse_strides: rejected }
      rank: any
  op_params: { variant: Cast }

return:
  outputs:
    - name: out
      dtype_rule: fixed(F64)
      shape_rule: same_as(src)
      layout_guarantee: contiguous
      aliasing: none

caps:
  awkward_layout_strategy: requires_contiguous
  fast_paths:
    - { when: "all_inputs_contiguous", class: cheap_elementwise }
  in_place: false
  alignment_bytes: 64
  access_granularity_bits: 8

cost:
  provenance: judge_measured
  class: cheap_elementwise
  flops: "0"
  bytes_moved: "n * (4 + 8)"          # read N*4 (u32) + write N*8 (f64)
  overhead_ns: ~                      # launch cost not authored — judge_measured
  memory: { device_bytes: 0, host_bytes: "n * 8", disk_bytes: 0 }

precision:
  bit_stable_on_same_hardware: true
  max_ulp: 0                          # exact: full u32 range fits f64's 53-bit mantissa
  max_relative: ~
  max_absolute: ~
  audited: true
  notes: "Integer->float; lossless across the full u32 range (f64 53-bit mantissa covers u32); exact, deterministic."

determinism: bitwise
```

## cast_f32_to_u32  (f32 → u32)


Convert `f32` → `u32` via **truncation toward zero**. Out-of-range values are implementation-defined.

Walks a contiguous `f32` slice and collects `out[i] = in[i] as u32` into a fresh contiguous `u32`
`RefTensor` (`ops.rs:1232`). Same byte size in and out (4 bytes/elem). The Rust `as` float→int cast
truncates toward zero (drops the fractional part). Values outside `[0, u32::MAX]` produce
implementation-defined results and must not occur in well-formed graphs (Rust `as` saturates NaN→0
and clamps out-of-range, but the contract treats out-of-range as a caller error per the inventory's
"out-of-range UB" note). Bandwidth-bound elementwise op. Deterministic on the same hardware.
Contiguous-only.

```fkc
kernel: cast_f32_to_u32
op_kind: Cast
blurb: "Cast f32 -> u32; contiguous; trunc-toward-zero (out-of-range is caller error)."
backend: Cpu
kernel_source: "reference-oracle"
entry_point: "fuel_reference_backend::ops::cast_f32_to_u32"
kernel_revision_hash: auto

accept:
  inputs:
    - name: src
      dtypes: [F32]
      layout: { contiguous: required, strided: rejected, broadcast_stride0: rejected, start_offset: rejected, reverse_strides: rejected }
      rank: any
  op_params: { variant: Cast }

return:
  outputs:
    - name: out
      dtype_rule: fixed(U32)
      shape_rule: same_as(src)
      layout_guarantee: contiguous
      aliasing: none

caps:
  awkward_layout_strategy: requires_contiguous
  fast_paths:
    - { when: "all_inputs_contiguous", class: cheap_elementwise }
  in_place: false
  alignment_bytes: 64
  access_granularity_bits: 8

cost:
  provenance: judge_measured
  class: cheap_elementwise
  flops: "0"
  bytes_moved: "n * (4 + 4)"          # read N*4 (f32) + write N*4 (u32)
  overhead_ns: ~                      # launch cost not authored — judge_measured
  memory: { device_bytes: 0, host_bytes: "n * 4", disk_bytes: 0 }

precision:
  bit_stable_on_same_hardware: true
  max_ulp: ~                          # integer result; truncation toward zero (not a ULP claim)
  max_relative: ~
  max_absolute: ~
  audited: true
  notes: "Float->uint truncation toward zero (drops fractional part); values outside [0, u32::MAX] are out-of-range/caller-error (must not occur in well-formed graphs); deterministic per element."

determinism: same_hardware_bitwise
```

## cast_f64_to_u32  (f64 → u32)


Convert `f64` → `u32` via **truncation toward zero**. Out-of-range values are implementation-defined.

Walks a contiguous `f64` slice and collects `out[i] = in[i] as u32` into a fresh contiguous `u32`
`RefTensor` (`ops.rs:1238`). Output is half the input byte size (4 bytes/elem vs 8). The Rust `as`
float→int cast truncates toward zero. Values outside `[0, u32::MAX]` produce implementation-defined
results and must not occur in well-formed graphs (per the inventory's "trunc-toward-zero" note).
Bandwidth-bound elementwise op. Deterministic on the same hardware. Contiguous-only.

```fkc
kernel: cast_f64_to_u32
op_kind: Cast
blurb: "Cast f64 -> u32; contiguous; trunc-toward-zero (out-of-range is caller error)."
backend: Cpu
kernel_source: "reference-oracle"
entry_point: "fuel_reference_backend::ops::cast_f64_to_u32"
kernel_revision_hash: auto

accept:
  inputs:
    - name: src
      dtypes: [F64]
      layout: { contiguous: required, strided: rejected, broadcast_stride0: rejected, start_offset: rejected, reverse_strides: rejected }
      rank: any
  op_params: { variant: Cast }

return:
  outputs:
    - name: out
      dtype_rule: fixed(U32)
      shape_rule: same_as(src)
      layout_guarantee: contiguous
      aliasing: none

caps:
  awkward_layout_strategy: requires_contiguous
  fast_paths:
    - { when: "all_inputs_contiguous", class: cheap_elementwise }
  in_place: false
  alignment_bytes: 64
  access_granularity_bits: 8

cost:
  provenance: judge_measured
  class: cheap_elementwise
  flops: "0"
  bytes_moved: "n * (8 + 4)"          # read N*8 (f64) + write N*4 (u32)
  overhead_ns: ~                      # launch cost not authored — judge_measured
  memory: { device_bytes: 0, host_bytes: "n * 4", disk_bytes: 0 }

precision:
  bit_stable_on_same_hardware: true
  max_ulp: ~                          # integer result; truncation toward zero (not a ULP claim)
  max_relative: ~
  max_absolute: ~
  audited: true
  notes: "Float->uint truncation toward zero (drops fractional part); values outside [0, u32::MAX] are out-of-range/caller-error (must not occur in well-formed graphs); deterministic per element."

determinism: same_hardware_bitwise
```