libraryextensions/blender/demos/GpuBuild.xtl

GpuBuild.xtl -- source, resolved Core, typed XIR, real OpenCL fusion, and two saved device schedules. All geometry and animation are X_eTaL. Diagrams show compiler structure and logical work-items, not GPU dies. Import: "gb:" u_se< "GpuBuild"

source · imports vd: extensions/blender/lib/Video.xtl

ˡtitle : Char

value · line 8

title: this compiler-process video

ˡtitle ← "X_eTaL GPU: build"

ˡsubtitle : Char

value · line 10

subtitle: provenance and limits of this video

ˡsubtitle ← "real Core, XIR and OpenCL; saved M1 Max and RTX 5060 Ti profiles"

ˡlength : Float

value · line 12

length: nominal video seconds

ˡlength ← 36.0
Used in: ˡs̲cene

ˡcueTable : Float

value · line 14

cueTable: source, IR, fusion, profiles, buffers and verification

ˡcueTable ← f̲loat 7 2 r̲eshape 0 3  3 8  8 13  13 20  20 27  27 32  32 36
Used in: ˡs̲cene, _

ˡc̲ues : a -> Char

function · line 16

gb:c_ues stats: counts come from the compiler artifacts, not estimates

ˡc̲ues ← { s →
  ˡ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."
}
Used in: ˡs̲cene, _

ʰb̲oxes : Any b => (a, a, a) -> b -> a

function (private) · line 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) }
Used in: ˡs̲cene

ʰl̲abels : Any a => (Float, Float) -> a -> Float

function (private) · line 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) }
Used in: ˡs̲cene

ʰj̲oin : Box Char -> Box Char -> Box Char

function (private) · line 22
ʰj̲oin ← { a b → e̲nclose (d̲isclose a) c̲at "|" c̲at d̲isclose b }
Used in: ʰt̲exts

ʰt̲exts : a -> Char

function (private) · line 23
ʰt̲exts ← { values → d̲isclose 'ʰj̲oin r̲/ '{ v → e̲nclose f̲ormat v } e̲ach values }
Used in: ˡs̲cene

ˡs̲cene : (Num a, Num b, Num c, Num d, Any e) => (a, b, c, Char, Char, Char, d, Int) -> e -> Char

function · line 29

(size, nodes, edges, labels, inputs, coreLabels, buffers, stats) gb:s_cene 0: nodes are id/kind/type/items/kernel, edges are actual XIR dependencies. Compiler nodes move into their real fusion groups. Profile grids are logical launch slots; green marks valid stores for a 3 by 2 result.

ˡs̲cene ← { (size, nodes, edges, names, inputs, coreNames, bufferData, s) z →
  w ← 1 s̲elect size
  h ← 2 s̲elect size
  n ← t̲ally nodes
  ids ← f̲loor 1 s̲elect₂ nodes
  kind ← f̲loor 2 s̲elect₂ nodes
  ty ← f̲loor 3 s̲elect₂ nodes
  kernel ← f̲loor 5 s̲elect₂ nodes
  col ← ids − 1 + ty × '+ r̲/ f̲loor f̲loat ty = 0
  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
  d ← (w, h, 35, 13.0, 11.0) ᵛᵈf̲it 0
  ⍝ Literal input arrays, as values, not a code listing.
  a ← f̲loor n̲umbers inputs
  count ← t̲ally a
  ax ← (f̲loat (o̲ffsets count) m̲od 8) − 3.5
  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
  cp ← 3 3 r̲eshape -3 0 -0.7  0 0 -0.7  3 0 -0.7
  ⍝ Actual checked XIR, with typed values and dependencies.
  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
  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
  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
  ne ← t̲ally edges
  start ← (f̲loor 1 s̲elect₂ edges) s̲elect at
  end ← (f̲loor 2 s̲elect₂ edges) s̲elect at
  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
  rank ← '+ r̲/₂ f̲loor f̲loat (kernel '= t̲able kernel) ∧ ids '≥ t̲able ids
  mapped ← (kind > 0) ∧ kind < 5
  xx ← (f̲loat mapped) × -1.5 + f̲loat rank − 1
  xx2 ← xx + (4.0 − xx) × f̲loat kind = 5
  xx3 ← xx2 + ((1 s̲elect₂ at) − xx2) × f̲loat kind = 0
  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
  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)
  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)
  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
  ⍝ Saved matrix launch plans. Gray slots are padding, not idle hardware.
  m ← 11 s̲elect s
  r ← 13 s̲elect s
  grid ← o̲ffsets m + r
  rt ← grid ≥ m
  j ← grid − m × f̲loor f̲loat rt
  columns ← 2 + 14 × f̲loor f̲loat rt
  jx ← j m̲od columns
  jy ← j d̲iv columns
  gx ← ((1.0 − 2.0 × f̲loat rt) × -3.1) + 0.23 × ((f̲loat jx) − ((f̲loat columns) − 1.0) ÷ 2.0)
  gz ← 1.6 − 0.23 × f̲loat jy
  good ← ((n̲ot rt) ∧ j < 6) ∨ rt ∧ (jx < 2) ∧ jy < 3
  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
  gdims ← ((m + r) c̲at 3) r̲eshape 0.18 0.1 0.18
  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₂
    gdims c̲at₂ colors c̲at₂ ((m + r) c̲at 1) r̲eshape 0.4)
  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
  ⍝ Allocated buffer list; no fictional per-operation arrays survive fusion.
  nb ← t̲ally bufferData
  bi ← o̲ffsets nb
  br ← 1 + f̲loor 1 s̲elect₂ bufferData
  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
  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₂
    ((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)
  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
  resultText ← (f̲ormat 16 s̲elect s) c̲at "|" c̲at 3 ᵛᵈf̲ixed (f̲loat 17 s̲elect s) ÷ 1000.0
  ((ᵛᵈhead c̲at ((w, h, 30, ˡlength, 8 10 18, 35) ᵛᵈs̲tage 0)) c̲at
    ((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
    (("inputs", (ap, 0.7 0.15 0.6, 45 105 165 0.3) ʰb̲oxes 0) ᵛᵈb̲oxes 0) c̲at
    (("inputs", (count c̲at 2) r̲eshape 3 8) ᵛᵈs̲hown 0) c̲at
    (("input values", ʰt̲exts a, (ap, 0.35) ʰl̲abels 0) ᵛᵈl̲abels 0) c̲at
    (("input values", (count c̲at 2) r̲eshape 3 8) ᵛᵈs̲hown 0) c̲at
    (("Core", (cp, 2.5 0.15 1.0, 100 70 155 0.4) ʰb̲oxes 0) ᵛᵈb̲oxes 0) c̲at
    (("Core", 3 2 r̲eshape 3 8) ᵛᵈs̲hown 0) c̲at
    (("Core names", coreNames, (cp, 0.45) ʰl̲abels 0) ᵛᵈl̲abels 0) c̲at
    (("Core names", 3 2 r̲eshape 3 8) ᵛᵈs̲hown 0) c̲at
    (("values", boxes) ᵛᵈb̲oxes 0) c̲at
    (("values", spans) ᵛᵈs̲hown 0) c̲at
    (("value names", names, (at, 0.42) ʰl̲abels 0) ᵛᵈl̲abels 0) c̲at
    (("value names", spans) ᵛᵈs̲hown 0) c̲at
    (("dependencies", wires) ᵛᵈl̲ines 0) c̲at
    (("dependencies", (ne c̲at 2) r̲eshape 8 13) ᵛᵈs̲hown 0) c̲at
    (("values", 13.0 17.0, moves) ᵛᵈm̲oves 0) c̲at
    (("value names", 13.0 17.0, lm) ᵛᵈm̲oves 0) c̲at
    (("kernels", envelopes) ᵛᵈo̲utlines 0) c̲at
    (("kernels", 4 2 r̲eshape 17 20) ᵛᵈs̲hown 0) c̲at
    (("launch slots", gp) ᵛᵈb̲oxes 0) c̲at
    (("launch slots", ((m + r) c̲at 2) r̲eshape 20 27) ᵛᵈs̲hown 0) c̲at
    (("profiles", "M1 Max|RTX 5060 Ti", titles) ᵛᵈl̲abels 0) c̲at
    (("profiles", 2 2 r̲eshape 20 27) ᵛᵈs̲hown 0) c̲at
    (("buffers", bp) ᵛᵈb̲oxes 0) c̲at
    (("buffers", (nb c̲at 2) r̲eshape 27 32) ᵛᵈs̲hown 0) c̲at
    (("results", resultText, result) ᵛᵈl̲abels 0) c̲at
    (("results", 2 2 r̲eshape 32 36) ᵛᵈs̲hown 0) c̲at
    (((ˡtitle, ˡsubtitle, 1 8 r̲eshape 0 3 255 255 255 18 22 44) ᵛᵈc̲ards 0)) c̲at
    (ˡc̲ues s, ˡcueTable c̲at₂ 7 3 r̲eshape 255 255 255) ᵛᵈc̲aptions 0)
}
Used in: _