Documentation
¶
Overview ¶
Package cert records what has been checked about a serving image and checks the record against what is loaded.
A serving image is the model, the kernels, the settings and the step plan. A Manifest holds one entry per kernel the image launches, read from the cubin that runs it: the effect contract cudasass derives from its SASS and the census of its device-side wait loops. It also binds the model configuration, the settings and any receipts, such as a parity receipt or a peak-memory bound, each by the SHA-256 of what it covers and of the evidence that established it. The manifest is identified by the SHA-256 of its encoding. That binds content; it is not a signature.
Manifest.Check recomputes every covered hash from what is being loaded and refuses an image whose kernels, model or settings differ from the record, a kernel whose contract is not fully derived, and a kernel with a wait loop that is unbounded or unclassified. Manifest.Clause is the same check as a kernel.Clause, for the load and swap admission points: a module image is admitted only if its cubin is in the manifest, with an entry for each of its functions or, if it holds no code, as a data module.
Every property carries a label saying how it was established: PROVED for a kernel-checked theorem with an audited trust base, MODELED for a theorem about a model whose tie to the code is tested, TESTED for a property checked only by tests, and NOT_RUN for one not established. Check never upgrades a label.
This package is outside the compatibility promise of github.com/tmc/lib/nvidia.
Example ¶
cubin, dis := fixture(nil)
k, err := cert.NewKernel(cubin, dis, "fill")
if err != nil {
log.Fatal(err)
}
m := &cert.Manifest{
Version: cert.Version,
Model: cert.Bind([]byte(`{"hidden_size":2048}`), nil, cert.Tested),
Settings: cert.Bind([]byte(`{}`), nil, cert.Tested),
Kernels: []cert.Kernel{k},
}
img := cert.Image{
Model: []byte(`{"hidden_size":2048}`),
Settings: []byte(`{}`),
Modules: []cert.Module{{Cubin: cubin, Kernels: []string{"fill"}}},
}
fmt.Println("certified:", m.Check(img) == nil)
img.Model = []byte(`{"hidden_size":4096}`)
var r *admit.Refusal
fmt.Println("other model refused:", errors.As(m.Check(img), &r))
Output: certified: true other model refused: true
Index ¶
Examples ¶
Constants ¶
const Version = 1
Version is the manifest encoding this package reads and writes.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Binding ¶
type Binding struct {
Covers string `json:"covers"`
Evidence string `json:"evidence,omitempty"`
Label Label `json:"label"`
}
A Binding ties a property to the SHA-256 of what it covers and of the evidence that established it, both in lowercase hex.
type Image ¶
type Image struct {
Model []byte // the model configuration, such as config.json
Settings []byte // the serving settings, in the encoding the manifest bound
Modules []Module
}
An Image is what a server is about to load.
type Kernel ¶
type Kernel struct {
Cubin string `json:"cubin"` // SHA-256 of the cubin, hex
Name string `json:"name"`
Target string `json:"target"`
// Clauses maps each contract clause (sass.Clause.String) to ""
// when it was derived from the SASS, or to why it was not.
Clauses map[string]string `json:"clauses"`
Params []Param `json:"params,omitempty"`
// Waits counts the kernel's device-side waits by class
// (sass.WaitClass.String).
Waits map[string]int `json:"waits,omitempty"`
Label Label `json:"label"`
}
A Kernel is what was read from the SASS of one kernel in one cubin.
func NewKernel ¶
NewKernel reads the entry for kernel name from cubin and its disassembly dis. Extraction is tested against mutants, not proved, so the entry is labelled TESTED.
func NewModule ¶
func NewModule(cubin []byte, dis *sass.Disassembly) ([]Kernel, error)
NewModule reads an entry for every function in dis, the disassembly of cubin. A function whose entry cannot be read, such as one that is not a kernel, gets an entry with no derived clause and label NOT_RUN, so a certificate holding it refuses the module rather than leaving the function out.
type Manifest ¶
type Manifest struct {
Version int `json:"version"`
Model Binding `json:"model"` // the model configuration
Settings Binding `json:"settings"` // the serving settings
Receipts map[string]Binding `json:"receipts,omitempty"` // such as "parity" or "memory"
Kernels []Kernel `json:"kernels"` // ordered by cubin, then name
// Data lists, by the SHA-256 of the cubin and in order, the modules
// that hold no code, such as one that only initializes device globals.
Data []string `json:"data,omitempty"`
}
A Manifest records what has been checked about a serving image.
func Decode ¶
Decode reads a manifest and validates it. Unknown fields, another version, a malformed hash, an unknown label, or kernels or data modules out of order are errors.
func Load ¶
Load reads a manifest and refuses it unless its ID is want: a manifest whose fields were edited after it was pinned is not the one pinned.
func (*Manifest) Check ¶
Check refuses img unless m covers it: the model and settings hash to what m bound, every launched kernel has an entry for its cubin's hash, every such entry records the target read from the cubin, suffix included, and passes Kernel.Check. It recomputes every hash and target from img rather than trusting a recorded one. Each violation is a *kernel.Refusal of kind "certificate"; Check joins them all.
func (*Manifest) Clause ¶
Clause returns m's check as an admission clause of kind "certificate". It refuses a subject whose native image (Subject.Native) is not in m. A subject that names a kernel is refused if that kernel has no entry for the image or its entry fails Kernel.Check; one that names none, a whole module, is refused if any entry for the image fails it, and admitted if the image is one of m's data modules. An entry passes only if it records the image's target, suffix included, as Manifest.Check requires. At the load point a subject with no native image cannot be decided. A subject at another point with no native image is admitted: cudahotswap's swap and bind subjects carry launch arguments, which the kernel's contract clauses check, and a swap candidate's module has already been admitted at load.