interplane.Get Omega
Read in your language

yang

This project has not described itself yet.

Brought by drakestapleton

branch main Branches Tags History

yang / src / ufbi_check3_gb10.om

680 lines · 13323 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note src/ufbi_check3_gb10.om: Pure Seeded-OM-2 Zero-CUDA GB10 Runner for UFBI Check #3
3note (4D SU(2) Adversarial Twisted-Collar Search: Creutz Calibration Oracle +
4note Trickster Collar Zoo + Evolutionary Mutations + Held-Out Independent-Seed Judge).
5note
6note Composed after:
7note gpu/nvidia/native/nvrm/context.om
8note gpu/nvidia/native/blackwell/vector.om
9note gpu/nvidia/native/blackwell/launch.om
10note gpu/nvidia/native/blackwell/batch.om
11note om/encoder/bw_enc_sm121.om
12note src/ufbi_math.om
13note src/ufbi_check3_kernels.om
14
15note Per-collar measurement time series (up to 400 sweeps x 4 observables)
16note obs: 0=P1x1_int, 1=W1x2_int, 2=AdjP_int, 3=W2x2_int
17global tsData f64 1600
18global baseMean f64 4
19global baseStd f64 4
20global curMean f64 4
21global curErr f64 4
22global curZ f64 4
23
24text tC3Hdr "=== UFBI CHECK #3: 4D SU(2) ADVERSARIAL TWISTED-COLLAR SEARCH (PURE OM-2 ZERO-CUDA GB10) ===\n"
25text tC3Err "FAIL: GB10 native NVRM/kernel error stage="
26text tC3CalOk "ORACLE_SU2_CREUTZ_L8_B230: PASS <P>="
27text tC3CalBad "ORACLE_SU2_CREUTZ_L8_B230: FAIL <P>="
28text tC3CalRef " (published_ref=0.6023 err="
29text tC3Rp ")\n"
30text tC3Cols "stage\tL\tbeta\tcollar\tsweeps\tP1x1\tP1x1_err\tdP_Z\tW1x2\tdW1x2_Z\tAdjP\tdAdj_Z\tW2x2\tdW2x2_Z\tmax_Z\tus_total\n"
31text tTab "\t"
32text tNl "\n"
33text tS1 "screen"
34text tS2 "heldout"
35text tK0 "C0_cold"
36text tK1 "C1_z2_vortex"
37text tK2 "C2_z2_dual"
38text tK3 "C3_hot_haar"
39text tK4 "C4_frust_chk"
40text tK5 "C5_nonab_twist"
41text tK6 "C6_trick_vort"
42text tK7 "C7_trick_mut"
43text tC3Done "CHECK3_GB10_DONE status=PASS\n"
44
45note Build 4D periodic neighbor table on host & upload to dNbSite
46fn coordIdx c0 ulong c1 ulong c2 ulong c3 ulong L ulong to ulong
47r = add mul c0 L c1
48r = add mul r L c2
49ret add mul r L c3
50end
51
52fn buildNbTable L ulong to bool
53N = mul mul L L mul L L
54for s ulong N bound 65536
55c3 = rem s L
56t = div s L
57c2 = rem t L
58t = div t L
59c1 = rem t L
60c0 = div t L
61b = mul s 8
62put hNb b uint coordIdx rem add c0 1 L c1 c2 c3 L
63put hNb add b 1 uint coordIdx rem add c0 sub L 1 L c1 c2 c3 L
64put hNb add b 2 uint coordIdx c0 rem add c1 1 L c2 c3 L
65put hNb add b 3 uint coordIdx c0 rem add c1 sub L 1 L c2 c3 L
66put hNb add b 4 uint coordIdx c0 c1 rem add c2 1 L c3 L
67put hNb add b 5 uint coordIdx c0 c1 rem add c2 sub L 1 L c3 L
68put hNb add b 6 uint coordIdx c0 c1 c2 rem add c3 1 L L
69put hNb add b 7 uint coordIdx c0 c1 c2 rem add c3 sub L 1 L L
70end
71totalW = mul N 8
72off = ulong 0
73while lt off totalW bound 64
74cnt = sub totalW off
75if gt cnt 16384
76cnt = ulong 16384
77end
78for k ulong cnt bound 16384
79stageU32 k get hNb add off k
80end
81if not flushStage get dNbSite 0 mul off 4 cnt
82ret false
83end
84off = add off cnt
85end
86ret true
87end
88
89fn isBdryL s ulong L ulong to bool
90c3 = rem s L
91t = div s L
92c2 = rem t L
93t = div t L
94c1 = rem t L
95c0 = div t L
96lm1 = sub L 1
97if or eq c0 0 eq c0 lm1
98ret true
99end
100if or eq c1 0 eq c1 lm1
101ret true
102end
103if or eq c2 0 eq c2 lm1
104ret true
105end
106if or eq c3 0 eq c3 lm1
107ret true
108end
109ret false
110end
111
112fn isIntL s ulong L ulong to bool
113lo = div L 4
114hi = sub L lo
115c3 = rem s L
116t = div s L
117c2 = rem t L
118t = div t L
119c1 = rem t L
120c0 = div t L
121if or lt c0 lo ge c0 hi
122ret false
123end
124if or lt c1 lo ge c1 hi
125ret false
126end
127if or lt c2 lo ge c2 hi
128ret false
129end
130if or lt c3 lo ge c3 hi
131ret false
132end
133ret true
134end
135
136fn siteFlag s ulong L ulong freezeCollar bool to uint
137if and freezeCollar isBdryL s L
138ret uint 2
139end
140c3 = rem s L
141t = div s L
142c2 = rem t L
143t = div t L
144c1 = rem t L
145c0 = div t L
146ret uint and add add c0 c1 add c2 c3 1
147end
148
149fn buildFlags L ulong freezeCollar bool to bool
150N = mul mul L L mul L L
151totalW = mul N 4
152off = ulong 0
153while lt off totalW bound 32
154cnt = sub totalW off
155if gt cnt 16384
156cnt = ulong 16384
157end
158for k ulong cnt bound 16384
159stageU32 k siteFlag div add off k 4 L freezeCollar
160end
161if not flushStage get dFlags 0 mul off 4 cnt
162ret false
163end
164off = add off cnt
165end
166ret true
167end
168
169note =========================================================================
170note Collar Zoo Initialization (C0..C7)
171note =========================================================================
172fn setCollarAdv s ulong mu ulong L ulong cid ulong base ulong to void
173c3 = rem s L
174c2 = rem div s L L
175c1 = rem div s mul L L L
176c0 = div s mul mul L L L
177if eq cid 5
178if eq mu 0
179put hLinks base 0.0f32
180put hLinks add base 1 1.0f32
181end
182if eq mu 1
183put hLinks base 0.0f32
184put hLinks add base 2 1.0f32
185end
186if eq mu 2
187put hLinks base 0.0f32
188put hLinks add base 3 1.0f32
189end
190if eq mu 3
191put hLinks base 0.5f32
192put hLinks add base 1 0.5f32
193put hLinks add base 2 0.5f32
194put hLinks add base 3 0.5f32
195end
196ret
197end
198if eq cid 6
199if eq and add c0 c1 1 1
200put hLinks base neg 0.5f32
201put hLinks add base 1 0.5f32
202put hLinks add base 2 neg 0.5f32
203put hLinks add base 3 0.5f32
204else
205put hLinks base 0.0f32
206put hLinks add base 1 neg 0.70710678f32
207put hLinks add base 2 0.70710678f32
208put hLinks add base 3 0.0f32
209end
210ret
211end
212if or eq c0 0 eq c1 0
213put hLinks base neg 1.0f32
214end
215if or eq c2 0 eq c3 0
216put hLinks base 0.0f32
217put hLinks add base 1 f32 uRngNorm64
218put hLinks add base 2 f32 uRngNorm64
219put hLinks add base 3 f32 uRngNorm64
220qNormHost base
221end
222end
223
224fn setCollarLink s ulong mu ulong L ulong cid ulong to void
225base = mul add mul s 4 mu 4
226put hLinks base 1.0f32
227put hLinks add base 1 0.0f32
228put hLinks add base 2 0.0f32
229put hLinks add base 3 0.0f32
230if eq cid 0
231ret
232end
233if ge cid 5
234setCollarAdv s mu L cid base
235ret
236end
237if eq cid 3
238put hLinks base f32 uRngNorm64
239put hLinks add base 1 f32 uRngNorm64
240put hLinks add base 2 f32 uRngNorm64
241put hLinks add base 3 f32 uRngNorm64
242qNormHost base
243ret
244end
245c3 = rem s L
246c2 = rem div s L L
247c1 = rem div s mul L L L
248c0 = div s mul mul L L L
249if eq cid 4
250par = and add add c0 c1 add c2 c3 1
251if eq par 1
252if or eq mu 0 eq mu 2
253put hLinks base neg 1.0f32
254end
255end
256ret
257end
258if and eq c0 0 eq mu 0
259if ge c1 div L 2
260put hLinks base neg 1.0f32
261end
262end
263if eq cid 2
264if and eq c2 0 eq mu 2
265if ge c3 div L 2
266put hLinks base neg 1.0f32
267end
268end
269end
270end
271
272fn initLattice L ulong cid ulong freezeCollar bool seed ulong to bool
273N = mul mul L L mul L L
274uRngSeed seed
275for s ulong N bound 65536
276isB = and freezeCollar isBdryL s L
277for mu ulong 4
278if isB
279setCollarLink s mu L cid
280else
281base = mul add mul s 4 mu 4
282note Start interior near identity + small perturbation
283put hLinks base 0.85f32
284put hLinks add base 1 mul 0.25f32 f32 uRngNorm64
285put hLinks add base 2 mul 0.25f32 f32 uRngNorm64
286put hLinks add base 3 mul 0.25f32 f32 uRngNorm64
287qNormHost base
288end
289end
290end
291ret uploadLinks N
292end
293
294note =========================================================================
295note Live GB10 SU(2) Monte Carlo Sweep: 1 Heatbath + nOr Overrelaxation passes
296note =========================================================================
297note =========================================================================
298note Host Measurement of Central Observables (P1x1, W1x2, AdjP, W2x2)
299note =========================================================================
300fn hRect1x2 s ulong mu ulong nu ulong to f64
301a = new f32 4 0.0f32
302b = new f32 4 0.0f32
303p = new f32 4 0.0f32
304q = new f32 4 0.0f32
305s1 = getNb s mu 0
306s2 = getNb s1 mu 0
307hQLoad s mu a
308hQLoad s1 mu b
309hQMul a b p
310hQLoad s2 nu a
311hQMul p a q
312hQLoad getNb s1 nu 0 mu a
313hQConj a
314hQMul q a p
315hQLoad getNb s nu 0 mu a
316hQConj a
317hQMul p a q
318hQLoad s nu b
319hQConj b
320hQMul q b p
321ret f64 get p 0
322end
323
324fn hRect2x2 s ulong mu ulong nu ulong to f64
325a = new f32 4 0.0f32
326p = new f32 4 0.0f32
327q = new f32 4 0.0f32
328cur = s
329hQLoad cur mu p
330cur = getNb cur mu 0
331hQLoad cur mu a
332hQMul p a q
333cur = getNb cur mu 0
334hQLoad cur nu a
335hQMul q a p
336cur = getNb cur nu 0
337hQLoad cur nu a
338hQMul p a q
339cur = getNb cur nu 0
340cur = getNb cur mu 1
341hQLoad cur mu a
342hQConj a
343hQMul q a p
344cur = getNb cur mu 1
345hQLoad cur mu a
346hQConj a
347hQMul p a q
348cur = getNb cur nu 1
349hQLoad cur nu a
350hQConj a
351hQMul q a p
352cur = getNb cur nu 1
353hQLoad cur nu a
354hQConj a
355hQMul p a q
356ret f64 get q 0
357end
358
359global mcAcc f64 4
360global mcCnt ulong 1
361
362fn measureSite s ulong to void
363for mu ulong 4
364for nu ulong 4
365if lt mu nu
366vp = hPlaq s mu nu
367put mcAcc 0 add get mcAcc 0 vp
368put mcAcc 2 add get mcAcc 2 sub mul 4.0f64 mul vp vp 1.0f64
369put mcAcc 1 add get mcAcc 1 hRect1x2 s mu nu
370put mcAcc 3 add get mcAcc 3 hRect2x2 s mu nu
371put mcCnt 0 add get mcCnt 0 1
372end
373end
374end
375end
376
377fn measureCentral L ulong k ulong fullBox bool to void
378N = mul mul L L mul L L
379downloadLinks N
380for o ulong 4
381put mcAcc o 0.0f64
382end
383put mcCnt 0 0
384for s ulong N bound 65536
385if or fullBox isIntL s L
386measureSite s
387end
388end
389fc = f64 get mcCnt 0
390b = mul k 4
391for o ulong 4
392put tsData add b o div get mcAcc o fc
393end
394end
395
396fn sumBlk o ulong st ulong blkSz ulong to f64
397s = f64 0.0f64
398for j ulong blkSz bound 64
399s = add s get tsData add mul add st j 4 o
400end
401ret s
402end
403
404fn summarizeOne o ulong nMeas ulong to void
405blkSz = div nMeas 8
406tot = f64 0.0f64
407for k ulong nMeas bound 400
408tot = add tot get tsData add mul k 4 o
409end
410mean = div tot f64 nMeas
411put curMean o mean
412jkSum = f64 0.0f64
413for b ulong 8
414bs = sumBlk o mul b blkSz blkSz
415d = sub div sub tot bs f64 sub nMeas blkSz mean
416jkSum = add jkSum mul d d
417end
418put curErr o uSqrt64 mul 0.875f64 jkSum
419end
420
421fn summarizeTs nMeas ulong to void
422for o ulong 4
423summarizeOne o nMeas
424end
425end
426
427fn printCollarTag cid ulong to void
428if eq cid 0
429uPrint tK0
430end
431if eq cid 1
432uPrint tK1
433end
434if eq cid 2
435uPrint tK2
436end
437if eq cid 3
438uPrint tK3
439end
440if eq cid 4
441uPrint tK4
442end
443if eq cid 5
444uPrint tK5
445end
446if eq cid 6
447uPrint tK6
448end
449if eq cid 7
450uPrint tK7
451end
452end
453
454note =========================================================================
455note Physics Calibration Oracle: Periodic 8^4 SU(2) at beta=2.30 (Creutz ref ~0.6023)
456note =========================================================================
457fn runCreutzOracle to bool
458L = ulong 8
459N = ulong 4096
460if not buildNbTable L
461ret false
462end
463if not buildFlags L false
464ret false
465end
466if not seedGpuRng N 0xdeadbeef12345678
467ret false
468end
469if not initLattice L 0 false 0x1122334455667788
470ret false
471end
472note 50 thermalization sweeps (1 HB + 3 OR each)
473for sw ulong 50
474if not gpuSweep N 2.30f32 3
475ret false
476end
477end
478note 64 measurement sweeps
479for k ulong 64
480if not gpuSweep N 2.30f32 2
481ret false
482end
483measureCentral L k true
484end
485summarizeTs 64
486p = get curMean 0
487e = get curErr 0
488if and ge p 0.590f64 le p 0.615f64
489uPrint tC3CalOk
490uPrintF64 p
491uPrint tC3CalRef
492uPrintF64 e
493uPrint tC3Rp
494ret true
495end
496uPrint tC3CalBad
497uPrintF64 p
498uPrint tC3CalRef
499uPrintF64 e
500uPrint tC3Rp
501ret false
502end
503
504global armBeta f32 1
505global armSeed ulong 1
506
507fn computeZScores cid ulong to f64
508if eq cid 0
509for o ulong 4
510put baseMean o get curMean o
511put baseStd o get curErr o
512end
513end
514maxZ = f64 0.0f64
515for o ulong 4
516diff = uAbs64 sub get curMean o get baseMean o
517se = uSqrt64 add mul get curErr o get curErr o mul get baseStd o get baseStd o
518z = f64 0.0f64
519if gt se 0.000001f64
520z = div diff se
521end
522put curZ o z
523if gt z maxZ
524maxZ = z
525end
526end
527ret maxZ
528end
529
530fn printArmRow isHeld bool L ulong cid ulong nMeas ulong maxZ f64 us ulong to void
531if isHeld
532uPrint tS2
533else
534uPrint tS1
535end
536uPrint tTab
537uPrintU L
538uPrint tTab
539uPrintF64 f64 get armBeta 0
540uPrint tTab
541printCollarTag cid
542uPrint tTab
543uPrintU nMeas
544uPrint tTab
545uPrintF64 get curMean 0
546uPrint tTab
547uPrintF64 get curErr 0
548uPrint tTab
549uPrintF64 get curZ 0
550uPrint tTab
551uPrintF64 get curMean 1
552uPrint tTab
553uPrintF64 get curZ 1
554uPrint tTab
555uPrintF64 get curMean 2
556uPrint tTab
557uPrintF64 get curZ 2
558uPrint tTab
559uPrintF64 get curMean 3
560uPrint tTab
561uPrintF64 get curZ 3
562uPrint tTab
563uPrintF64 maxZ
564uPrint tTab
565uPrintU us
566uPrint tNl
567end
568
569fn runCollarArm isHeld bool L ulong cid ulong nTherm ulong nMeas ulong to f64
570t0 = monons
571beta = get armBeta 0
572seed = get armSeed 0
573N = mul mul L L mul L L
574if not seedGpuRng N add seed mul cid 7919
575exit 31
576end
577if not initLattice L cid true add seed mul cid 104729
578exit 32
579end
580for sw ulong nTherm bound 200
581if not gpuSweep N beta 3
582exit 33
583end
584end
585for k ulong nMeas bound 400
586if not gpuSweep N beta 2
587exit 34
588end
589measureCentral L k false
590end
591summarizeTs nMeas
592maxZ = computeZScores cid
593us = div ulong sub monons t0 1000
594printArmRow isHeld L cid nMeas maxZ us
595ret maxZ
596end
597
598fn allocBuf bytes ulong cached bool to long
599m = nvalloc bytes cached
600if le m 0
601uPrint tC3Err
602uPrintU ulong get nvstage 0
603uPrint tNl
604exit 6
605end
606ret m
607end
608
609fn runBetaSweep L ulong beta f32 to void
610bestCid = ulong 1
611bestZ = f64 0.0f64
612nTh = ulong 32
613nMs = ulong 48
614if eq L 16
615nTh = ulong 24
616nMs = ulong 32
617end
618put armBeta 0 beta
619put armSeed 0 0x1000001
620for cid ulong 8
621z = runCollarArm false L cid nTh nMs
622if and gt cid 0 gt z bestZ
623bestZ = z
624bestCid = cid
625end
626end
627put armSeed 0 0x99999991
628z0 = runCollarArm true L 0 mul nTh 2 mul nMs 3
629zW = runCollarArm true L bestCid mul nTh 2 mul nMs 3
630end
631
632fn runLSweep L ulong to bool
633if not buildNbTable L
634ret false
635end
636if not buildFlags L true
637ret false
638end
639runBetaSweep L 2.30f32
640runBetaSweep L 2.60f32
641runBetaSweep L 3.00f32
642ret true
643end
644
645fn main to int
646uPrint tC3Hdr
647rcOpen = openWilsonKernels
648if ne rcOpen 0
649if eq rcOpen 2
650uPrint tC3Err
651uPrintU ulong get nvstage 0
652uPrint tNl
653end
654ret rcOpen
655end
656put dLinks 0 allocBuf 4194304 true
657put dStaples 0 allocBuf 4194304 true
658put dFlags 0 allocBuf 1048576 true
659put dNbSite 0 allocBuf 2097152 true
660put dRng 0 allocBuf 262144 true
661
662if not runCreutzOracle
663rc = nvmclose
664ret 10
665end
666
667uPrint tC3Cols
668if not runLSweep 8
669rc = nvmclose
670ret 11
671end
672if not runLSweep 16
673rc = nvmclose
674ret 12
675end
676
677uPrint tC3Done
678rc = nvmclose
679ret 0
680end