cudacallgraph

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: 26 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 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

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 ConstInt

type ConstInt struct {
	Value int64 `json:"value"`
	Known bool  `json:"known"`
}

ConstInt distinguishes a constant zero from an unknown value.

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

func Read(name string, r io.Reader) (*Graph, error)

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

func ReadChromeTrace(name string, r io.Reader) (*Graph, error)

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

func ReadFile(name string) (*Graph, error)

ReadFile reads a standalone GPU artifact. It never invokes a compiler, disassembler process, driver, or device. See Read for supported formats.

func ReadGo

func ReadGo(fset *token.FileSet, files []*ast.File, info *types.Info) (*Graph, error)

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

func ReadProfile(name string, r io.Reader, collapse bool) (*Graph, error)

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.

func (*Graph) Merge

func (g *Graph) Merge(other *Graph) error

Merge adds other's records, preserving distinct artifact identities. It rejects conflicting definitions of the same ID. Other and g must be nonnil.

func (*Graph) WriteJSON

func (g *Graph) WriteJSON(w io.Writer) error

WriteJSON writes g as indented JSON.

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 Scope

type Scope struct {
	Process string `json:"process"`
	Range   string `json:"range"`
}

Scope identifies an expected NVTX range on a recorded process.

type ScopeCoverage

type ScopeCoverage struct {
	Scope
	KernelSamples int `json:"kernel_samples"`
}

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

type TileIRFact struct {
	Function *tileir.Function `json:"function"`
}

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.

Directories

Path Synopsis
Package launchgo resolves typed Go CUDA launch sites to their available kernel identities.
Package launchgo resolves typed Go CUDA launch sites to their available kernel identities.

Jump to

Keyboard shortcuts

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