ring

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: 15 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 ring decodes device-side in-kernel %globaltimer event ring buffers.

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

Index

Constants

View Source
const DefaultMaxStuckPolls = 4

DefaultMaxStuckPolls is the default number of consecutive LiveStreamConsumer.Poll calls a reserved event slot may remain unsealed before Poll reports a stuck-ring error.

View Source
const EventSize = 32

EventSize is the size in bytes of one recorded event.

Variables

View Source
var ErrNoEvents = errors.New("cudaprofile: no events recorded")

ErrNoEvents reports a well-formed buffer that recorded nothing and dropped nothing: a kernel that never reached cudaprofile_end, or was given another buffer.

View Source
var Header string

Header is cudaprofile.cuh, the device side: cudaprofile_begin, cudaprofile_end, cudaprofile_record and cudaprofile_now.

Functions

func NewBuffer

func NewBuffer(c Config) ([]byte, error)

NewBuffer returns a zeroed buffer laid out for c, with its header written. Copy it to device memory and pass the device pointer to the kernel; copy all of it back for Decode.

Types

type Config

type Config struct {
	Rings    int
	Capacity int // events per ring
}

A Config describes a buffer: Rings rings of Capacity events each. Events from SM s go to ring s % Rings, so Rings at least the device's SM count gives each SM its own ring.

func (Config) Size

func (c Config) Size() (int, error)

Size returns the size in bytes of a buffer laid out for c.

type DropError

type DropError struct {
	Dropped uint64
}

A DropError reports events lost because their ring was full.

func (*DropError) Error

func (e *DropError) Error() string

type Event

type Event struct {
	Start, End uint64
	SM         uint32 // %smid when the span ended
	Block      uint32 // linear block index
	Warp       uint16 // warp index within the block
	ID         uint16
}

An Event is one span recorded by cudaprofile_end. Times are %globaltimer readings in nanoseconds.

func (Event) Duration

func (e Event) Duration() time.Duration

Duration returns the span's length.

func (Event) IsMarker

func (e Event) IsMarker() bool

IsMarker reports whether e is a zero-length point marker (Start == End).

type LiveStreamConsumer

type LiveStreamConsumer struct {
	// contains filtered or unexported fields
}

LiveStreamConsumer incrementally polls a coherent or host-mapped [cudaprofile] buffer while a persistent kernel executes, decoding newly sealed events and optionally recycling consumed slots.

func NewLiveStreamConsumer

func NewLiveStreamConsumer(c Config) (*LiveStreamConsumer, error)

NewLiveStreamConsumer constructs a LiveStreamConsumer for buffers created with c.

func (*LiveStreamConsumer) DrainAndResetRing

func (lsc *LiveStreamConsumer) DrainAndResetRing(b []byte) ([]Event, error)

DrainAndResetRing polls all remaining sealed events across all rings, zeroes the consumed event slots, and resets ring counters, drop counters, and consumer cursors to 0 so b can be reused across epochs without reallocating.

The producer kernel MUST be quiesced (for example after stream synchronization or at a host-synchronized epoch barrier) before calling DrainAndResetRing; resetting counters while device warps are actively calling atomicAdd races on the ring counters and slots.

func (*LiveStreamConsumer) Poll

func (lsc *LiveStreamConsumer) Poll(b []byte) (events []Event, dropped uint64, err error)

Poll scans b from the current per-ring cursors, decoding newly sealed events and advancing each ring cursor up to the first unsealed slot or the ring's recorded event count. The returned dropped count is the delta of newly dropped events since the previous Poll call. If a reserved slot remains unsealed across MaxStuckPolls consecutive polls, Poll returns an error.

func (*LiveStreamConsumer) SetMaxStuckPolls

func (lsc *LiveStreamConsumer) SetMaxStuckPolls(n int)

SetMaxStuckPolls configures the number of consecutive polls a reserved slot may remain unsealed before LiveStreamConsumer.Poll returns a stuck-ring error. Setting n <= 0 disables stuck-ring detection.

type Trace

type Trace struct {
	Config  Config
	Events  []Event // ordered by SM, start, block, warp and id
	Dropped uint64  // events lost to full rings
}

A Trace is a decoded buffer.

func Decode

func Decode(b []byte) (*Trace, error)

Decode decodes a buffer written by kernels using Header. It checks the header against the buffer's length, and checks every slot: each reserved slot must hold a sealed event with start <= end from an SM that maps to its ring, and every unreserved slot must be zero.

If any ring overflowed, Decode returns the trace and a *DropError. If nothing was recorded or dropped, it returns the trace and ErrNoEvents. Any other error means the buffer is not a capture.

func (*Trace) WriteChromeTrace

func (t *Trace) WriteChromeTrace(w io.Writer, names map[uint16]string) error

WriteChromeTrace writes t as Chrome Trace Event JSON, which ui.perfetto.dev and chrome://tracing load. Each SM is a process, so Perfetto shows one track group per SM, and each warp is a thread within it, numbered block*32 + warp. names maps event ids to span names; an id it lacks is named "id N". Times are microseconds from the earliest start, and otherData records that start as origin_ns.

The dropped count goes in otherData and, when nonzero, in a global instant event, so a trace that lost events says so on its timeline. Point markers (Event.IsMarker) are emitted as thread-scoped instant events ("ph":"i","s":"t") without a duration field. WriteChromeTrace returns ErrNoEvents for a trace with no events and no drops.

Jump to

Keyboard shortcuts

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