Problem
Shared memory pointers and global pointers are both pushed onto !forth.stack as raw i64 values. By the time @ / ! are lowered, pointer provenance (address space) is lost.
This causes ambiguous lowering (llvm.inttoptr + generic llvm.load/store) and can lead to incorrect PTX memory access behavior for shared memory kernels (observed as CUDA illegal memory access in tiled matmul test).
Proposal
Introduce explicit shared-memory words and keep existing words global by default:
@ / ! -> global memory load/storeS@ / S! -> shared memory load/store
This makes address-space intent explicit at the operation level, even when stack values are untyped runtime i64 addresses.
Why this approach (short term)
- Minimal disruption to current untyped stack design
- Avoids full pointer tagging/type-provenance redesign
- Allows generating address-space-correct lowering for shared memory now
Scope
- Add new words to parser/translator:
S@, S! - Add dialect ops for shared load/store (or equivalent explicit markers)
- Lower
S@ / S! via workgroup/shared address-space pointers - Keep
@ / ! semantics as global memory access - Update docs and kernel examples/tests (including tiled matmul) to use
S@ / S! for shared buffers
Non-goals
- No pointer tagging in this issue
- No redesign of
!forth.stack value representation
Acceptance criteria
- Tiled shared-memory matmul test passes with
S@ / S! - Generated PTX/shared path uses shared-address-space accesses (e.g.
ld.shared/st.shared or equivalent address-space-correct form) - Existing global-memory tests using
@ / ! continue to pass
Follow-ups
Longer-term, consider pointer provenance/tagging if we want truly generic @ / ! over mixed pointer kinds at runtime.
Problem
Shared memory pointers and global pointers are both pushed onto
!forth.stackas rawi64values. By the time@/!are lowered, pointer provenance (address space) is lost.This causes ambiguous lowering (
llvm.inttoptr+ genericllvm.load/store) and can lead to incorrect PTX memory access behavior for shared memory kernels (observed as CUDA illegal memory access in tiled matmul test).Proposal
Introduce explicit shared-memory words and keep existing words global by default:
@/!-> global memory load/storeS@/S!-> shared memory load/storeThis makes address-space intent explicit at the operation level, even when stack values are untyped runtime
i64addresses.Why this approach (short term)
Scope
S@,S!S@/S!via workgroup/shared address-space pointers@/!semantics as global memory accessS@/S!for shared buffersNon-goals
!forth.stackvalue representationAcceptance criteria
S@/S!ld.shared/st.sharedor equivalent address-space-correct form)@/!continue to passFollow-ups
Longer-term, consider pointer provenance/tagging if we want truly generic
@/!over mixed pointer kinds at runtime.