Summary
Add a debug compilation mode that inserts stack overflow/underflow checks and optional bounds checks on loads/stores, producing clear failures instead of silent corruption or CUDA illegal-memory accesses.
Motivation
Release lowering trusts the programmer:
- Fixed stack of 256 cells with no underflow/overflow traps
@ / ! / shared variants perform raw address arithmetic
- Failures often surface as wrong answers or GPU faults far from the offending Forth word
A debug mode is the natural complement to compile-time stack-effect checking.
Proposed design
warpforthc kernel.forth -o k.ptx --debug
# or: -O0 --check-stack --check-bounds
Stack checks
- Before pop: if SP == 0 → trap (e.g.
gpu.printf + assert, or write a well-known error code to a status buffer)
- Before push: if SP >= 255 → trap
- Optional high-water mark side channel for tests
Memory checks (optional, costlier)
- When dynamic extents or declared sizes are known, check index in range before load/store
- Shared vs global: optional assert that
S@ addresses fall in shared attribution (hard; best-effort)
Performance
- Default off for release / demos
- On for
gpu_test debug configurations and local development
Acceptance criteria
Related
Summary
Add a debug compilation mode that inserts stack overflow/underflow checks and optional bounds checks on loads/stores, producing clear failures instead of silent corruption or CUDA illegal-memory accesses.
Motivation
Release lowering trusts the programmer:
@/!/ shared variants perform raw address arithmeticA debug mode is the natural complement to compile-time stack-effect checking.
Proposed design
warpforthc kernel.forth -o k.ptx --debug # or: -O0 --check-stack --check-boundsStack checks
gpu.printf+ assert, or write a well-known error code to a status buffer)Memory checks (optional, costlier)
S@addresses fall in shared attribution (hard; best-effort)Performance
gpu_testdebug configurations and local developmentAcceptance criteria
--debug(or equivalent) flag onwarpforthcRelated