ptxsync

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 4, 2026 License: Apache-2.0 Imports: 5 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

PTX synchronization check

ptxsync.Check parses PTX with ptxast and uses the existing ptxpass CFG. For each kernel entry it reports a source-order diagnostic or a finite full-CTA barrier schedule in execution order. The schedule is useful for checking simple generated kernels while keeping unsupported protocols visible.

A checked path contains only direct, unpredicated jumps, bounded register operations, full-CTA barriers with immediate IDs 0 through 15, and unconditional termination. Every participating thread follows the same static path. The source is assumed to be legal for its target, with ordinary instruction progress. This check covers participation. It does not establish memory safety, liveness of other CTAs, or agreement with compiled SASS.

UNKNOWN identifies unresolved predicates, participant counts, targets, loops, instructions, or ordering requirements. mbarrier needs an object, phase, arrival, and wait analysis. Async copy and proxy fences need alias and completion analysis. Scoped atomics and fences need the scope, address, reader/writer, and publication ordering proved together. The presence of an acquire or release mnemonic alone is insufficient. The general Check entry point reports those cases as diagnostics.

Finite protocol checks

CheckProtocol recognizes three finite idioms. Each participant's instruction path is straight-line, with an explicit .reqntid 1,1,1. The source must be legal for its target with ordinary instruction progress. The named objects must be exclusive to the selected participants. For SharedAsyncCopy, the caller must attest to one CTA and no competing global destination writer through ProtocolPremises. The PTX thread-count directive supplies the threads per CTA. Addresses are direct symbols with no offset.

Idiom Checked property
CTAMBarrier A single, initially uninitialized local shared object is initialized to one arrival. The same thread makes that arrival and tests its returned primary-phase token against the same object. It has no async transactions or subsequent phase. The matcher does not require later code to act on wait success.
SharedAsyncCopy A 16-byte shared store precedes a generic-to-async proxy fence for shared CTA memory. The bulk copy uses the named shared source and a separate named global destination. A group commit and full wait follow the copy. The check covers completion for the issuing thread.
GridPublication A publisher stores a scalar payload, then publishes a one-shot flag at GPU scope with a release store or an exchange that includes release semantics. A subscriber acquires the same flag at GPU scope and reads the payload only when its test observes publication. The flag starts at zero. Each entry runs once with one CTA on the same GPU. The payload check is conditional on observation and gives no scheduling or progress guarantee.

CheckProtocol accepts only those shapes. It reports UNKNOWN on unresolved state, participant, identity, phase, extent, or scope. Each finite matcher has a separate model and tested tie described below. The ordering rules come from the NVIDIA PTX ISA.

Model and checking

MODELED + TESTED. The Lean model takes an already projected, finite sequence of local steps and full-CTA arrivals. It proves that an accepted schedule is nonempty, is a valid traversal, and is the only schedule a traversal of that abstract sequence can produce. It assumes the Go CFG projection and the PTX instruction interpretation. The differential test uses hand-associated PTX and model inputs, including legal barrier reuse, unreachable instructions, an unsupported branch, an invalid ID, and a path without a barrier. It does not compare all PTX inputs. The checker has no native hardware qualification.

From the nvidia module:

(cd x/isa/ptxsync/lean && lake build)
PTXSYNC_LEAN="$PWD/x/isa/ptxsync/lean/.lake/build/bin/ptxsyncmodel" \
  go test -count=1 -race ./x/isa/ptxsync
(cd x/isa/ptxsync/lean && lean-audit.sh -all -lock statements.lock)

The standalone Lean project uses Lean 4.35.0 and core only. The original schedule theorems use only propext. The Go/Lean tie rejects substitutions that raise the barrier bound to 17 or lower it to 15. The statement lock pins the three theorem signatures.

Grid publication model

MODELED + TESTED. The model operates on a projection of the fixed publisher and subscriber paths. Its Boolean check is equivalent to the predicate requiring distinct flag and payload names, a supported GPU-scoped release form and acquire on the same flag, the value-one test using the acquired register, and a positive guard on the read of the same payload. Its second theorem shows that an acquire supplying the value for that guard observed the publication. The theorem's exhaustive flag origins are an initial zero and the single publisher.

