Documentation
¶
Overview ¶
Package syncprobe measures device, stream, and event synchronization latency.
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 ¶
const ( WorkArith = 0 // multiply and add in registers WorkGlobal = 2 // loads from global memory, a line per lane per repetition WorkBulk = 3 // rounds of four 8 KB bulk copies from global to shared memory PollAcquire = 0 // ld.acquire.gpu PollRelaxed = 1 // ld.relaxed.gpu PollBackoff = 2 // ld.relaxed.gpu, then __nanosleep of 64 ns doubling to 1024 ns, as x/cudaready waits )
Kinds of work and of polling in the neighbour kernel, as it numbers them.
const ( ProtoFence = 0 // A: stores, __threadfence, flag; the consumer polls with ld.acquire.gpu ProtoFenceSys = 1 // A with __threadfence_system ProtoNoFence = 2 // A without the fence: not a correct protocol ProtoDataSeq = 3 // B: stores only; each lane polls one slot at a time ProtoOneLane = 4 // A, but only lane 0 of the consumer acquires the flag: not a correct protocol ProtoData = 5 // B: stores only; each lane reads all its slots and repeats until none is empty ProtoRelaxed = 6 // A; the consumer polls with ld.relaxed.gpu, then fence.acquire.gpu )
Protocols of probe P5, as the kernel numbers them.
const AnySM = 0xffffffff
AnySM, as a P5 kernel's psm, puts the producer in block 0 and the consumer in block 1.
Variables ¶
var Ops = []Op{ {Name: "empty", Body: `acc = acc * 1664525u + i;`}, {Name: "timer", Body: `acc += (u32)now();`}, {Name: "ld.weak", Body: load("weak")}, {Name: "ld.volatile", Body: `acc += *(volatile u32*)flag;`}, {Name: "ld.relaxed.gpu", Body: load("relaxed.gpu")}, {Name: "ld.acquire.gpu", Body: load("acquire.gpu")}, {Name: "ld.relaxed.sys", Body: load("relaxed.sys")}, {Name: "ld.acquire.sys", Body: load("acquire.sys")}, {Name: "poll.volatile", Body: `if (*(volatile u32*)flag == 0) { fail++; break; }`}, {Name: "poll.relaxed.gpu", Body: poll("relaxed.gpu")}, {Name: "poll.acquire.gpu", Body: poll("acquire.gpu")}, {Name: "poll.relaxed.gpu+fence.acquire.gpu", Body: poll("relaxed.gpu") + " " + fence("fence.acquire.gpu")}, {Name: "threadfence_block", Body: `__threadfence_block();`}, {Name: "threadfence", Body: `__threadfence();`}, {Name: "threadfence_system", Body: `__threadfence_system();`}, {Name: "fence.acq_rel.cta", Body: fence("fence.acq_rel.cta")}, {Name: "fence.acq_rel.gpu", Body: fence("fence.acq_rel.gpu")}, {Name: "fence.acq_rel.sys", Body: fence("fence.acq_rel.sys")}, {Name: "fence.sc.gpu", Body: fence("fence.sc.gpu")}, {Name: "fence.sc.sys", Body: fence("fence.sc.sys")}, {Name: "fence.release.gpu", Body: fence("fence.release.gpu")}, {Name: "fence.release.sys", Body: fence("fence.release.sys")}, {Name: "fence.acquire.gpu", Body: fence("fence.acquire.gpu")}, {Name: "fence.acquire.sys", Body: fence("fence.acquire.sys")}, {Name: "st.weak", Body: store("weak")}, {Name: "st.relaxed.gpu", Body: store("relaxed.gpu")}, {Name: "st.release.gpu", Body: store("release.gpu")}, {Name: "st.release.sys", Body: store("release.sys")}, {Name: "st+threadfence", Body: store("weak") + ` __threadfence();`}, {Name: "st+threadfence_system", Body: store("weak") + ` __threadfence_system();`}, { Name: "mbarrier.self", Body: `asm volatile("mbarrier.arrive.shared::cta.b64 _, [%0];" :: "r"(mb0) : "memory"); fail += !mbar_wait(mb0, i & 1, maxspin);`, }, { Name: "mbarrier.pingpong", Peer: true, Body: `asm volatile("mbarrier.arrive.shared::cta.b64 _, [%0];" :: "r"(mb0) : "memory"); if (!mbar_wait(mb1, i & 1, maxspin)) { fail++; break; }`, }, }
Ops lists the primitives of probe P4. The first is the control: the timed loop with one multiply and add in it, since the compiler deletes an empty one. A spelling the toolchain rejects is reported by the device test and has no samples.
var Slots = []Slot{
{
Name: "bf16", CType: "unsigned short", PTX: "u16", Empty: "0xffffu",
Encode: "(hash(n) >> 16 == 0xffffu ? 0xfffeu : hash(n) >> 16)",
},
{
Name: "f32sum", CType: "unsigned int", PTX: "u32", Empty: "0u",
Encode: "(n % 4 == 0 ? 0x80000000u : __float_as_uint((float)(n % 4)))",
},
}
Slots lists the buffers of probe P5. A bf16 slot is empty when all its bits are set. A float slot of a sum is empty when it is +0, and a real zero is written as -0.
Functions ¶
func CensusSource ¶
func CensusSource() string
CensusSource returns the CUDA source of a kernel that stores the SM id of each block of its grid.
func Control ¶
Control returns the control arm of a P4 or P5 arm. A P4 arm is "op/load/reps". With 8192 repetitions its control is the same arm with 4096, which costs the same per repetition; under a load it is the same op on an idle SM; otherwise it is the empty loop. A P5 arm is "proto/slot/k/load" and its control is the fenced protocol A with the same buffer and load; the control of a "proto.reset" arm is "A.reset". A neighbour arm is "nb/work/poll/where/n" and its control is the same work with no pollers. Other arms have no control.
func NeighbourSource ¶
func NeighbourSource() string
NeighbourSource returns the CUDA source of the neighbour kernel.
Types ¶
type Op ¶
type Op struct {
Name string
Setup string // C++ statements run once, before the timed loop
Body string // C++ statements run reps times between two timer reads
Peer bool // a second warp of the block answers on the mbarriers
}
An Op is one synchronization primitive timed by the P4 kernel.
type Row ¶
type Row struct {
Arm, Control, Unit string
N int
Median, Min, Max float64
CV float64 // standard deviation over mean
Ratio float64 // Median over the control's median; 0 without a control
Verdict string // "control", "resolved", "unresolved" or ""
}
A Row summarizes one arm against its control.
func Summarize ¶
Summarize returns one row per arm in order of first appearance. The control of an arm is named by control; an arm it maps to "" has none.
The null spread of a control is the distance between the largest and the smallest sample of the control and of the samples of the same arm marked null, which are repeats of it. An arm whose median differs from its control's median by no more than that spread is unresolved.
Example ¶
package main
import (
"github.com/tmc/lib/nvidia/x/obs/diag/syncprobe"
"os"
)
func main() {
samples := []syncprobe.Sample{
{Arm: "empty/idle/4096", NS: 10, Unit: "ns"},
{Arm: "empty/idle/4096", NS: 12, Unit: "ns"},
{Arm: "empty/idle/4096", NS: 11, Unit: "ns", Null: true},
{Arm: "threadfence/idle/4096", NS: 400, Unit: "ns"},
{Arm: "threadfence/idle/4096", NS: 420, Unit: "ns"},
{Arm: "ld.weak/idle/4096", NS: 12, Unit: "ns"},
{Arm: "ld.weak/idle/4096", NS: 12, Unit: "ns"},
}
syncprobe.Fprint(os.Stdout, syncprobe.Summarize(samples, syncprobe.Control))
}
Output: arm n median min max cv control ratio verdict unit empty/idle/4096 2 11.0 10.0 12.0 0.129 empty/idle/4096 1.00 control ns threadfence/idle/4096 2 410.0 400.0 420.0 0.034 empty/idle/4096 37.27 resolved ns ld.weak/idle/4096 2 12.0 12.0 12.0 0.000 empty/idle/4096 1.09 unresolved ns
type Sample ¶
type Sample struct {
Probe string `json:"probe"`
Arm string `json:"arm"`
Null bool `json:"null"`
Sample int `json:"sample"`
Order int `json:"order"`
NS float64 `json:"ns"`
Unit string `json:"unit"`
SMs int `json:"sms"`
CodeBytes int `json:"code_bytes"`
CubinSHA256 string `json:"cubin_sha256"`
Driver string `json:"driver"`
Toolkit string `json:"toolkit"`
Note string `json:"note"`
}
A Sample is one timed launch, one line of a probe's JSONL.