Documentation
¶
Overview ¶
Package cudadevicetable holds GPU device facts that were read from a real device, separated from the ones that were not.
Device tables in this module have been hand-written from datasheets: an architecture name mapped to a dozen integers, with nothing recording where any of them came from. That shape fails silently. A wrong shared-memory capacity does not produce an error, it produces an occupancy number that is plausible and wrong, and no arithmetic downstream can tell it from a right one. The same table is also maintained in more than one package, so two copies can disagree indefinitely without anything noticing.
This package keeps one table, generated rather than typed, in which every value carries its own provenance:
Probed read from a live device through a named driver attribute Derived computed from probed values in the same record Unverified hand-entered; no device has confirmed it Reported measured or read by someone outside this repository; no rows held here Unknown no source states it; the value is 0 and is not a reading
The rule that makes the distinction hold is structural rather than editorial: a Value may claim Probed only if it names the driver.DevAttr constant it was read through, and Table.Validate rejects a record that breaks it. A datasheet figure cannot be relabelled as a measurement without also naming a real attribute to have measured it with, which is a check a test can run and a claim a reader can reproduce.
The table is deliberately sparse. It holds architectures somebody has actually run cmd/cudadevicetable against, not every architecture the module can compile for; Lookup reports a miss for the rest rather than inventing a plausible entry. Absence here means nobody probed it, which is the honest answer and a useful one.
The table holds a second kind of fact, keyed separately. Architecture describes silicon; Target describes what an assembler accepts for it. They are not the same question and cannot share a key: setmaxnreg is accepted at sm_90a and rejected at sm_90, which is one piece of hardware, so a table that normalized the feature suffix away would have to record one of those two answers wrongly.
Feature facts are read with ptxas rather than a device, which is why the table can describe Hopper and GB200 while this project has only ever attached a GB10. The instrument bounds the claim, and the bound is worth stating plainly: an accepted fixture means the assembler emitted code for that target, not that the instruction is fast, not that it is correct on silicon, and not that any device here ran it. It is the answer to "will this build", which is the question the packages that consumed hand-written capability flags were actually asking.
Two rules make the feature side hold. A Probed feature must name the ptxas invocation and the fixture that produced it, so a reader who doubts it can re-run it. And a feature rejected at every probed target is refused by Table.Validate rather than recorded: a fixture that assembles nowhere is broken, and its negatives are not measurements. That rule has already earned its place -- the first wgmma fixture written here used a constant matrix descriptor that segfaults ptxas 13.0.88, and a classifier reading any non-zero exit as "unsupported" reported wgmma unsupported on sm_90a, the one target that supports it.
Guard turns the probed answers into the preprocessor condition a kernel tests before using a feature, in place of a hand-written list of __CUDA_ARCH_FEAT_ macros. testdata/guards.txt records nvcc evaluating every guard for every target, and a test checks each evaluation against the probe; rerun testdata/gen-guards.sh after changing either.
A code generator planning for hardware nobody here has attached still needs SM counts and shared-memory limits, so the package also holds a datasheet: one Profile per product (H200, B200, GB300, GB10, ...), in which every value is Unverified and cites its source, or is Unknown where no source states it, as for Rubin's SM count. LookupProfile replaces a product's datasheet values with probed ones wherever this table holds a probe of that product, and answers feature questions from the probed targets. The datasheet is the one hand-entered table here; a generator that must not act on it can check each value's Source.
A value someone outside this repository measured, or read from a driver, and reported is Reported, with a note citing the report. Nothing here can reproduce it, but the lookups return it and planners use it like a datasheet figure; a result priced from it carries its Source and Note, so a reader can see it rests on an outside report. The GB300 Max-Q's SM count, L2 size, memory size, memory read rate, cold-code launch costs and copy rates are reported values.
Devices the table does not list ¶
Adding a device is a measurement and a file, not a change to this package. cmd/cudadevicetable -measure writes a Facts record of the attached device: its name and compute capability as the driver reports them, its driver attributes, total memory, a measured streaming-read rate, and whether a read-only file mapping can be read from a kernel, each with how it was measured and the conditions it was measured under. A record is keyed by the device's name, never by an architecture alone. Register, or a path in $CUDADEVICETABLE_FACTS, supplies records to every lookup here at run time.
A supplied record takes precedence over the built-in table value by value: what it measured replaces the built-in value for its device, probed or datasheet, and what it did not measure stays as built in. For a product the table does not list, the record alone makes the profile, and a value nothing measured is Unknown, not a neighbour's. A device with neither a row nor a record is refused with ErrUnknownDevice, as before. BuiltinFacts returns the embedded probes in the same form, and Facts.Compare lists where a record and the table disagree.
The measuring procedure has been run on one device, a GB10; its record is testdata/facts-gb10.json.
Regenerate on a host with the device attached:
go run ./cmd/cudadevicetable -update x/cudadevicetable/devices.json
Regenerate the feature facts on any host with a CUDA toolchain:
go run ./cmd/cudadevicetable -ptxas /usr/local/cuda/bin/ptxas -update x/cudadevicetable/devices.json
ReadLocalityDomains reads how many CUDA locality domains a device has and how many SMs each holds, and Facts.LocalityDomains reads the same from a record. A driver that predates the attributes leaves them unreported, which is not the same as one domain. B200-, GB200- and GB300-class parts are the devices expected to report more than one.
This package is outside the compatibility promise of github.com/tmc/lib/nvidia. Its API may change or be removed in patch releases.
Index ¶
- Constants
- Variables
- func Architectures() []string
- func BuildTargets(results []Result, probe FeatureProbe) (map[string]Target, error)
- func Conflict(product, field string) string
- func FeatureNames() []string
- func FindPTXAS() (string, error)
- func FixtureVersion() (string, error)
- func Fixtures() map[string]string
- func Guard(feature string) (string, error)
- func LocalityHBMBandwidth(domains []LocalityProfile, domain *int, writeFraction float64) float64
- func Normalize(arch string) string
- func ProfileNames() []string
- func Register(f Facts) error
- func TargetName(major, minor int) string
- func Targets() []string
- func TargetsSupporting(feature string) []string
- func Unregister(f Facts)
- type Answer
- type Architecture
- type AttributeReader
- type Conditions
- type Copy
- type Difference
- type Facts
- func (f Facts) Compare() []Difference
- func (f Facts) ComputeCapability() (major, minor int, err error)
- func (f Facts) Copy(kind, locality string) (Copy, bool)
- func (f Facts) Encode() ([]byte, error)
- func (f Facts) LocalityDomains() LocalityDomains
- func (f Facts) Mapping(mode string) (HostMapping, bool)
- func (f Facts) Profile() (Profile, error)
- func (f Facts) SMs() int
- func (f Facts) Validate() error
- type Feature
- type FeatureProbe
- type HostLoad
- type HostMapping
- type Identity
- type LocalityDomains
- type LocalityLatency
- type LocalityProfile
- type LocalityProfileSet
- type Memory
- type Outcome
- type Probe
- type Profile
- type ReadPoint
- type Resolver
- type Result
- type Source
- type Statement
- type StreamRead
- type Table
- type Target
- type Value
Examples ¶
Constants ¶
const ( // AssumeSupported is for a feature whose misuse the assembler catches // downstream: emit the instruction, and a target that does not have it // fails to compile, loudly, with the real diagnostic. Refusing instead // would make every new GPU less capable than an old one until someone // regenerates a table, which is the wrong failure for hardware that is // almost certainly a superset of what came before. AssumeSupported = true // AssumeAbsent is for a feature whose absence would otherwise flow // onward silently -- anything feeding a geometry, occupancy or roofline // number, where a wrong value is wrong in the way that reads as right. AssumeAbsent = false )
Fallback policies for Answer.Or. Which one is right is decided by what catches the mistake, not by optimism.
const ( // ModeRegistered registers the mapping with cuMemHostRegister and // reads it through the device pointer the driver returns: what // x/cudammap's MappedFile.Register does. ModeRegistered = "registered" // ModePageable registers nothing and reads the mapping through its // host address, which a device with the pageableMemoryAccess // attribute allows. ModePageable = "pageable" )
Modes of the host-mapping probe, for HostMapping.Mode. Both map a file with PROT_READ, as x/cudammap does, and read it from a kernel without copying it.
const ( StageGate = "gate" // the device's attributes do not allow it; nothing was tried StageMap = "map" // the file could not be mapped into the process StageRegister = "register" // cuMemHostRegister, cuMemHostGetDevicePointer or cuMemHostUnregister failed StageReadback = "readback" // a kernel read the mapping and got other bytes, or failed )
Stages of the host-mapping probe, for HostMapping.Stage.
const ( CopyHostToDevice = "host-to-device" // from pinned host memory to device memory CopyPeer = "peer" // from this device's memory to another device's )
Kinds of copy, for Copy.Kind.
const ( LocalityLocal = "local" // the host buffer is on the GPU's own NUMA node LocalityRemote = "remote" // the host buffer is on another NUMA node )
Localities of a host-to-device copy, for Copy.Locality. The measurer states which one a copy had; nothing in the measurement checks it.
const ( AttrLocalityDomainCount = "localityDomainCount" AttrLocalityDomainSMs = "localityDomainMultiprocessorCount" )
Attribute names under which Facts records a device's locality domains.
const FactsEnv = "CUDADEVICETABLE_FACTS"
FactsEnv names the environment variable that supplies records to this package's lookups: a list of record files, or directories of *.json records, separated as $PATH is. It is read once, at the first lookup.
A path that cannot be read, or a record that does not validate, is not skipped: Supplied, LookupFacts and every lookup that returns an error report it until the process is restarted with the variable fixed, so a record an operator supplied is never silently replaced by a built-in row.
const FactsVersion = 1
FactsVersion is the version of the encoded Facts. Decoding refuses any other version: a later version may change what a field means.
Variables ¶
var ErrUnknownDevice = errors.New("unknown device")
ErrUnknownDevice is wrapped by the errors of LookupProfile, LookupDevice, LookupDeviceName and LookupFacts when neither the built-in table nor a supplied record describes the device asked for. Measuring the device with cmd/cudadevicetable -measure and supplying the record is the remedy; using another device's values is not.
Functions ¶
func Architectures ¶
func Architectures() []string
Architectures returns the probed architecture keys in sorted order.
func BuildTargets ¶
func BuildTargets(results []Result, probe FeatureProbe) (map[string]Target, error)
BuildTargets turns probe results into table records. A feature accepted nowhere is reported as an error rather than recorded: see the positive control rule in validateTargets.
func Conflict ¶
Conflict describes product's field's disagreement, as "priced at [vr] 3000; [rubinarch] states 3600", or returns "" when there is none.
func FeatureNames ¶
func FeatureNames() []string
FeatureNames returns the feature names recorded for any target, sorted.
func FindPTXAS ¶
FindPTXAS locates an assembler to resolve unprobed targets with. It returns an error rather than a guess when there is none, because a missing assembler must degrade to "unmeasured" and not to a fabricated answer.
$PTXAS names an assembler outright. Otherwise the CUDA toolkit installs are tried before $PATH, because a distribution package can leave an older ptxas earlier on PATH than the toolkit's own -- and an assembler that predates a target does not report that it is too old, it reports that the target is unsupported. Resolving through PATH first would record that answer as a measurement. cudatool.SearchPaths lists what is tried.
func FixtureVersion ¶
FixtureVersion reports the PTX .version the fixtures declare. It is read from the fixtures rather than written down beside them, so the version recorded in a probe stamp cannot drift from the one actually assembled.
Fixtures that disagreed would make a single stamp false for some of the answers it covers, so disagreement is an error rather than a first match.
func Fixtures ¶
Fixtures returns the embedded probe fixtures keyed by feature name, which is the fixture's base name.
func Guard ¶
Guard returns a C preprocessor condition that holds when device code is compiled for a target the table records as accepting feature, so that kernels can test the probed answer instead of a hand-written list of __CUDA_ARCH_FEAT_ macros.
A target such as sm_90 contributes __CUDA_ARCH__ == 900, which holds for sm_90a too; an arch-specific target such as sm_100a contributes defined(__CUDA_ARCH_FEAT_SM100_ALL). Targets the table does not hold, such as family targets (sm_100f) or architectures nobody probed, and answers that were not Probed, contribute nothing: the condition is false for them, and the kernel takes its fallback.
Guard returns an error for a feature no target records, or one that no probed target accepts.
Example ¶
package main
import (
"fmt"
"github.com/tmc/lib/nvidia/x/isa/devicetable"
)
func main() {
g, err := devicetable.Guard("tcgen05")
if err != nil {
panic(err)
}
fmt.Printf("#if %s\n// tcgen05 path\n#endif\n", g)
}
Output: #if defined(__CUDA_ARCH__) && (defined(__CUDA_ARCH_FEAT_SM100_ALL) || defined(__CUDA_ARCH_FEAT_SM103_ALL) || defined(__CUDA_ARCH_FEAT_SM107_ALL) || defined(__CUDA_ARCH_FEAT_SM110_ALL)) // tcgen05 path #endif
func LocalityHBMBandwidth ¶
func LocalityHBMBandwidth(domains []LocalityProfile, domain *int, writeFraction float64) float64
LocalityHBMBandwidth returns a measured bandwidth in GB/s. A nil domain sums the separate domain rates for an evenly serviced streaming workload. Zero means the requested rate is unmeasured.
func Normalize ¶
Normalize canonicalizes an architecture string to the "sm_NNN" form used as a table key, dropping any feature suffix.
func ProfileNames ¶
func ProfileNames() []string
ProfileNames returns the targets and products LookupProfile accepts, sorted, including the products supplied records add.
func Register ¶
Register supplies f to the lookups of this package for the rest of the process, as a record named by $CUDADEVICETABLE_FACTS is.
A supplied record takes precedence over the built-in table, value by value: for the product it names, each value it measured replaces the built-in one, probed or datasheet, and every value it did not measure stays as built in. A record of a product the table does not list adds that product; see Facts.Profile. Of two records of one device the one with the later date is used. A registered record and one from the environment are treated alike.
Example ¶
A record written by cmd/cudadevicetable -measure makes its device answerable by the lookups. The record here was measured on a GB10; it is relabelled to stand for a device the table does not list.
package main
import (
"errors"
"fmt"
"log"
"os"
"github.com/tmc/lib/nvidia/x/isa/devicetable"
)
func main() {
data, err := os.ReadFile("testdata/facts-gb10.json")
if err != nil {
log.Fatal(err)
}
f, err := devicetable.DecodeFacts(data)
if err != nil {
log.Fatal(err)
}
f.Device.Name = "NVIDIA Example Device"
_, err = devicetable.LookupDeviceName(f.Device.Name)
fmt.Println(errors.Is(err, devicetable.ErrUnknownDevice))
if err := devicetable.Register(f); err != nil {
log.Fatal(err)
}
defer devicetable.Unregister(f)
p, err := devicetable.LookupDeviceName(f.Device.Name)
if err != nil {
log.Fatal(err)
}
fmt.Println(p.Target, p.Product, p.SMs.Value, p.SMs.Source, p.MemoryReadGBps.Value, p.MemoryReadGBps.Source)
}
Output: true sm_121a Example Device 48 probed 234 probed
func TargetName ¶
TargetName returns the PTX target LookupProfile lists a device of compute capability major.minor under: the arch-specific sm_XYa from sm_90 on, and the plain sm_XY before it, where no sm_XYa exists. For example, 8.9 is "sm_89" and 12.1 is "sm_121a".
An sm_XYa target accepts every instruction its architecture has, such as wgmma at sm_90a, and its code runs on that architecture only.
The name is ptxas's, nvdisasm's and NVRTC's. The Tile IR assembler names the same device without the suffix and refuses the suffixed spelling; x/tileiras.WithArch builds that name from the same compute capability. The two are different names for one device, not two targets to choose between, and neither tool's name should be passed to the other.
Example ¶
package main
import (
"fmt"
"github.com/tmc/lib/nvidia/x/isa/devicetable"
)
func main() {
for _, cc := range [][2]int{{8, 9}, {9, 0}, {12, 1}} {
target := devicetable.TargetName(cc[0], cc[1])
p, err := devicetable.LookupProfile(target)
if err != nil {
panic(err)
}
fmt.Printf("%s %q %d\n", target, p.Product, p.SMs.Value)
}
}
Output: sm_89 "" 0 sm_90a "" 0 sm_121a "GB10" 48
func TargetsSupporting ¶
TargetsSupporting returns the probed targets that accept the named feature, sorted. It is the answer to "then where does this work", which is the question a rejection raises and the one a hand-written error message gets wrong as soon as the toolchain moves.
func Unregister ¶
func Unregister(f Facts)
Unregister removes every record Register supplied for f's device. It does not remove a record that came from the environment.
Types ¶
type Answer ¶
type Answer struct {
Target string
Feature string
// Supported is meaningful only when Measured is true.
Supported bool
// Measured reports whether an instrument produced Supported. When it is
// false, Supported is false because a zero value has to be something,
// not because anything said so.
Measured bool
// Source names the instrument, empty when Measured is false.
Source string
// Diagnostic is the assembler's rejection message, when there is one.
Diagnostic string
}
Answer is what is known about one feature at one target, together with whether anything actually looked.
A bool cannot hold this. "The assembler rejected it" and "no assembler has been pointed at it" are different facts with different right responses, and collapsing them into false is how a target nobody has probed acquires a confident row of negatives. Target.Supports keeps them apart with an error; Answer keeps them apart in a value, so a caller can carry the distinction instead of handling it at the point of lookup.
func Ask ¶
Ask returns what the table knows about feature at target. It never guesses: a target the table does not cover, or a feature it never probed, comes back with Measured false. Use Answer.Or to state the fallback explicitly.
type Architecture ¶
type Architecture struct {
Architecture string `json:"architecture"`
// Probe is nil when no value in Attributes is [Probed].
Probe *Probe `json:"probe,omitempty"`
Attributes map[string]Value `json:"attributes"`
}
Architecture is the set of known facts for one GPU architecture.
func Lookup ¶
func Lookup(arch string) (Architecture, bool)
Lookup returns the record for arch, which may be written "sm_121" or "sm121" in any case. The architecture suffix used for feature-specific codegen ("sm_121a") resolves to its base architecture, because the suffix selects an instruction set and does not describe different hardware.
A miss means no device with that architecture has been probed. It does not mean the architecture is unsupported, and callers must not substitute a neighbouring architecture's record for a missing one: an occupancy or roofline figure computed from the wrong architecture is wrong in exactly the way that reads as right.
A supplied record (see Register) answers for an architecture the table has no probe of, and for the device the table did probe it replaces the attributes it holds. A record of some other device of a probed architecture does not displace the built-in probe here, since the key holds one device; LookupFacts and LookupDevice find it by name.
func (Architecture) Attr ¶
func (a Architecture) Attr(name string) (Value, bool)
Attr returns the named attribute.
func (Architecture) ProbedAttr ¶
func (a Architecture) ProbedAttr(name string) (int64, error)
ProbedAttr returns the named attribute only if it was read from a device. Use it wherever a wrong value would flow onward silently: it converts a datasheet figure from a plausible number into an error.
type AttributeReader ¶
type AttributeReader interface {
Attribute(driver.DeviceAttribute) (int32, error)
}
An AttributeReader reads a device attribute. driver.Device is one.
type Conditions ¶
type Conditions struct {
// Host is a label the measurer chose for the machine, or empty. It is
// never filled in from the host name: a record is committed and
// shared, and the name of the machine it came from is not its to say.
Host string `json:"host,omitempty"`
Date time.Time `json:"date"`
Tool string `json:"tool"` // the command that measured, such as "cmd/cudadevicetable -measure"
// Commit is the revision of the measuring code. It is required when
// the record holds a timed or executed section, because those depend
// on a kernel only the commit identifies.
Commit string `json:"commit,omitempty"`
CUDADriver int `json:"cuda_driver,omitempty"` // cuDriverGetVersion, such as 13000; required as Commit is
KernelDriver string `json:"kernel_driver,omitempty"` // NVIDIA kernel module version, such as "580.95.05"
Compiler string `json:"compiler,omitempty"` // what compiled the measuring kernels, such as "NVRTC 13.0"
Platform string `json:"platform,omitempty"` // GOOS/GOARCH of the measuring process
// Load is the host's load when the measurement began, where it could
// be read.
Load *HostLoad `json:"load,omitempty"`
}
Conditions records what a measurement was taken with and under, so a reader can tell whether it still applies.
type Copy ¶
type Copy struct {
Kind string `json:"kind"` // CopyHostToDevice or CopyPeer
// Locality says, for a host-to-device copy, where the pinned host
// buffer was relative to the GPU: LocalityLocal or LocalityRemote, as
// the measurer stated it. It is empty for a peer copy.
Locality string `json:"locality,omitempty"`
// Peer names, for a peer copy, the device copied to: its name and
// ordinal, such as "NVIDIA GB300 (device 1)". It is empty for a
// host-to-device copy.
Peer string `json:"peer,omitempty"`
Method string `json:"method"` // the copy call, buffers, timing and statistic
Bytes uint64 `json:"bytes"` // bytes per timed copy
Runs int `json:"runs"`
MedianGBps float64 `json:"median_gbps"`
MinGBps float64 `json:"min_gbps"`
MaxGBps float64 `json:"max_gbps"`
}
A Copy is the rate of one kind of copy over Runs timed copies of Bytes bytes each. A rate is in GB/s, 10⁹ bytes per second.
type Difference ¶
type Difference struct {
Name string // the value's name, as devices.json spells it
Supplied Value
Builtin Value
}
A Difference is one value on which a record and the built-in table disagree.
func (Difference) String ¶
func (d Difference) String() string
type Facts ¶
type Facts struct {
Version int `json:"version"`
Device Identity `json:"device"`
Conditions Conditions `json:"conditions"`
// Attributes holds driver device attributes under the names
// devices.json uses, such as "multiprocessorCount". Every value is
// [Probed] and names the driver.DevAttr constant it was read through,
// or, for a value no attribute reports, the driver function that
// answered it, as cuOccupancyMaxPotentialClusterSize answers
// "clusterSize". multiprocessorCount, the SM count, is required.
Attributes map[string]Value `json:"attributes"`
Memory *Memory `json:"memory,omitempty"`
StreamRead *StreamRead `json:"stream_read,omitempty"`
// HostMappings holds the outcome of each way of reading a read-only
// file mapping from a kernel that was tried, at most one per mode.
HostMappings []HostMapping `json:"host_mappings,omitempty"`
// Copies holds the copy rates that were timed, at most one per kind
// and locality.
Copies []Copy `json:"copies,omitempty"`
}
Facts is one measurement of one device: what the driver reported, what was timed on it, and the conditions it was taken under. cmd/cudadevicetable -measure writes one, and Register or $CUDADEVICETABLE_FACTS supplies one to the lookups of this package at run time, which is how a device the table does not list becomes usable without a change to this module.
A Facts holds measurements only. Every value says how it was read, and a value that was not measured is absent: a nil section, or a missing attribute. Zero never stands for "not measured", and Facts.Validate refuses a section that is present and empty.
func BuiltinFacts ¶
func BuiltinFacts() []Facts
BuiltinFacts returns the probes embedded in this package as records, in architecture order: what a built-in row is, written the way a supplied one is. A record holds the probed attributes only. The embedded probes timed nothing and mapped nothing, so the records have no memory, stream-read, host-mapping or copy section.
func DecodeFacts ¶
DecodeFacts decodes and validates one record. An unknown field is an error, since a field this version does not know may change what the others mean.
func LookupFacts ¶
LookupFacts returns the record of the device of compute capability major.minor that reports its name as name: the supplied record if there is one, and otherwise the built-in probe of that device (BuiltinFacts). With neither, the error wraps ErrUnknownDevice.
func ReadFacts ¶
ReadFacts decodes the record in the file at path, or every *.json record in the directory at path, in name order.
func Supplied ¶
Supplied returns the records supplied to this process, by Register and by $CUDADEVICETABLE_FACTS, one per device: the newest. The error is the one reading the environment's records produced, if any; the registered records are returned with it.
func (Facts) Compare ¶
func (f Facts) Compare() []Difference
Compare returns each value f measured that differs from the built-in table's value for the same device, ignoring every supplied record, in name order: the driver attributes against the built-in probe of the device, and the profile values against the device's listed product. A device the table does not hold has nothing to differ from, and neither has a value the table holds as Unknown.
Example ¶
package main
import (
"fmt"
"log"
"github.com/tmc/lib/nvidia/x/isa/devicetable"
)
func main() {
fs, err := devicetable.ReadFacts("testdata/facts-gb10.json")
if err != nil {
log.Fatal(err)
}
// A record that disagrees with the built-in probe.
f := fs[0]
v := f.Attributes["maxBlocksPerMultiprocessor"]
v.Value = 16
f.Attributes["maxBlocksPerMultiprocessor"] = v
for _, d := range f.Compare() {
fmt.Println(d)
}
}
Output: maxBlocksPerMultiprocessor: record 16 (probed), built-in 24 (probed)
func (Facts) ComputeCapability ¶
ComputeCapability returns the device's compute capability.
func (Facts) Copy ¶
Copy returns the copy f records of kind and locality, and false if f timed none. A peer copy has the empty locality.
func (Facts) Encode ¶
Encode returns f as indented JSON with a trailing newline. It refuses a record that does not validate.
func (Facts) LocalityDomains ¶
func (f Facts) LocalityDomains() LocalityDomains
LocalityDomains returns the locality domains f records, under AttrLocalityDomainCount and AttrLocalityDomainSMs. A record taken with a driver that did not report them has neither attribute, and the result is unreported.
func (Facts) Mapping ¶
func (f Facts) Mapping(mode string) (HostMapping, bool)
Mapping returns the outcome f records for mode, and false if f did not probe it.
func (Facts) Profile ¶
Profile returns the profile f gives its device.
For a product the built-in table lists, it is that product's profile with each value f measured in place of the built-in one: the driver attributes, the L2 size and the cluster sizes among them; the memory size, if f's Memory was read with cuDeviceTotalMem; the achieved read rate, MemoryReadGBps, if f holds a device-resident StreamRead; and the copy rates f's Copy sections time. Each rate is the median, rounded to a whole GB/s. A measured rate never replaces a cited peak: MemoryGBps keeps the table's figure.
For any other product it is a profile built from f alone, and f must hold the attributes a planner sizes a launch by and a device-resident StreamRead; a record without them is an error, not a profile with holes. Its MemoryGBps is Unknown, since a read rate is not a peak. Two values no measurement here produces, Tensor Memory and NVLink bandwidth, and the cluster sizes where f holds none, take the value every listed product of the same target has, marked Unverified with a note saying so, and are Unknown when the target is not listed or its products differ. The values Profile holds that f does not measure, such as the cold-code costs, are Unknown.
type Feature ¶
type Feature struct {
// Supported is what the instrument reported, not what a datasheet says.
Supported bool `json:"supported"`
Source Source `json:"source"`
// Instrument names the assembler invocation that produced the answer,
// for example "ptxas -arch=sm_90a". Required when Source is [Probed],
// empty otherwise.
Instrument string `json:"instrument,omitempty"`
// Fixture names the file in ptxprobe/ that was assembled. Required when
// Source is [Probed]: without it the claim cannot be re-run, and a
// feature fact that cannot be re-run is a datasheet figure wearing a
// measurement's label.
Fixture string `json:"fixture,omitempty"`
// Diagnostic is the assembler's first error line for an unsupported
// feature. It is what distinguishes a target rejection from a fixture
// that never assembled anywhere.
Diagnostic string `json:"diagnostic,omitempty"`
// Note explains why a fact could not be probed. Required when Source is
// [Unverified].
Note string `json:"note,omitempty"`
}
Feature is one instruction-set fact: whether the assembler accepts a construct for an exact target.
Feature facts are keyed by target rather than by architecture, unlike the Architecture attributes, because the feature suffix is the whole point. setmaxnreg is accepted at sm_90a and rejected at sm_90, which is the same silicon; the suffix selects an instruction set, so a table that normalized it away would have to pick one of two contradictory answers.
type FeatureProbe ¶
type FeatureProbe struct {
Tool string `json:"tool"`
ToolVersion string `json:"toolVersion"`
PTXVersion string `json:"ptxVersion"`
Host string `json:"host"`
ProbedAt string `json:"probedAt"`
}
FeatureProbe identifies the assembler a target's feature facts were read with. A feature answer is a property of a toolchain version as much as of the hardware: a construct rejected by one ptxas can be accepted by the next.
func NewFeatureProbe ¶
func NewFeatureProbe(ptxasPath, host, ptxVersion string) (FeatureProbe, error)
NewFeatureProbe records the assembler identity for a probe run.
type HostMapping ¶
type HostMapping struct {
Mode string `json:"mode"`
Method string `json:"method"`
Works bool `json:"works"`
Bytes uint64 `json:"bytes"` // size of the file mapped
Stage string `json:"stage,omitempty"` // empty when Works
Status string `json:"status,omitempty"` // the error, when not Works
Code *int `json:"code,omitempty"` // the CUresult or errno behind Status, where there was one
// Read is the streaming-read rate through the mapping, where the
// probe timed it. Its SMs is the device's SM count.
Read *ReadPoint `json:"read,omitempty"`
}
HostMapping is the outcome of reading a read-only file mapping from a kernel in one HostMapping.Mode.
Works means all of it happened: the file was mapped, registered if the mode registers, a kernel summed every word of it, and the sum equalled the host's. Otherwise Stage says how far the probe got and Status holds what stopped it.
type Identity ¶
type Identity struct {
Name string `json:"name"` // cuDeviceGetName, such as "NVIDIA GB10"
ComputeCapability string `json:"compute_capability"` // "major.minor", such as "12.1"
Architecture string `json:"architecture"` // "sm_" + major + minor, such as "sm_121"
}
Identity names a device as the driver reports it.
type LocalityDomains ¶
type LocalityDomains struct {
// Reported is whether the driver reported a domain count.
Reported bool
// Count is the number of domains, as read. It is 0 when not Reported.
Count int
// SMsPerDomain is the number of SMs in each domain, not counting
// supplemental SMs, or 0 when the driver does not report it.
SMsPerDomain int
}
LocalityDomains describes how a device divides its SMs and memory into CUDA locality domains, as the driver reports them through driver.DevAttrLocalityDomainCount and driver.DevAttrLocalityDomainMultiprocessorCount.
A driver that does not know the attributes reports neither, and Reported is false: the device may or may not be divided, and nothing here can say which. A driver that knows them reports a count of 1 (or 0) for an undivided device. B200-, GB200- and GB300-class parts are the devices expected to report more than one.
func ReadLocalityDomains ¶
func ReadLocalityDomains(dev AttributeReader) (LocalityDomains, error)
ReadLocalityDomains reads dev's locality domains. An attribute the driver refuses as an invalid value, as a driver older than the attribute does, is unreported; any other error is returned.
Example ¶
A driver older than the locality-domain attributes refuses them; the device is then reported as unreported rather than as one domain.
package main
import (
"fmt"
"github.com/tmc/lib/nvidia/driver"
"github.com/tmc/lib/nvidia/x/isa/devicetable"
)
// attrs is an [cudadevicetable.AttributeReader] that reports the
// attributes it holds and refuses the rest as a driver that does not know
// them does, with ErrInvalidValue wrapped in a CallError.
type attrs map[driver.DeviceAttribute]int32
func (a attrs) Attribute(attr driver.DeviceAttribute) (int32, error) {
v, ok := a[attr]
if !ok {
return 0, &driver.CallError{Func: "cuDeviceGetAttribute", Result: driver.ErrInvalidValue}
}
return v, nil
}
func main() {
for _, dev := range []devicetable.AttributeReader{
attrs{},
attrs{driver.DevAttrLocalityDomainCount: 1, driver.DevAttrLocalityDomainMultiprocessorCount: 48},
attrs{driver.DevAttrLocalityDomainCount: 2, driver.DevAttrLocalityDomainMultiprocessorCount: 74},
} {
l, err := devicetable.ReadLocalityDomains(dev)
if err != nil {
fmt.Println(err)
continue
}
fmt.Println(l, l.Divided())
}
}
Output: locality domains unreported false 1 locality domain false 2 locality domains of 74 SMs true
func (LocalityDomains) Divided ¶
func (l LocalityDomains) Divided() bool
Divided reports whether the driver reported more than one domain.
func (LocalityDomains) String ¶
func (l LocalityDomains) String() string
type LocalityLatency ¶
type LocalityLatency struct {
NearReadNs float64 `json:"near_read_ns,omitempty"`
FarReadNs float64 `json:"far_read_ns,omitempty"`
NearWriteNs float64 `json:"near_write_ns,omitempty"`
FarWriteNs float64 `json:"far_write_ns,omitempty"`
}
LocalityLatency records dependent access latency in nanoseconds. A zero field means the corresponding access was not measured.
type LocalityProfile ¶
type LocalityProfile struct {
Domain int `json:"domain"`
SMs int `json:"sms,omitempty"`
SMIDs []uint32 `json:"sm_ids,omitempty"`
L2Bytes uint64 `json:"l2_bytes,omitempty"`
HBMReadGBps float64 `json:"hbm_read_gbps,omitempty"`
HBMWriteGBps float64 `json:"hbm_write_gbps,omitempty"`
L2 LocalityLatency `json:"l2"`
HBM LocalityLatency `json:"hbm"`
}
LocalityProfile holds measurements for a single allocation domain. Empty and zero measurement fields are unmeasured. Domain is an ordinal; zero is the first domain.
type LocalityProfileSet ¶
type LocalityProfileSet struct {
Conditions Conditions `json:"conditions"`
Domains []LocalityProfile `json:"domains"`
}
LocalityProfileSet contains the domain measurements taken in one probe run.
type Memory ¶
type Memory struct {
TotalBytes uint64 `json:"total_bytes"`
Instrument string `json:"instrument"` // such as "cuDeviceTotalMem"
// FreeBytes is what cuMemGetInfo reported free before anything was
// allocated. It is a condition of the measurement, not a device fact.
FreeBytes *uint64 `json:"free_bytes,omitempty"`
}
Memory is the device's memory as the driver reports it. On a device that shares memory with the host it is the memory the driver will let CUDA use, not the size of a separate pool.
type Outcome ¶
type Outcome int
Outcome is what the assembler did with a fixture.
const ( // Accepted means ptxas assembled the fixture for the target. Accepted Outcome = iota // Rejected means ptxas refused the fixture and said the construct is not // supported for the target. This is the only negative that is a fact // about the target. Rejected // Crashed means ptxas died on a signal. A crash says something about the // assembler and nothing about the target. Crashed // Inconclusive means ptxas failed for some other reason -- a malformed // fixture, a PTX version too old for the target, a missing file. It is // not evidence either way. Inconclusive )
type Probe ¶
type Probe struct {
Device string `json:"device"`
ComputeCapability string `json:"computeCapability"`
DriverVersion string `json:"driverVersion"`
Host string `json:"host"`
ProbedAt string `json:"probedAt"`
Tool string `json:"tool"`
}
Probe identifies the device a record was read from. Without it a probed value is unreproducible, which makes it indistinguishable from a datasheet figure that merely claims to be a measurement.
type Profile ¶
type Profile struct {
// LocalityDomains holds product-specific probe measurements; nil means unmeasured.
LocalityDomains *LocalityProfileSet `json:"locality_domains,omitempty"`
Target string // PTX target the generator emits for, such as "sm_103a"
Product string // product the per-product values describe, such as "GB300"
SMs Value // streaming multiprocessors
ThreadsPerSM Value // resident threads per SM
BlocksPerSM Value // resident blocks per SM
TMEMPerSM Value // bytes of Tensor Memory per SM; 0 without tcgen05
ClusterSize Value // largest portable thread block cluster
ClusterSizeOptin Value // largest cluster with cudaFuncAttributeNonPortableClusterSizeAllowed
MemoryGBps Value // device memory bandwidth, the cited peak, 10⁹ bytes per second
MemoryReadGBps Value // device memory streaming-read rate a kernel achieved, 10⁹ bytes per second; never the peak
NVLinkGBps Value // GPU-to-GPU NVLink bandwidth per GPU, both directions; 0 without NVLink
NVLinkGen Value // NVLink generation; 0 without NVLink
L2Bytes Value // bytes of L2 cache
MemoryBytes Value // bytes of device memory, as the driver reports its total
// ColdCodeL2Ns and ColdCodeMemoryNs are what a launch adds, in
// nanoseconds, when its code is not in the SM and must be fetched from
// L2 or from device memory. The cost is per launch, not per byte of
// code, and it is not an instruction-cache limit.
ColdCodeL2Ns Value
ColdCodeMemoryNs Value
HostToDeviceGBps Value // host-to-device copy rate from the GPU's own NUMA node, 10⁹ bytes per second
HostToDeviceRemoteGBps Value // host-to-device copy rate from another NUMA node, 10⁹ bytes per second
PeerGBps Value // GPU-to-GPU copy rate, 10⁹ bytes per second
}
A Profile is what a code generator needs to know about the GPU it emits for: the PTX target, the resource limits that decide tile shapes and grid sizes, and the bandwidths a cost model divides by.
Every number is a Value and keeps its provenance. A profile for a probed device carries the probed values (see LookupProfile); every other value is a datasheet figure, Unverified, whose Note cites where it came from, or Unknown where no source states it. Check Value.Known before using a value of a profile no device has probed. A generator that must not act on a datasheet figure can check Source, and one that plans offline for hardware it cannot attach can still plan.
A value someone outside this repository reported is Reported, and its Note cites the report. It is used like a datasheet figure; a result priced from it should carry its Source and Note.
func LookupDevice ¶
LookupDevice returns the profile of a device of compute capability major.minor that reports its name as name, such as "NVIDIA L4": the profile of the product name names (LookupProfile), or else of the one product of the device's target (TargetName) every word of whose name is a word of name, as "A100 SXM4 40GB" is of "NVIDIA A100-SXM4-40GB". A few devices report a name that does not spell their product, such as the H100 SXM's "NVIDIA H100 80GB HBM3"; LookupDevice knows those.
A device whose name names no one listed product, or an empty name, gets its target's first profile only when the target's products agree in memory and NVLink bandwidth, the values a device does not report and a cost model divides by; otherwise LookupDevice returns an error rather than another product's numbers. So "NVIDIA H100" is an error, since the SXM, PCIe and NVL parts differ, and an sm_89 device not named L4, L40S or RTX 4090, such as the L40, is an error.
That fallback returns the first product's SM count along with the shared bandwidth, under the first product's name: an unnamed sm_100a device is answered as a B200. A caller that will divide by the SM count must check that Profile.Product names its device, or supply a record of the device (see Register), which LookupDevice then returns for its name. A supplied product takes part in the agreement test like a listed one. A compute capability with no profile at all is an error wrapping ErrUnknownDevice.
Example ¶
package main
import (
"fmt"
"github.com/tmc/lib/nvidia/x/isa/devicetable"
)
func main() {
for _, name := range []string{"NVIDIA L4", "NVIDIA L40S", ""} {
p, err := devicetable.LookupDevice(name, 8, 9)
if err != nil {
fmt.Println(err)
continue
}
fmt.Println(p.Product, p.MemoryGBps.Value)
}
}
Output: L4 300 L40S 864 cudadevicetable: device "" is not one sm_89 product, and they differ in bandwidth: name one of L40S, L4, RTX 4090
func LookupDeviceName ¶
LookupDeviceName returns the profile of the device that reports its name as name when the name alone says which listed product it is: the one product of any target every word of whose name is a word of name, matched as by LookupDevice, or the product a name such as the H100 SXM's "NVIDIA H100 80GB HBM3" stands for.
A name that names no listed product or more than one is an error. So is "NVIDIA H100", which names none of the H100 SXM, PCIe and NVL parts, and so is a PTX target such as "sm_90a", which names an instruction set and not a product. Where the device's compute capability is known, use LookupDevice.
Example ¶
package main
import (
"fmt"
"github.com/tmc/lib/nvidia/x/isa/devicetable"
)
func main() {
for _, name := range []string{"NVIDIA H100 80GB HBM3", "NVIDIA A100-SXM4-40GB", "NVIDIA H100"} {
p, err := devicetable.LookupDeviceName(name)
if err != nil {
fmt.Println(err)
continue
}
fmt.Println(p.Product, p.SMs.Value)
}
}
Output: H100 SXM 132 A100 SXM4 40GB 108 cudadevicetable: device "NVIDIA H100" names no listed product: unknown device
func LookupProfile ¶
LookupProfile returns the profile named by name: a product such as "GB300" or "NVIDIA GB10", in any case, or a PTX target such as "sm_103a". Where the table holds a probe of that product (see Lookup), the probed values replace the datasheet ones.
A target's profile is its products': a value on which they disagree, such as the SM count of sm_90a's H100 and H200, is Unknown, and Product is empty unless the target has one product. Look a product up by name, or with LookupDevice, for its own values.
A supplied record (see Register) replaces the values it measured in the profile of the product it names, and a record of a product the table does not list adds that product, to its target as well. A name neither the table nor a record knows is an error wrapping ErrUnknownDevice.
A product name must be the product's whole name: "GB300" is not the GB300 Max-Q, and "GB300 Max-Q" is not the GB300.
Example ¶
package main
import (
"fmt"
"github.com/tmc/lib/nvidia/x/isa/devicetable"
)
func main() {
p, err := devicetable.LookupProfile("sm_103a")
if err != nil {
panic(err)
}
tcgen05, _ := p.Supports("tcgen05")
fmt.Printf("%q %d %s\n", p.Product, p.SMs.Value, p.SMs.Source)
fmt.Println(p.SharedPerBlockOptin.Value, tcgen05)
}
Output: "" 0 unknown 232448 true
func TargetProfiles ¶
TargetProfiles returns the profile of every listed product for target, in table order, then of each product a supplied record adds. The products of one target can differ in SM count and bandwidth but not in instruction set or per-SM limits.
func (Profile) Supports ¶
Supports reports whether ptxas accepts the named feature for p.Target, as recorded by the feature probe (see Target.Supports). It is an error for a target or feature that was never probed.
type ReadPoint ¶
type ReadPoint struct {
SMs int `json:"sms"`
BytesInFlightPerSM int `json:"bytes_in_flight_per_sm"`
Runs int `json:"runs"`
MedianGBps float64 `json:"median_gbps"`
MinGBps float64 `json:"min_gbps"`
MaxGBps float64 `json:"max_gbps"`
}
A ReadPoint is the rate of one launch geometry over Runs timed launches.
type Resolver ¶
type Resolver struct {
// contains filtered or unexported fields
}
A Resolver answers feature questions for targets the checked-in table does not cover, by assembling the embedded fixtures with a real ptxas.
This is what keeps the table from being an allowlist. devices.json is a fast offline path holding what was measured before release; a Resolver measures the rest on demand, so a GPU that ships after this code does gets real answers rather than the defaults of its nearest recorded ancestor. The answers it produces carry the same provenance as the checked-in ones, and are cached per target for the life of the Resolver -- probing is a process launch per fixture, which is cheap once and wasteful in a loop.
The zero Resolver is not usable; see NewResolver.
func NewResolver ¶
NewResolver returns a Resolver using the ptxas at path. host is recorded in the probe stamp of anything it measures.
func (*Resolver) Ask ¶
Ask returns the table's answer when it has one, and otherwise probes. A probe that fails for any reason -- no assembler, a crash, a PTX version too old for the target -- returns an unmeasured Answer, never a negative one.
func (*Resolver) Resolve ¶
Resolve probes every embedded fixture for one target and returns the record, caching it. The record is subject to the same provenance rules as a checked-in one -- including the positive control, which is why Resolve probes the whole fixture set rather than the one feature asked about. Those rules are applied to the checked-in table with the new record merged in, because the control they contain is a property of a corpus and not of a single target.
type Result ¶
type Result struct {
Feature string
Target string
Outcome Outcome
Diagnostic string
Command string
}
Result is one fixture assembled for one target.
func ProbeFeature ¶
ProbeFeature assembles one fixture for one target with the ptxas at ptxasPath and classifies the result.
ptxas signals failure with exit status 255, not 1, and dies with a signal on some malformed input. Reading any non-zero status as "unsupported" turns both of those into confident negatives, which is how a broken fixture becomes a row of hardware facts.
type Source ¶
type Source string
Source records how a Value was obtained. The zero value is invalid: a value with no stated source is exactly the thing this package exists to make impossible.
const ( // Probed means the value was read from a live device through the driver // attribute named in Value.Attribute. Probed Source = "probed" // Derived means the value was computed from probed values in the same // record. Value.Note states the arithmetic. Derived Source = "derived" // Unverified means the value was hand-entered and no device has // confirmed it. It may still be correct; nothing here says it is. Unverified Source = "unverified" // Unknown means no source states the value. Value is 0, which is not // a reading: Note says what is missing. Only a [Profile] holds unknown // values: a target's, where its products differ, and that of a product // only a supplied record describes (see [Facts.Profile]). Unknown Source = "unknown" // Reported means someone outside this repository measured the value, // or read it from a driver, and reported it, and no row of it is held // here: nothing in this module can reproduce it or check how it was // taken. Note must say who reported it and when. A reported value is // used like any other; a result priced from one should carry its // Source and Note, so a reader can see it rests on an outside report. Reported Source = "reported" )
type Statement ¶
type Statement struct {
Source string // the key in this package's source list, e.g. "[vr]"
Published string // the source's publication date, or "undated"
Fetched string // the date it was read
Figure float64 // in the field's unit
Quote string // the source's words
}
A Statement is one source's figure for a datasheet field, quoted.
func Statements ¶
Statements returns every source's figure for product's field when the sources disagree, the recorded one first, or nil when they agree or only one source states it.
type StreamRead ¶
type StreamRead struct {
Method string `json:"method"` // kernel, buffer, timing and statistic
Residency string `json:"residency"` // where the bytes were: "device" for a device allocation
BufferBytes uint64 `json:"buffer_bytes"` // bytes read per timed launch
GBps float64 `json:"gbps"`
Sweep []ReadPoint `json:"sweep"`
}
StreamRead is a measured streaming-read rate: the bytes per second a kernel sustains reading a buffer far larger than any cache once, in order, with nothing else to do. A rate is in GB/s, 10⁹ bytes per second.
GBps is not an input. It is the highest median among the Sweep points that ran on every SM, and Facts.Validate refuses anything else.
type Table ¶
type Table struct {
Schema int `json:"schema"`
Architectures map[string]Architecture `json:"architectures"`
// Targets holds instruction-set facts, keyed by exact PTX target. It is
// separate from Architectures because the two answer different
// questions: Architectures describes silicon, Targets describes what an
// assembler accepts for it. See [Feature].
Targets map[string]Target `json:"targets,omitempty"`
}
Table is the full set of architectures with recorded facts.
type Target ¶
type Target struct {
Target string `json:"target"`
// Probe is nil when no feature in Features is [Probed].
Probe *FeatureProbe `json:"probe,omitempty"`
Features map[string]Feature `json:"features"`
}
Target is the set of feature facts for one exact PTX target.
func LookupTarget ¶
LookupTarget returns the feature record for an exact target such as "sm_90a". Unlike Lookup it does not drop the feature suffix, and it does not fall back to the base target: sm_121a's answers are not sm_121's.
func (Target) Diagnostic ¶
Diagnostic returns the assembler's recorded rejection message for a feature, or "" when the feature is supported or was never probed.
func (Target) Supports ¶
Supports reports whether the target accepts the named feature. It returns an error rather than false when the fact was never probed, so that an absent measurement cannot be read as a negative one. "No instrument has looked" and "the instrument said no" are different answers, and a bool cannot hold both.
type Value ¶
type Value struct {
Value int64 `json:"value"`
Source Source `json:"source"`
// Instrument names what the value was read through: a driver attribute
// ("DevAttrMaxSharedMemoryPerMultiprocessor"), a CUDA runtime device
// property ("cudaDeviceProp.l2CacheSize"), or one of the driver
// functions that report or time a value: cuDeviceTotalMem,
// cuOccupancyMaxPotentialClusterSize, cuMemcpyHtoDAsync and
// cuMemcpyPeerAsync. Required when Source is [Probed], empty otherwise.
//
// Not every hardware fact has a driver attribute behind it -- the
// largest cluster a kernel may launch with is answered by an occupancy
// query, and a copy rate by timing copies -- and a value may have been
// read through another instrument before a driver attribute for it was
// probed, as the built-in GB10 L2 size was, so requiring a driver
// attribute specifically would force a real measurement to be recorded
// as unverified. The requirement is that the instrument be named and
// recognizable, not that it be of one kind.
Instrument string `json:"instrument,omitempty"`
// Note explains a derivation or records why a value could not be
// probed. Required when Source is [Derived], [Unverified] or
// [Reported].
Note string `json:"note,omitempty"`
}
Value is one device fact together with how it was obtained.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package instrument says, for each hardware value the planners in this module read, what measures it on the device it describes.
|
Package instrument says, for each hardware value the planners in this module read, what measures it on the device it describes. |