The flag and payload must designate disjoint scalar global objects. Each entry runs once with one CTA and one thread on the same GPU. The flag initially holds zero. No other agent accesses these objects during the protocol. The checked source shape supplies the register and predicate links. The PTX memory model supplies release/acquire ordering once the read-from edge is known. The Lean model does not establish the PTX parser or Go projection for arbitrary input, runtime launch configuration, progress, or SASS behavior.

TestLeanPublication compares independent PTX and model fixtures for three supported release forms and twelve changes to order, scope, identity, values, or guard dataflow. The same test detects a Go mutation that accepts a negative guard and one that rejects an acquire-release exchange. The theorem lock includes both publication theorems. Their axiom audit recorded only propext and Quot.sound.

Async-copy model

MODELED + TESTED. The abstract trace moves from empty to staged, fenced, issued, committed, and completed. The Lean theorem proves that acceptance supplies both launch attestations, identical shared object identity, the 16-byte extent, a wait limit of zero groups, and a valid traversal of those transitions. The accepted steps are a fixed sequence of one issuing thread.

The source-level claim requires legal PTX, valid aligned and distinct source and destination objects, one CTA with one thread, no competing accesses, and normal progress. The runtime attestations supply facts absent from the source. The interpretation of store, proxy fence, and bulk-group operations comes from the PTX ISA. The Lean theorem does not establish those hardware effects.

TestLeanAsyncCopy compares independent PTX and model fixtures for the complete protocol, an equivalent wait literal, and eight changes to launch premises, fencing, object identity, extent, or completion order. The tie detects permissive acceptance of a generic fence in place of the proxy fence and restrictive rejection of a hexadecimal spelling of zero. The axiom audit recorded only propext and Quot.sound for the async-copy theorem.

Mbarrier lifetime model

MODELED + TESTED. The Lean model relates a fresh object to one initialization with an expected count of one, a synchronous arrival that creates an opaque token, and a test on the same object with that token. Its theorem proves that acceptance supplies the explicit one-thread CTA condition and a valid traversal of this abstract lifetime. The model tracks token identity, with no assumption about its bit representation.

Each CTA has one thread and its own properly aligned shared object. The object starts fresh, with no competing access or tracked async transaction. The tested instruction consumes the phase identity from the unchanged register defined by the immediately preceding arrival. The PTX ISA supplies instruction and memory semantics. The model covers one phase and does not infer a wait result, useful progress, reuse, or safety once another operation invalidates the object.

TestLeanMBarrier includes two accepted constant spellings and nine negative cases spanning participant count, lifetime, object identity, and stale or clobbered tokens. The tie detects acceptance of a foreign token and rejection of a hexadecimal spelling of one. The axiom audit recorded only propext and Quot.sound for the mbarrier theorem.

Documentation

Overview

Package ptxsync checks conservative subsets of PTX synchronization.

It uses PTX source control flow to certify uniform participation in full-CTA barrier phases along a finite, thread-independent path. It checks selected finite synchronization idioms and reports where a kernel requires analysis outside that subset, including memory barriers, async proxies, and release/acquire protocols.

This package is outside the compatibility promise of github.com/tmc/lib/nvidia. Its API may change or be removed in patch releases.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Barrier

type Barrier struct {
	Line int
	ID   uint8
}

Barrier identifies one static full-CTA synchronization instruction.

type Finding

type Finding struct {
	Line   int
	Reason string
}

Finding explains why the checker could not establish a schedule.

type Protocol

type Protocol uint8

Protocol selects a finite synchronization idiom. Each idiom has a narrower assurance claim than checking arbitrary PTX.

const (
	// CTAMBarrier checks one local object's initialization, single
	// synchronous arrival, and test of the returned phase token.
	CTAMBarrier Protocol = iota + 1
	// SharedAsyncCopy checks one local store, generic-to-async proxy
	// fence, bulk copy, commit, and completion wait.
	SharedAsyncCopy
	// GridPublication checks a release/acquire flag handoff between
	// two named single-thread entries on the same GPU. The supplied
	// entries model the publisher and subscriber, in that order.
	GridPublication
)

type ProtocolPremises

