Documentation
¶
Overview ¶
Package stallmap attributes a kernel's PC sampling stalls to its SASS instructions and source lines.
Build joins per-instruction samples, as limiter.Collect keeps them under Options.KeepPCs, onto the kernel's disassembly. The result is a Map whose JSON form (schema cudaprof-stallmap/v1) lists every instruction with its stall mix and totals each source line, so a reader or a viewer can see where a kernel waits and why:
dis, _ := sass.ParseString(nvdisasmText) // nvdisasm -g of a -lineinfo cubin
m, err := stallmap.Build("decode", in.PCs, dis.Functions[0], cubin)
for _, l := range m.Hot(3) {
fmt.Println(l.File, l.Line, l.Samples, l.Top)
}
A Map describes one kernel; a capture of several kernels is written as JSON lines, one Map per line. File names are base names; a map never carries a directory. Stall reasons are CUPTI's names with the "smsp__pcsamp_warps_issue_stalled_" prefix dropped; the "_not_issued" companion counts are dropped too, since each repeats part of another reason, so a PC's samples are the sum of its stalls.
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"
"github.com/tmc/lib/nvidia/x/isa/sass"
"github.com/tmc/lib/nvidia/x/obs/cudaprof/limiter"
"github.com/tmc/lib/nvidia/x/obs/cudaprof/stallmap"
)
func main() {
fn := &sass.Function{Name: "scale", Instructions: []sass.Instruction{
{Address: 0x00, Opcode: "LDG.E", SourceFile: "scale.cu", SourceLine: 7},
{Address: 0x10, Opcode: "FMUL", SourceFile: "scale.cu", SourceLine: 7},
{Address: 0x20, Opcode: "STG.E", SourceFile: "scale.cu", SourceLine: 8},
}}
samples := []limiter.PCSample{
{Function: "scale", Offset: 0x10, Stalls: map[string]uint64{"smsp__pcsamp_warps_issue_stalled_long_scoreboard": 90}},
{Function: "scale", Offset: 0x20, Stalls: map[string]uint64{"smsp__pcsamp_warps_issue_stalled_lg_throttle": 10}},
}
m, err := stallmap.Build("scale", samples, fn, nil)
if err != nil {
fmt.Println(err)
return
}
for _, l := range m.Hot(2) {
fmt.Printf("%s:%d %d %s\n", l.File, l.Line, l.Samples, l.Top)
}
}
Output: scale.cu:7 90 long_scoreboard scale.cu:8 10 lg_throttle
Index ¶
Examples ¶
Constants ¶
const Schema = "cudaprof-stallmap/v1"
Schema is the version of the JSON form of a Map.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Line ¶
type Line struct {
File string `json:"file"`
Line int `json:"line"`
Text string `json:"text,omitempty"`
Samples uint64 `json:"samples"`
Stalls map[string]uint64 `json:"stalls"`
Top string `json:"top"`
PCs []uint64 `json:"pcs"`
}
A Line is the samples of every instruction compiled from one source line. File is a base name: the map never carries a directory. Text is the line's source, trimmed, once Map.AddSource has been given the file.
type Map ¶
type Map struct {
Schema string `json:"schema"`
Kernel string `json:"kernel"`
// Device, Arch (such as "sm_121a"), Launches and GPUTimeNs describe
// the capture when the caller knows them; Build leaves them zero.
Device string `json:"device,omitempty"`
Arch string `json:"arch,omitempty"`
Launches int `json:"launches,omitempty"`
GPUTimeNs float64 `json:"gpu_time_ns,omitempty"`
// CubinSHA256 identifies the code the offsets index, when Build was
// given the cubin.
CubinSHA256 string `json:"cubin_sha256,omitempty"`
TotalSamples uint64 `json:"total_samples"`
// UnlocatedSamples fell on PCs with no source line. UnknownSamples,
// a part of them, fell on offsets the disassembly does not hold, which
// means the samples and the code are not from the same build.
UnlocatedSamples uint64 `json:"unlocated_samples"`
UnknownSamples uint64 `json:"unknown_samples"`
// Reasons totals each stall reason over the kernel, most samples first.
Reasons []Reason `json:"reasons"`
// PCs is every instruction of the kernel, in address order.
PCs []PC `json:"pcs"`
// Lines totals the instructions of each source line, most samples
// first. A PC with no source line is in no Line.
Lines []Line `json:"lines"`
}
A Map attributes one kernel's PC sampling stalls to its SASS instructions and the source lines they were compiled from.
func Build ¶
func Build(kernel string, samples []limiter.PCSample, fn *sass.Function, cubin []byte) (*Map, error)
Build joins samples of kernel onto fn, the kernel's disassembly. Line information comes from fn's instructions: disassemble with source lines (nvdisasm -g, sass.Options.SourceLines) from a cubin built with -lineinfo. Samples of other functions are ignored. cubin may be nil; it only identifies the code in the map.
type PC ¶
type PC struct {
Offset uint64 `json:"offset"`
Predicate string `json:"predicate,omitempty"`
Opcode string `json:"opcode"`
Operands string `json:"operands,omitempty"`
File string `json:"file,omitempty"`
Line int `json:"line,omitempty"`
Samples uint64 `json:"samples,omitempty"`
Stalls map[string]uint64 `json:"stalls,omitempty"`
Top string `json:"top,omitempty"`
}
A PC is one SASS instruction and the samples at it. Stalls are keyed by the short names of limiter.ReasonName, issued samples under "selected", so Samples is the sum of Stalls. A PC sampled at an offset the disassembly lacks has no Opcode.