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 ¶
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.
const EventSize = 32
EventSize is the size in bytes of one recorded event.
Variables ¶
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.
var Header string
Header is cudaprofile.cuh, the device side: cudaprofile_begin, cudaprofile_end, cudaprofile_record and cudaprofile_now.
Functions ¶
Types ¶
type Config ¶
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.
type DropError ¶
type DropError struct {
Dropped uint64
}
A DropError reports events lost because their ring was full.
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.
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 ¶
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 ¶
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.