CodeQL / Multiplication result converted to larger type
Multiplication result may overflow 'unsigned int' before it is converted to 'unsigned long'.
Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.
Brought by drakestapleton
Multiplication result may overflow 'unsigned int' before it is converted to 'unsigned long'.
Independent review of PR head 88c90355 (fresh checkout; no GPU runs). Verdict: no blockers. The kernel is correct by design and by the evidence for the shapes it accepts. Four should-fix items, mostly about guards and what the evidence and description say.
None.
src/omega_blackwell_codegen_tgemm.c:199-200 computes (row0 + tid/SPAN) * N + cx*SPAN + ... with a 32-bit IMAD before the wide *4. src/omega_blackwell_codegen_tgemm.c:78 does the same for the B start, (kb0*128 + 8t) * N + n0w. omega_gpu_tgemm_spec (src/omega_gpu_tgemm_api.c:20-22) bounds m only by 65535 tiles and n by 2^17. So any call with m*n >= 2^32 is accepted and silently writes to the wrong rows of C. No trainer shape is near this today (largest is about 8192x50304 = 4.1e8). A table with large kb0 times N has the same problem on the B side. Fix: refuse (uint64_t)m * n >= 2^32 in omega_gpu_tgemm_spec, and document kb0*128*n < 2^32 for caller-built tables. Confidence 85.
src/omega_gpu_tgemm_api.c:66-67 frees, reallocates and rewrites the shared g.tab before omega_gpu_session_lock() at :69. A second thread calling omega_gpu_tgemm can free or overwrite the table while the first thread's kernel is reading it. pfgemm avoids this because its caller owns the table. Fix: build and sync the table under the lock (if the lock is recursive), or state "single caller thread" in the header. Confidence 80.
k50304.log:1 says rt 8 warps 16, because n = 768 is a multiple of 256. tools/run_gpu_tgemm_chip.sh:11 says "warps 8" as well. As a result, the default path for n % 256 != 0 (rt 4 x 8 warps, which the lm_head forward with N = 50304 will take) only ran on the chip through the forced knob (warps8.log, at N 768). N = 50304 never ran on the chip.
rt2.log:1,4 is a FAIL. The uncached setup hit a channel-creation CHIP_FAIL. The run is informational, but the PR body does not mention it.
tests/gpu_tgemm_test.c:187), ad/bd/cd, poison, y1/y2 and the problem buffers are leaked.
Fix: correct the body and the script comment, say what happened in rt2, add a chip shape with n % 256 != 0, and free the buffers on the setup-failure path.
src/omega_blackwell_codegen.h:84) and all four simulators (tests/bw_warp_sim.h:142, bw_warp_sim_tc.h:169, bw_warp_sim_k.h:148, bw_warp_sim_pa.h:158) still model a 32-bit Rc. Only src/omega_blackwell_codegen_tgemm.c:120-121 and the PR body record the chip behaviour. The one live user (src/omega_gpu_elementwise_api.c:354) passes Rc = RZ, so it is safe today. Any future IMAD.HI with a register Rc would pass the simulator and fail on the chip. The "Rc is a 64-bit pair" explanation also comes from a single failing run, not from a probe. This PR cannot touch the enum or the sims (scope), so please open a follow-up issue: a chip probe of IMAD.HI with Rc != RZ, then either model it or have the sims refuse a non-RZ Rc. Also add a Cortex lesson.
tests/gpu_tgemm_test.c:10,233: the default --peak 120.64 is labelled "peak.log". 120.64 is in peak-window1.log; peak.log best is 117.26. A run without --peak would show percentages about 3% low against the gate window.
src/omega_gpu_tgemm_api.c:11: omega_gpu_tgemm_bm() returns 128 when the default picks rt 4 (n % 256 != 0, bm 64). Padding to 128 is still a valid multiple, but the name suggests it is exact.
src/omega_blackwell_codegen_tgemm.c:143,166-168): nkb = 0 in a caller-built table (the fill_launch_locked path) wraps the counter and runs about 2^32 blocks past A and B until the timeout. Kernel-side clamping, or a header warning next to tiles_va, would help.
tests/gpu_tgemm_test.c:60-63: the "production" spec list has k 50304 n 768 rt 4 w 8, but the API picks rt 8 x 16 warps for n 768. The real production pick for the lm_head forward (k 768 n 50304, rt 4 w 8) is not in the budget list.
src/omega_blackwell_codegen_tgemm.c:213) is enforced but never shown to fire in a test. The GPR gate is shown to fire (rt 8 x 8 warps is refused).
device.txt records dirty=1. This is most likely the untracked evidence folder the script creates before running git status (tools/run_gpu_tgemm_chip.sh:18-20). Running git status before mkdir would remove the doubt. build.log only records "gpu_tc_peak_test is up to date", so it does not show the test binary being built at 5b10b824.
make test-gpu-tgemm (Makefile:2568) is not called by any workflow. I grepped .github/workflows and found no tgemm or pfgemm test call. The host and sim proofs only run when the chip script runs. Please add it to a host-suites job (it needs the physics checkout for headers).
omega_gpu_matmul_api.*, the encoder, the IR enum, omega_bw_em.h and the patch step are untouched. tests/gpu_tc_peak_test.c is not changed by this PR (it comes from main, 5faa0f70).
spec_ok requires this to fit within the staging buffers (tgemm.c:24).
spec_ok refuses anything over 16384 (tgemm.c:23). The QMD builder refuses the same (src/omega_blackwell_qmd.c:116) and programs SHIFTED7 = 128. Word 36 keeps the min/target SM config of 32 KB, so rt 8 sits exactly at the cap.
i^1) stays in range for even rt.
smem_bytes exactly (tests/bw_warp_sim_tc.h:150).
prog->count > 1000 returns -1 (tgemm.c:213). Declared registers > 128, or a declared/peak mismatch, return -1 (:215). The API refuses threads x declared > 65536 (api.c fill_launch). I rebuilt and got the same numbers: 800 instructions, peak 125, declared 128.
make test-gpu-tgemm locally (physics at 6d7cf0d): host-only PASS and sim PASS, identical to host-only.log and sim.log. An extra mutant of my own (dropping + 8h from the epilogue row offset) failed the sim: 131072 of 131072 outputs differ. Extra sim cases at the production rt 8 x 16 warps with nkb 3 (kb0 1) were bit-identical in both orders. rt 8 with aqn 2 was refused by codegen, as expected. All local edits were reverted.
Reviewed by an independent Claude Opus 5.5 reviewer for the orchestrator.
github-import 1
aien-dev/omega-mv
487
d0ffdd3c3ad61b9cdc717ea9e46637e9c445bc7d
{"kind":"github-import","owner":"aien-dev","repo":"omega-mv","number":487,"url":"https://github.com/aien-dev/omega-mv/pull/487","export_sha256":"967c79e26a893657b5cdaa45efd442be5dbd2ecfe68e25f9a8c1b5da4d60d452","imported_utc":"2026-11-18T16:38:02Z","metadata":"unavailable","state_derived":true}