Documentation
¶
Overview ¶
Package cudatool runs CUDA binary utilities without a shell, and answers what options the installed toolkit's utilities accept.
Resolving a tool ¶
LookTool prefers a CUDA toolkit install over PATH, because a distribution package can leave an older build of a tool earlier on PATH than the toolkit's own, and such a build may not merely be out of date: it can fail to start against the libraries it finds, or refuse the machine's devices. An explicit path is taken as given, and CUDA_HOME, CUDA_PATH or CUDA_ROOT name a root ahead of the default prefixes.
Option differences between toolkits ¶
Options move between releases, and a command line that works under one toolkit can fail under another. Measured across the toolkits installed on the GB10 host, 13.0 to 13.4 renamed nvcc's --sanitize to --fdevice-sanitize, added five ptxas options and two nvlink options, and left nvdisasm's and cuobjdump's option names alone. Going further back, nvdisasm gained --emit-json in 12.8: it is absent in 12.6 and present in every later toolkit on that host, and it is the one option the packages in this tree emit that an installed toolkit may not have.
The recorded option sets cover 12.6, 13.0 and 13.4, the three versions worth distinguishing, not every prefix a host happens to carry. A version with no record is not a refusal: Capabilities reads its --help instead, which costs one extra execution and answers for the tool actually installed.
Within compute-sanitizer, --kill and --track-unused-memory take no argument on any recorded version, and passing one is rejected outright rather than ignored. The 2022.4.1 build that Ubuntu installs as /usr/bin/compute-sanitizer spells both with an argument, so an option's arity is as much a property of the installed tool as its name is.
So that callers need not guess, the optiondata directory holds one distilled option set per tool per toolkit version: a line per option naming its arity, its short form, its documented default and its enumerated values. That form is a fifth the size of the help output it came from, it is what a command line actually depends on, and a diff of two versions is the flag difference itself.
Capabilities answers from that record whenever it covers the resolved toolkit, which costs one --version run. A toolkit newer than anything recorded is asked directly with --help, and the answer reports Probed so a caller can say it is working beyond what was measured.
Recording a new toolkit ¶
TestCorpusMatchesInstalledToolkits compares the record against every toolkit installed on the host, and is the gate on an upgrade: a changed option, arity, default or value list fails there rather than in a caller. To record a toolkit this machine has:
go test ./internal/cudatool -update
To record one only another machine has, capture its help output there as <tool>-<version>.txt and distill it here. Note that custom flags must follow the package argument:
for v in 12.6 13.0 13.4; do
for t in nvcc ptxas nvdisasm cuobjdump nvlink nvprune compute-sanitizer; do
ssh gpu-host /usr/local/cuda-$v/bin/$t --help > raw/$t-$v.txt
done
done
go test ./internal/cudatool -update -helpdir=raw
Review the diff: it is the flag difference between the toolkits, and it is worth reading rather than committing unseen.
Index ¶
- Constants
- Variables
- func Args(flags ...Flag) []string
- func IsExecutableFile(path string) bool
- func KnownOptions(tool string, v Version) (Options, Version, bool)
- func LookTool(tool, path string) (string, error)
- func SearchPaths(tool string) []string
- func SupportedArchitectures(v Version) []string
- func Tools() []string
- type Arity
- type Caps
- type Flag
- type Limits
- type Option
- type Options
- type Output
- type Version
Constants ¶
const ( ToolComputeSanitizer = "compute-sanitizer" ToolCUObjDump = "cuobjdump" ToolNVCC = "nvcc" ToolNVDisasm = "nvdisasm" ToolNvjitlink = "nvjitlink" ToolNVLink = "nvlink" ToolNVPrune = "nvprune" ToolPTXAS = "ptxas" )
Known tool names recorded in optiondata.
Variables ¶
var ErrOutputLimit = errors.New("tool output limit exceeded")
ErrOutputLimit means output exceeded the retained byte budget. Truncated output must not be used to qualify a successful parse or inspection.
var ErrToolNotFound = errors.New("cuda tool not found")
ErrToolNotFound means no executable was found for a tool.
var ErrUnsupportedOption = errors.New("option not supported by this toolkit")
ErrUnsupportedOption means the resolved tool does not accept an option as the command line spells it, either because the option is absent from that toolkit or because its arity differs.
var KnownGPUArchitectures = []string{}/* 102 elements not displayed */
KnownGPUArchitectures lists all unique GPU architectures (compute_*, sm_*, lto_*) recorded across toolkits in optiondata, sorted.
Functions ¶
func Args ¶
Args returns the command-line form of flags: a bare flag contributes its name, and a flag with a value contributes its name followed by that value as a separate argument.
func IsExecutableFile ¶
IsExecutableFile reports whether path is a regular file with an execute bit set. A directory of the same name, or a file that cannot be executed, is not a candidate.
func KnownOptions ¶
KnownOptions returns the option set the corpus records for a tool at a toolkit version. An exact match is used when present; otherwise the highest recorded version below v answers, since a version we did not measure is described by the last one we did. A version above everything recorded has no answer here and reports false, which is what sends Capabilities to the tool itself.
func LookTool ¶
LookTool returns the executable to run for a CUDA tool.
A non-empty path is resolved the way a shell would, including a bare name on PATH, and nothing else is tried: an explicit path is a decision, not a hint. An empty path tries the toolkit installs SearchPaths names for the tool and then the tool name on PATH. The error wraps ErrToolNotFound.
func SearchPaths ¶
SearchPaths returns the executables LookTool tries for a tool before PATH, in order. The list is empty on GOOS values the CUDA toolkit does not ship for, leaving PATH as the only source.
A toolkit install is preferred over PATH because a distribution package can leave an older build of a tool earlier on PATH than the toolkit's own. Such a binary is not merely out of date: it does not know the current devices, and one that shipped against different libraries fails to start at all rather than reporting that it is too old. Checking the toolkit first picks the build that matches the libraries beside it.
func SupportedArchitectures ¶
SupportedArchitectures returns the GPU architectures recorded for the given toolkit version.
Types ¶
type Arity ¶
type Arity int
Arity says whether an option takes an argument. It is a property of the option as the tool spells it, not of the Go type a caller holds: passing an argument to a Bare option is an error the tool reports rather than ignores, and compute-sanitizer in particular rejects the whole command line.
type Caps ¶
type Caps struct {
// Path is the executable the capabilities describe.
Path string
// Tool is its base name, as the corpus keys it.
Tool string
// Version is the toolkit version the tool reports, or the one its install
// prefix names for a tool that reports none.
Version Version
// Source is the version whose recorded option set Options came from. It
// differs from Version when the corpus covers no exact match.
Source Version
// Options is the option set.
Options Options
// Probed reports that Options came from running the tool's --help rather
// than from the shipped corpus, which happens for a toolkit newer than
// anything measured.
Probed bool
}
Caps is what one resolved executable accepts.
func Capabilities ¶
Capabilities returns what the named tool accepts. An empty explicit path resolves the tool the way LookTool does.
The shipped corpus answers whenever it covers the resolved toolkit version, so the usual call runs the tool once, for --version. A toolkit newer than anything measured is asked directly, with --help, and the answer records Probed so a caller can report that it is working beyond what was measured.
func (Caps) Arity ¶
Arity returns how an option is spelled. It reports false for an option the tool does not accept, which a caller must not emit at all.
func (Caps) Check ¶
Check reports whether the tool accepts every flag as spelled. The error wraps ErrUnsupportedOption and names the tool, the toolkit version, where the option set came from, and every flag at fault, so one error describes the whole difference rather than the first one found.
An arity mismatch is a failure in both directions: a tool that spells an option bare rejects the whole command line when an argument follows it, and one that requires an argument consumes the next word when none is given.
func (Caps) CheckNames ¶
CheckNames reports whether the tool accepts every named option, saying nothing about arity. It is for options a caller passes through as text, where the argument form is the caller's business but the name is still either accepted or rejected. Arguments that do not begin with a dash are ignored, since in an argument list they are the values of the options before them.
type Flag ¶
Flag is one option a command line means to emit, with the argument that follows it when the option takes one.
An empty Value means the flag stands alone, so a Flag describes its own arity: the command line built from a Flag and the arity checked against the tool cannot disagree.
type Limits ¶
Limits bounds one tool invocation. Zero fields use 256 MiB aggregate stdout and stderr and a 60-second timeout. A shorter caller deadline takes precedence.
type Option ¶
type Option struct {
// Name is the long form, including the leading dashes.
Name string
// Short is the alternate spelling the help output pairs with Name, empty
// when the tool documents none.
Short string
// Arity says whether an argument follows.
Arity Arity
// Default is the argument used when the option is absent, as documented.
// Empty means the help output names none.
Default string
// Values are the arguments the help output enumerates, in the order
// given. Nil means the help output constrains the argument no further,
// which is not a promise that any value is accepted.
Values []string
}
Option is one command-line option a tool accepts.
type Options ¶
type Options []Option
Options is a tool's option set, sorted by name.
func ParseHelp ¶
ParseHelp extracts the option set from a tool's --help output. The CUDA binary utilities and compute-sanitizer print different grammars, so the grammar is detected rather than configured.
func ParseText ¶
ParseText reads back what Options.Text wrote. Blank lines and lines beginning with # are ignored.
func (Options) Text ¶
Text returns the canonical one-line-per-option form, sorted by name:
--binary value short=-b values=SM100,SM100a --kill bare --tool value default=memcheck values=memcheck,racecheck
It is what this package stores and compares, rather than the help output it came from: it holds the facts a command line depends on, it is a fifth the size, and a diff of two versions' text is the flag difference itself.
type Output ¶
type Output struct {
Path string
Args []string
Stdout []byte
Stderr []byte
ExitCode int // -1 if no process exit status was available
Duration time.Duration
Truncated bool
MaxOutputBytes int64
Timeout time.Duration
}
Output retains the executable, arguments, and both output streams, even on error.
func Run ¶
Run resolves path before changing directories. Cancellation is observable with errors.Is.
func RunWithLimits ¶
func RunWithLimits(ctx context.Context, limits Limits, path, dir string, stdin io.Reader, args ...string) (Output, error)
RunWithLimits runs a tool, retaining at most the configured output bytes. Budget exhaustion cancels and reaps the direct child. The returned error matches ErrOutputLimit, and timeout/cancellation remain observable with Is.
type Version ¶
type Version struct {
Major, Minor int
}
Version is a CUDA toolkit version. The zero value is not a version.
func KnownVersions ¶
KnownVersions returns the toolkit versions the corpus covers for a tool, in increasing order.
func ParseVersion ¶
ParseVersion returns the toolkit version named in a tool's --version output.
compute-sanitizer is the exception: it reports its own product version, as in "Version 2026.3.0.0 (build 38637409)", which names no toolkit. ParseVersion returns false for it, leaving the caller to resolve the version another way.
func VersionFromPath ¶
VersionFromPath returns the toolkit version named by the install prefix an executable sits in. It is how compute-sanitizer's toolkit version is recovered, since the tool itself does not report one.
Symbolic links are resolved first: a multi-version install is usually reached through /usr/local/cuda, whose own name carries no version while its target's does.