Skip to content

GPU-05 workgroup barrier: __sync_threads + Barrier.arrive_and_wait #26

Closed

Description

@K-T0BIAS

Add a CUDA-style workgroup barrier on the @Gpu path so cooperative kernels can
synchronize within a local workgroup (same scope as CUDA __syncthreads).

Expose two call forms from cthreads.sync that lower to the same GLSL
barrier (no host locks / no GLSL spinlocks):

  • __sync_threads(): CUDA-familiar
  • Barrier.arrive_and_wait(): beginner-friendly; not Barrier(...) construction

Motivation

  • Enable shared-memory tiles / reductions later (__sync_threads is the first step)
  • Keep one import surface: from cthreads.sync import Barrier, __sync_threads
  • Reuse the existing GPU CallPlugin pattern (AST name / Attribute match)

Scope (explicit)

  • Workgroup / block local only (GLSL barrier() + memoryBarrierShared())
  • Not grid-wide sync (that stays multi-dispatch / host join)
  • Not Python mid-run observe
  • CPU Barrier(parties).arrive_and_wait() unchanged (host mutex/CV barrier)
  • @Gpu rejects Barrier(n) / Barrier() construction with a clear error

Implementation sketch

  • Stub: cthreads.sync.__sync_threads
  • Plugin: gpu/compiler/translation/plugins/sync_threads.py
  • Wire GpuFlow.expr_stmt so call statements lower through CallPlugins
  • Tests: both forms emit barrier(); constructor rejected
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

sub-featurePiece of a larger enchancement

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions