libraryextensions/blender/demos/GpuRun.xtl

GpuRun.xtl -- checked OpenCL execution, event timing and reduction. X_eTaL chooses all geometry, colors and animation. Device timestamps time commands; work-group placement and local-memory cells are diagrams. Import: "gr:" u_se< "GpuRun"

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

ˡtitle : Char

value · line 8

title: the execution video

ˡtitle ← "X_eTaL GPU: execution"

ˡsubtitle : Char

value · line 10

subtitle: measured device and scope

ˡsubtitle ← "RTX 5060 Ti: checked results and OpenCL event timestamps"

ˡlength : Float

value · line 12

length: video seconds

ˡlength ← 36.0
Used in: ˡs̲cene

ˡcueTable : Float

value · line 14

cueTable: narration spans

ˡcueTable ← f̲loat 7 2 r̲eshape 0 3  3 9  9 14  14 22  22 28  28 33  33 36
Used in: ˡs̲cene, _

ˡc̲ues : Float -> Char

function · line 16

gr:c_ues stats: measured counts and units, with limits explicit

ˡc̲ues ← { s →
  ˡtitle c̲at ": " c̲at ˡsubtitle c̲at "|RTX: four buffers, " c̲at (f̲ormat f̲loor 3 s̲elect s) c̲at " bytes uploaded, " c̲at (f̲ormat f̲loor 4 s̲elect s) c̲at " bytes read back. M1 Max shares physical memory; its panel is architectural. No M1 timing captured.|Four kernels, one work-group each: map, sum, map, sum. The device reports " c̲at (f̲ormat f̲loor 1 s̲elect s) c̲at " compute units. Queue order is measured; placement is not.|256 local slots: eight inputs and 248 zeros. Barriers halve the active lanes until slot zero holds 32. Algorithm illustration in slow motion.|One warm trial: " c̲at (3 ᵛᵈf̲ixed 11 s̲elect s) c̲at " us executing kernels over " c̲at (3 ᵛᵈf̲ixed 12 s̲elect s) c̲at " us. Bars and gaps share one measured device-time axis.|Host binding, upload, launch wait, readback: one scale. Device execution is inside launch wait. Setup: " c̲at (3 ᵛᵈf̲ixed 5 s̲elect s) c̲at " ms, separate. Three trials retained; no speedup claim.|32 and 16.625: device, XIR interpreter and both pinned evaluators agree. The independent observer and pinned GPU runtime match."
}
Used in: ˡs̲cene, _

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

function (private) · line 20
ʰb̲oxes ← { (p, dims, color) z → p c̲at₂ (((t̲ally p) c̲at 3) r̲eshape dims) c̲at₂ (((t̲ally p) c̲at 4) r̲eshape color) }
Used in: ˡs̲cene

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

function (private) · line 21
ʰl̲abels ← { (p, size) z → p c̲at₂ (((t̲ally p) c̲at 4) r̲eshape size c̲at 235 245 255) }
Used in: ˡs̲cene

ˡs̲cene : (Num a, Any b) => (a, Float, Float, Char, Float, Char, Char) -> b -> Char

function · line 26

(size, stats, timings, timingLabels, reduction, reductionLabels, hostLabels) gr:s_cene 0: real event widths and host phases on separate scales; transfer motion, work-groups and reduction states are algorithm diagrams.