type ProtocolPremises struct {
	// SingleCTA attests that the async-copy entry is launched as one CTA.
	SingleCTA bool
	// ExclusiveDestination attests that no other thread, launch, or
	// host operation can write the global copy destination while the
	// async-copy entry is running.
	ExclusiveDestination bool
}

ProtocolPremises contains caller attestations about a launch and its environment. The checker cannot infer these facts from PTX.

type ProtocolReport

type ProtocolReport struct {
	Status  Status
	Lines   []int
	Finding Finding // populated for Unknown
}

ProtocolReport is the result of checking one recognized idiom. On a checked result Lines gives the protocol instruction lines in order; for GridPublication the publisher precedes the subscriber.

func CheckProtocol

func CheckProtocol(source []byte, kind Protocol, premises ProtocolPremises, entries ...string) (ProtocolReport, error)

CheckProtocol checks the named entry or pair of entries. All entries must have .reqntid 1,1,1 and be straight-line. The caller supplies legal PTX for the target, normal progress, and exclusive access to named objects by the selected participants. SharedAsyncCopy requires both explicit launch premises. GridPublication further assumes the flag is initially zero, the two entries run once with one CTA each, and the CTAs run on the same GPU. Its guarantee is conditional on observing the release, regardless of whether or when the subscriber observes it.

The result applies to protocol shape and ordering, not memory allocation, launch admission, or arbitrary kernel safety. A result of Unknown has no safety implication.

type ReductionReport

type ReductionReport struct {
	Entry      string
	Status     Status
	Barriers   []Barrier
	WarpSyncs  []int // PTX lines of proved full-warp shfl.sync / bar.warp.sync instructions
	SharedSync bool  // true when shared stores and loads are separated by a full-CTA barrier
	Findings   []Finding
}

ReductionReport is the source-level synchronization check for a scoped warp and shared-memory reduction kernel entry.

func CheckReduction

func CheckReduction(source []byte) ([]ReductionReport, error)

CheckReduction parses source and checks each kernel entry for a scoped warp/shared-memory reduction contract:

  • Entry parameters loaded via ld.param.* are CTA-uniform.
  • Every full-CTA bar.sync has an immediate ID in [0, 15], no participant count, and executes under CTA-uniform control flow (never inside a warp-divergent, lane-divergent, or data-dependent branch).
  • Every shfl.sync.* or bar.warp.sync has a full-warp immediate member mask (0xffffffff / -1) and executes under warp-uniform or CTA-uniform control flow (never inside a lane-divergent or data-dependent branch).
  • The %tid.x >> 5 (and %tid.x / 32) warp-uniformity rule assumes a warp-aligned CTA launch where blockDim.x % 32 == 0 so threads sharing %tid.x >> 5 belong to the same hardware warp.
  • Registers assigned under a divergent branch arm inherit that branch's divergence scope so joins/phis across divergent arms cannot synthesize false CTA- or warp-uniformity.
  • When both st.shared.* and ld.shared.* appear, no CFG path from any st.shared.* to any ld.shared.* may bypass a proved full-CTA bar.sync.
  • Unmodeled ordering or collective instructions (mbarrier, async copy, tcgen05, mma/wgmma, multimem, vote/match/redux/elect, setmaxnreg, griddepcontrol, volatile, atomics, fences, acquire/release/relaxed) are always rejected as UNKNOWN.

An entry with no proved warp or CTA synchronization is reported as UNKNOWN.

type Report

type Report struct {
	Entry    string
	Status   Status
	Barriers []Barrier
	Findings []Finding
}

Report is the source-level check for one entry. Barriers is populated only when the schedule is established and gives its execution order.

func Check

func Check(source []byte) ([]Report, error)

Check parses source and reports on each kernel entry in source order. The checker assumes legal PTX for the target and does not validate operand types, address validity, memory ordering, or machine-code lowering.

Example
reports, err := Check([]byte(header + ".entry k() { bar.sync 0; ret; }"))
if err != nil {
	fmt.Println(err)
	return
}
fmt.Println(reports[0].Status, reports[0].Barriers[0].ID)
Output:
CHECKED 0

type Status

type Status uint8

Status describes the scope of a check.

const (
	// Unknown means the check has not established its stated property.
	Unknown Status = iota
	// Checked means the check established its stated property under
	// that check's documented assumptions.
	Checked
)

func (Status) String

func (s Status) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL