Skip to content

TypedPython: vectorise element-wise loops over array.array buffers without giving up per-element atomicity #226

Closed

Description

@b-re-w

Follow-up to #149/#225 (leader decision 2026-10-17: keep relaxed atomic element access; plain access is a data race in the C memory model, which N-9 does not allow).

Measured (quiet window, 11 interleaved pairs, 2,000,000 doubles, 3.15.0rc1t):

  • an element-wise store loop (a[i] = a[i] * k) is 2.54x slower with relaxed atomics than with plain access, because the compiler does not vectorise atomic accesses;
  • a read-and-reduce loop is unaffected (1.001), since the strict-FP reduction is not vectorised anyway.

Idea to investigate: emit explicitly vectorised code whose vector loads and stores are element-wise single-copy atomic on the target (aligned NEON / SSE / AVX element accesses are single-copy atomic per element on arm64 and x86-64). Express this so the C memory model still sees per-element atomic accesses, for example a target-specific helper with a documented guarantee. Prove or measure that no tearing below 8 bytes can occur.

Done when: the scale kernel's cost is within 10% of plain access, and a design note states per target why each element access stays single-copy atomic.

Activity

  1. added a commit that references this issue on Oct 25, 2026
  2. b-re-w commented on Oct 25, 2026

    @b-re-w
    MemberAuthor

    Landed in develop via #270

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions