Skip to content

Model scalar GM ops in auto sync#951

Open
TaoTao-real wants to merge 9 commits into
hw-native-sys:mainfrom
TaoTao-real:codex/scalar-gm-sync-model
Open

Model scalar GM ops in auto sync#951
TaoTao-real wants to merge 9 commits into
hw-native-sys:mainfrom
TaoTao-real:codex/scalar-gm-sync-model

Conversation

@TaoTao-real

Copy link
Copy Markdown
Contributor

Summary

  • Model pto.load_scalar / pto.store_scalar as PIPE_S memory operations in auto-sync analysis.
  • Teach InsertSync and GraphSyncSolver to trace scalar pointer aliases through pto.addptr and pointer-to-pointer pto.castptr.
  • Preserve the actual address space of function pointer/memref arguments so UB scalar accesses are not accidentally modeled as GM payload accesses.
  • Add lit coverage for TSTORE <-> load_scalar/store_scalar GM hazards on both --enable-insert-sync and --enable-graph-sync-solver.

Motivation

Design

  • load_scalar/store_scalar remain ordinary PTO ops; this PR does not add public IR or memory consistency actions.
  • InsertSync now creates a PIPE_S compound for scalar pointer memory ops when their pointer is known in the alias map.
  • GraphSyncSolver mirrors the same scalar RW modeling.
  • addptr keeps the parent alias range while adding a static byte offset when available; dynamic offsets stay conservative.
  • This PR only restores pipe ordering. Cache maintenance such as dcci/CMO remains explicit user/PyPTO responsibility.

Testing

  • ninja -C build ptoas
  • git diff --check
  • llvm-lit -v build/test/lit --filter 'scalar_gm_tstore_sync'
  • llvm-lit -v build/test/lit --filter 'issue696_scalar_gm_store_flush|issue735_tci_pipe_s_sync|ptr_int_cast'
  • ptoas --pto-arch=a5 --enable-insert-sync --pto-backend=vpto --emit-vpto test/vpto/cases/micro-op/scalar-load-store/load-store-scalar-ub/kernel.pto -o /tmp/load_store_scalar_ub.vpto

Risk / Rollback

  • Risk: additional sync can appear when scalar GM ops and tile stores alias the same root, which is the intended correctness fix.
  • Rollback: revert this PR to return scalar PTO ops to being invisible to auto-sync.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces support for tracking and synchronizing scalar memory operations (such as load and store scalar operations) executing on the S-pipeline (PIPE_S) to prevent races with asynchronous tile stores. It updates the IR translators to handle pointer additions and casts, retrieves address spaces dynamically from pointer and memref types, and adds a test suite to verify the synchronization behavior. The reviewer suggests adding a defensive null check when retrieving the memory space from a pointer type to prevent potential null pointer dereferences.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment on lines +363 to +364
if (auto ptrType = dyn_cast<pto::PtrType>(argType)) {
space = ptrType.getMemorySpace().getAddressSpace();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Defensive Programming: To prevent potential null pointer dereferences, it is safer to defensively check if ptrType.getMemorySpace() is non-null before calling .getAddressSpace(), similar to how memRefType.getMemorySpace() is handled below.

    if (auto ptrType = dyn_cast<pto::PtrType>(argType)) {
      if (auto spaceAttr = ptrType.getMemorySpace())
        space = spaceAttr.getAddressSpace();
    }

@TaoTao-real
TaoTao-real force-pushed the codex/scalar-gm-sync-model branch from c2bcd85 to e05a0ce Compare July 20, 2026 08:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant