sourceextensions/blender/demos/GpuBuild.xtl

1⍝│ GpuBuild.xtl -- source, resolved Core, typed XIR, real OpenCL fusion, 2⍝│ and two saved device schedules. All geometry and animation are X_eTaL. 3⍝│ Diagrams show compiler structure and logical work-items, not GPU dies. 4⍝│ Import: "gb:" u_se< "GpuBuild" 5"vd:" u̲se< "Video" 6 7⍝│ title: this compiler-process video 8ˡtitle ← "X_eTaL GPU: build" 9⍝│ subtitle: provenance and limits of this video 10ˡsubtitle ← "real Core, XIR and OpenCL; saved M1 Max and RTX 5060 Ti profiles" 11⍝│ length: nominal video seconds 12ˡlength ← 36.0 13⍝│ cueTable: source, IR, fusion, profiles, buffers and verification 14ˡcueTable ← f̲loat 7 2 r̲eshape 0 3 3 8 8 13 13 20 20 27 27 32 32 36 15⍝│ gb:c_ues stats: counts come from the compiler artifacts, not estimates 16ˡc̲ues ← { s → 17 ˡtitle c̲at ": " c̲at ˡsubtitle c̲at "|Source arrays enter Core. The GPU lowerer resolves " c̲at (f̲ormat 18 s̲elect s) c̲at " called Accel closures and inlines their bodies.|Typed XIR: " c̲at (f̲ormat 1 s̲elect s) c̲at " values; " c̲at (f̲ormat 2 s̲elect s) c̲at " elementwise operations and " c̲at (f̲ormat 3 s̲elect s) c̲at " reductions. Int is i64; these profiles emit Float as f32.|Real OpenCL C: each elementwise chain fuses into one kernel. The two sums remain separate: " c̲at (f̲ormat 4 s̲elect s) c̲at " kernels total. Envelopes are compiler groups.|Saved schedules, matrix example: six output stores. M1 profile: untiled, " c̲at (f̲ormat 11 s̲elect s) c̲at " work-items. RTX profile: 16 by 16 tile, " c̲at (f̲ormat 13 s̲elect s) c̲at " slots with edge padding. No timing comparison.|Fusion avoids " c̲at (f̲ormat 6 s̲elect s) c̲at " intermediate arrays; " c̲at (f̲ormat 5 s̲elect s) c̲at " buffers remain. Blue inputs, green map results, orange sums. Both profiles use a 256-item reduction group.|32 and 16.625: both pinned evaluators and the XIR interpreter agree. Emitted kernels pass OpenCL C syntax checks. Device execution and profiling follow separately." 18} 19 20ʰb̲oxes ← { (positions, dims, color) z → positions c̲at₂ (((t̲ally positions) c̲at 3) r̲eshape dims) c̲at₂ (((t̲ally positions) c̲at 4) r̲eshape color) } 21ʰl̲abels ← { (positions, size) z → (positions + (s̲hape positions) r̲eshape 0.0 -0.2 0.0) c̲at₂ (((t̲ally positions) c̲at 4) r̲eshape size c̲at 240 245 255) } 22ʰj̲oin ← { a b → e̲nclose (d̲isclose a) c̲at "|" c̲at d̲isclose b } 23ʰt̲exts ← { values → d̲isclose 'ʰj̲oin r̲/ '{ v → e̲nclose f̲ormat v } e̲ach values } 24 25⍝│ (size, nodes, edges, labels, inputs, coreLabels, buffers, stats) gb:s_cene 0: 26⍝│ nodes are id/kind/type/items/kernel, edges are actual XIR dependencies. 27⍝│ Compiler nodes move into their real fusion groups. Profile grids are 28⍝│ logical launch slots; green marks valid stores for a 3 by 2 result. 29ˡs̲cene ← { (size, nodes, edges, names, inputs, coreNames, bufferData, s) z → 30 w ← 1 s̲elect size 31 h ← 2 s̲elect size 32 n ← t̲ally nodes 33 ids ← f̲loor 1 s̲elect₂ nodes 34 kind ← f̲loor 2 s̲elect₂ nodes 35 ty ← f̲loor 3 s̲elect₂ nodes 36 kernel ← f̲loor 5 s̲elect₂ nodes 37 col ← ids − 1 + ty × '+ r̲/ f̲loor f̲loat ty = 0 38 at ← 2 1 t̲ranspose (3 c̲at n) r̲eshape (1.2 × (f̲loat col) − 4.0) c̲at (n r̲eshape 0.0) c̲at 1.6 − 3.2 × f̲loat ty 39 d ← (w, h, 35, 13.0, 11.0) ᵛᵈf̲it 0 40 ⍝ Literal input arrays, as values, not a code listing. 41 a ← f̲loor n̲umbers inputs 42 count ← t̲ally a 43 ax ← (f̲loat (o̲ffsets count) m̲od 8) − 3.5 44 ap ← 2 1 t̲ranspose (3 c̲at count) r̲eshape ax c̲at (count r̲eshape 0.0) c̲at 2.8 − 1.1 × f̲loat (o̲ffsets count) d̲iv 8 45 cp ← 3 3 r̲eshape -3 0 -0.7 0 0 -0.7 3 0 -0.7 46 ⍝ Actual checked XIR, with typed values and dependencies. 47 rgb ← f̲loat 2 1 t̲ranspose (3 c̲at n) r̲eshape (65 + 185 × ty) c̲at (160 − 25 × ty) c̲at 245 − 160 × ty 48 boxes ← at c̲at₂ ((n c̲at 3) r̲eshape 0.8 0.15 0.65) c̲at₂ rgb c̲at₂ (n c̲at 1) r̲eshape 0.4 49 spans ← 2 1 t̲ranspose (2 c̲at n) r̲eshape (n r̲eshape 8.0) c̲at 20.0 − 7.0 × f̲loat kind = 0 50 ne ← t̲ally edges 51 start ← (f̲loor 1 s̲elect₂ edges) s̲elect at 52 end ← (f̲loor 2 s̲elect₂ edges) s̲elect at 53 wires ← (start + (s̲hape start) r̲eshape 0.0 0.12 0.0) c̲at₂ (end + (s̲hape end) r̲eshape 0.0 0.12 0.0) c̲at₂ (ne c̲at 4) r̲eshape 100 150 190 0.02 54 rank ← '+ r̲/₂ f̲loor f̲loat (kernel '= t̲able kernel) ∧ ids '≥ t̲able ids 55 mapped ← (kind > 0) ∧ kind < 5 56 xx ← (f̲loat mapped) × -1.5 + f̲loat rank − 1 57 xx2 ← xx + (4.0 − xx) × f̲loat kind = 5 58 xx3 ← xx2 + ((1 s̲elect₂ at) − xx2) × f̲loat kind = 0 59 fused ← 2 1 t̲ranspose (3 c̲at n) r̲eshape xx3 c̲at (n r̲eshape 0.0) c̲at 3 s̲elect₂ at 60 moves ← (n c̲at 2 c̲at 6) r̲eshape r̲avel ((at c̲at₂ (n c̲at 3) r̲eshape 0.8 0.15 0.65) c̲at₂ fused c̲at₂ (n c̲at 3) r̲eshape 0.8 0.15 0.65) 61 lm ← (n c̲at 2 c̲at 6) r̲eshape r̲avel (((at + (n c̲at 3) r̲eshape 0.0 -0.2 0.0) c̲at₂ (n c̲at 3) r̲eshape 1.0) c̲at₂ (fused + (n c̲at 3) r̲eshape 0.0 -0.2 0.0) c̲at₂ (n c̲at 3) r̲eshape 1.0) 62 envelopes ← 4 10 r̲eshape -0.5 0.2 1.6 3.6 0.2 1.2 90 200 245 1 4 0.2 1.6 1.6 0.2 1.2 90 200 245 1 0 0.2 -1.6 4.6 0.2 1.2 245 150 90 1 4 0.2 -1.6 1.6 0.2 1.2 245 150 90 1 63 ⍝ Saved matrix launch plans. Gray slots are padding, not idle hardware. 64 m ← 11 s̲elect s 65 r ← 13 s̲elect s 66 grid ← o̲ffsets m + r 67 rt ← grid ≥ m 68 j ← grid − m × f̲loor f̲loat rt 69 columns ← 2 + 14 × f̲loor f̲loat rt 70 jx ← j m̲od columns 71 jy ← j d̲iv columns 72 gx ← ((1.0 − 2.0 × f̲loat rt) × -3.1) + 0.23 × ((f̲loat jx) − ((f̲loat columns) − 1.0) ÷ 2.0) 73 gz ← 1.6 − 0.23 × f̲loat jy 74 good ← ((n̲ot rt) ∧ j < 6) ∨ rt ∧ (jx < 2) ∧ jy < 3 75 colors ← 2 1 t̲ranspose (3 c̲at m + r) r̲eshape (55 + 25 × f̲loat good) c̲at (65 + 175 × f̲loat good) c̲at 80 + 80 × f̲loat good 76 gdims ← ((m + r) c̲at 3) r̲eshape 0.18 0.1 0.18 77 gp ← ((2 1 t̲ranspose (3 c̲at m + r) r̲eshape gx c̲at ((m + r) r̲eshape 0.0) c̲at gz) c̲at₂ 78 gdims c̲at₂ colors c̲at₂ ((m + r) c̲at 1) r̲eshape 0.4) 79 titles ← 2 7 r̲eshape -3.1 -0.2 2.4 0.6 235 240 255 3.1 -0.2 2.4 0.6 235 240 255 80 ⍝ Allocated buffer list; no fictional per-operation arrays survive fusion. 81 nb ← t̲ally bufferData 82 bi ← o̲ffsets nb 83 br ← 1 + f̲loor 1 s̲elect₂ bufferData 84 bc ← f̲loat 2 1 t̲ranspose (3 c̲at nb) r̲eshape (br s̲elect 60 60 250) c̲at (br s̲elect 140 220 160) c̲at br s̲elect 240 130 80 85 bp ← ((2 1 t̲ranspose (3 c̲at nb) r̲eshape (1.2 × (f̲loat bi m̲od 4) − 1.5) c̲at (nb r̲eshape 0.0) c̲at 1.4 − 1.6 × f̲loat bi d̲iv 4) c̲at₂ 86 ((nb c̲at 3) r̲eshape 0.85 0.15 0.75) c̲at₂ bc c̲at₂ (nb c̲at 1) r̲eshape 0.4) 87 result ← 2 7 r̲eshape -2.5 -0.2 1.0 1.1 100 250 160 2.5 -0.2 1.0 1.1 250 180 100 88 resultText ← (f̲ormat 16 s̲elect s) c̲at "|" c̲at 3 ᵛᵈf̲ixed (f̲loat 17 s̲elect s) ÷ 1000.0 89 ((ᵛᵈhead c̲at ((w, h, 30, ˡlength, 8 10 18, 35) ᵛᵈs̲tage 0)) c̲at 90 ((0.0 36.0, 2 3 r̲eshape 0.0 c̲at (n̲eg d) c̲at 0.0, 2 3 r̲eshape 0.0) ᵛᵈc̲amera 0) c̲at 91 (("inputs", (ap, 0.7 0.15 0.6, 45 105 165 0.3) ʰb̲oxes 0) ᵛᵈb̲oxes 0) c̲at 92 (("inputs", (count c̲at 2) r̲eshape 3 8) ᵛᵈs̲hown 0) c̲at 93 (("input values", ʰt̲exts a, (ap, 0.35) ʰl̲abels 0) ᵛᵈl̲abels 0) c̲at 94 (("input values", (count c̲at 2) r̲eshape 3 8) ᵛᵈs̲hown 0) c̲at 95 (("Core", (cp, 2.5 0.15 1.0, 100 70 155 0.4) ʰb̲oxes 0) ᵛᵈb̲oxes 0) c̲at 96 (("Core", 3 2 r̲eshape 3 8) ᵛᵈs̲hown 0) c̲at 97 (("Core names", coreNames, (cp, 0.45) ʰl̲abels 0) ᵛᵈl̲abels 0) c̲at 98 (("Core names", 3 2 r̲eshape 3 8) ᵛᵈs̲hown 0) c̲at 99 (("values", boxes) ᵛᵈb̲oxes 0) c̲at 100 (("values", spans) ᵛᵈs̲hown 0) c̲at 101 (("value names", names, (at, 0.42) ʰl̲abels 0) ᵛᵈl̲abels 0) c̲at 102 (("value names", spans) ᵛᵈs̲hown 0) c̲at 103 (("dependencies", wires) ᵛᵈl̲ines 0) c̲at 104 (("dependencies", (ne c̲at 2) r̲eshape 8 13) ᵛᵈs̲hown 0) c̲at 105 (("values", 13.0 17.0, moves) ᵛᵈm̲oves 0) c̲at 106 (("value names", 13.0 17.0, lm) ᵛᵈm̲oves 0) c̲at 107 (("kernels", envelopes) ᵛᵈo̲utlines 0) c̲at 108 (("kernels", 4 2 r̲eshape 17 20) ᵛᵈs̲hown 0) c̲at 109 (("launch slots", gp) ᵛᵈb̲oxes 0) c̲at 110 (("launch slots", ((m + r) c̲at 2) r̲eshape 20 27) ᵛᵈs̲hown 0) c̲at 111 (("profiles", "M1 Max|RTX 5060 Ti", titles) ᵛᵈl̲abels 0) c̲at 112 (("profiles", 2 2 r̲eshape 20 27) ᵛᵈs̲hown 0) c̲at 113 (("buffers", bp) ᵛᵈb̲oxes 0) c̲at 114 (("buffers", (nb c̲at 2) r̲eshape 27 32) ᵛᵈs̲hown 0) c̲at 115 (("results", resultText, result) ᵛᵈl̲abels 0) c̲at 116 (("results", 2 2 r̲eshape 32 36) ᵛᵈs̲hown 0) c̲at 117 (((ˡtitle, ˡsubtitle, 1 8 r̲eshape 0 3 255 255 255 18 22 44) ᵛᵈc̲ards 0)) c̲at 118 (ˡc̲ues s, ˡcueTable c̲at₂ 7 3 r̲eshape 255 255 255) ᵛᵈc̲aptions 0) 119}