Documentation
¶
Overview ¶
Package cudatimer measures what the SM timer registers mean: the tick of %globaltimer, whether a split LO/HI read can tear, the SM clock rate against %globaltimer, and whether %globaltimer agrees across SMs.
Source is the device side, CUDA C compiled with cudaphase.h as a header. Its kernels write raw reads; the functions here judge them:
- Steps summarizes consecutive reads: zero steps, the smallest nonzero step, their GCD and the alignment of the values. Steps.Tick reports the tick only when some reads repeated, which shows the reader was faster than the tick.
- DecodeTears and SummarizeTears read the rows of the timer_tear_* kernels: each reader's backward steps and the reads around the first change of the high word.
- SeriesGHz turns (cycles, nanoseconds) samples into clock rates. The per-block rate is ikettrace.SummarizeClock's.
- EstimateOffset is the NTP estimate of one SM's timer offset from ping-pong exchanges, with its bound; SummarizeReleases measures the spread of first reads after a flag in global memory releases every SM.
The native test (CUDATIMER_NATIVE=1, under an inherited GPU lock) loads the cubin it disassembles, checks the timer instructions in each loop, and writes a JSON report and ledger rows.
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 ( TearWindow = 16 // reads kept around the first change of the high word TearRow = 8 + TearWindow // uint64 values per tear reader ReleaseRow = 4 // uint64 values per block per release PingRow = 4 // uint64 values per block per round )
Layout of the device rows, matching cudatimer.cu.
Variables ¶
var Source string
Source is the device side of the probes. Compile it with cudaphase.h (ikettrace.PhaseHeader) available as a header.
var TearKernels = []string{
"timer_tear_gt64",
"timer_tear_gtsplit",
"timer_tear_gtretry",
"timer_tear_gtdelayed",
"timer_tear_clocksplit",
"timer_tear_clock64",
}
Tear kernels, in the order of their modes.
Functions ¶
func DecodePings ¶
DecodePings splits timer_pingpong output for blocks blocks of rounds rounds into each peer's exchanges and every block's smid. Block 0 is the reference; its exchanges are nil. The 48-bit times the device sends are not used: rows hold full reads.
Types ¶
type Exchange ¶
type Exchange struct{ T1, T2, T3 uint64 }
An Exchange is one ping-pong round between a reference SM and a peer: the reference reads T1 and sends, the peer reads T2 on receipt and replies, and the reference reads T3 on receipt.
type Offset ¶
type Offset struct {
Offset float64 // nanoseconds
Bound float64 // half the round trip of the best round, plus one tick
RTT uint64 // round trip of the best round
Rounds int
}
An Offset is the NTP estimate of a peer's timer minus the reference's. The true offset lies within Bound of Offset.
func EstimateOffset ¶
EstimateOffset estimates a peer's offset from the round with the shortest round trip. The peer's T2 lies between T1 and T3 on the reference's clock, so offset = T2 - (T1+T3)/2 within (T3-T1)/2; a read quantized to tick moves each bound by up to one tick.
Example ¶
package main
import (
"fmt"
"github.com/tmc/lib/nvidia/x/obs/cudatimer"
)
func main() {
// The peer reads 5,300 between the reference's 5,000 and 5,400.
o, _ := cudatimer.EstimateOffset([]cudatimer.Exchange{{T1: 5000, T2: 5300, T3: 5400}}, 32)
fmt.Printf("offset %.0f ns +- %.0f, contains 0: %v\n", o.Offset, o.Bound, o.Contains(0))
}
Output: offset 100 ns +- 232, contains 0: true
type Release ¶
type Release struct {
First []uint64 // warp 0's read, by block
Second []uint64 // warp 1's read, by block
SM []int // smid, by block
Releaser int // block that set the flag
}
A Release is one release's first reads, by block.
type ReleaseSummary ¶
type ReleaseSummary struct {
Releases int
SMs int // distinct SMs that read
Spread []float64 // per release: latest minus earliest warp 0 read, releaser excluded
Floor []float64 // per release: largest |warp 1 - warp 0| within one block
// contains filtered or unexported fields
}
ReleaseSummary describes first reads after each release, in nanoseconds.
func SummarizeReleases ¶
func SummarizeReleases(rs []Release) ReleaseSummary
SummarizeReleases measures each release's spread, excluding the block that released (it reads the flag it wrote, not one it polled), and the floor from two warps of the same block, which share an SM and so share any timer offset.
func (ReleaseSummary) LateBy ¶
func (s ReleaseSummary) LateBy(b int) float64
LateBy returns block b's median lateness over the releases it did not release: its warp 0 read minus the median warp 0 read of the non-releasing blocks.
type Steps ¶
type Steps struct {
Readers int
Deltas int // consecutive pairs
Zero int // pairs that read the same value
Backward int // pairs whose second read is lower
MinNonzero uint64 // smallest forward step, 0 if none
GCD uint64 // GCD of the forward steps
Align uint64 // largest power of two dividing every value read; 0 if every value was 0
Hist map[uint64]int // forward steps by size
// contains filtered or unexported fields
}
Steps summarizes consecutive reads of one counter. Add each reader's reads separately; deltas never cross readers.
func (*Steps) Tick ¶
Tick returns the counter's tick: the step every forward step is a multiple of. It is resolved only if some reads repeated, so the reader sampled faster than the counter moved, the smallest step equals the GCD, and no step went backward. Otherwise the smallest step bounds the tick from above and the error says why.
Example ¶
A reader that samples faster than the counter moves sees repeats, so its steps resolve the tick.
package main
import (
"fmt"
"github.com/tmc/lib/nvidia/x/obs/cudatimer"
)
func main() {
var s cudatimer.Steps
s.Add([]uint64{1024, 1056, 1056, 1088, 1152, 1184})
tick, err := s.Tick()
fmt.Println(tick, err)
}
Output: 32 <nil>
type Tear ¶
type Tear struct {
Reads uint64
Backward uint64 // reads lower than the read before them
Wrapped bool // the high word changed during the run
FirstPrev uint64 // the first backward step, from FirstPrev to FirstCur
FirstCur uint64
MaxBack uint64 // the largest backward step
SM int // smid, or -1 if the row was never written
Window []uint64 // reads around the first change of the high word
}
A Tear is one reader's row from a timer_tear_* kernel.
func DecodeTears ¶
DecodeTears splits a tear kernel's output into readers.
type TearSummary ¶
type TearSummary struct {
Readers int // rows written
Wrapped int // readers whose high word changed: the denominator
Torn int // wrapped readers that stepped backward
Backward uint64 // backward steps over all readers
Reads uint64
WindowTorn int // wrapped readers whose kept window steps backward
Unwrapped int // readers that never saw the high word change; excluded
}
TearSummary counts tears over readers.
func SummarizeTears ¶
func SummarizeTears(ts []Tear) TearSummary
SummarizeTears counts the readers that saw the high word change and, of those, the ones that stepped backward, from the device's own count and, independently, from the window of reads it kept.