launchprobe

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: 10 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 launchprobe measures CUDA kernel launch latency and queue overhead.

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 (
	LayerA  = "launch_layer_a"
	LayerB  = "launch_layer_b"
	Persist = "launch_persist"
)

Kernel names in Source.

View Source
const (
	TriggerEarly = 1 << iota // griddepcontrol.launch_dependents on landing
	TriggerLate              // griddepcontrol.launch_dependents after the piece
	GridWait                 // griddepcontrol.wait before the piece
	FlagWait                 // poll done[piece] until every block of the previous piece signaled
	Signal                   // fence and add one to done[piece+1] after the piece
	SameCode                 // Persist: run code block A in every piece, not A and B in turn
)

Flags of the kernels' flags argument.

View Source
const TimedOut = 1 << 63

TimedOut marks a polls word whose wait gave up.

View Source
const Words = 6

Words is the number of 64-bit words a block writes per piece: the %globaltimer time it landed, started the piece, finished the piece's code block and ended the piece; its SM number plus one; and the polls its wait took, with TimedOut set if the wait hit its bound.

Variables

This section is empty.

Functions

func Control

func Control(arm string) string

Control returns the control arm of an arm. An arm is "metric:mode/grid/fit/code/span". Its control is the stream arm with the same metric and the same other parts, which is its own control, with two exceptions that are the probe's known-answer and code comparisons: the stream arm of span 160 is controlled by that of span 80, and the stream arm whose kernels alternate two large code blocks ("bigalt") by the one that repeats one ("bigsame"). Other strings have no control.

Example
package main

import (
	"fmt"
	"github.com/tmc/lib/nvidia/x/obs/diag/launchprobe"
)

func main() {
	fmt.Println(launchprobe.Control("gap:gpdl-late/all/fill/small/80"))
}
Output:
gap:stream/all/fill/small/80

func Fprint

func Fprint(w io.Writer, rows []Row) error

Fprint writes rows as a table.

func Median

func Median(v []float64) float64

Median returns the median of v, or 0 if v is empty.

func Source

func Source(stmts int) string

Source returns the source of the probe's three kernels. Each layer kernel runs one piece and the persistent kernel runs pieces of them:

void launch_layer_a(u64* stamps, u32* done, u32* sink, u32 piece, u32 span, u32 flags, u32 maxspin)
void launch_layer_b(the same)
void launch_persist(u64* stamps, u32* done, u32* sink, u32 pieces, u32 span, u32 flags, u32 maxspin)

Thread 0 of each block does the work; the other threads return. A piece is: land, wait as flags say, run a straight-line code block of stmts statements once, spin until span nanoseconds of %globaltimer have passed since the code block, write Words words at stamps[(piece*grid+block)*Words], and signal as flags say. Layer A and layer B differ only in their code block, which has the same length and different constants; the persistent kernel holds both and runs A in even pieces and B in odd ones. With stmts zero there is no code block.

done must hold pieces+1 words, done[0] the grid size and the rest zero.

Types

type Chain

type Chain struct {
	// Gaps[i] is the time from the last block's end of piece i to the
	// first block's start of piece i+1.
	Gaps []float64
	// Span is the time from the first start of the first piece to the
	// last end of the last piece, and Sum the sum over pieces of the time
	// from the piece's first start to its last end. Span less Sum is the
	// sum of Gaps: the time no piece ran.
	Span, Sum float64
	// Medians over blocks and pieces: the spin (end less code), the code
	// block (code less start) and the wait (start less land).
	Work, Code, Wait float64
	// Stagger is the median over pieces of the time from the piece's
	// first start to its last start.
	Stagger float64
	// Landings holds one entry per block of pieces 1 and up whose SM also
	// ran the previous piece.
	Landings []Landing
	// Ahead is the median, over the blocks of pieces 1 and up, of the time
	// from the block's landing to the previous piece's last end: positive
	// when blocks are resident before the piece they wait for is over.
	Ahead  float64
	Early  int    // blocks that landed before the previous piece's last end
	Moved  int    // blocks whose SM did not run the previous piece
	SMs    int    // distinct SMs over the chain
	Shared int    // blocks beyond the first on an SM within one piece
	Polls  uint64 // polls over all waits
}

A Chain is the reduction of one chain's stamps.

func Analyze

func Analyze(stamps []uint64, pieces, grid int) (Chain, error)

Analyze reduces the stamps of a chain of pieces pieces on grid blocks, Words words per piece and block as the kernels of Source write them. It returns an error if a block wrote no stamps, a wait timed out, or a block's stamps run backward.

Example
package main

import (
	"fmt"
	"github.com/tmc/lib/nvidia/x/obs/diag/launchprobe"
)

func main() {
	// Two pieces on one block: land, start, code, end, SM+1, polls.
	stamps := []uint64{
		1000, 1000, 1000, 81000, 8, 0,
		86000, 86000, 86000, 166000, 8, 0,
	}
	c, err := launchprobe.Analyze(stamps, 2, 1)
	if err != nil {
		fmt.Println(err)
		return
	}
	fmt.Println(c.Gaps, c.Span, c.Sum, c.Idle(), c.Landings[0].SM, c.Landings[0].NS)
}
Output:
[5000] 165000 160000 5000 7 5000

func (Chain) Idle

func (c Chain) Idle() float64

Idle returns the time in the chain's span that no piece ran.

type Landing

type Landing struct {
	Piece int // the piece the block runs
	SM    int
	NS    float64
}

A Landing is the landing gap of one block: from the end of the last block that ran the previous piece on SM to this block's landing there. It is negative when the block landed while its predecessor still ran.

type Row

type Row struct {
	Arm, Control, Unit string
	N                  int
	Median, Min, Max   float64
	CV                 float64 // standard deviation over mean
	Delta              float64 // Median less the control's median
	Ratio              float64 // Median over the control's median; 0 without a control
	Spread             float64 // the control's null spread
	Verdict            string  // "control", "resolved", "unresolved" or ""
}

A Row summarizes one arm against its control.

func Summarize

func Summarize(samples []Sample, control func(arm string) string, tick float64) []Row

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, or by no more than two steps of the timer, tick, is unresolved.

type SMSample

type SMSample struct {
	Run    int     `json:"run"`
	Device int     `json:"device"`
	SMID   int     `json:"smid"`
	Metric string  `json:"metric"`
	NS     float64 `json:"ns"`
}

An SMSample is one SM's landing gap in one chain, one line of the probe's per-SM JSONL.

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 metric of one chain, one line of the probe's JSONL.

func Read

func Read(r io.Reader) ([]Sample, error)

Read decodes JSONL samples from r.

Jump to

Keyboard shortcuts

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