Skip to content

Commit f19db6a

Browse files
borisbatclaude
andcommitted
dasLLAMA: scope the cm2 test's scratch arrays
Copilot round 2: 55 plain `var ... : array<T>` locals in test_vulkan_tier_cm2 never finalized, so the suite leaked its scratch across every arm. A plain `var` does not finalize at scope exit in daslang, which is exactly the per-call-array rule the tree already carries. make_offs is deliberately untouched — it does `return <- offs`, and inscope on a moved-out local double-finalizes. Verified: cm2 6/6 with no leak lines, lint clean. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019ruKZPG8G7SPEUyZtvBzcT
1 parent d1df409 commit f19db6a

1 file changed

Lines changed: 55 additions & 55 deletions

File tree

modules/dasLLAMA/tests/test_vulkan_tier_cm2.das

Lines changed: 55 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,11 @@ def private ref_ffn(offs1, offs3, offs2 : array<int64>; nreg : int;
122122
gout |> resize(int(nrows * N))
123123
let nb = int(N / 32l)
124124
let nbh = int(NFE / 32l)
125-
var gate : array<float>
126-
var up : array<float>
127-
var h : array<float>
128-
var hq : array<int>
129-
var hs : array<float>
125+
var inscope gate : array<float>
126+
var inscope up : array<float>
127+
var inscope h : array<float>
128+
var inscope hq : array<int>
129+
var inscope hs : array<float>
130130
gate |> resize(int(NFE))
131131
up |> resize(int(NFE))
132132
h |> resize(int(NFE))
@@ -216,17 +216,17 @@ def test_vulkan_moe_ffn_cm2(t : T?) {
216216
feint("no Vulkan device or no NV_cooperative_matrix2; cm2 twin untestable here\n")
217217
return
218218
}
219-
var wq1 : array<int8>
220-
var ws1 : array<float>
221-
var wq3 : array<int8>
222-
var ws3 : array<float>
223-
var wq2 : array<int8>
224-
var ws2 : array<float>
219+
var inscope wq1 : array<int8>
220+
var inscope ws1 : array<float>
221+
var inscope wq3 : array<int8>
222+
var inscope ws3 : array<float>
223+
var inscope wq2 : array<int8>
224+
var inscope ws2 : array<float>
225225
fill_stack(wq1, ws1, NE * NFE, N, 0l, true)
226226
fill_stack(wq3, ws3, NE * NFE, N, 5l, true)
227227
fill_stack(wq2, ws2, NE * N, NFE, 9l, true)
228-
var wqb : array<uint8>
229-
var no_ws : array<uint8> // q8n stacks upload with an EMPTY scale plane
228+
var inscope wqb : array<uint8>
229+
var inscope no_ws : array<uint8> // q8n stacks upload with an EMPTY scale plane
230230
pack_q8n(wq1, ws1, NE * NFE, N, wqb)
231231
let up_ok = moe_gpu_upload_stack(wqb, no_ws, WOFF1, N, NE * NFE, 6)
232232
if (!up_ok) {
@@ -242,16 +242,16 @@ def test_vulkan_moe_ffn_cm2(t : T?) {
242242

243243
// decode arm: 2 rows, 1 per region — the q8n native-block GEMV + the Q8_0 requant
244244
// mid-chain; int-exact like the q8 suite's decode arm
245-
var xq : array<int8>
246-
var xs : array<float>
245+
var inscope xq : array<int8>
246+
var inscope xs : array<float>
247247
fill_acts(xq, xs, 2l)
248-
var offs1 <- make_offs([1l, 2l], [0l, 1l], [1l, 1l], WOFF1, ege1)
249-
var offs3 <- make_offs([1l, 2l], [0l, 1l], [1l, 1l], WOFF3, ege1)
250-
var offs2 <- make_offs([1l, 2l], [0l, 1l], [1l, 1l], WOFF2, ege2)
251-
var gout : array<float>
248+
var inscope offs1 <- make_offs([1l, 2l], [0l, 1l], [1l, 1l], WOFF1, ege1)
249+
var inscope offs3 <- make_offs([1l, 2l], [0l, 1l], [1l, 1l], WOFF3, ege1)
250+
var inscope offs2 <- make_offs([1l, 2l], [0l, 1l], [1l, 1l], WOFF2, ege2)
251+
var inscope gout : array<float>
252252
gout |> resize(int(2l * N))
253253
matmul_moe_gpu_ffn(gout, offs1, offs3, offs2, 2l, xq, xs, N, NFE, 2l, 6, 6, 6, false)
254-
var refv : array<float>
254+
var inscope refv : array<float>
255255
ref_ffn(offs1, offs3, offs2, 2, wq1, ws1, wq3, ws3, wq2, ws2, xq, xs, 2l, true,
256256
WOFF1, WOFF3, WOFF2, refv)
257257
var c = compare_gout(gout, refv)
@@ -262,9 +262,9 @@ def test_vulkan_moe_ffn_cm2(t : T?) {
262262
// batch arm: 40 rows, 2 regions, deliberately unpadded — underfilled 128-wide token
263263
// tiles + the 96 = 64+32 weight-tail tile on the down twin (clamp/discard coverage)
264264
fill_acts(xq, xs, 40l)
265-
var boffs1 <- make_offs([0l, 2l], [0l, 24l], [24l, 16l], WOFF1, ege1)
266-
var boffs3 <- make_offs([0l, 2l], [0l, 24l], [24l, 16l], WOFF3, ege1)
267-
var boffs2 <- make_offs([0l, 2l], [0l, 24l], [24l, 16l], WOFF2, ege2)
265+
var inscope boffs1 <- make_offs([0l, 2l], [0l, 24l], [24l, 16l], WOFF1, ege1)
266+
var inscope boffs3 <- make_offs([0l, 2l], [0l, 24l], [24l, 16l], WOFF3, ege1)
267+
var inscope boffs2 <- make_offs([0l, 2l], [0l, 24l], [24l, 16l], WOFF2, ege2)
268268
gout |> resize(int(40l * N))
269269
matmul_moe_gpu_ffn(gout, boffs1, boffs3, boffs2, 2l, xq, xs, N, NFE, 40l, 6, 6, 6, false)
270270
ref_ffn(boffs1, boffs3, boffs2, 2, wq1, ws1, wq3, ws3, wq2, ws2, xq, xs, 40l, false,
@@ -276,9 +276,9 @@ def test_vulkan_moe_ffn_cm2(t : T?) {
276276

277277
// multi-tile arm: a 130-row region spans two token tiles (128 + 2-row tail)
278278
fill_acts(xq, xs, 200l)
279-
var moffs1 <- make_offs([0l, 1l], [0l, 130l], [130l, 70l], WOFF1, ege1)
280-
var moffs3 <- make_offs([0l, 1l], [0l, 130l], [130l, 70l], WOFF3, ege1)
281-
var moffs2 <- make_offs([0l, 1l], [0l, 130l], [130l, 70l], WOFF2, ege2)
279+
var inscope moffs1 <- make_offs([0l, 1l], [0l, 130l], [130l, 70l], WOFF1, ege1)
280+
var inscope moffs3 <- make_offs([0l, 1l], [0l, 130l], [130l, 70l], WOFF3, ege1)
281+
var inscope moffs2 <- make_offs([0l, 1l], [0l, 130l], [130l, 70l], WOFF2, ege2)
282282
gout |> resize(int(200l * N))
283283
matmul_moe_gpu_ffn(gout, moffs1, moffs3, moffs2, 2l, xq, xs, N, NFE, 200l, 6, 6, 6, false)
284284
ref_ffn(moffs1, moffs3, moffs2, 2, wq1, ws1, wq3, ws3, wq2, ws2, xq, xs, 200l, false,
@@ -290,8 +290,8 @@ def test_vulkan_moe_ffn_cm2(t : T?) {
290290

291291
// combined arm: the routed weighted-sum reduce composed onto the twin chain, judged
292292
// against the same combine of the GPU's OWN per-row gout (isolates the combine op)
293-
var cw : array<float>
294-
var cinv : array<uint>
293+
var inscope cw : array<float>
294+
var inscope cinv : array<uint>
295295
cw |> resize(40)
296296
cinv |> resize(40)
297297
for (g in range(40)) {
@@ -301,10 +301,10 @@ def test_vulkan_moe_ffn_cm2(t : T?) {
301301
fill_acts(xq, xs, 40l)
302302
gout |> resize(int(40l * N))
303303
matmul_moe_gpu_ffn(gout, boffs1, boffs3, boffs2, 2l, xq, xs, N, NFE, 40l, 6, 6, 6, false)
304-
var comb : array<float>
304+
var inscope comb : array<float>
305305
comb |> resize(int(10l * N))
306306
matmul_moe_gpu_ffn_combined(comb, boffs1, boffs3, boffs2, 2l, xq, xs, cw, cinv, N, NFE, 40l, 10l, 6, 6, 6, false)
307-
var combref : array<float>
307+
var inscope combref : array<float>
308308
combref |> resize(int(10l * N))
309309
for (p in range(10)) {
310310
for (i in range(int(N))) {
@@ -322,13 +322,13 @@ def test_vulkan_moe_ffn_cm2(t : T?) {
322322

323323
// mixed arm: fmt-0 gate/up (the mm/sdot4 rail) + q8n down — the actf16 mid-step
324324
// keyed on the DOWN stack composes with a non-cm2 front half (the gemma triple shape)
325-
var wsb : array<uint8>
325+
var inscope wsb : array<uint8>
326326
pack_upload(wq1, ws1, wqb, wsb)
327327
t |> success(moe_gpu_upload_stack(wqb, wsb, WOFFQ1, N, NE * NFE, 0), "mixed-arm q8 gate uploaded")
328328
pack_upload(wq3, ws3, wqb, wsb)
329329
t |> success(moe_gpu_upload_stack(wqb, wsb, WOFFQ3, N, NE * NFE, 0), "mixed-arm q8 up uploaded")
330-
var xoffs1 <- make_offs([0l, 2l], [0l, 24l], [24l, 16l], WOFFQ1, ege1)
331-
var xoffs3 <- make_offs([0l, 2l], [0l, 24l], [24l, 16l], WOFFQ3, ege1)
330+
var inscope xoffs1 <- make_offs([0l, 2l], [0l, 24l], [24l, 16l], WOFFQ1, ege1)
331+
var inscope xoffs3 <- make_offs([0l, 2l], [0l, 24l], [24l, 16l], WOFFQ3, ege1)
332332
fill_acts(xq, xs, 40l)
333333
gout |> resize(int(40l * N))
334334
matmul_moe_gpu_ffn(gout, xoffs1, xoffs3, boffs2, 2l, xq, xs, N, NFE, 40l, 0, 0, 6, false)
@@ -362,17 +362,17 @@ def test_vulkan_moe_ffn_cm2_streamed(t : T?) {
362362
feint("no Vulkan device or no NV_cooperative_matrix2; cm2 twin untestable here\n")
363363
return
364364
}
365-
var wq1 : array<int8>
366-
var ws1 : array<float>
367-
var wq3 : array<int8>
368-
var ws3 : array<float>
369-
var wq2 : array<int8>
370-
var ws2 : array<float>
365+
var inscope wq1 : array<int8>
366+
var inscope ws1 : array<float>
367+
var inscope wq3 : array<int8>
368+
var inscope ws3 : array<float>
369+
var inscope wq2 : array<int8>
370+
var inscope ws2 : array<float>
371371
fill_stack(wq1, ws1, NE * NFE, N, 21l, true)
372372
fill_stack(wq3, ws3, NE * NFE, N, 26l, true)
373373
fill_stack(wq2, ws2, NE * N, NFE, 30l, true)
374-
var wqb : array<uint8>
375-
var no_ws : array<uint8>
374+
var inscope wqb : array<uint8>
375+
var inscope no_ws : array<uint8>
376376
pack_q8n(wq1, ws1, NE * NFE, N, wqb)
377377
let up_ok = moe_gpu_upload_stack(wqb, no_ws, SWOFF, N, NE * NFE, 6, [stream = true])
378378
if (!up_ok) {
@@ -385,16 +385,16 @@ def test_vulkan_moe_ffn_cm2_streamed(t : T?) {
385385
t |> success(moe_gpu_upload_stack(wqb, no_ws, SWOFF + 2000000l, NFE, NE * N, 6, [stream = true]), "streamed q8n down mirrored")
386386
let ege1 = NFE * N
387387
let ege2 = N * NFE
388-
var xq : array<int8>
389-
var xs : array<float>
388+
var inscope xq : array<int8>
389+
var inscope xs : array<float>
390390
fill_acts(xq, xs, 40l)
391-
var offs1 <- make_offs([0l, 2l], [0l, 24l], [24l, 16l], SWOFF, ege1)
392-
var offs3 <- make_offs([0l, 2l], [0l, 24l], [24l, 16l], SWOFF + 1000000l, ege1)
393-
var offs2 <- make_offs([0l, 2l], [0l, 24l], [24l, 16l], SWOFF + 2000000l, ege2)
394-
var gout : array<float>
391+
var inscope offs1 <- make_offs([0l, 2l], [0l, 24l], [24l, 16l], SWOFF, ege1)
392+
var inscope offs3 <- make_offs([0l, 2l], [0l, 24l], [24l, 16l], SWOFF + 1000000l, ege1)
393+
var inscope offs2 <- make_offs([0l, 2l], [0l, 24l], [24l, 16l], SWOFF + 2000000l, ege2)
394+
var inscope gout : array<float>
395395
gout |> resize(int(40l * N))
396396
matmul_moe_gpu_ffn(gout, offs1, offs3, offs2, 2l, xq, xs, N, NFE, 40l, 6, 6, 6, false)
397-
var refv : array<float>
397+
var inscope refv : array<float>
398398
ref_ffn(offs1, offs3, offs2, 2, wq1, ws1, wq3, ws3, wq2, ws2, xq, xs, 40l, false,
399399
SWOFF, SWOFF + 1000000l, SWOFF + 2000000l, refv)
400400
let c = compare_gout(gout, refv)
@@ -419,22 +419,22 @@ def test_vulkan_arena_cm2(t : T?) {
419419
feint("no Vulkan device or no NV_cooperative_matrix2; cm2 arena untestable here\n")
420420
return
421421
}
422-
var wq : array<int8>
423-
var ws : array<float>
422+
var inscope wq : array<int8>
423+
var inscope ws : array<float>
424424
fill_stack(wq, ws, NFE, N, 13l, false)
425-
var wqb : array<uint8>
426-
var no_ws : array<uint8>
425+
var inscope wqb : array<uint8>
426+
var inscope no_ws : array<uint8>
427427
pack_q8n(wq, ws, NFE, N, wqb)
428428
if (!vk_arena_reserve(6, NFE * (N / 32l))) {
429429
feint("fmt-6 arena reserve refused (no device); skipping\n")
430430
return
431431
}
432432
let blk = vk_arena_place(wqb, no_ws, N, NFE, 6)
433433
t |> success(blk >= 0l, "q8n arena placement accepted an empty scale plane")
434-
var xq : array<int8>
435-
var xs : array<float>
434+
var inscope xq : array<int8>
435+
var inscope xs : array<float>
436436
fill_acts(xq, xs, 1l)
437-
var y : array<float>
437+
var inscope y : array<float>
438438
y |> resize(int(NFE))
439439
vk_arena_gemv(y, blk, N, NFE, 6, xq, xs)
440440
let nb = int(N / 32l)

0 commit comments

Comments
 (0)