ˡs̲cene ← { (size, s, timings, timingLabels, reduction, reductionLabels, hostLabels) z →
  w ← 1 s̲elect size
  h ← 2 s̲elect size
  d ← (w, h, 35, 13.0, 11.0) ᵛᵈf̲it 0
  ⍝ Two memory architectures; only the RTX panel has captured timings.
  outlines ← 3 10 r̲eshape -3.0 0.2 1.3 4.0 0.2 2.5 80 160 245 0.8  3.0 0.2 1.3 4.0 0.2 2.5 245 170 80 0.8  0.0 0.2 -2.0 10.0 0.2 1.5 100 230 160 0.8
  titles ← 3 7 r̲eshape -3 -0.2 3 0.5 235 245 255  3 -0.2 3 0.5 235 245 255  0 -0.2 -2 0.45 235 245 255
  inputs ← 4 3 r̲eshape -4 0 1.8  -2 0 1.8  -4 0 0.8  -2 0 0.8
  moved ← inputs + 4 3 r̲eshape 6 0 0
  moves ← 4 2 6 r̲eshape r̲avel (inputs c̲at₂ 4 3 r̲eshape 1.2 0.15 0.65) c̲at₂ moved c̲at₂ 4 3 r̲eshape 1.2 0.15 0.65
  ⍝ Logical groups remain outside the CU outline: no invented placement.
  n ← f̲loor 1 s̲elect s
  i ← o̲ffsets n
  p ← 2 1 t̲ranspose (3 c̲at n) r̲eshape (0.6 × f̲loat i m̲od 6) c̲at (n r̲eshape 0.2) c̲at 1.5 − 0.6 × f̲loat i d̲iv 6
  groups ← 4 3 r̲eshape -4 0 1.8  -4 0 0.7  -4 0 -0.4  -4 0 -1.5
  ⍝ Exact Int local-memory tree, 256 lanes, barrier after each fold.
  lane ← o̲ffsets 256
  lp ← 2 1 t̲ranspose 3 256 r̲eshape (0.24 × (f̲loat lane m̲od 16) − 1.8) c̲at (256 r̲eshape 0.0) c̲at 1.8 − 0.24 × f̲loat lane d̲iv 16
  active ← lane '< t̲able 256 128 64 32 16 8 4 2 1
  glow ← 0.08 + 2.0 × f̲loat active ∧ (2 1 t̲ranspose reduction) > 0.0
  ⍝ Four kernels: common microsecond scale including the real gaps.
  begin ← 1 s̲elect₂ timings
  end ← 2 s̲elect₂ timings
  span ← 12 s̲elect s
  x ← -4.8 + 9.6 × ((begin + end) ÷ 2.0) ÷ span
  rowZ ← 1.8 − 0.85 × f̲loat o̲ffsets 4
  bars ← (2 1 t̲ranspose 3 4 r̲eshape x c̲at (4 r̲eshape 0.0) c̲at rowZ) c̲at₂ (2 1 t̲ranspose 3 4 r̲eshape (9.6 × (end − begin) ÷ span) c̲at (4 r̲eshape 0.15) c̲at 4 r̲eshape 0.3) c̲at₂ 4 4 r̲eshape 80 210 180 0.5
  labels ← 2 1 t̲ranspose 3 4 r̲eshape (4 r̲eshape 0.0) c̲at (4 r̲eshape -0.2) c̲at rowZ + 0.4
  axis ← "0 to " c̲at (3 ᵛᵈf̲ixed span) c̲at " us (one shared scale)"
  ⍝ Host phases use their own clock. Launch wait contains device time.
  host ← 4 t̲ake 6 d̲rop s
  before ← 0.0 c̲at (1 s̲elect host) c̲at ((1 s̲elect host) + 2 s̲elect host) c̲at '+ r̲/ 3 t̲ake host
  hp ← ((2 1 t̲ranspose 3 4 r̲eshape (-4.8 + 9.6 × (before + host ÷ 2.0) ÷ 6 s̲elect s) c̲at (4 r̲eshape 0.0) c̲at (4 r̲eshape -0.8)) c̲at₂
    (2 1 t̲ranspose 3 4 r̲eshape (9.6 × host ÷ 6 s̲elect s) c̲at (4 r̲eshape 0.15) c̲at 4 r̲eshape 0.6) c̲at₂ 4 4 r̲eshape 120 130 245 0.5  65 160 245 0.5  80 220 170 0.5  245 175 65 0.5)
  hz ← 1.8 − 0.7 × f̲loat o̲ffsets 4
  hl ← 2 1 t̲ranspose 3 4 r̲eshape (4 r̲eshape 0.0) c̲at (4 r̲eshape -0.2) c̲at hz + 0.6
  ((ᵛᵈ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
    (("memory", outlines) ᵛᵈo̲utlines 0) c̲at
    (("memory", 3 2 r̲eshape 3 9) ᵛᵈs̲hown 0) c̲at
    (("memory names", "RTX host|RTX device|M1 Max: unified (architecture)", titles) ᵛᵈl̲abels 0) c̲at
    (("memory names", 3 2 r̲eshape 3 9) ᵛᵈs̲hown 0) c̲at
    (("uploads", (inputs, 1.2 0.15 0.65, 65 155 245 0.5) ʰb̲oxes 0) ᵛᵈb̲oxes 0) c̲at
    (("uploads", 4 2 r̲eshape 3 9) ᵛᵈs̲hown 0) c̲at
    (("uploads", 4.0 7.0, moves) ᵛᵈm̲oves 0) c̲at
    (("compute units", (p, 0.45 0.15 0.45, 70 105 150 0.2) ʰb̲oxes 0) ᵛᵈo̲utlines 0) c̲at
    (("compute units", (n c̲at 2) r̲eshape 9 14) ᵛᵈs̲hown 0) c̲at
    (("groups", (groups, 2.7 0.15 0.7, 80 220 170 0.4) ʰb̲oxes 0) ᵛᵈb̲oxes 0) c̲at
    (("groups", 4 2 r̲eshape 9 14) ᵛᵈs̲hown 0) c̲at
    (("group names", "map Int|sum Int|map Float|sum Float", (groups + 4 3 r̲eshape 0 -0.2 0, 0.4) ʰl̲abels 0) ᵛᵈl̲abels 0) c̲at
    (("group names", 4 2 r̲eshape 9 14) ᵛᵈs̲hown 0) c̲at
    (("groups", "glow", 8 3 r̲eshape 1 9 2  1 10 0.1  2 10 2  2 11 0.1  3 11 2  3 12 0.1  4 12 2  4 13 0.1) ᵛᵈs̲teps 0) c̲at
    (("local slots", (lp, 0.19 0.1 0.19, 245 175 65 0.1) ʰb̲oxes 0) ᵛᵈb̲oxes 0) c̲at
    (("local slots", 256 2 r̲eshape 14 22) ᵛᵈs̲hown 0) c̲at
    (("local slots", 256 9 r̲eshape 14.0 15.0 16.0 17.0 18.0 19.0 20.0 21.0 21.8, glow) ᵛᵈg̲lows 0) c̲at
    (("local values", 0.0 0.35 0.055 250 210 140, reductionLabels, 14.0 15.0 16.0 17.0 18.0 19.0 20.0 21.0 21.8 22.0) ᵛᵈr̲eadout 0) c̲at
    (("event bars", bars) ᵛᵈb̲oxes 0) c̲at
    (("event bars", 4 2 r̲eshape 22 28) ᵛᵈs̲hown 0) c̲at
    (("event names", timingLabels, (labels, 0.5) ʰl̲abels 0) ᵛᵈl̲abels 0) c̲at
    (("event names", 4 2 r̲eshape 22 28) ᵛᵈs̲hown 0) c̲at
    (("event axis", axis, 1 7 r̲eshape 0 -0.2 2.7 0.4 235 245 255) ᵛᵈl̲abels 0) c̲at
    (("event axis", 1 2 r̲eshape 22 28) ᵛᵈs̲hown 0) c̲at
    (("host phases", hp) ᵛᵈb̲oxes 0) c̲at
    (("host phases", 4 2 r̲eshape 28 33) ᵛᵈs̲hown 0) c̲at
    (("host names", hostLabels, (hl, 0.5) ʰl̲abels 0) ᵛᵈl̲abels 0) c̲at
    (("host names", 4 2 r̲eshape 28 33) ᵛᵈs̲hown 0) c̲at
    (("results", "32|16.625", 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) ᵛᵈl̲abels 0) c̲at
    (("results", 2 2 r̲eshape 33 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: _