cert

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 4, 2026 License: Apache-2.0 Imports: 11 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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.

func Bind

func Bind(covered, evidence []byte, l Label) Binding

Bind returns the binding of a property of covered established by evidence, which may be nil.

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

func NewKernel(cubin []byte, dis *sass.Disassembly, name string) (Kernel, error)

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.

func (Kernel) Check

func (k Kernel) Check() error

Check refuses k if a clause of its contract was not derived from the SASS, or if it has a wait loop that is unbounded or that the analysis could not classify.

type Label

type Label string

A Label says how a property was established.

const (
	Proved  Label = "PROVED"  // a kernel-checked theorem with an audited trust base
	Modeled Label = "MODELED" // a theorem about a model whose tie to the code is tested
	Tested  Label = "TESTED"  // checked by tests only
	NotRun  Label = "NOT_RUN" // not established
)

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

func Decode(r io.Reader) (*Manifest, error)

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

func Load(r io.Reader, want string) (*Manifest, error)

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

func (m *Manifest) Check(img Image) error

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

func (m *Manifest) Clause() kernel.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.

func (*Manifest) Encode

func (m *Manifest) Encode(w io.Writer) error

Encode writes m in its canonical form: the form ID hashes.

func (*Manifest) ID

func (m *Manifest) ID() (string, error)

ID returns the SHA-256 of m's canonical encoding, in hex.

func (*Manifest) Sort

func (m *Manifest) Sort()

Sort orders m's kernels and data modules as its encoding requires.

type Module

type Module struct {
	Cubin   []byte
	Kernels []string
}

A Module is one cubin and the kernels the server launches from it.

type Param

type Param struct {
	Ordinal int  `json:"ordinal"`
	Align   int  `json:"align"` // what a launch must give
	Read    bool `json:"read,omitempty"`
	Write   bool `json:"write,omitempty"`
}

A Param is the contract of one pointer parameter.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL