Skip to content

Proposal: split global vs shared memory words (@/! and S@/S!) #36

Description

@tetsuo-cpp

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/store
  • S@ / 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

  1. Add new words to parser/translator: S@, S!
  2. Add dialect ops for shared load/store (or equivalent explicit markers)
  3. Lower S@ / S! via workgroup/shared address-space pointers
  4. Keep @ / ! semantics as global memory access
  5. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions