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_check8_gb10.om

1236 lines · 26132 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note src/ufbi_check8_gb10.om: Pure Seeded-OM-2 Zero-CUDA GB10 Runner for UFBI Check #8
3note (Phase II Multi-Scale Gauge-Covariant Block-Spin RG Flow & Effective Dobrushin-Shlosman
4note Contraction Across L=16 -> L1=8 -> L2=4 for beta in {1.50, 2.00, 2.30, 2.50, 2.70, 6.00}).
5note
6note What Check #8 measures directly on physical GB10 silicon:
7note 1. Runtime RG_GAUGE_COV_ASSERT: applies a random local SU(2) gauge transformation g(x)
8note on 16^4, runs Swendsen 2x gauge-covariant blocking (16^4 -> 8^4 -> 4^4) on both U
9note and U^g, and asserts max |P^(k)(U^g) - P^(k)(U)| <= 1e-4 at every RG scale k=0,1,2.
10note 2. Runtime ZERO_CONTACT_ASSERT: swaps frozen collar C0_cold vs C3_hot_haar on a fixed
11note interior 16^4 config and asserts max |O^(k)(B1) - O^(k)(B0)| == 0.000000 at all
12note 3 RG scales k=0 (a), k=1 (2a), k=2 (4a).
13note 3. In-situ periodic bulk SU(2) plaquette calibration curve <P_bulk>(beta) on periodic 8^4
14note for beta in {0.25, 0.50, 1.00, 1.50, 2.00, 2.30, 2.50, 3.00, 4.00, 6.00} so each
15note blocked plaquette <P^(k)> maps directly to a non-perturbative running coupling beta_eff(k).
16note 4. Multi-scale RG flow & scale-by-scale Dobrushin boundary sensitivity on frozen-collar 16^4
17note (C0_cold vs C3_hot_haar & C8_smooth_hol, 256 measurements = 512 GPU sweeps/arm) at
18note beta in {1.50, 2.00, 2.30, 2.50, 2.70, 6.00}:
19note O0: P^(0) (fine scale a, 16^4 core [6,10)^4)
20note O1: P^(1) (RG-1 scale 2a, 8^4 core [3,5)^4)
21note O2: P^(2) (RG-2 scale 4a, 4^4 center X=(1,1,1,1))
22note O3: Adj^(1)(RG-1 scale 2a, adjoint plaquette 4*(P^(1))^2 - 1)
23note O4: Adj^(2)(RG-2 scale 4a, adjoint plaquette 4*(P^(2))^2 - 1)
24note
25note Composed after:
26note gpu/nvidia/native/nvrm/context.om
27note gpu/nvidia/native/blackwell/vector.om
28note gpu/nvidia/native/blackwell/launch.om
29note gpu/nvidia/native/blackwell/batch.om
30note om/encoder/bw_enc_sm121.om
31note src/ufbi_math.om
32note src/ufbi_check3_kernels.om
33
34global uCodePos ulong 1
35global uEntry ulong 8
36global uCodeMap long 1
37global uCodeFail uint 1
38global uBind uint 32
39global uBindN ulong 1
40global uDirty uint 1
41
42global dLinks long 1
43global dStaples long 1
44global dFlags long 1
45global dNbSite long 1
46global dRng long 1
47
48note Fine 16^4 (65536 sites x 16 = 1048576 f32), RG-1 8^4 (4096 x 16 = 65536), RG-2 4^4 (256 x 16 = 4096)
49global hL0 f32 1048576
50global hL1 f32 65536
51global hL2 f32 4096
52global hGauge f32 262144
53global hNb uint 524288
54global hStage uchar 65536
55
56note 5 observables x 256 sweeps = 1280 f64
57global tsData f64 1280
58global baseMean f64 5
59global baseErr f64 5
60global baseSig f64 5
61global curMean f64 5
62global curErr f64 5
63global curSig f64 5
64global curDelta f64 5
65global curZ f64 5
66global curRBulk f64 5
67global mcAcc f64 6
68global mcCnt ulong 1
69global armBeta f32 1
70global armSeed ulong 1
71global rgSrcLvl ulong 1
72global rgDstLvl ulong 1
73global rgLf ulong 1
74
75note 10-point periodic bulk calibration table (beta_i -> <P_bulk>(beta_i))
76global calBeta f64 10
77global calPlaq f64 10
78
79text tC8Hdr "=== UFBI CHECK #8: PHASE-II MULTI-SCALE GAUGE-COVARIANT BLOCK-SPIN RG FLOW & DOBRUSHIN CONTRACTION (PURE OM-2 GB10) ===\n"
80text tC8Err "FAIL: GB10 native NVRM/kernel error stage="
81text tC8GcFail "FAIL: RG_GAUGE_COV_ASSERT violated! err="
82text tC8GcOk "RG_GAUGE_COV_ASSERT scales=3 max_gauge_err="
83text tC8ZcFail "FAIL: ZERO_CONTACT_ASSERT violated! err="
84text tC8ZcOk "ZERO_CONTACT_ASSERT L=16 scales=3 max_direct_err="
85text tC8Pass " status=PASS\n"
86text tC8CalHdr "=== IN-SITU PERIODIC 8^4 SU(2) BULK CALIBRATION CURVE ===\n"
87text tC8CalCols "cal_beta\tcal_P_bulk\n"
88text tC8RgHdr "=== MULTI-SCALE BLOCK-SPIN RG FLOW (16^4 -> 8^4 -> 4^4) ===\n"
89text tC8Cols "beta\tcollar\tsweeps\tP0_m\tP1_m\tP2_m\tbeff_0\tbeff_1\tbeff_2\tdP0_Rb\tdP0_Z\tdP1_Rb\tdP1_Z\tdP2_Rb\tdP2_Z\tdA1_Rb\tdA1_Z\tdA2_Rb\tdA2_Z\tus\n"
90text tTab "\t"
91text tNl "\n"
92text tK0 "C0_cold"
93text tK3 "C3_hot_haar"
94text tK8 "C8_smooth_hol"
95text tC8Done "CHECK8_GB10_DONE status=PASS rg_gauge_cov_verified=1 zero_contact_verified=1\n"
96
97fn uCodeWrite w view ulong 4 to void
98p = get uCodePos 0
99b = new uchar 16 0
100if gt get uCodeMap 0 0
101for i ulong 16
102put b i uchar and shr get w div i 4 mul rem i 4 8 255
103end
104if ne mapwrite get uCodeMap 0 p b 0 16 16
105put uCodeFail 0 1
106end
107end
108put uCodePos 0 add p 16
109end
110
111fn uEmitAllKernels to void
112put uCodePos 0 0
113for id ulong 3
114p = mul div add get uCodePos 0 255 256 256
115put uEntry id p
116put uCodePos 0 p
117put uPc 0 0
118put uGuard 0 0
119ok = false
120if eq id 0
121ok = uEmitSu2Staple
122end
123if eq id 1
124ok = uEmitSu2Overrelax
125end
126if eq id 2
127ok = uEmitSu2Heatbath
128end
129if not ok
130exit 4
131end
132uDone
133end
134end
135
136fn uArg u uint to void
137i = get uBindN 0
138put uBind i u
139put uBindN 0 add i 1
140end
141
142fn uPtr va ulong to void
143uArg gblo va
144uArg gbhi va
145end
146
147fn uRecord id ulong gx uint bx uint to bool
148gbqmd 1
149a = add mapaddr get uCodeMap 0 get uEntry id
150put gbq1 32 gblo shr a 4
151put gbq1 33 or uint and shr a 36 2097151 20971520
152put gbq1 59 gblo shr a 8
153put gbq1 34 or uint 65536 bx
154put gbq1 35 or uint 131073 shl uint 64 8
155put gbq1 36 78923784
156put gbq1 37 0
157put gbq1 39 gx
158put gbq1 40 1
159put gbq1 41 1
160put gbcb 216 bx
161put gbcb 220 gx
162put gbcb 221 1
163put gbcb 222 1
164cb = mapaddr get gbmem 1
165words = get uBindN 0
166endva = add cb add 896 mul words 4
167put gbcb 212 gbhi endva
168put gbcb 213 gblo endva
169put gbused 0 0
170gbsetup
171if ne get uDirty 0 0
172gbmth 0 40 4
173gbemit 0
174gbemit 0
175gbemit 0
176gbemit 2281701376
177put uDirty 0 0
178end
179gbdma cb 224
180for j ulong 224
181gbemit get gbcb j
182end
183gbdma add cb 896 uint words
184for j ulong words bound 32
185gbemit get uBind j
186end
187q = mapaddr get gbmem 2
188gbinline q false
189gbdma add q 8192 1
190gbemit 1
191gbinline add q 4096 true
192gbrel add mapaddr get gbmem 3 32 6
193put uBindN 0 0
194ret gbappend id get gbst 1
195end
196
197fn uRunKernel id ulong gx uint bx uint to bool
198put uDirty 0 1
199if not gbbegin 1
200ret false
201end
202if not uRecord id gx bx
203ret false
204end
205ret gbbsubmit 2000000000
206end
207
208fn stageU32 k ulong v uint to void
209b = mul k 4
210put hStage b uchar and v 255
211put hStage add b 1 uchar and shr v 8 255
212put hStage add b 2 uchar and shr v 16 255
213put hStage add b 3 uchar and shr v 24 255
214end
215
216fn stageF32 k ulong v f32 to void
217stageU32 k bitcast uint v
218end
219
220fn flushStage m long offBytes ulong nWords ulong to bool
221nb = mul nWords 4
222ret eq mapwrite m offBytes hStage 0 nb long nb
223end
224
225fn uploadLinks N ulong to bool
226totalF = mul N 16
227off = ulong 0
228while lt off totalF bound 128
229cnt = sub totalF off
230if gt cnt 16384
231cnt = ulong 16384
232end
233for k ulong cnt bound 16384
234stageF32 k get hL0 add off k
235end
236if not flushStage get dLinks 0 mul off 4 cnt
237ret false
238end
239off = add off cnt
240end
241ret true
242end
243
244fn coordIdx c0 ulong c1 ulong c2 ulong c3 ulong L ulong to ulong
245r = add mul c0 L c1
246r = add mul r L c2
247ret add mul r L c3
248end
249
250fn stepCoord s ulong L ulong dir ulong delta ulong to ulong
251c3 = rem s L
252t = div s L
253c2 = rem t L
254t = div t L
255c1 = rem t L
256c0 = div t L
257if eq dir 0
258c0 = rem add c0 delta L
259end
260if eq dir 1
261c1 = rem add c1 delta L
262end
263if eq dir 2
264c2 = rem add c2 delta L
265end
266if eq dir 3
267c3 = rem add c3 delta L
268end
269ret coordIdx c0 c1 c2 c3 L
270end
271
272fn buildNbTable L ulong to bool
273N = mul mul L L mul L L
274for s ulong N bound 65536
275c3 = rem s L
276t = div s L
277c2 = rem t L
278t = div t L
279c1 = rem t L
280c0 = div t L
281b = mul s 8
282put hNb b uint coordIdx rem add c0 1 L c1 c2 c3 L
283put hNb add b 1 uint coordIdx rem add c0 sub L 1 L c1 c2 c3 L
284put hNb add b 2 uint coordIdx c0 rem add c1 1 L c2 c3 L
285put hNb add b 3 uint coordIdx c0 rem add c1 sub L 1 L c2 c3 L
286put hNb add b 4 uint coordIdx c0 c1 rem add c2 1 L c3 L
287put hNb add b 5 uint coordIdx c0 c1 rem add c2 sub L 1 L c3 L
288put hNb add b 6 uint coordIdx c0 c1 c2 rem add c3 1 L L
289put hNb add b 7 uint coordIdx c0 c1 c2 rem add c3 sub L 1 L L
290end
291totalW = mul N 8
292off = ulong 0
293while lt off totalW bound 64
294cnt = sub totalW off
295if gt cnt 16384
296cnt = ulong 16384
297end
298for k ulong cnt bound 16384
299stageU32 k get hNb add off k
300end
301if not flushStage get dNbSite 0 mul off 4 cnt
302ret false
303end
304off = add off cnt
305end
306ret true
307end
308
309fn isBdryL s ulong L ulong to bool
310c3 = rem s L
311t = div s L
312c2 = rem t L
313t = div t L
314c1 = rem t L
315c0 = div t L
316lm1 = sub L 1
317if or eq c0 0 eq c0 lm1
318ret true
319end
320if or eq c1 0 eq c1 lm1
321ret true
322end
323if or eq c2 0 eq c2 lm1
324ret true
325end
326if or eq c3 0 eq c3 lm1
327ret true
328end
329ret false
330end
331
332fn isBox4 s ulong L ulong lo ulong hi ulong to bool
333c3 = rem s L
334t = div s L
335c2 = rem t L
336t = div t L
337c1 = rem t L
338c0 = div t L
339if or lt c0 lo ge c0 hi
340ret false
341end
342if or lt c1 lo ge c1 hi
343ret false
344end
345if or lt c2 lo ge c2 hi
346ret false
347end
348if or lt c3 lo ge c3 hi
349ret false
350end
351ret true
352end
353
354fn downloadBox L ulong lo ulong hi ulong to void
355N = mul mul L L mul L L
356lm = get dLinks 0
357for s ulong N bound 65536
358if isBox4 s L lo hi
359base = mul s 16
360for k ulong 16
361put hL0 add base k bitcast f32 uint mapget lm mul add base k 4 4
362end
363end
364end
365end
366
367fn siteFlag s ulong L ulong freezeCollar bool to uint
368if and freezeCollar isBdryL s L
369ret uint 2
370end
371c3 = rem s L
372t = div s L
373c2 = rem t L
374t = div t L
375c1 = rem t L
376c0 = div t L
377ret uint and add add c0 c1 add c2 c3 1
378end
379
380fn buildFlags L ulong freezeCollar bool to bool
381N = mul mul L L mul L L
382totalW = mul N 4
383off = ulong 0
384while lt off totalW bound 32
385cnt = sub totalW off
386if gt cnt 16384
387cnt = ulong 16384
388end
389for k ulong cnt bound 16384
390stageU32 k siteFlag div add off k 4 L freezeCollar
391end
392if not flushStage get dFlags 0 mul off 4 cnt
393ret false
394end
395off = add off cnt
396end
397ret true
398end
399
400fn seedGpuRng N ulong seed ulong to bool
401uRngSeed seed
402off = ulong 0
403while lt off N bound 16
404cnt = sub N off
405if gt cnt 16384
406cnt = ulong 16384
407end
408for k ulong cnt bound 16384
409r = uint and uRngNext 0xffffffff
410if eq r 0
411r = uint 0x9e3779b9
412end
413stageU32 k r
414end
415if not flushStage get dRng 0 mul off 4 cnt
416ret false
417end
418off = add off cnt
419end
420ret true
421end
422
423fn qNormHost base ulong to void
424a0 = get hL0 base
425a1 = get hL0 add base 1
426a2 = get hL0 add base 2
427a3 = get hL0 add base 3
428n2 = add add mul a0 a0 mul a1 a1 add mul a2 a2 mul a3 a3
429if le n2 0.0000000001f32
430put hL0 base 1.0f32
431put hL0 add base 1 0.0f32
432put hL0 add base 2 0.0f32
433put hL0 add base 3 0.0f32
434ret
435end
436inv = f32 div 1.0f64 uSqrt64 f64 n2
437put hL0 base mul a0 inv
438put hL0 add base 1 mul a1 inv
439put hL0 add base 2 mul a2 inv
440put hL0 add base 3 mul a3 inv
441end
442
443fn setCollarLink s ulong mu ulong L ulong cid ulong to void
444base = mul add mul s 4 mu 4
445put hL0 base 1.0f32
446put hL0 add base 1 0.0f32
447put hL0 add base 2 0.0f32
448put hL0 add base 3 0.0f32
449if eq cid 0
450ret
451end
452if eq cid 3
453put hL0 base f32 uRngNorm64
454put hL0 add base 1 f32 uRngNorm64
455put hL0 add base 2 f32 uRngNorm64
456put hL0 add base 3 f32 uRngNorm64
457qNormHost base
458ret
459end
460if eq cid 8
461if eq mu 0
462put hL0 base 0.0f32
463put hL0 add base 1 1.0f32
464end
465if eq mu 1
466put hL0 base 0.0f32
467put hL0 add base 2 1.0f32
468end
469if eq mu 2
470put hL0 base 0.0f32
471put hL0 add base 3 1.0f32
472end
473if eq mu 3
474put hL0 base 0.5f32
475put hL0 add base 1 0.5f32
476put hL0 add base 2 0.5f32
477put hL0 add base 3 0.5f32
478end
479end
480end
481
482fn initLatticeHost L ulong cid ulong freezeCollar bool seed ulong to void
483N = mul mul L L mul L L
484uRngSeed seed
485for s ulong N bound 65536
486isB = and freezeCollar isBdryL s L
487for mu ulong 4
488if isB
489setCollarLink s mu L cid
490else
491base = mul add mul s 4 mu 4
492put hL0 base 0.85f32
493put hL0 add base 1 mul 0.25f32 f32 uRngNorm64
494put hL0 add base 2 mul 0.25f32 f32 uRngNorm64
495put hL0 add base 3 mul 0.25f32 f32 uRngNorm64
496qNormHost base
497end
498end
499end
500end
501
502fn initLattice L ulong cid ulong freezeCollar bool seed ulong to bool
503N = mul mul L L mul L L
504initLatticeHost L cid freezeCollar seed
505ret uploadLinks N
506end
507
508fn gpuRunStaple N ulong mu ulong par ulong to bool
509gx = uint div add N 255 256
510nu0 = ulong 0
511nu1 = ulong 1
512nu2 = ulong 2
513if eq mu 0
514nu0 = ulong 1
515nu1 = ulong 2
516nu2 = ulong 3
517end
518if eq mu 1
519nu0 = ulong 0
520nu1 = ulong 2
521nu2 = ulong 3
522end
523if eq mu 2
524nu0 = ulong 0
525nu1 = ulong 1
526nu2 = ulong 3
527end
528uPtr mapaddr get dLinks 0
529uPtr mapaddr get dStaples 0
530uPtr mapaddr get dFlags 0
531uPtr mapaddr get dNbSite 0
532uArg uint N
533uArg uint mu
534uArg uint par
535uArg uint nu0
536uArg uint nu1
537uArg uint nu2
538ret uRunKernel 0 gx 256
539end
540
541fn gpuRunOverrelax N ulong mu ulong par ulong to bool
542gx = uint div add N 255 256
543uPtr mapaddr get dLinks 0
544uPtr mapaddr get dStaples 0
545uPtr mapaddr get dFlags 0
546uArg uint N
547uArg uint mu
548uArg uint par
549ret uRunKernel 1 gx 256
550end
551
552fn gpuRunHeatbath N ulong mu ulong par ulong beta f32 to bool
553gx = uint div add N 255 256
554uPtr mapaddr get dLinks 0
555uPtr mapaddr get dStaples 0
556uPtr mapaddr get dFlags 0
557uPtr mapaddr get dRng 0
558uArg uint N
559uArg uint mu
560uArg uint par
561uArg bitcast uint beta
562ret uRunKernel 2 gx 256
563end
564
565fn gpuSweep N ulong beta f32 nOr ulong to bool
566for mu ulong 4
567for par ulong 2
568if not gpuRunStaple N mu par
569ret false
570end
571if not gpuRunHeatbath N mu par beta
572ret false
573end
574for r ulong nOr bound 8
575if not gpuRunStaple N mu par
576ret false
577end
578if not gpuRunOverrelax N mu par
579ret false
580end
581end
582end
583end
584ret true
585end
586
587note =========================================================================
588note Quaternion Helpers + Gauge-Covariant Swendsen 2x Block-Spin RG (lvl 0->1->2)
589note lvl: 0=hL0 (16^4), 1=hL1 (8^4), 2=hL2 (4^4)
590note =========================================================================
591fn hQMul a view f32 4 b view f32 4 o edit f32 4 to void
592v = mul get a 0 get b 0
593v = sub v mul get a 1 get b 1
594v = sub v mul get a 2 get b 2
595v = sub v mul get a 3 get b 3
596put o 0 v
597v = mul get a 0 get b 1
598v = add v mul get a 1 get b 0
599v = add v mul get a 2 get b 3
600v = sub v mul get a 3 get b 2
601put o 1 v
602v = mul get a 0 get b 2
603v = sub v mul get a 1 get b 3
604v = add v mul get a 2 get b 0
605v = add v mul get a 3 get b 1
606put o 2 v
607v = mul get a 0 get b 3
608v = add v mul get a 1 get b 2
609v = sub v mul get a 2 get b 1
610v = add v mul get a 3 get b 0
611put o 3 v
612end
613
614fn hQConj q edit f32 4 to void
615put q 1 neg get q 1
616put q 2 neg get q 2
617put q 3 neg get q 3
618end
619
620fn hQNorm q edit f32 4 to void
621n2 = mul get q 0 get q 0
622n2 = add n2 mul get q 1 get q 1
623n2 = add n2 mul get q 2 get q 2
624n2 = add n2 mul get q 3 get q 3
625if le n2 0.0000000001f32
626put q 0 1.0f32
627put q 1 0.0f32
628put q 2 0.0f32
629put q 3 0.0f32
630ret
631end
632inv = f32 div 1.0f64 uSqrt64 f64 n2
633for c ulong 4
634put q c mul get q c inv
635end
636end
637
638fn loadLvl lvl ulong s ulong mu ulong dst edit f32 4 to void
639b = mul add mul s 4 mu 4
640if eq lvl 0
641put dst 0 get hL0 b
642put dst 1 get hL0 add b 1
643put dst 2 get hL0 add b 2
644put dst 3 get hL0 add b 3
645ret
646end
647if eq lvl 1
648put dst 0 get hL1 b
649put dst 1 get hL1 add b 1
650put dst 2 get hL1 add b 2
651put dst 3 get hL1 add b 3
652ret
653end
654put dst 0 get hL2 b
655put dst 1 get hL2 add b 1
656put dst 2 get hL2 add b 2
657put dst 3 get hL2 add b 3
658end
659
660fn storeLvl lvl ulong s ulong mu ulong src view f32 4 to void
661b = mul add mul s 4 mu 4
662if eq lvl 0
663put hL0 b get src 0
664put hL0 add b 1 get src 1
665put hL0 add b 2 get src 2
666put hL0 add b 3 get src 3
667ret
668end
669if eq lvl 1
670put hL1 b get src 0
671put hL1 add b 1 get src 1
672put hL1 add b 2 get src 2
673put hL1 add b 3 get src 3
674ret
675end
676put hL2 b get src 0
677put hL2 add b 1 get src 1
678put hL2 add b 2 get src 2
679put hL2 add b 3 get src 3
680end
681
682note Swendsen 2x1 blocked staple from fine site x to x+2*mu via +-nu (reads rgSrcLvl, rgLf)
683fn addBlockStaple x ulong mu ulong nu ulong isBack bool dst edit f32 4 to void
684lvl = get rgSrcLvl 0
685Lf = get rgLf 0
686a = new f32 4 0.0f32
687b = new f32 4 0.0f32
688p = new f32 4 0.0f32
689q = new f32 4 0.0f32
690x2m = stepCoord stepCoord x Lf mu 1 Lf mu 1
691if not isBack
692xn = stepCoord x Lf nu 1
693loadLvl lvl x nu a
694loadLvl lvl xn mu b
695hQMul a b p
696loadLvl lvl stepCoord xn Lf mu 1 mu a
697hQMul p a q
698loadLvl lvl x2m nu a
699hQConj a
700hQMul q a p
701else
702xm = stepCoord x Lf nu sub Lf 1
703loadLvl lvl xm nu a
704hQConj a
705loadLvl lvl xm mu b
706hQMul a b p
707loadLvl lvl stepCoord xm Lf mu 1 mu a
708hQMul p a q
709loadLvl lvl stepCoord x2m Lf nu sub Lf 1 nu a
710hQMul q a p
711end
712for c ulong 4
713put dst c add get dst c get p c
714end
715end
716
717fn coarseToFine X ulong Lf ulong to ulong
718Lc = div Lf 2
719c3 = rem X Lc
720t = div X Lc
721c2 = rem t Lc
722t = div t Lc
723c1 = rem t Lc
724c0 = div t Lc
725ret coordIdx mul c0 2 mul c1 2 mul c2 2 mul c3 2 Lf
726end
727
728note Compute ONE Swendsen gauge-covariant 2x blocked link at coarse site X (fine origin x = 2X)
729fn blockLinkOne X ulong mu ulong to void
730srcLvl = get rgSrcLvl 0
731Lf = get rgLf 0
732x = coarseToFine X Lf
733u1 = new f32 4 0.0f32
734u2 = new f32 4 0.0f32
735w0 = new f32 4 0.0f32
736st = new f32 4 0.0f32
737loadLvl srcLvl x mu u1
738loadLvl srcLvl stepCoord x Lf mu 1 mu u2
739hQMul u1 u2 w0
740for nu ulong 4
741if ne nu mu
742addBlockStaple x mu nu false st
743addBlockStaple x mu nu true st
744end
745end
746wS = div 0.5f32 6.0f32
747for c ulong 4
748put w0 c add mul 0.5f32 get w0 c mul wS get st c
749end
750hQNorm w0
751storeLvl get rgDstLvl 0 X mu w0
752end
753
754note Block sites in coarse box [cLo, cHi)^4 from srcLvl (size Lf) into dstLvl (size Lf/2)
755fn blockBox srcLvl ulong dstLvl ulong Lf ulong cLo ulong cHi ulong to void
756put rgSrcLvl 0 srcLvl
757put rgDstLvl 0 dstLvl
758put rgLf 0 Lf
759Lc = div Lf 2
760Nc = mul mul Lc Lc mul Lc Lc
761for X ulong Nc bound 4096
762if isBox4 X Lc cLo cHi
763for mu ulong 4
764blockLinkOne X mu
765end
766end
767end
768end
769
770fn plaqLvl lvl ulong L ulong s ulong mu ulong nu ulong to f64
771a = new f32 4 0.0f32
772b = new f32 4 0.0f32
773p = new f32 4 0.0f32
774q = new f32 4 0.0f32
775loadLvl lvl s mu a
776loadLvl lvl stepCoord s L mu 1 nu b
777hQMul a b p
778loadLvl lvl stepCoord s L nu 1 mu a
779hQConj a
780hQMul p a q
781loadLvl lvl s nu b
782hQConj b
783hQMul q b p
784ret f64 get p 0
785end
786
787fn accumPlaqSite lvl ulong L ulong s ulong to void
788for mu ulong 4
789for nu ulong 4
790if lt mu nu
791vp = plaqLvl lvl L s mu nu
792put mcAcc 4 add get mcAcc 4 vp
793put mcAcc 5 add get mcAcc 5 sub mul 4.0f64 mul vp vp 1.0f64
794put mcCnt 0 add get mcCnt 0 1
795end
796end
797end
798end
799
800fn evalPlaqBox lvl ulong L ulong lo ulong hi ulong accIdx ulong to f64
801N = mul mul L L mul L L
802put mcAcc 4 0.0f64
803put mcAcc 5 0.0f64
804put mcCnt 0 0
805for s ulong N bound 65536
806if isBox4 s L lo hi
807accumPlaqSite lvl L s
808end
809end
810fc = f64 get mcCnt 0
811put mcAcc accIdx div get mcAcc 5 fc
812ret div get mcAcc 4 fc
813end
814
815note Full 3-scale evaluation on 16^4 (strictly zero contact with frozen shell {0, 15}!):
816note RG-1 (L1=8): block box [1, 7)^4 -> fine sites read in [1, 14] (ZERO 0, ZERO 15!)
817note RG-2 (L2=4): block box [1, 3)^4 -> L1 sites read in [1, 6] (subset of [1, 7)^4!)
818note O0 = P^(0) on 16^4 core [6, 10)^4
819note O1 = P^(1) on 8^4 core [3, 5)^4, O3 = Adj^(1)
820note O2 = P^(2) on 4^4 center [1, 2)^4, O4 = Adj^(2)
821fn evalMultiScale res edit f64 5 to void
822blockBox 0 1 16 1 7
823blockBox 1 2 8 1 3
824p0 = evalPlaqBox 0 16 6 10 0
825p1 = evalPlaqBox 1 8 3 5 1
826p2 = evalPlaqBox 2 4 1 2 2
827put res 0 p0
828put res 1 p1
829put res 2 p2
830put res 3 get mcAcc 1
831put res 4 get mcAcc 2
832end
833
834note =========================================================================
835note Runtime Self-Checks:
836note 1. RG_GAUGE_COV_ASSERT: random local SU(2) gauge transform on 16^4 -> 0 error at k=0,1,2!
837note 2. ZERO_CONTACT_ASSERT: swap frozen shell {0,15} C0->C3 -> 0.000000 error at k=0,1,2!
838note =========================================================================
839fn applyGauge16Link s ulong mu ulong g view f32 4 to void
840u = new f32 4 0.0f32
841g2 = new f32 4 0.0f32
842t1 = new f32 4 0.0f32
843t2 = new f32 4 0.0f32
844loadLvl 0 s mu u
845xp = stepCoord s 16 mu 1
846b2 = mul xp 4
847for c ulong 4
848put g2 c get hGauge add b2 c
849end
850hQConj g2
851hQMul g u t1
852hQMul t1 g2 t2
853hQNorm t2
854storeLvl 0 s mu t2
855end
856
857fn applyRandomGauge16 to void
858g = new f32 4 0.0f32
859uRngSeed 0x44449999
860for s ulong 65536
861put g 0 f32 uRngNorm64
862put g 1 f32 uRngNorm64
863put g 2 f32 uRngNorm64
864put g 3 f32 uRngNorm64
865hQNorm g
866b = mul s 4
867for c ulong 4
868put hGauge add b c get g c
869end
870end
871for s ulong 65536
872b = mul s 4
873for c ulong 4
874put g c get hGauge add b c
875end
876for mu ulong 4
877applyGauge16Link s mu g
878end
879end
880end
881
882fn assertRgGaugeCov to void
883initLatticeHost 16 3 true 0x88881111
884v0 = new f64 5 0.0f64
885v1 = new f64 5 0.0f64
886evalMultiScale v0
887applyRandomGauge16
888evalMultiScale v1
889maxE = f64 0.0f64
890for o ulong 5
891e = uAbs64 sub get v1 o get v0 o
892if gt e maxE
893maxE = e
894end
895end
896if gt maxE 0.0001f64
897uPrint tC8GcFail
898uPrintF64 maxE
899uPrint tNl
900exit 98
901end
902uPrint tC8GcOk
903uPrintF64 maxE
904uPrint tC8Pass
905end
906
907fn assertZeroContact8 to void
908initLatticeHost 16 0 true 0x77772222
909v0 = new f64 5 0.0f64
910v1 = new f64 5 0.0f64
911evalMultiScale v0
912uRngSeed 0x99993333
913for s ulong 65536
914if isBdryL s 16
915for mu ulong 4
916setCollarLink s mu 16 3
917end
918end
919end
920evalMultiScale v1
921maxE = f64 0.0f64
922for o ulong 5
923e = uAbs64 sub get v1 o get v0 o
924if gt e maxE
925maxE = e
926end
927end
928if gt maxE 0.000000000001f64
929uPrint tC8ZcFail
930uPrintF64 maxE
931uPrint tNl
932exit 99
933end
934uPrint tC8ZcOk
935uPrintF64 maxE
936uPrint tC8Pass
937end
938
939note =========================================================================
940note In-Situ Periodic 8^4 Bulk Calibration + Piecewise-Linear Inverse beta_eff(P)
941note =========================================================================
942fn runCalPoint idx ulong beta f32 to void
943N = ulong 4096
944if not seedGpuRng N add 0xc0100001 mul idx 7919
945exit 21
946end
947if not initLattice 8 0 false add 0xc0100001 mul idx 104729
948exit 22
949end
950for sw ulong 48
951if not gpuSweep N beta 3
952exit 23
953end
954end
955acc = f64 0.0f64
956for k ulong 32
957if not gpuSweep N beta 2
958exit 24
959end
960downloadBox 8 0 8
961acc = add acc evalPlaqBox 0 8 0 8 0
962end
963pMean = div acc 32.0f64
964put calBeta idx f64 beta
965put calPlaq idx pMean
966uPrintF64 f64 beta
967uPrint tTab
968uPrintF64 pMean
969uPrint tNl
970end
971
972fn invertBetaEff p f64 to f64
973if le p get calPlaq 0
974ret mul get calBeta 0 div p get calPlaq 0
975end
976for i ulong 9
977p0 = get calPlaq i
978p1 = get calPlaq add i 1
979if le p p1
980b0 = get calBeta i
981b1 = get calBeta add i 1
982dp = sub p1 p0
983if le dp 0.000001f64
984ret b0
985end
986ret add b0 mul sub b1 b0 div sub p p0 dp
987end
988end
989ret get calBeta 9
990end
991
992note =========================================================================
993note Statistics (16-Block Jackknife over 256 Measurements + Bulk Sigma)
994note =========================================================================
995fn storeMeas8 k ulong to void
996downloadBox 16 1 15
997v = new f64 5 0.0f64
998evalMultiScale v
999b = mul k 5
1000for o ulong 5
1001put tsData add b o get v o
1002end
1003end
1004
1005fn sumBlk8 o ulong st ulong blkSz ulong to f64
1006s = f64 0.0f64
1007for j ulong blkSz bound 32
1008s = add s get tsData add mul add st j 5 o
1009end
1010ret s
1011end
1012
1013fn summarizeOne8 o ulong nMeas ulong to void
1014blkSz = div nMeas 16
1015tot = f64 0.0f64
1016for k ulong nMeas bound 256
1017tot = add tot get tsData add mul k 5 o
1018end
1019mean = div tot f64 nMeas
1020put curMean o mean
1021vSum = f64 0.0f64
1022for k ulong nMeas bound 256
1023dv = sub get tsData add mul k 5 o mean
1024vSum = add vSum mul dv dv
1025end
1026put curSig o uSqrt64 div vSum f64 sub nMeas 1
1027jkSum = f64 0.0f64
1028for b ulong 16
1029bs = sumBlk8 o mul b blkSz blkSz
1030d = sub div sub tot bs f64 sub nMeas blkSz mean
1031jkSum = add jkSum mul d d
1032end
1033put curErr o uSqrt64 mul 0.9375f64 jkSum
1034end
1035
1036fn summarizeTs8 nMeas ulong to void
1037for o ulong 5
1038summarizeOne8 o nMeas
1039end
1040end
1041
1042fn computeDiffZR8 cid ulong to void
1043if eq cid 0
1044for o ulong 5
1045put baseMean o get curMean o
1046put baseErr o get curErr o
1047put baseSig o get curSig o
1048put curDelta o 0.0f64
1049put curZ o 0.0f64
1050put curRBulk o 0.0f64
1051end
1052ret
1053end
1054for o ulong 5
1055diff = uAbs64 sub get curMean o get baseMean o
1056se = uSqrt64 add mul get curErr o get curErr o mul get baseErr o get baseErr o
1057z = f64 0.0f64
1058if gt se 0.0000001f64
1059z = div diff se
1060end
1061rBulk = f64 0.0f64
1062sb = get baseSig o
1063if gt sb 0.0000001f64
1064rBulk = div diff sb
1065end
1066put curDelta o diff
1067put curZ o z
1068put curRBulk o rBulk
1069end
1070end
1071
1072fn printRow8 cid ulong nMeas ulong us ulong to void
1073uPrintF64 f64 get armBeta 0
1074uPrint tTab
1075if eq cid 0
1076uPrint tK0
1077end
1078if eq cid 3
1079uPrint tK3
1080end
1081if eq cid 8
1082uPrint tK8
1083end
1084uPrint tTab
1085uPrintU nMeas
1086uPrint tTab
1087uPrintF64 get curMean 0
1088uPrint tTab
1089uPrintF64 get curMean 1
1090uPrint tTab
1091uPrintF64 get curMean 2
1092uPrint tTab
1093uPrintF64 invertBetaEff get curMean 0
1094uPrint tTab
1095uPrintF64 invertBetaEff get curMean 1
1096uPrint tTab
1097uPrintF64 invertBetaEff get curMean 2
1098for o ulong 5
1099uPrint tTab
1100uPrintF64 get curRBulk o
1101uPrint tTab
1102uPrintF64 get curZ o
1103end
1104uPrint tTab
1105uPrintU us
1106uPrint tNl
1107end
1108
1109fn runArm8 beta f32 cid ulong nTherm ulong nMeas ulong to void
1110t0 = monons
1111put armBeta 0 beta
1112seed = get armSeed 0
1113N = ulong 65536
1114if not seedGpuRng N add seed mul cid 7919
1115exit 31
1116end
1117if not initLattice 16 cid true add seed mul cid 104729
1118exit 32
1119end
1120for sw ulong nTherm bound 128
1121if not gpuSweep N beta 3
1122exit 33
1123end
1124end
1125for k ulong nMeas bound 256
1126if not gpuSweep N beta 2
1127exit 34
1128end
1129if not gpuSweep N beta 2
1130exit 35
1131end
1132storeMeas8 k
1133end
1134summarizeTs8 nMeas
1135computeDiffZR8 cid
1136us = div ulong sub monons t0 1000
1137printRow8 cid nMeas us
1138end
1139
1140fn runBeta8 beta f32 seed ulong to void
1141put armSeed 0 seed
1142runArm8 beta 0 64 256
1143runArm8 beta 3 64 256
1144runArm8 beta 8 64 256
1145end
1146
1147fn allocBuf bytes ulong cached bool to long
1148m = nvalloc bytes cached
1149if le m 0
1150uPrint tC8Err
1151uPrintU ulong get nvstage 0
1152uPrint tNl
1153exit 6
1154end
1155ret m
1156end
1157
1158fn main to int
1159uPrint tC8Hdr
1160if not gbopen 1
1161uPrint tC8Err
1162uPrintU ulong get nvstage 0
1163uPrint tNl
1164ret 2
1165end
1166if not gbbopen
1167ret 3
1168end
1169put uCodeMap 0 0
1170uEmitAllKernels
1171csize = mul div add get uCodePos 0 4095 4096 4096
1172cm = nvalloc csize false
1173if le cm 0
1174ret 4
1175end
1176put uCodeMap 0 cm
1177put uCodeFail 0 0
1178uEmitAllKernels
1179if ne get uCodeFail 0 0
1180ret 5
1181end
1182
1183put dLinks 0 allocBuf 4194304 true
1184put dStaples 0 allocBuf 4194304 true
1185put dFlags 0 allocBuf 1048576 true
1186put dNbSite 0 allocBuf 2097152 true
1187put dRng 0 allocBuf 262144 true
1188
1189note Self-checks on 16^4 host RG blocking before touching GPU MC
1190assertRgGaugeCov
1191assertZeroContact8
1192
1193note Step 1: In-situ 10-point periodic 8^4 SU(2) calibration curve
1194uPrint tC8CalHdr
1195uPrint tC8CalCols
1196if not buildNbTable 8
1197rc = nvmclose
1198ret 10
1199end
1200if not buildFlags 8 false
1201rc = nvmclose
1202ret 11
1203end
1204runCalPoint 0 0.25f32
1205runCalPoint 1 0.50f32
1206runCalPoint 2 1.00f32
1207runCalPoint 3 1.50f32
1208runCalPoint 4 2.00f32
1209runCalPoint 5 2.30f32
1210runCalPoint 6 2.50f32
1211runCalPoint 7 3.00f32
1212runCalPoint 8 4.00f32
1213runCalPoint 9 6.00f32
1214
1215note Step 2: Frozen-collar 16^4 Multi-Scale RG Flow (16^4 -> 8^4 -> 4^4)
1216uPrint tC8RgHdr
1217uPrint tC8Cols
1218if not buildNbTable 16
1219rc = nvmclose
1220ret 12
1221end
1222if not buildFlags 16 true
1223rc = nvmclose
1224ret 13
1225end
1226runBeta8 1.50f32 0x80010001
1227runBeta8 2.00f32 0x80020001
1228runBeta8 2.30f32 0x80030001
1229runBeta8 2.50f32 0x80040001
1230runBeta8 2.70f32 0x80050001
1231runBeta8 6.00f32 0x80060001
1232
1233uPrint tC8Done
1234rc = nvmclose
1235ret 0
1236end