Documentation
¶
Index ¶
- func Annotate(tier *PipelineTier)
- func BindStallmap(tiers []PipelineTier, m *stallmap.Map) error
- func BindTraceLinks(tiers []PipelineTier)
- func CleanMLIR(raw string) (string, []int)
- func MLIRFiles(files map[string][]byte, preferred string) (raw, clean string)
- func MLIRFunctionName(line string) (string, bool)
- func MLIRListings(rawName, rawText, cleanName, cleanText string) (PipelineTier, PipelineTier)
- func MLIRTiers(file, text string) (PipelineTier, PipelineTier)
- func ReadLimiter(r io.Reader) (*limiter.Verdict, error)
- func ReadStallmap(r io.Reader) (*stallmap.Map, error)
- func Render(w io.Writer, data *PipelineViewData) error
- func RenderDiff(w io.Writer, data *DiffViewData) error
- func SpillKind(line string) string
- func WriteSnapshot(w io.Writer, data *PipelineViewData) error
- type DiffInstruction
- type DiffRow
- type DiffRowType
- type DiffSummary
- type DiffViewData
- type PipelineLine
- type PipelineModule
- type PipelineTier
- type PipelineViewData
- type RecompileSource
- type SourceLocation
- type SpillCounts
- type SpillDelta
- type SpillIndex
- type SpillOrigin
- type SpillRollup
- type SpillTrace
- type StallShiftSummary
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Annotate ¶
func Annotate(tier *PipelineTier)
Annotate resolves instruction and source identities from retained text. Missing source file identities remain empty; a line number alone is not a match.
Example ¶
package main
import (
"fmt"
"github.com/tmc/lib/nvidia/internal/cudaview"
)
func main() {
tier := cudaview.PipelineTier{Language: "cuda", FileName: "kernel.cu", Lines: []cudaview.PipelineLine{{Num: 1, Text: "// CUDA source"}}}
cudaview.Annotate(&tier)
fmt.Println(tier.Lines[0].SourceFile, tier.Lines[0].SourceLine)
}
Output: kernel.cu 1
func BindStallmap ¶
func BindStallmap(tiers []PipelineTier, m *stallmap.Map) error
BindStallmap assigns PC sampling heat to the named SASS kernel and sums it over its correlated PTX and MLIR lines. Each percentage uses total kernel PC samples as its denominator and excludes issued ("selected") samples.
Example ¶
tiers := []PipelineTier{{Language: "sass", Lines: []PipelineLine{{Kernel: "f", Opcode: "EXIT", Offset: "0000"}}}}
m := &stallmap.Map{Kernel: "f", TotalSamples: 4, PCs: []stallmap.PC{
{Opcode: "EXIT", Samples: 4, Stalls: map[string]uint64{"selected": 3, "wait": 1}},
}}
if err := BindStallmap(tiers, m); err != nil {
panic(err)
}
fmt.Println(tiers[0].Lines[0].StallPct)
Output: 25
func BindTraceLinks ¶
func BindTraceLinks(tiers []PipelineTier)
BindTraceLinks assigns trace identities to MLIR, PTX and SASS rows. Source paths are retained verbatim in the inspector. Matching uses normalized paths, never an unqualified line number.
func CleanMLIR ¶
CleanMLIR removes location definitions and contracts trailing annotations. The returned slice maps each clean line to its one-based raw line number.
func MLIRFiles ¶
MLIRFiles finds a single raw MLIR dump and its optional cleaned companion. The preferred name is used only when it names a textual MLIR artifact.
func MLIRFunctionName ¶
MLIRFunctionName reports a function definition in a textual MLIR listing.
func MLIRListings ¶
func MLIRListings(rawName, rawText, cleanName, cleanText string) (PipelineTier, PipelineTier)
MLIRListings uses a supplied clean dump when its operation lines match the raw projection in order. An inconsistent dump falls back to the projection.
func MLIRTiers ¶
func MLIRTiers(file, text string) (PipelineTier, PipelineTier)
MLIRTiers builds raw and clean views of a single textual MLIR artifact.
func ReadLimiter ¶
ReadLimiter reads one kernel's limiter verdict.
Example ¶
verdict, err := ReadLimiter(strings.NewReader(`{"kernel":"f","limiter":"latency","confidence":0.8}`))
if err != nil {
panic(err)
}
fmt.Println(verdict.Kernel, verdict.Limiter)
Output: f latency
func ReadStallmap ¶
ReadStallmap reads one stallmap/v1 document and validates its PC counts.
Example ¶
m, err := ReadStallmap(strings.NewReader(`{"schema":"cudaprof-stallmap/v1","kernel":"f","pcs":[{"offset":0,"opcode":"EXIT"}]}`))
if err != nil {
panic(err)
}
fmt.Println(m.Kernel)
Output: f
func Render ¶
func Render(w io.Writer, data *PipelineViewData) error
Render writes a self-contained pipeline page.
Example ¶
package main
import (
"bytes"
"fmt"
"strings"
"github.com/tmc/lib/nvidia/internal/cudaview"
)
func main() {
data := &cudaview.PipelineViewData{Title: "Kernel listing"}
var out bytes.Buffer
if err := cudaview.Render(&out, data); err != nil {
fmt.Println(err)
return
}
fmt.Println(strings.Contains(out.String(), "<title>Kernel listing</title>"))
}
Output: true
func RenderDiff ¶
func RenderDiff(w io.Writer, data *DiffViewData) error
RenderDiff writes an offline comparison page.
Example ¶
package main
import (
"bytes"
"fmt"
"strings"
"github.com/tmc/lib/nvidia/internal/cudaview"
)
func main() {
var out bytes.Buffer
if err := cudaview.RenderDiff(&out, &cudaview.DiffViewData{Title: "Comparison"}); err != nil {
fmt.Println(err)
return
}
fmt.Println(strings.Contains(out.String(), "<title>Comparison</title>"))
}
Output: true
func WriteSnapshot ¶
func WriteSnapshot(w io.Writer, data *PipelineViewData) error
WriteSnapshot writes compact source data and indexed kernel selections.
Example ¶
package main
import (
"bytes"
"fmt"
"strings"
"github.com/tmc/lib/nvidia/internal/cudaview"
)
func main() {
var out bytes.Buffer
data := &cudaview.PipelineViewData{Tiers: []cudaview.PipelineTier{{Name: "SASS", Lines: []cudaview.PipelineLine{{Num: 1, Text: "EXIT;"}}}}}
if err := cudaview.WriteSnapshot(&out, data); err != nil {
fmt.Println(err)
return
}
fmt.Println(strings.Count(out.String(), "EXIT;"))
}
Output: 1
Types ¶
type DiffInstruction ¶
type DiffInstruction struct {
Address uint64 `json:"address,omitempty"`
Offset string `json:"offset,omitempty"`
Predicate string `json:"predicate,omitempty"`
Opcode string `json:"opcode,omitempty"`
Operands string `json:"operands,omitempty"`
Raw string `json:"raw,omitempty"`
Text string `json:"text,omitempty"`
SourceFile string `json:"source_file,omitempty"`
PTXLine int `json:"ptx_line,omitempty"`
SpillTrace *SpillTrace `json:"spill_trace,omitempty"`
SourceLine int `json:"source_line,omitempty"`
IsLocalMemory bool `json:"is_local_memory,omitempty"`
LocalMemoryType string `json:"local_memory_type,omitempty"`
Pressure string `json:"pressure,omitempty"`
PressureTooltip string `json:"pressure_tooltip,omitempty"`
LiveGPR int `json:"live_gpr,omitempty"`
LivePred int `json:"live_pred,omitempty"`
LiveUGPR int `json:"live_ugpr,omitempty"`
LiveUPred int `json:"live_upred,omitempty"`
StallPct float64 `json:"stall_pct,omitempty"`
StallBreakdown map[string]float64 `json:"stall_breakdown,omitempty"`
StallTooltip string `json:"stall_tooltip,omitempty"`
SemanticTag string `json:"semantic_tag,omitempty"`
}
DiffInstruction represents an annotated SASS instruction in the differential viewer.
type DiffRow ¶
type DiffRow struct {
StallDeltaKnown bool `json:"stall_delta_known,omitempty"`
Num int `json:"num"`
Type DiffRowType `json:"type"`
Base *DiffInstruction `json:"base,omitempty"`
Candidate *DiffInstruction `json:"candidate,omitempty"`
StallDelta float64 `json:"stall_delta,omitempty"`
StallReason string `json:"stall_reason,omitempty"`
StallSummary string `json:"stall_summary,omitempty"`
NewSpill bool `json:"new_spill,omitempty"`
HasLocalMemory bool `json:"has_local_memory,omitempty"`
}
DiffRow represents a single aligned comparison row between baseline and candidate.
type DiffRowType ¶
type DiffRowType string
DiffRowType specifies the relationship between baseline and candidate instructions in a diff row.
const ( DiffRowMatch DiffRowType = "match" DiffRowAdd DiffRowType = "add" DiffRowDelete DiffRowType = "delete" DiffRowModify DiffRowType = "modify" )
type DiffSummary ¶
type DiffSummary struct {
BaseInstructions int `json:"base_instructions"`
TargetInstructions int `json:"target_instructions"`
InstructionDelta int `json:"instruction_delta"`
BaseSizeBytes int `json:"base_size_bytes"`
TargetSizeBytes int `json:"target_size_bytes"`
TotalSizeDelta int `json:"total_size_delta"`
BaseBranches int `json:"base_branches"`
TargetBranches int `json:"target_branches"`
BranchDelta int `json:"branch_delta"`
NewSpillSites int `json:"new_spill_sites,omitempty"`
LocalMemoryAdded int `json:"local_memory_added"`
LocalMemoryRemoved int `json:"local_memory_removed"`
LocalMemoryDelta int `json:"local_memory_delta"`
HasDurationMetric bool `json:"has_duration_metric,omitempty"`
BaseRuntimeUs float64 `json:"base_runtime_us,omitempty"`
TargetRuntimeUs float64 `json:"target_runtime_us,omitempty"`
DurationDeltaUs float64 `json:"duration_delta_us,omitempty"`
Speedup float64 `json:"speedup,omitempty"`
HasSampleMetric bool `json:"has_sample_metric,omitempty"`
BaseSamples int64 `json:"base_samples,omitempty"`
TargetSamples int64 `json:"target_samples,omitempty"`
SampleDelta int64 `json:"sample_delta,omitempty"`
SampleShiftSummary string `json:"sample_shift_summary,omitempty"`
Substitutions []sass.OpcodeSubstitution `json:"substitutions,omitempty"`
TopStallShifts []StallShiftSummary `json:"top_stall_shifts,omitempty"`
}
DiffSummary contains high-level differential statistics between two captures.
type DiffViewData ¶
type DiffViewData struct {
BaseLimiter *limiter.Verdict `json:"base_limiter,omitempty"`
TargetLimiter *limiter.Verdict `json:"target_limiter,omitempty"`
LimiterComparison *limiter.Comparison `json:"limiter_comparison,omitempty"`
AddedSpills []SpillDelta `json:"added_spills"`
SpillContext []PipelineTier `json:"spill_context,omitempty"`
Title string `json:"title"`
BaseCapture string `json:"base_capture"`
TargetCapture string `json:"target_capture"`
Kernels []string `json:"kernels"`
ActiveKernel string `json:"active_kernel"`
KernelRows map[string][]DiffRow `json:"kernel_rows"`
ActiveRows []DiffRow `json:"active_rows"`
Summary DiffSummary `json:"summary"`
KernelSummaries map[string]DiffSummary `json:"kernel_summaries"`
}
DiffViewData is the data model passed to the differential web template and HTTP endpoints.
func (*DiffViewData) ToJSON ¶
func (d *DiffViewData) ToJSON() template.JS
ToJSON serializes DiffViewData to JavaScript-safe JSON for offline viewing.
type PipelineLine ¶
type PipelineLine struct {
Kernel string `json:"kernel,omitempty"`
Predicate string `json:"predicate,omitempty"`
Operands string `json:"operands,omitempty"`
Encoding string `json:"encoding,omitempty"`
Num int `json:"num"`
Text string `json:"text"`
Opcode string `json:"opcode,omitempty"`
Category string `json:"category,omitempty"`
Offset string `json:"offset,omitempty"`
StallDelta *float64 `json:"stall_delta,omitempty"`
StallPct float64 `json:"stall_pct,omitempty"`
StallBreakdown map[string]float64 `json:"stall_breakdown,omitempty"`
StallTooltip string `json:"stall_tooltip,omitempty"`
HoverDoc string `json:"hover_doc,omitempty"`
RemarkBadge string `json:"remark_badge,omitempty"`
RemarkTooltip string `json:"remark_tooltip,omitempty"`
LaunchKernel string `json:"launch_kernel,omitempty"`
SemanticTag string `json:"semantic_tag,omitempty"`
Rollup SpillRollup `json:"rollup,omitzero"`
SpillKind string `json:"spill_kind,omitempty"`
SpillTrace *SpillTrace `json:"spill_trace,omitempty"`
TraceKeys []string `json:"trace_keys,omitempty"`
OperationLine int `json:"operation_line,omitempty"`
RawLine int `json:"raw_line,omitempty"`
PTXLine int `json:"ptx_line,omitempty"`
Locations []SourceLocation `json:"locations,omitempty"`
ArtifactLocation SourceLocation `json:"artifact_location,omitzero"`
SourceFile string `json:"source_file,omitempty"`
SourceLine int `json:"source_line,omitempty"`
Pressure string `json:"pressure,omitempty"`
PressureTooltip string `json:"pressure_tooltip,omitempty"`
}
PipelineLine represents an annotated line in a pipeline tier.
type PipelineModule ¶
type PipelineModule struct {
ID string
Name string
Data *PipelineViewData
}
PipelineModule identifies one captured artifact generation.
type PipelineTier ¶
type PipelineTier struct {
Name string `json:"name"`
FileName string `json:"file_name"`
Language string `json:"language"`
Lines []PipelineLine `json:"lines"`
}
PipelineTier represents one stage in the Go -> CUDA C++ -> Tile IR -> PTX -> SASS compilation hierarchy.
type PipelineViewData ¶
type PipelineViewData struct {
Limiter *limiter.Verdict `json:"limiter,omitempty"`
Diagnostics []string `json:"diagnostics,omitempty"`
Modules []PipelineModule `json:"-"`
Title string `json:"title"`
Device string `json:"device"`
Architecture string `json:"architecture"`
CaptureFile string `json:"capture_file"`
Kernels []string `json:"kernels"`
ActiveKernel string `json:"active_kernel"`
Tiers []PipelineTier `json:"tiers"`
KernelTiers map[string][]PipelineTier `json:"kernel_tiers"`
Remarks string `json:"remarks,omitempty"`
RemarksCount int `json:"remarks_count,omitempty"`
TileIRAudit string `json:"tileir_audit,omitempty"`
TileIROpcodes map[string]int `json:"tileir_opcodes,omitempty"`
CFGDot string `json:"cfg_dot,omitempty"`
// Hierarchy maps a kernel to the JSON of its memory-hierarchy record, a
// cudaoccupancy.Hierarchy, which the hierarchy panel draws.
Hierarchy map[string]json.RawMessage `json:"hierarchy,omitempty"`
// Recompile carries one entry per module the NVRTC panel can recompile.
// It is empty when the capture retained no CUDA C++ source.
Recompile []*RecompileSource `json:"recompile,omitempty"`
}
PipelineViewData is the data model passed to the web template and API endpoints.
func ReadArtifacts ¶
func ReadArtifacts(paths []string) (*PipelineViewData, error)
ReadArtifacts opens source and assembly files without invoking external tools.
Example ¶
package main
import (
"fmt"
"github.com/tmc/lib/nvidia/internal/cudaview"
)
func main() {
data, err := cudaview.ReadArtifacts([]string{"testdata/kernel.sass"})
if err != nil {
fmt.Println(err)
return
}
fmt.Println(data.Tiers[4].Lines[1].Opcode)
}
Output: EXIT
type RecompileSource ¶
type RecompileSource struct {
ID string `json:"id"`
Name string `json:"name"`
File string `json:"file"`
Arch string `json:"arch,omitempty"`
Options []string `json:"options,omitempty"`
Recorded bool `json:"recorded"`
// Suggested is the option list the panel offers for the second side:
// Options plus --use_fast_math.
Suggested []string `json:"suggested,omitempty"`
Source string `json:"-"`
PTX string `json:"-"`
SASS string `json:"-"`
}
A RecompileSource is one module's CUDA C++ source, together with the artifacts the capture retained for it. The viewer recompiles the source under caller-chosen NVRTC options and compares the result against those artifacts, so a capture taken without --use_fast_math can be read beside the same source compiled with it.
A capture holds one of these per module, because a program compiles modules separately and need not pass NVRTC the same options for each: ds4-min compiles its math module without --use_fast_math and its Q8_0 quantizer with it, and its probe modules target a virtual architecture rather than a physical one. One option list per capture would describe at most one module and silently misreport the rest.
type SourceLocation ¶
type SourceLocation struct {
File string `json:"file"`
Line int `json:"line"`
Col int `json:"col,omitempty"`
Frame string `json:"frame,omitempty"`
}
SourceLocation is a leaf in an MLIR location, in callee-before-caller or fused operand order. File retains the path recorded by the compiler.
type SpillCounts ¶
type SpillCounts struct {
STL int `json:"stl"`
LDL int `json:"ldl"`
PTXLines []int `json:"ptx_lines,omitempty"`
SASSLines []int `json:"sass_lines,omitempty"`
SASSOffsets []string `json:"sass_offsets,omitempty"`
}
SpillCounts records local loads and stores at one operation in one build.
type SpillDelta ¶
type SpillDelta struct {
Kernel string `json:"kernel"`
SourceFile string `json:"source_file,omitempty"`
SourceLine int `json:"source_line,omitempty"`
RawMLIRLine int `json:"raw_mlir_line,omitempty"`
CleanMLIRLine int `json:"clean_mlir_line,omitempty"`
MLIROp string `json:"mlir_op,omitempty"`
Before SpillCounts `json:"before"`
After SpillCounts `json:"after"`
Added SpillCounts `json:"added"`
}
SpillDelta groups added local-memory instructions by their retained origin. A missing MLIR coordinate indicates an unresolved or ambiguous origin.
type SpillIndex ¶
type SpillIndex struct {
// contains filtered or unexported fields
}
SpillIndex indexes one build's retained artifacts for repeated lookups.
func IndexSpills ¶
func IndexSpills(tiers []PipelineTier) *SpillIndex
IndexSpills builds source and instruction indexes from annotated tiers.
func (*SpillIndex) Trace ¶
func (idx *SpillIndex) Trace(kernel string, inst sass.Instruction) SpillTrace
Trace returns the retained locations for one instruction. An explicit PTX listing binding is preferred over source-line matching.
type SpillOrigin ¶
type SpillOrigin struct {
RawLine int `json:"raw_line"`
CleanLine int `json:"clean_line"`
Operation string `json:"operation"`
Kernel string `json:"-"`
Source []SourceLocation `json:"source,omitempty"`
}
SpillOrigin describes a source-correlated candidate MLIR operation. More than one operation can share the compiler's source line.
type SpillRollup ¶
type SpillRollup struct {
SASS int `json:"sass,omitempty"`
STL int `json:"stl,omitempty"`
LDL int `json:"ldl,omitempty"`
}
SpillRollup counts instructions correlated to an MLIR operation.
type SpillTrace ¶
type SpillTrace struct {
SASSLine int `json:"sass_line,omitempty"`
PTXLines []int `json:"ptx_lines,omitempty"`
Frames []SourceLocation `json:"frames,omitempty"`
Origins []SpillOrigin `json:"origins,omitempty"`
}
SpillTrace joins retained source coordinates with PTX and MLIR lines. Missing locations leave the corresponding evidence empty.
type StallShiftSummary ¶
type StallShiftSummary struct {
Reason string `json:"reason"`
BaseCount int64 `json:"base_count"`
TargetCount int64 `json:"target_count"`
Delta int64 `json:"delta"`
ShiftPct float64 `json:"shift_pct"`
ShiftStr string `json:"shift_str"`
}
StallShiftSummary records the aggregate shift of a PC stall reason across two captures.