Documentation
¶
Overview ¶
Package cudacallgraph links host launches, GPU source, and recorded artifacts. CUDA C, Tile IR, PTX, cubins, and SASS listings can be inspected without a device or compiler. Unresolved links remain explicit; a matching symbol name alone does not establish that two artifacts came from the same compilation.
This package is outside the compatibility promise of github.com/tmc/lib/nvidia. Its API may change or be removed in patch releases.
Example ¶
package main
import (
"fmt"
"strings"
"github.com/tmc/lib/nvidia/x/obs/cudacallgraph"
)
func main() {
g, err := cudacallgraph.Read("scale.cu", strings.NewReader("__global__ void scale(float *x) { x[0] *= 2; }"))
if err != nil {
fmt.Println(err)
return
}
fmt.Println(g.Kernels[0].Name, g.Kernels[0].Entry)
}
Output: scale true
Index ¶
- type CompileFact
- type ConstInt
- type CubinFact
- type Edge
- type Graph
- func Read(name string, r io.Reader) (*Graph, error)
- func ReadChromeTrace(name string, r io.Reader) (*Graph, error)
- func ReadFile(name string) (*Graph, error)
- func ReadGo(fset *token.FileSet, files []*ast.File, info *types.Info) (*Graph, error)
- func ReadProfile(name string, r io.Reader, collapse bool) (*Graph, error)
- func ReadProfileLimits(name string, r io.Reader, collapse bool, limits cudaprof.Limits) (*Graph, error)
- type HostFrame
- type Input
- type Kernel
- type LaunchSite
- type Position
- type SASSFact
- type Scope
- type ScopeCoverage
- type SourceFact
- type TileIRFact
- type Unknown
- type WorkerCoverage
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CompileFact ¶
type CompileFact struct {
Tool string `json:"tool"`
Flags []string `json:"flags,omitempty"`
FlagsKnown bool `json:"flags_known"`
SourceSHA256 string `json:"source_sha256,omitempty"`
OutputSHA256 string `json:"output_sha256,omitempty"`
}
CompileFact records observed compiler inputs. FlagsKnown is false when flags are computed dynamically, including when Flags has some known entries.
type CubinFact ¶
type CubinFact struct {
Arch string `json:"arch"`
Metadata elf.Kernel `json:"metadata"`
TextBytes uint64 `json:"text_bytes"`
}
CubinFact contains recorded ELF metadata. TextBytes is read from the text section, not estimated from a source file or instruction count.
type Edge ¶
type Edge struct {
From string `json:"from"`
To string `json:"to"`
Kind string `json:"kind"`
Pos Position `json:"position"`
Evidence string `json:"evidence"`
}
Edge records a relationship with its evidence. Kind distinguishes host launches, device calls, and compiler-observed lowering relationships.
type Graph ¶
type Graph struct {
Inputs []Input `json:"inputs,omitempty"`
Kernels []*Kernel `json:"kernels,omitempty"`
Launches []*LaunchSite `json:"launches,omitempty"`
Edges []Edge `json:"edges,omitempty"`
Unknowns []Unknown `json:"unknowns,omitempty"`
}
Graph is an offline account of launches and GPU functions. Its zero value is an empty graph. IDs include artifact contents and symbols, so two modules with identically named kernels remain distinct.
func Read ¶
Read inspects CUDA C (.cu/.cuh), Tile IR (.mlir/.tileir/.tilebc), PTX, cubin (including .cubin.hex), uncompressed fatbinary entries, or a .sass listing. The name selects the parser and supplies source positions. Missing native SASS tables leave cubin metadata available with an explicit Unknown, rather than invoking nvdisasm. Unsupported formats are errors.
func ReadChromeTrace ¶
ReadChromeTrace reads a PyTorch/Kineto Chrome trace, optionally gzip compressed. Up to 1 GiB of decoded JSON is accepted. CUDA runtime or driver events are joined to kernels using recorded correlation IDs. Ambiguous IDs leave the host unresolved.
func ReadFile ¶
ReadFile reads a standalone GPU artifact. It never invokes a compiler, disassembler process, driver, or device. See Read for supported formats.
func ReadGo ¶
ReadGo builds a call graph from the type-checked files of one Go package. Unresolved sites remain in Launches with a corresponding Unknown record.
func ReadProfile ¶
ReadProfile reads an embedded cudaprof capture. Frames are listed from caller to callee. When collapse is set, CUDA launch and cgo transition frames are omitted from the displayed stack.
func ReadProfileLimits ¶
func ReadProfileLimits(name string, r io.Reader, collapse bool, limits cudaprof.Limits) (*Graph, error)
ReadProfileLimits is ReadProfile with explicit capture read limits. The zero value of limits uses cudaprof's default bounds.
func (*Graph) CountScopes ¶
func (g *Graph) CountScopes(scopes []Scope) []ScopeCoverage
CountScopes matches ranges by exact process and name.
func (*Graph) Coverage ¶
func (g *Graph) Coverage(expected []string) []WorkerCoverage
Coverage returns process-level sample counts. A sampled profile may aggregate several launches into one sample.
type HostFrame ¶
type HostFrame struct {
Symbol string `json:"symbol"`
Name string `json:"name"`
Language string `json:"language,omitempty"`
Pos Position `json:"position"`
}
HostFrame is a retained profile frame with its original and display symbols.
type Input ¶
type Input struct {
File string `json:"file"`
Format string `json:"format"`
SHA256 string `json:"sha256"`
}
Input identifies the exact bytes that were inspected.
type Kernel ¶
type Kernel struct {
ID string `json:"id"`
Name string `json:"name"`
Entry bool `json:"entry"`
Pos Position `json:"position"`
Source *SourceFact `json:"source,omitempty"`
TileIR *TileIRFact `json:"tileir,omitempty"`
PTX *ptx.Kernel `json:"ptx,omitempty"`
Cubin *CubinFact `json:"cubin,omitempty"`
SASS *SASSFact `json:"sass,omitempty"`
}
Kernel is a GPU entry or device function. Only layers actually read from an input are populated. Source and compiled artifacts are joined only with explicit provenance, never by an unqualified function name.
type LaunchSite ¶
type LaunchSite struct {
Process string `json:"process,omitempty"`
GraphNode string `json:"graph_node,omitempty"`
HostFrames []HostFrame `json:"host_frames,omitempty"`
NVTX []string `json:"nvtx,omitempty"`
Attribution string `json:"attribution,omitempty"`
ID string `json:"id"`
Pos Position `json:"position"`
Language string `json:"language"`
Caller string `json:"caller"`
Kind string `json:"kind"`
KernelID string `json:"kernel_id,omitempty"`
KernelName string `json:"kernel_name,omitempty"`
InClosure bool `json:"in_closure,omitempty"`
Grid [3]ConstInt `json:"grid"`
Block [3]ConstInt `json:"block"`
DynamicSmem ConstInt `json:"dynamic_smem"`
Stream string `json:"stream,omitempty"`
Compile *CompileFact `json:"compile,omitempty"`
}
LaunchSite describes a source or profile-observed host launch. KernelID is empty when the target has not been resolved. Language need not be Go.
type Position ¶
type Position struct {
File string `json:"file"`
Line int `json:"line,omitempty"`
Column int `json:"column,omitempty"`
}
Position is a source coordinate. A zero line or column is unknown.
type SASSFact ¶
type SASSFact struct {
Arch string `json:"arch,omitempty"`
Function *sass.Function `json:"function"`
CFG *sass.CFG `json:"-"`
}
SASSFact contains decoded or explicitly supplied instructions. CFG is kept out of JSON because it contains links back to the instruction graph.
type ScopeCoverage ¶
ScopeCoverage counts kernel samples whose recorded NVTX hierarchy includes the scope. A sample may belong to several nested scopes.
type SourceFact ¶
type SourceFact struct {
Language string `json:"language"`
Text string `json:"text"`
Includes []string `json:"includes,omitempty"`
}
SourceFact contains a lexically recognized CUDA function. It does not claim C++ semantic analysis, template instantiation, or compiler output.
type TileIRFact ¶
TileIRFact preserves parsed operations, parameter types, shapes, source locations, and attached compiler remarks using the repository's Tile IR AST. It is a peer of CUDA C input and does not imply a PTX intermediate.
type Unknown ¶
type Unknown struct {
Pos Position `json:"position"`
Subject string `json:"subject"`
Reason string `json:"reason"`
}
Unknown explains a missing fact or unsupported input without substituting a zero measurement or inventing a cross-artifact relationship.
type WorkerCoverage ¶
type WorkerCoverage struct {
Process string `json:"process"`
Observed bool `json:"observed"`
KernelSamples int `json:"kernel_samples"`
AttributedSamples int `json:"attributed_samples"`
GraphNodeSamples int `json:"graph_node_samples"`
}
WorkerCoverage counts observed GPU samples by recorded process. An expected worker without samples is included with Observed false.