interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

branch main Branches Tags History

omega-mv / gpu / forge / hardware.om

854 lines · 22210 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
2note gpu/forge/hardware.om: FORGE physical machine descriptors, canonical SHA-256
3note digesting, V1 GB10 KAT verification, and strict physical bounds validation.
4note Ported from physics-mv (forge/forge_descriptor.{h,c}, forge/v2/forge_substrate_v2.h,
5note contracts/native-dgx-spark-draft.json).
6note Composable OM-2 library module (compose after si/directives/om2.om).
7
8note ---- Core FORGE Data Structures (all structs declared before first fn) ----
9
10struct ForgeHwId hw_id uint substrate_class uint pci_vendor uint pci_device uint rm_compute_class uint rm_sm_version uint sm_count uint warp_size uint max_warps_sm uint max_thr_cta uint max_gpr uint obs_flags uint end
11
12struct ForgeHwCap smem_cta uint smem_sm uint mem_total ulong mem_avail ulong bw_gbps f64 peak_fp32_tf f64 dtype_flags uint feature_flags uint op_flags uint max_power_w f64 max_temp_mc int max_queues uint end
13
14struct ForgeContract req_id ulong op_class uint dtype uint dim_m ulong dim_n ulong dim_k ulong batch ulong cta_req uint thr_req uint smem_req uint gpr_req uint extra_ws ulong error_kind uint req_substrate uint req_qual uint req_wave_cap uint end
15
16struct ForgeBudget lat_us f64 energy_mj f64 power_w f64 temp_mc int now_epoch_s ulong supply_uv uint end
17
18struct ForgeEnvCheck ok uint violation uint ws_bytes ulong traffic_bytes ulong flops ulong eff_ctas uint eff_thr uint waves uint arith_int f64 comp_us f64 bw_us f64 roof_us f64 est_power_w f64 est_energy_mj f64 compute_bound uint end
19
20struct ForgeProvider prov_id uint hw_id uint substrate_class uint qual_status uint error_kind uint cal_req uint cal_epoch_s ulong cal_window_s ulong cal_tmin_mc int cal_tmax_mc int fault_state uint active_queues uint lowering_kind uint end
21
22struct ForgeAdmit admitted uint status uint prov_id uint hw_id uint env_viol uint has_dig_fb uint elig_cnt uint end
23
24struct ForgePlan admitted uint status uint violation uint prov_id uint hw_id uint substrate_class uint qual_status uint lowering_kind uint tile_m uint tile_n uint tile_k uint grid_x uint grid_y uint block_x uint waves uint compute_bound uint end
25
26struct ForgeSeals plan_id ulong 4 desc_hash ulong 4 req_hash ulong 4 aegis_tok ulong 4 end
27
28note ---- Hardware Profile IDs ----
29const FG_HW_GB10_SM121 uint 1
30const FG_HW_AARCH64_GRACE uint 2
31const FG_HW_GENERIC_CPU uint 3
32const FG_HW_ANALOG_SIM uint 4
33const FG_HW_UNQUAL_GPU uint 5
34const FG_HW_OPTICAL_SIM uint 6
35
36note ---- FORGE V2 Substrate Classes (frozen numeric ids from forge_substrate_v2.h) ----
37const FG_SUB_INVALID uint 0x0000
38const FG_SUB_DIGITAL_CPU uint 0x0001
39const FG_SUB_DIGITAL_GPU uint 0x0002
40const FG_SUB_ANALOG_IN_MEMORY uint 0x0010
41const FG_SUB_NEUROMORPHIC uint 0x0020
42const FG_SUB_FPGA_CGRA uint 0x0030
43const FG_SUB_OPTICAL_PHOTONIC uint 0x0040
44const FG_SUB_RESERVED_FIRST uint 0x8000
45
46note ---- Operation Family Bitmask (forge_substrate_v2.h) ----
47const FG_OP_MATVEC uint 1
48const FG_OP_MATMUL uint 2
49const FG_OP_CONV uint 4
50const FG_OP_ELEMENTWISE uint 8
51const FG_OP_REDUCTION uint 16
52const FG_OP_SPIKE_INT uint 32
53const FG_OP_TRANSFORM uint 64
54const FG_OP_SAMPLE uint 128
55const FG_OP_GENERAL uint 256
56const FG_OP_KNOWN_MASK uint 0x1ff
57
58note ---- Precision / Dtype Bitmask ----
59const FG_DT_FP32 uint 1
60const FG_DT_FP16 uint 2
61const FG_DT_BF16 uint 4
62const FG_DT_FP8 uint 8
63const FG_DT_INT8 uint 16
64const FG_DT_INT32 uint 32
65const FG_DT_U64 uint 64
66const FG_DT_FP64 uint 128
67const FG_DT_KNOWN_MASK uint 0xff
68
69note ---- Hardware Feature Flags (forge_descriptor.h + tensor cores) ----
70const FG_FEAT_UNIFIED_MEM uint 1
71const FG_FEAT_COMPUTE_B uint 2
72const FG_FEAT_GPFIFO_A uint 4
73const FG_FEAT_USERMODE_A uint 8
74const FG_FEAT_PAGE_FAULT uint 16
75const FG_FEAT_TENSOR_CORES uint 32
76
77note ---- Hardware Validation Error Codes ----
78const FG_HWVAL_OK uint 0
79const FG_HWVAL_BAD_SUBSTRATE uint 1
80const FG_HWVAL_BAD_GEOMETRY uint 2
81const FG_HWVAL_BAD_MEMORY uint 3
82const FG_HWVAL_BAD_ROOFLINE uint 4
83const FG_HWVAL_BAD_THERMAL uint 5
84const FG_HWVAL_BAD_CAPS uint 6
85const FG_HWVAL_BAD_GB10_ID uint 7
86
87note ---- Text Constants for V1 KAT (forge_descriptor.c:456-466) ----
88text fg_kat_bdf "000f:01:00.0"
89text fg_kat_drv "580.173.02"
90text fg_kat_vbios "9a.0b.2d.00.00"
91text fg_kat_hex "10d63d05f888eaba4fe473c5f17febe22f462f543ae0c2b005a9a8e5417e09fd"
92
93note ---- Pure-Omega FIPS 180-4 SHA-256 (self-contained, stateless) ----
94
95fn fg_sha_kinit k edit uint 64 to void
96put k 0 0x428a2f98
97put k 1 0x71374491
98put k 2 0xb5c0fbcf
99put k 3 0xe9b5dba5
100put k 4 0x3956c25b
101put k 5 0x59f111f1
102put k 6 0x923f82a4
103put k 7 0xab1c5ed5
104put k 8 0xd807aa98
105put k 9 0x12835b01
106put k 10 0x243185be
107put k 11 0x550c7dc3
108put k 12 0x72be5d74
109put k 13 0x80deb1fe
110put k 14 0x9bdc06a7
111put k 15 0xc19bf174
112put k 16 0xe49b69c1
113put k 17 0xefbe4786
114put k 18 0x0fc19dc6
115put k 19 0x240ca1cc
116put k 20 0x2de92c6f
117put k 21 0x4a7484aa
118put k 22 0x5cb0a9dc
119put k 23 0x76f988da
120put k 24 0x983e5152
121put k 25 0xa831c66d
122put k 26 0xb00327c8
123put k 27 0xbf597fc7
124put k 28 0xc6e00bf3
125put k 29 0xd5a79147
126put k 30 0x06ca6351
127put k 31 0x14292967
128put k 32 0x27b70a85
129put k 33 0x2e1b2138
130put k 34 0x4d2c6dfc
131put k 35 0x53380d13
132put k 36 0x650a7354
133put k 37 0x766a0abb
134put k 38 0x81c2c92e
135put k 39 0x92722c85
136put k 40 0xa2bfe8a1
137put k 41 0xa81a664b
138put k 42 0xc24b8b70
139put k 43 0xc76c51a3
140put k 44 0xd192e819
141put k 45 0xd6990624
142put k 46 0xf40e3585
143put k 47 0x106aa070
144put k 48 0x19a4c116
145put k 49 0x1e376c08
146put k 50 0x2748774c
147put k 51 0x34b0bcb5
148put k 52 0x391c0cb3
149put k 53 0x4ed8aa4a
150put k 54 0x5b9cca4f
151put k 55 0x682e6ff3
152put k 56 0x748f82ee
153put k 57 0x78a5636f
154put k 58 0x84c87814
155put k 59 0x8cc70208
156put k 60 0x90befffa
157put k 61 0xa4506ceb
158put k 62 0xbef9a3f7
159put k 63 0xc67178f2
160ret
161end
162
163fn fg_sha_be32 b view uchar 64 off ulong to uint
164b0 = uint get b off
165b1 = uint get b add off 1
166b2 = uint get b add off 2
167b3 = uint get b add off 3
168t0 = or shl b0 24 shl b1 16
169t1 = or shl b2 8 b3
170ret or t0 t1
171end
172
173fn fg_sha_sched blk view uchar 64 w edit uint 64 to void
174for i ulong 16
175off = mul i 4
176put w i fg_sha_be32 blk off
177end
178i = ulong 16
179while lt i 64 bound 48
180x1 = get w sub i 15
181s0 = xor xor rotr x1 7 rotr x1 18 shr x1 3
182x2 = get w sub i 2
183s1 = xor xor rotr x2 17 rotr x2 19 shr x2 10
184v = add add get w sub i 16 s0 add get w sub i 7 s1
185put w i v
186i = add i 1
187end
188ret
189end
190
191fn fg_sha_t1 e uint f uint g uint h uint kw uint to uint
192s1 = xor xor rotr e 6 rotr e 11 rotr e 25
193ch = xor and e f and not e g
194ret add add add h s1 ch kw
195end
196
197fn fg_sha_t2 a uint b uint c uint to uint
198s0 = xor xor rotr a 2 rotr a 13 rotr a 22
199maj = xor xor and a b and a c and b c
200ret add s0 maj
201end
202
203fn fg_sha_round v edit uint 8 ki uint wi uint to void
204kw = add ki wi
205t1 = fg_sha_t1 get v 4 get v 5 get v 6 get v 7 kw
206t2 = fg_sha_t2 get v 0 get v 1 get v 2
207put v 7 get v 6
208put v 6 get v 5
209put v 5 get v 4
210put v 4 add get v 3 t1
211put v 3 get v 2
212put v 2 get v 1
213put v 1 get v 0
214put v 0 add t1 t2
215ret
216end
217
218fn fg_sha_compress st edit uint 8 blk view uchar 64 k view uint 64 to void
219w = new uint 64 0
220fg_sha_sched blk w
221v = new uint 8 0
222for i ulong 8
223put v i get st i
224end
225for i ulong 64
226fg_sha_round v get k i get w i
227end
228for i ulong 8
229put st i add get st i get v i
230end
231ret
232end
233
234fn fg_sha_store st view uint 8 dst edit uchar 32 to void
235for i ulong 8
236v = get st i
237off = mul i 4
238put dst off uchar and shr v 24 0xff
239put dst add off 1 uchar and shr v 16 0xff
240put dst add off 2 uchar and shr v 8 0xff
241put dst add off 3 uchar and v 0xff
242end
243ret
244end
245
246fn fg_sha256 msg view uchar * dst edit uchar 32 to void
247st = new uint 8 0
248put st 0 0x6a09e667
249put st 1 0xbb67ae85
250put st 2 0x3c6ef372
251put st 3 0xa54ff53a
252put st 4 0x510e527f
253put st 5 0x9b05688c
254put st 6 0x1f83d9ab
255put st 7 0x5be0cd19
256k = new uint 64 0
257fg_sha_kinit k
258blk = new uchar 64 0
259n = len msg
260pos = ulong 0
261while le add pos 64 n bound 256
262for j ulong 64
263put blk j get msg add pos j
264end
265fg_sha_compress st blk k
266pos = add pos 64
267end
268remn = sub n pos
269for j ulong 64
270put blk j uchar 0
271end
272j = ulong 0
273while lt j remn bound 64
274put blk j get msg add pos j
275j = add j 1
276end
277put blk remn uchar 0x80
278if ge remn 56
279fg_sha_compress st blk k
280for z ulong 64
281put blk z uchar 0
282end
283end
284bits = mul n 8
285put blk 56 uchar and shr bits 56 0xff
286put blk 57 uchar and shr bits 48 0xff
287put blk 58 uchar and shr bits 40 0xff
288put blk 59 uchar and shr bits 32 0xff
289put blk 60 uchar and shr bits 24 0xff
290put blk 61 uchar and shr bits 16 0xff
291put blk 62 uchar and shr bits 8 0xff
292put blk 63 uchar and bits 0xff
293fg_sha_compress st blk k
294fg_sha_store st dst
295ret
296end
297
298note ---- Little-Endian Serialization Helpers ----
299
300fn fg_put_u16 buf edit uchar * off ulong v uint to void
301put buf off uchar and v 0xff
302put buf add off 1 uchar and shr v 8 0xff
303ret
304end
305
306fn fg_put_u32 buf edit uchar * off ulong v uint to void
307put buf off uchar and v 0xff
308put buf add off 1 uchar and shr v 8 0xff
309put buf add off 2 uchar and shr v 16 0xff
310put buf add off 3 uchar and shr v 24 0xff
311ret
312end
313
314fn fg_put_u64 buf edit uchar * off ulong v ulong to void
315put buf off uchar and v 0xff
316put buf add off 1 uchar and shr v 8 0xff
317put buf add off 2 uchar and shr v 16 0xff
318put buf add off 3 uchar and shr v 24 0xff
319put buf add off 4 uchar and shr v 32 0xff
320put buf add off 5 uchar and shr v 40 0xff
321put buf add off 6 uchar and shr v 48 0xff
322put buf add off 7 uchar and shr v 56 0xff
323ret
324end
325
326fn fg_copy_bytes dst edit uchar * doff ulong src view uchar * n ulong to void
327i = ulong 0
328while lt i n bound 256
329put dst add doff i get src i
330i = add i 1
331end
332ret
333end
334
335fn fg_hex_nibble v uint to uchar
336if lt v 10
337ret uchar add v 48
338end
339ret uchar add sub v 10 97
340end
341
342fn fg_digest_to_hex dig view uchar 32 dst edit uchar 64 to void
343for i ulong 32
344b = uint get dig i
345put dst mul i 2 fg_hex_nibble and shr b 4 0xf
346put dst add mul i 2 1 fg_hex_nibble and b 0xf
347end
348ret
349end
350
351fn fg_bytes_eq a view uchar * b view uchar * n ulong to bool
352if lt len a n
353ret false
354end
355if lt len b n
356ret false
357end
358i = ulong 0
359while lt i n bound 256
360if ne get a i get b i
361ret false
362end
363i = add i 1
364end
365ret true
366end
367
368note ---- Physical Machine Descriptors ----
369
370fn fg_hw_load_gb10 hid edit ForgeHwId hcap edit ForgeHwCap to void
371note DGX Spark GB10 Blackwell (sm_121): 48 SMs, 6144 cores, 273 GB/s unified LPDDR5x
372put hid hw_id FG_HW_GB10_SM121
373put hid substrate_class FG_SUB_DIGITAL_GPU
374put hid pci_vendor uint 0x10de
375put hid pci_device uint 0x2e12
376put hid rm_compute_class uint 0x0000cec0
377put hid rm_sm_version uint 0x00000a04
378put hid sm_count uint 48
379put hid warp_size uint 32
380put hid max_warps_sm uint 48
381put hid max_thr_cta uint 1024
382put hid max_gpr uint 128
383put hid obs_flags uint 0x1ffff
384put hcap smem_cta uint 49152
385put hcap smem_sm uint 233472
386put hcap mem_total ulong 130660888576
387put hcap mem_avail ulong 126917984256
388put hcap bw_gbps 273.0f64
389put hcap peak_fp32_tf 31.0f64
390put hcap dtype_flags uint 0xff
391put hcap feature_flags uint 0x3f
392put hcap op_flags uint 0x1df
393put hcap max_power_w 140.0f64
394put hcap max_temp_mc int 85000
395put hcap max_queues uint 4
396ret
397end
398
399fn fg_hw_load_grace hid edit ForgeHwId hcap edit ForgeHwCap to void
400note DGX Spark Grace AArch64 CPU: 20 cores, unified LPDDR5x, no FP8 hardware
401put hid hw_id FG_HW_AARCH64_GRACE
402put hid substrate_class FG_SUB_DIGITAL_CPU
403put hid pci_vendor uint 0
404put hid pci_device uint 0
405put hid rm_compute_class uint 0
406put hid rm_sm_version uint 0
407put hid sm_count uint 20
408put hid warp_size uint 1
409put hid max_warps_sm uint 1
410put hid max_thr_cta uint 64
411put hid max_gpr uint 32
412put hid obs_flags uint 0x2800
413put hcap smem_cta uint 65536
414put hcap smem_sm uint 1048576
415put hcap mem_total ulong 130660888576
416put hcap mem_avail ulong 126917984256
417put hcap bw_gbps 180.0f64
418put hcap peak_fp32_tf 1.6f64
419put hcap dtype_flags uint 0xf7
420put hcap feature_flags uint 0x01
421put hcap op_flags uint 0x1df
422put hcap max_power_w 65.0f64
423put hcap max_temp_mc int 90000
424put hcap max_queues uint 4
425ret
426end
427
428fn fg_hw_load_generic_cpu hid edit ForgeHwId hcap edit ForgeHwCap to void
429note Generic portable AArch64/host CPU profile: 8 cores, 16 GiB RAM, no FP16/BF16/FP8
430put hid hw_id FG_HW_GENERIC_CPU
431put hid substrate_class FG_SUB_DIGITAL_CPU
432put hid pci_vendor uint 0
433put hid pci_device uint 0
434put hid rm_compute_class uint 0
435put hid rm_sm_version uint 0
436put hid sm_count uint 8
437put hid warp_size uint 1
438put hid max_warps_sm uint 1
439put hid max_thr_cta uint 32
440put hid max_gpr uint 32
441put hid obs_flags uint 0x2800
442put hcap smem_cta uint 32768
443put hcap smem_sm uint 262144
444put hcap mem_total ulong 17179869184
445put hcap mem_avail ulong 12884901888
446put hcap bw_gbps 64.0f64
447put hcap peak_fp32_tf 0.5f64
448put hcap dtype_flags uint 0xf1
449put hcap feature_flags uint 0x01
450put hcap op_flags uint 0x11b
451put hcap max_power_w 45.0f64
452put hcap max_temp_mc int 95000
453put hcap max_queues uint 2
454ret
455end
456
457fn fg_hw_load_analog_sim hid edit ForgeHwId hcap edit ForgeHwCap to void
458note FORGE V2 AR2 simulated analog in-memory matvec substrate (SIMULATED_DEVELOPMENT)
459put hid hw_id FG_HW_ANALOG_SIM
460put hid substrate_class FG_SUB_ANALOG_IN_MEMORY
461put hid pci_vendor uint 0
462put hid pci_device uint 0
463put hid rm_compute_class uint 0
464put hid rm_sm_version uint 0
465put hid sm_count uint 4
466put hid warp_size uint 1
467put hid max_warps_sm uint 1
468put hid max_thr_cta uint 64
469put hid max_gpr uint 16
470put hid obs_flags uint 0
471put hcap smem_cta uint 16384
472put hcap smem_sm uint 65536
473put hcap mem_total ulong 16777216
474put hcap mem_avail ulong 8388608
475put hcap bw_gbps 100.0f64
476put hcap peak_fp32_tf 4.0f64
477put hcap dtype_flags uint 0x70
478put hcap feature_flags uint 0
479put hcap op_flags uint 0x01
480put hcap max_power_w 15.0f64
481put hcap max_temp_mc int 70000
482put hcap max_queues uint 1
483ret
484end
485
486fn fg_hw_load_unqual_gpu hid edit ForgeHwId hcap edit ForgeHwCap to void
487note Unqualified discrete GPU profile (non-GB10, BLOCKED_HARDWARE until silicon gate)
488put hid hw_id FG_HW_UNQUAL_GPU
489put hid substrate_class FG_SUB_DIGITAL_GPU
490put hid pci_vendor uint 0x1002
491put hid pci_device uint 0x74a1
492put hid rm_compute_class uint 0
493put hid rm_sm_version uint 0
494put hid sm_count uint 64
495put hid warp_size uint 64
496put hid max_warps_sm uint 32
497put hid max_thr_cta uint 1024
498put hid max_gpr uint 256
499put hid obs_flags uint 0
500put hcap smem_cta uint 65536
501put hcap smem_sm uint 65536
502put hcap mem_total ulong 68719476736
503put hcap mem_avail ulong 64424509440
504put hcap bw_gbps 1600.0f64
505put hcap peak_fp32_tf 80.0f64
506put hcap dtype_flags uint 0xff
507put hcap feature_flags uint 0x20
508put hcap op_flags uint 0x1df
509put hcap max_power_w 350.0f64
510put hcap max_temp_mc int 85000
511put hcap max_queues uint 4
512ret
513end
514
515fn fg_hw_load_optical hid edit ForgeHwId hcap edit ForgeHwCap to void
516note Optical photonic substrate profile (NOT_RUN, no hardware qualified)
517put hid hw_id FG_HW_OPTICAL_SIM
518put hid substrate_class FG_SUB_OPTICAL_PHOTONIC
519put hid pci_vendor uint 0
520put hid pci_device uint 0
521put hid rm_compute_class uint 0
522put hid rm_sm_version uint 0
523put hid sm_count uint 4
524put hid warp_size uint 1
525put hid max_warps_sm uint 1
526put hid max_thr_cta uint 64
527put hid max_gpr uint 16
528put hid obs_flags uint 0
529put hcap smem_cta uint 16384
530put hcap smem_sm uint 65536
531put hcap mem_total ulong 16777216
532put hcap mem_avail ulong 8388608
533put hcap bw_gbps 120.0f64
534put hcap peak_fp32_tf 8.0f64
535put hcap dtype_flags uint 0x71
536put hcap feature_flags uint 0
537put hcap op_flags uint 0x03
538put hcap max_power_w 20.0f64
539put hcap max_temp_mc int 65000
540put hcap max_queues uint 1
541ret
542end
543
544fn fg_hw_load_profile pid uint hid edit ForgeHwId hcap edit ForgeHwCap to bool
545if eq pid FG_HW_GB10_SM121
546fg_hw_load_gb10 hid hcap
547ret true
548end
549if eq pid FG_HW_AARCH64_GRACE
550fg_hw_load_grace hid hcap
551ret true
552end
553if eq pid FG_HW_GENERIC_CPU
554fg_hw_load_generic_cpu hid hcap
555ret true
556end
557if eq pid FG_HW_ANALOG_SIM
558fg_hw_load_analog_sim hid hcap
559ret true
560end
561if eq pid FG_HW_UNQUAL_GPU
562fg_hw_load_unqual_gpu hid hcap
563ret true
564end
565if eq pid FG_HW_OPTICAL_SIM
566fg_hw_load_optical hid hcap
567ret true
568end
569ret false
570end
571
572note ---- Substrate Class & Alias Verification ----
573
574fn fg_sub_is_known sc uint to bool
575if eq sc FG_SUB_DIGITAL_CPU
576ret true
577end
578if eq sc FG_SUB_DIGITAL_GPU
579ret true
580end
581if eq sc FG_SUB_ANALOG_IN_MEMORY
582ret true
583end
584if eq sc FG_SUB_NEUROMORPHIC
585ret true
586end
587if eq sc FG_SUB_FPGA_CGRA
588ret true
589end
590if eq sc FG_SUB_OPTICAL_PHOTONIC
591ret true
592end
593ret false
594end
595
596fn fg_sub_is_digital sc uint to bool
597if eq sc FG_SUB_DIGITAL_CPU
598ret true
599end
600if eq sc FG_SUB_DIGITAL_GPU
601ret true
602end
603ret false
604end
605
606note Matches forge_descriptor.c:495: sm_121 derived strictly from observed RM fields
607fn fg_hw_alias_is_sm121 hid view ForgeHwId to bool
608if eq get hid rm_compute_class uint 0x0000cec0
609if eq get hid rm_sm_version uint 0x00000a04
610ret true
611end
612end
613ret false
614end
615
616note ---- Strict Physical Bounds Validation ----
617
618fn fg_hw_validate hid view ForgeHwId hcap view ForgeHwCap to uint
619sc = get hid substrate_class
620if not fg_sub_is_known sc
621ret FG_HWVAL_BAD_SUBSTRATE
622end
623if eq get hid sm_count 0
624ret FG_HWVAL_BAD_GEOMETRY
625end
626if eq get hid warp_size 0
627ret FG_HWVAL_BAD_GEOMETRY
628end
629if eq get hid max_warps_sm 0
630ret FG_HWVAL_BAD_GEOMETRY
631end
632if eq get hid max_thr_cta 0
633ret FG_HWVAL_BAD_GEOMETRY
634end
635if eq get hid max_gpr 0
636ret FG_HWVAL_BAD_GEOMETRY
637end
638mt = get hcap mem_total
639ma = get hcap mem_avail
640if eq mt 0
641ret FG_HWVAL_BAD_MEMORY
642end
643if eq ma 0
644ret FG_HWVAL_BAD_MEMORY
645end
646if gt ma mt
647ret FG_HWVAL_BAD_MEMORY
648end
649if gt get hcap smem_cta get hcap smem_sm
650ret FG_HWVAL_BAD_MEMORY
651end
652if le get hcap bw_gbps 0.0f64
653ret FG_HWVAL_BAD_ROOFLINE
654end
655if le get hcap peak_fp32_tf 0.0f64
656ret FG_HWVAL_BAD_ROOFLINE
657end
658if le get hcap max_power_w 0.0f64
659ret FG_HWVAL_BAD_THERMAL
660end
661tmc = get hcap max_temp_mc
662if le tmc 0
663ret FG_HWVAL_BAD_THERMAL
664end
665if gt tmc 125000
666ret FG_HWVAL_BAD_THERMAL
667end
668if eq get hcap dtype_flags 0
669ret FG_HWVAL_BAD_CAPS
670end
671if eq get hcap op_flags 0
672ret FG_HWVAL_BAD_CAPS
673end
674if eq get hcap max_queues 0
675ret FG_HWVAL_BAD_CAPS
676end
677if fg_hw_alias_is_sm121 hid
678if ne get hid pci_vendor uint 0x10de
679ret FG_HWVAL_BAD_GB10_ID
680end
681if ne get hid warp_size 32
682ret FG_HWVAL_BAD_GB10_ID
683end
684if gt get hid max_gpr 128
685ret FG_HWVAL_BAD_GB10_ID
686end
687end
688ret FG_HWVAL_OK
689end
690
691note ---- Canonical Hardware Descriptor Digest (SHA-256) ----
692
693fn fg_hw_digest hid view ForgeHwId hcap view ForgeHwCap dst edit uchar 32 to void
694buf = new uchar 128 0
695put buf 0 uchar 70
696put buf 1 uchar 71
697put buf 2 uchar 72
698put buf 3 uchar 87
699put buf 4 uchar 45
700put buf 5 uchar 86
701put buf 6 uchar 49
702put buf 7 uchar 0
703fg_put_u32 buf 8 get hid hw_id
704fg_put_u32 buf 12 get hid substrate_class
705fg_put_u32 buf 16 get hid pci_vendor
706fg_put_u32 buf 20 get hid pci_device
707fg_put_u32 buf 24 get hid rm_compute_class
708fg_put_u32 buf 28 get hid rm_sm_version
709fg_put_u32 buf 32 get hid sm_count
710fg_put_u32 buf 36 get hid warp_size
711fg_put_u32 buf 40 get hid max_warps_sm
712fg_put_u32 buf 44 get hid max_thr_cta
713fg_put_u32 buf 48 get hid max_gpr
714fg_put_u32 buf 52 get hid obs_flags
715fg_put_u32 buf 56 get hcap smem_cta
716fg_put_u32 buf 60 get hcap smem_sm
717fg_put_u64 buf 64 get hcap mem_total
718fg_put_u64 buf 72 get hcap mem_avail
719bw_m = ulong mul get hcap bw_gbps 1000.0f64
720fg_put_u64 buf 80 bw_m
721tf_m = ulong mul get hcap peak_fp32_tf 1000.0f64
722fg_put_u64 buf 88 tf_m
723fg_put_u32 buf 96 get hcap dtype_flags
724fg_put_u32 buf 100 get hcap feature_flags
725fg_put_u32 buf 104 get hcap op_flags
726pw_m = ulong mul get hcap max_power_w 1000.0f64
727fg_put_u64 buf 108 pw_m
728fg_put_u32 buf 116 uint get hcap max_temp_mc
729fg_put_u32 buf 120 get hcap max_queues
730fg_put_u32 buf 124 uint 0
731fg_sha256 buf dst
732ret
733end
734
735note ---- V1 GB10 208-byte Canonical Serialization Known Answer Test (KAT) ----
736note Exact match for physics-mv/forge/forge_descriptor.c:447-493
737note Expected SHA-256: 10d63d05f888eaba4fe473c5f17febe22f462f543ae0c2b005a9a8e5417e09fd
738
739fn fg_hw_v1_kat_build buf edit uchar 208 to void
740fg_put_u16 buf 0 uint 0x10de
741fg_put_u16 buf 2 uint 0x2e12
742fg_put_u16 buf 4 uint 0x10de
743fg_put_u16 buf 6 uint 0x0000
744fg_copy_bytes buf 8 fg_kat_bdf len fg_kat_bdf
745for i ulong 16
746put buf add 24 i uchar add i 1
747end
748fg_put_u32 buf 40 uint 0x0000cec0
749fg_put_u32 buf 44 uint 0x00000a04
750fg_put_u32 buf 48 uint 32
751fg_put_u32 buf 52 uint 48
752fg_put_u32 buf 56 uint 6144
753fg_put_u32 buf 60 uint 2
754fg_copy_bytes buf 64 fg_kat_drv len fg_kat_drv
755fg_copy_bytes buf 96 fg_kat_vbios len fg_kat_vbios
756fg_copy_bytes buf 128 fg_kat_drv len fg_kat_drv
757fg_put_u64 buf 160 ulong 130660888576
758fg_put_u64 buf 168 ulong 0x1ffffffffff
759fg_put_u32 buf 176 uint 4096
760fg_put_u32 buf 180 uint 1024
761fg_put_u32 buf 184 uint 49152
762fg_put_u32 buf 188 uint 0x1f
763fg_put_u32 buf 192 uint 0x1ffff
764ret
765end
766
767fn fg_hw_v1_kat to bool
768buf = new uchar 208 0
769fg_hw_v1_kat_build buf
770dig = new uchar 32 0
771fg_sha256 buf dig
772hex = new uchar 64 0
773fg_digest_to_hex dig hex
774ret fg_bytes_eq hex fg_kat_hex 64
775end
776
777note ---- Pack/Unpack 32-byte Digests <-> 4x u64 Words (for ForgeSeals) ----
778
779fn fg_pack_be64 b view uchar 32 off ulong to ulong
780r = ulong 0
781for i ulong 8
782v = ulong get b add off i
783r = or shl r 8 v
784end
785ret r
786end
787
788fn fg_unpack_be64 v ulong dst edit uchar 32 off ulong to void
789put dst off uchar and shr v 56 0xff
790put dst add off 1 uchar and shr v 48 0xff
791put dst add off 2 uchar and shr v 40 0xff
792put dst add off 3 uchar and shr v 32 0xff
793put dst add off 4 uchar and shr v 24 0xff
794put dst add off 5 uchar and shr v 16 0xff
795put dst add off 6 uchar and shr v 8 0xff
796put dst add off 7 uchar and v 0xff
797ret
798end
799
800fn fg_seals_put_plan s edit ForgeSeals d view uchar 32 to void
801for i ulong 4
802put s plan_id i fg_pack_be64 d mul i 8
803end
804ret
805end
806
807fn fg_seals_get_plan s view ForgeSeals d edit uchar 32 to void
808for i ulong 4
809fg_unpack_be64 get s plan_id i d mul i 8
810end
811ret
812end
813
814fn fg_seals_put_desc s edit ForgeSeals d view uchar 32 to void
815for i ulong 4
816put s desc_hash i fg_pack_be64 d mul i 8
817end
818ret
819end
820
821fn fg_seals_get_desc s view ForgeSeals d edit uchar 32 to void
822for i ulong 4
823fg_unpack_be64 get s desc_hash i d mul i 8
824end
825ret
826end
827
828fn fg_seals_put_req s edit ForgeSeals d view uchar 32 to void
829for i ulong 4
830put s req_hash i fg_pack_be64 d mul i 8
831end
832ret
833end
834
835fn fg_seals_get_req s view ForgeSeals d edit uchar 32 to void
836for i ulong 4
837fg_unpack_be64 get s req_hash i d mul i 8
838end
839ret
840end
841
842fn fg_seals_put_tok s edit ForgeSeals d view uchar 32 to void
843for i ulong 4
844put s aegis_tok i fg_pack_be64 d mul i 8
845end
846ret
847end
848
849fn fg_seals_get_tok s view ForgeSeals d edit uchar 32 to void
850for i ulong 4
851fg_unpack_be64 get s aegis_tok i d mul i 8
852end
853ret
854end