cudatimer

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: 6 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.

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

View Source
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

View Source
var Source string

Source is the device side of the probes. Compile it with cudaphase.h (ikettrace.PhaseHeader) available as a header.

View Source
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

func DecodePings(buf []uint64, blocks, rounds int) ([][]Exchange, []int, error)

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.

func Median

func Median(v []float64) float64

Median returns the median of v, the mean of the middle two for an even count, or NaN for none. It does not modify v.

func SeriesGHz

func SeriesGHz(series []uint64) []float64

SeriesGHz returns the clock rate, in cycles per nanosecond, between consecutive (cycles, nanoseconds) samples. Samples are pairs in a flat slice; a pair of zeros ends the series.

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

func EstimateOffset(ex []Exchange, tick uint64) (Offset, error)

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

func (Offset) Contains

func (o Offset) Contains(x float64) bool

Contains reports whether the true offset can be x.

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.

func DecodeReleases

func DecodeReleases(buf []uint64, blocks int) ([]Release, error)

DecodeReleases splits timer_release output for blocks blocks.

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) Add

func (s *Steps) Add(reads []uint64)

Add adds one reader's reads, in the order it read them.

func (*Steps) Tick

func (s *Steps) Tick() (uint64, error)

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

func DecodeTears(buf []uint64) ([]Tear, error)

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.

Jump to

Keyboard shortcuts

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