errbound

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 errbound checks kernel outputs against error bounds derived from a reference computation graph at a declared precision.

A fixed allclose tolerance is too strict for some outputs and too loose for others. errbound instead asks, for one input, whether any honest kernel could have produced the output: it evaluates the reference Graph in FP64 and propagates, element by element, the worst-case error of a kernel that computes the same function at the declared Precision in any evaluation order. An output outside that bound is rejected; no honest kernel could have produced it.

An honest kernel may:

  • reassociate sums, differences, reductions and dot products in any order or tree shape, including blocked, pairwise, sorted and compensated orders, and fold a bias into an accumulator;
  • contract a product into an accumulator (FMA) or not;
  • round matrix-multiply operands to the declared Operand format;
  • compute exp as exp2 of a rounded argument, rsqrt directly or as 1/sqrt, and use math functions with errors up to Precision.MathUnits;
  • shift a softmax by any value up to the row's largest magnitude, including the running maximum of an online softmax;
  • compute in any format at least as precise as declared.

Computing in a narrower format than declared is precision shedding. Coherent and Pow2 inputs make shedding errors add up with one sign, so it shows up where random inputs hide it. It is detectable only while the narrower format's unit roundoff exceeds the bound's relative size, which grows with reduction length: an FP32 matmul over an inner dimension of 16384 cannot rule out tf32 operands. Report.Unexcluded names the formats Check could not rule out.

The bounds are worst-case: an honest kernel typically lands at a few thousandths of its bound, and a defect whose error is below the bound, roughly n·u relative for a reduction of length n in a format with unit roundoff u, is accepted. errbound catches gross and structural cheats, not subtle numeric ones; Coherent inputs and probes cover part of that gap.

Because the bounds grow with reduction length, when a bound cannot tell an honest kernel from one returning zeros, or cannot be established at all, Bounds.Certify abstains rather than accepting. A bound on one input says nothing about the next, and a kernel that ignores part of its input can be within bound on inputs where that part does not matter. Check therefore certifies several inputs and adds probes: for each group of input elements (each half of every axis, the last index of every axis, one random element) it shifts the group and certifies the shifted input, which catches kernels that skip or estimate part of a reduction, and it requires outputs that do not depend on the group, by the graph's structure, to stay unchanged, which catches kernels that read inputs they must not, such as future tokens.

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"
	"math"
	"math/rand/v2"

	"github.com/tmc/lib/nvidia/x/obs/diag/errbound"
)

func main() {
	// The reference: RMS normalization of 4 rows of 256.
	g := errbound.NewGraph()
	x, w := g.Input("x", 4, 256), g.Input("w", 256)
	g.Output(x.RMSNorm(w, 1e-5))

	r := rand.New(rand.NewPCG(1, 2))
	xs := errbound.Normal(1)(r, errbound.Binary32, 4*256)
	ws := errbound.Normal(1)(r, errbound.Binary32, 256)
	b, err := g.Bound(errbound.FP32, [][]float64{xs, ws})
	if err != nil {
		panic(err)
	}

	// An honest FP32 kernel, and one that skips the reduction because
	// standard normal rows have an RMS near 1.
	honest := make([]float64, len(xs))
	skipped := make([]float64, len(xs))
	for i := range 4 {
		var ss float32
		for j := range 256 {
			v := float32(xs[i*256+j])
			ss += v * v
		}
		inv := float32(1 / math.Sqrt(float64(ss/256+1e-5)))
		for j := range 256 {
			honest[i*256+j] = float64(float32(xs[i*256+j]) * inv * float32(ws[j]))
			skipped[i*256+j] = float64(float32(xs[i*256+j]) * float32(ws[j]))
		}
	}
	for _, out := range [][]float64{honest, skipped} {
		c, err := b.Certify([][]float64{out})
		if err != nil {
			panic(err)
		}
		fmt.Println(c.Verdict)
	}
}
Output:
accept
reject

Index

Examples

Constants

View Source
const Algorithm = "errbound/v1"

Algorithm names the rules Bound uses to propagate error bounds. It changes whenever what a bound covers changes, so a receipt that records it can be checked by rebuilding the bounds with the same rules.

Variables

View Source
var (
	Binary64      = Format{Name: "fp64", Bits: 53, MinExp: -1022, MaxFinite: math.MaxFloat64}
	Binary32      = Format{Name: "fp32", Bits: 24, MinExp: -126, MaxFinite: math.MaxFloat32}
	TensorFloat32 = Format{Name: "tf32", Bits: 11, MinExp: -126, MaxFinite: 0x1.ffcp127}
	BFloat16      = Format{Name: "bf16", Bits: 8, MinExp: -126, MaxFinite: 0x1.fep127}
	Binary16      = Format{Name: "fp16", Bits: 11, MinExp: -14, MaxFinite: 65504}
	E4M3          = Format{Name: "e4m3", Bits: 4, MinExp: -6, MaxFinite: 448, NoInf: true}
	E5M2          = Format{Name: "e5m2", Bits: 3, MinExp: -14, MaxFinite: 57344}
)

Formats a precision declaration can name.

View Source
var (
	// FP32 is IEEE single precision throughout.
	FP32 = Precision{Name: "fp32", Input: Binary32, Operand: Binary32, Compute: Binary32, Accumulate: Binary32, Output: Binary32, MathUnits: 8}

	// BF16 stores inputs and outputs in bfloat16, computes and accumulates
	// in single precision, and may round matrix-multiply operands to
	// bfloat16.
	BF16 = Precision{Name: "bf16", Input: BFloat16, Operand: BFloat16, Compute: Binary32, Accumulate: Binary32, Output: BFloat16, MathUnits: 8}

	// FP16 is BF16 with IEEE half precision storage.
	FP16 = Precision{Name: "fp16", Input: Binary16, Operand: Binary16, Compute: Binary32, Accumulate: Binary32, Output: Binary16, MathUnits: 8}

	// FP8 stores inputs and matrix-multiply operands in E4M3, computes and
	// accumulates in single precision, and stores bfloat16 outputs. A
	// kernel whose tensor-core accumulator keeps fewer bits, as some FP8
	// paths do between promotions, declares a narrower Accumulate.
	FP8 = Precision{Name: "fp8", Input: E4M3, Operand: E4M3, Compute: Binary32, Accumulate: Binary32, Output: BFloat16, MathUnits: 8}
)

Declarations for common task precisions.

Functions

This section is empty.

Types

type Bounds

type Bounds struct {
	Precision Precision

	// Ref holds the reference value of every output element.
	Ref [][]float64

	// Err bounds |honest - Ref| for every output element. It includes the
	// reference's own error. An element whose bound is +Inf is
	// uncertified: the bound could not be established, for example a
	// divisor whose bound includes zero.
	Err [][]float64

	// MaxLooseness is the largest ‖Err‖₂/‖Ref‖₂ for which [Bounds.Certify]
	// accepts. Above it the bound cannot tell an honest kernel from one
	// that returns zeros, and Certify abstains. Bound sets it to 0.25.
	MaxLooseness float64
}

Bounds holds, for one input, a graph's FP64 reference outputs and a bound on how far any honest kernel's outputs can be from them.

func (*Bounds) Certify

func (b *Bounds) Certify(outputs [][]float64) (*Certificate, error)

Certify checks a kernel's outputs, in output order, against b. An element passes iff |got-ref| <= err·(1+2⁻⁴⁰); a NaN output fails. An element with a +Inf bound is uncertified, and a NaN or negative bound is an error.

Example
package main

import (
	"fmt"

	"github.com/tmc/lib/nvidia/x/obs/diag/errbound"
)

func main() {
	// (a+b)+c in FP32 with a and b large and opposite. An honest kernel
	// may add a+(b+c) instead and get 2 rather than 1.75, so the bound
	// must cover both; it is then too loose to accept anything, but a
	// result far outside it is still rejected.
	g := errbound.NewGraph()
	a, b, c := g.Input("a", 1), g.Input("b", 1), g.Input("c", 1)
	g.Output(a.Add(b).Add(c))
	bd, err := g.Bound(errbound.FP32, [][]float64{{1 << 24}, {-(1 << 24) + 1}, {0.75}})
	if err != nil {
		panic(err)
	}
	for _, got := range []float64{1.75, 2, 100} {
		cert, err := bd.Certify([][]float64{{got}})
		if err != nil {
			panic(err)
		}
		fmt.Println(got, cert.Verdict)
	}
}
Output:
1.75 abstain
2 abstain
100 reject

func (*Bounds) ErrSHA256

func (b *Bounds) ErrSHA256() string

ErrSHA256 returns the digest of the bounds, computed as for Bounds.RefSHA256.

Example
package main

import (
	"fmt"
	"log"

	"github.com/tmc/lib/nvidia/x/obs/diag/errbound"
)

func main() {
	g := errbound.NewGraph()
	g.Output(g.Input("x", 2).Exp())
	b, err := g.Bound(errbound.FP32, [][]float64{{0, 1}})
	if err != nil {
		log.Fatal(err)
	}
	// A receipt records the rules and the digests of what they produced.
	fmt.Println(errbound.Algorithm)
	fmt.Println(len(b.RefSHA256()), b.ErrSHA256() == b.ErrSHA256())
}
Output:
errbound/v1
71 true

func (*Bounds) RefSHA256

func (b *Bounds) RefSHA256() string

RefSHA256 returns the digest of the reference values, as "sha256:<hex>": SHA-256 of every output's float64 little-endian bytes, concatenated in output order.

func (*Bounds) Resolution

func (b *Bounds) Resolution() float64

Resolution returns the smallest relative bound Err/|Ref| over the elements with a finite, nonzero bound, or +Inf if there are none. A kernel whose arithmetic is off by a relative error well below the resolution cannot be told apart from an honest one at these inputs.

Example
package main

import (
	"fmt"
	"log"
	"math/rand/v2"

	"github.com/tmc/lib/nvidia/x/obs/diag/errbound"
)

func main() {
	// A dot product's bound grows with its length, and with it the
	// smallest relative error the bound can detect.
	for _, k := range []int{256, 16384} {
		g := errbound.NewGraph()
		a, b := g.Input("a", 1, k), g.Input("b", k, 1)
		g.Output(a.MatMul(b))
		r := rand.New(rand.NewPCG(1, 2))
		in := [][]float64{errbound.Coherent(1)(r, errbound.Binary32, k), errbound.Coherent(1)(r, errbound.Binary32, k)}
		bs, err := g.Bound(errbound.FP32, in)
		if err != nil {
			log.Fatal(err)
		}
		res := bs.Resolution()
		fmt.Printf("K=%d: resolution %.1e, tf32 detectable %v\n", k, res, errbound.TensorFloat32.Unit() > res)
	}
}
Output:
K=256: resolution 1.5e-05, tf32 detectable true
K=16384: resolution 9.8e-04, tf32 detectable false

type Certificate

type Certificate struct {
	Verdict Verdict
	Reason  string

	Elements   int // output elements checked
	Certified  int // elements with a finite bound
	Violations int // elements outside their bound

	// Worst is the element with the largest Ratio: the worst violation's
	// evidence for a Reject, the tightest margin for an Accept.
	Worst Element

	// Looseness is ‖Err‖₂/‖Ref‖₂ over certified elements, the bound's size
	// relative to the output.
	Looseness float64
}

A Certificate is the evidence for one input's verdict.

func (*Certificate) String

func (c *Certificate) String() string

type Element

type Element struct {
	Output int     // output number
	Index  int     // row-major element index
	Got    float64 // kernel output
	Ref    float64 // FP64 reference
	Bound  float64 // honest error bound
}

An Element locates one output element and its check.

func (Element) Ratio

func (e Element) Ratio() float64

Ratio returns |Got-Ref|/Bound, at most 1 for an element within its bound.

func (Element) String

func (e Element) String() string

type Fill

type Fill func(r *rand.Rand, f Format, n int) []float64

A Fill generates n input values representable in f.

func Coherent

func Coherent(scale float64) Fill

Coherent fills with values in [scale, 2·scale), for scale a power of two, whose low significand bits make rounding to any narrower format (TF32, FP16, BF16, E4M3) round down. A kernel that sheds precision on these inputs makes errors of one sign that add up coherently in sums, while an honest kernel's bound does not grow with them, so shedding that random inputs hide shows up.

Example
package main

import (
	"fmt"
	"math/rand/v2"

	"github.com/tmc/lib/nvidia/x/obs/diag/errbound"
)

func main() {
	r := rand.New(rand.NewPCG(1, 2))
	x := errbound.Coherent(1)(r, errbound.Binary32, 1)[0]
	// Rounding to every narrower format rounds down.
	for _, f := range []errbound.Format{errbound.TensorFloat32, errbound.Binary16, errbound.BFloat16, errbound.E4M3} {
		fmt.Println(f.Name, f.Round(x) < x)
	}
}
Output:
tf32 true
fp16 true
bf16 true
e4m3 true

func Normal

func Normal(scale float64) Fill

Normal fills with normal values of standard deviation scale.

Example
package main

import (
	"fmt"
	"math/rand/v2"

	"github.com/tmc/lib/nvidia/x/obs/diag/errbound"
)

func main() {
	r := rand.New(rand.NewPCG(1, 2))
	xs := errbound.Normal(1)(r, errbound.BFloat16, 4)
	for _, x := range xs {
		fmt.Println(x == errbound.BFloat16.Round(x))
	}
}
Output:
true
true
true
true

func Pow2

func Pow2(lo, hi int) Fill

Pow2 fills with powers of two 2^k, k uniform in [lo, hi]. Products with powers of two are exact, so Pow2 beside a Coherent input keeps the coherent rounding direction through multiplications.

Example
package main

import (
	"fmt"
	"math/rand/v2"

	"github.com/tmc/lib/nvidia/x/obs/diag/errbound"
)

func main() {
	r := rand.New(rand.NewPCG(1, 2))
	fmt.Println(errbound.Pow2(-2, 2)(r, errbound.Binary32, 6))
}
Output:
[2 2 2 2 0.5 0.25]

func Uniform

func Uniform(lo, hi float64) Fill

Uniform fills with values uniform in [lo, hi).

Example
package main

import (
	"fmt"
	"math/rand/v2"

	"github.com/tmc/lib/nvidia/x/obs/diag/errbound"
)

func main() {
	r := rand.New(rand.NewPCG(1, 2))
	for _, x := range errbound.Uniform(0, 1)(r, errbound.Binary32, 3) {
		fmt.Println(0 <= x && x < 1)
	}
}
Output:
true
true
true

type Format

type Format struct {
	Name string

	// Bits is the significand precision, including the implicit leading
	// bit: 24 for IEEE binary32.
	Bits int

	// MinExp is the exponent of the smallest positive normal value:
	// -126 for binary32.
	MinExp int

	// MaxFinite is the largest finite magnitude.
	MaxFinite float64

	// NoInf reports that the format has no infinities, so a value that
	// overflows becomes NaN (E4M3).
	NoInf bool
}

A Format is a binary floating-point format with round-to-nearest-even rounding.

func (Format) Eta

func (f Format) Eta(ftz bool) float64

Eta returns the largest absolute error of rounding a value in the subnormal range to nearest, half the subnormal spacing. With flush to zero the error is up to the smallest normal value instead.

func (Format) Representable

func (f Format) Representable(x float64) bool

Representable reports whether x is a finite value of f.

func (Format) Round

func (f Format) Round(x float64) float64

Round rounds x to the nearest value of f, ties to even. A finite result beyond MaxFinite becomes an infinity, or NaN when the format has none. Round requires f.Bits <= 53.

Example
package main

import (
	"fmt"

	"github.com/tmc/lib/nvidia/x/obs/diag/errbound"
)

func main() {
	fmt.Println(errbound.BFloat16.Round(1+1.0/256), errbound.BFloat16.Round(1+3.0/256))
	fmt.Println(errbound.E4M3.Round(500), errbound.Binary16.Round(70000))
}
Output:
1 1.015625
NaN +Inf

func (Format) Unit

func (f Format) Unit() float64

Unit returns the unit roundoff 2^-Bits, the largest relative error of rounding a normal value to nearest.

type Graph

type Graph struct {
	// contains filtered or unexported fields
}

A Graph is a reference computation: the slow, obviously correct form of the function a kernel implements. The checker evaluates it in FP64 and derives error bounds and input-output dependencies from it.

Elementwise operations broadcast as NumPy does. Reductions keep the reduced axis with size 1, so their results broadcast back against their operand. A Graph records the first construction error, which Graph.Err and every later evaluation report.

func NewGraph

func NewGraph() *Graph

NewGraph returns an empty graph.

Example
package main

import (
	"fmt"
	"log"

	"github.com/tmc/lib/nvidia/x/obs/diag/errbound"
)

func main() {
	// y = softmax(W·x + b) over the 4 rows of W.
	g := errbound.NewGraph()
	w, x, b := g.Input("w", 4, 3), g.Input("x", 3, 1), g.Input("b", 4, 1)
	g.Output(w.MatMul(x).Add(b).Softmax(0))
	bs, err := g.Bound(errbound.FP32, [][]float64{
		{1, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 1},
		{1, 2, 3},
		{0, 0, 0, 0},
	})
	if err != nil {
		log.Fatal(err)
	}
	for i, v := range bs.Ref[0] {
		fmt.Printf("%.4f ± %.1e\n", v, bs.Err[0][i])
	}
}
Output:
0.0063 ± 3.0e-08
0.0170 ± 8.3e-08
0.0463 ± 2.3e-07
0.9304 ± 5.0e-06

func (*Graph) Bound

func (g *Graph) Bound(p Precision, inputs [][]float64) (*Bounds, error)

Bound evaluates g on inputs, given in input order and representable in p.Input, and bounds the error of an honest kernel at precision p.

func (*Graph) Const

func (g *Graph) Const(c float64) *Value

Const adds a scalar constant. An honest kernel uses the constant rounded to the Compute format.

func (*Graph) Err

func (g *Graph) Err() error

Err returns the first error recorded while building g.

func (*Graph) Input

func (g *Graph) Input(name string, shape ...int) *Value

Input adds a named input tensor of the given shape. Inputs are passed to kernels in the order they are added.

func (*Graph) Inputs

func (g *Graph) Inputs() []*Value

Inputs returns g's inputs in kernel argument order.

func (*Graph) Output

func (g *Graph) Output(vs ...*Value)

Output marks vs as the graph's outputs, in the order kernels produce them.

func (*Graph) Outputs

func (g *Graph) Outputs() []*Value

Outputs returns g's outputs in kernel result order.

type InputResult

type InputResult struct {
	Name string // "normal-0", "coherent", ...
	*Certificate
}

An InputResult is the certificate for one input.

type Kernel

type Kernel func(ctx context.Context, in, out [][]float64) error

A Kernel computes a graph's outputs. in holds one slice per graph input and out one slice per graph output, in graph order. Check fills out with NaN before every call, so a kernel that leaves an element unwritten, or returns a previous call's result, is caught.

type Options

type Options struct {
	// Seed seeds input generation.
	Seed uint64

	// Inputs is the number of ordinary inputs to certify; 0 means 2.
	Inputs int

	// NoCoherent skips the Coherent and Pow2 inputs that expose precision
	// shedding, for tasks whose inputs must keep a structure such as a
	// mask.
	NoCoherent bool

	// NoProbes skips the dependency probes.
	NoProbes bool
}

Options controls Check. The zero value is usable.

type Precision

type Precision struct {
	Name string

	Input      Format
	Operand    Format
	Compute    Format
	Accumulate Format
	Output     Format

	// MathUnits bounds the relative error of exp, log, sqrt, rsqrt and
	// division, in units of Compute's unit roundoff. The default 8 covers
	// the CUDA single-precision functions (at most 2 ulp for expf, exp2f
	// and rsqrtf) and the fast-math forms __expf and __fdividef; exp's
	// argument-reduction error, which grows with |x|, is bounded
	// separately.
	MathUnits float64

	// FTZ allows subnormal results to flush to zero.
	FTZ bool
}

A Precision declares what an honest kernel for a task may do. An honest kernel computes the reference function in any evaluation order, with each operation rounded to nearest in a format at least as precise as the one declared for it:

  • Input is the format the task's inputs are stored in. The checker generates inputs representable in it.
  • Operand is the format matrix-multiply operands may be rounded to before they are multiplied, as tensor-core kernels do with intermediates such as attention probabilities.
  • Compute is the format of elementwise arithmetic, math functions and intermediate values.
  • Accumulate is the format of sums, dot products and matrix-multiply accumulators.
  • Output is the format results are stored in.

Computing in a less precise format than declared is precision shedding, and the checker rejects it where the bound can tell.

type ProbeResult

type ProbeResult struct {
	Group string

	// Dependent counts output elements that depend on the group, and
	// Moved those whose reference moved by more than the sum of their
	// bounds at the two inputs: outputs no honest kernel could leave
	// unchanged.
	Dependent, Moved int

	// Leaked counts output elements that do not depend on the group but
	// changed anyway: by more than the sum of their bounds at the two
	// inputs, or at all if the task is Deterministic.
	Leaked int
	Leak   Element // first leaked element; Got is the probe output, Ref the base output

	*Certificate // the certificate at the shifted input
}

A ProbeResult describes one probe: the base input with one group of input elements shifted.

func (*ProbeResult) Verdict

func (p *ProbeResult) Verdict() Verdict

Verdict returns the probe's verdict: Reject if the kernel's output at the shifted input is outside its bound or leaked, else the certificate's.

type Report

type Report struct {
	Task    string
	Verdict Verdict
	Reason  string

	Inputs []InputResult
	Probes []ProbeResult

	// Resolution is the smallest [Bounds.Resolution] over the inputs.
	// Unexcluded names the formats narrower than the declared precision
	// whose unit roundoff is at most Resolution: a kernel that rounds to
	// one of them where the declaration says it must not may be
	// accepted. Matmul reductions over long inner dimensions reach this
	// for tf32 operands, as the bound grows with the dimension.
	Resolution float64
	Unexcluded []string
}

A Report is the outcome of Check.

func Check

func Check(ctx context.Context, t Task, k Kernel, opts *Options) (*Report, error)

Check certifies kernel k on t: on ordinary inputs, on inputs that expose precision shedding, and on probes that shift one group of input elements at a time and require the outputs that depend on the group, and only those, to respond. It returns Reject if any certificate rejects or any probe leaks, Abstain if none does but some certificate abstains, and Accept otherwise.

Example
package main

import (
	"context"
	"fmt"
	"math"

	"github.com/tmc/lib/nvidia/x/obs/diag/errbound"
)

func main() {
	// x / ‖x‖_F over a 512×512 tensor of uniform [0,1) values.
	g := errbound.NewGraph()
	x := g.Input("x", 512, 512)
	g.Output(x.Div(x.Mul(x).Sum(1).Sum(0).Sqrt()))
	task := errbound.Task{Name: "frobenius", Graph: g, Precision: errbound.FP32, Fills: []errbound.Fill{errbound.Uniform(0, 1)}}

	// A lemon that skips the reduction: E[x²] = 1/3, so ‖x‖ ≈ √(N/3).
	constNorm := func(_ context.Context, in, out [][]float64) error {
		norm := math.Sqrt(float64(len(in[0])) / 3)
		for i, v := range in[0] {
			out[0][i] = float64(float32(v / norm))
		}
		return nil
	}
	rep, err := errbound.Check(context.Background(), task, constNorm, &errbound.Options{NoCoherent: true})
	if err != nil {
		panic(err)
	}
	for _, in := range rep.Inputs {
		fmt.Println(in.Name, in.Verdict)
	}
	fmt.Println(rep.Verdict, "by probe:", rep.Probes[0].Verdict() == errbound.Reject)
}
Output:
normal-0 accept
normal-1 accept
reject by probe: true

func (*Report) String

func (r *Report) String() string

type Task

type Task struct {
	Name      string
	Graph     *Graph
	Precision Precision

	// Fills holds one Fill per graph input for ordinary inputs. A missing
	// or nil Fill means Normal(1).
	Fills []Fill

	// Formats holds the storage format of each graph input, for a kernel
	// whose inputs differ, such as bfloat16 weights beside FP32
	// activations. Every input Check generates, ordinary, coherent or
	// shifted by a probe, is representable in its input's format. A
	// missing or zero Format means Precision.Input.
	Formats []Format

	// Deterministic declares that the kernel returns bit-identical
	// outputs for identical inputs. A probe then requires outputs that do
	// not depend on the shifted group to stay exactly unchanged, which
	// catches a kernel that reads inputs it should not even when the
	// result stays within bound. Otherwise they may move within their
	// bounds, as an honest kernel using atomics or split-K reductions
	// may. Declaring a nondeterministic kernel deterministic can reject
	// it.
	Deterministic bool
}

A Task is a reference graph, the precision honest kernels use, and how to fill its inputs.

type Value

type Value struct {
	// contains filtered or unexported fields
}

A Value is a tensor in a Graph.

func (*Value) Add

func (a *Value) Add(b *Value) *Value

Add returns a + b.

func (*Value) Div

func (a *Value) Div(b *Value) *Value

Div returns a / b.

func (*Value) Exp

func (a *Value) Exp() *Value

Exp returns e^a.

func (*Value) Log

func (a *Value) Log() *Value

Log returns the natural logarithm of a.

func (*Value) MatMul

func (a *Value) MatMul(b *Value) *Value

MatMul returns the matrix product of a [M,K] and b [K,N]. An honest kernel may round operands to the Operand format and accumulate the K products in any order.

func (*Value) Max

func (a *Value) Max(axis int) *Value

Max returns the maximum of a along axis, keeping the axis with size 1.

func (*Value) Mean

func (a *Value) Mean(axis int) *Value

Mean returns the mean of a along axis, keeping the axis with size 1.

func (*Value) Mul

func (a *Value) Mul(b *Value) *Value

Mul returns a · b.

func (*Value) Name

func (v *Value) Name() string

Name returns v's name: the input name, or the operation and node number.

func (*Value) Neg

func (a *Value) Neg() *Value

Neg returns -a.

func (*Value) RMSNorm

func (a *Value) RMSNorm(w *Value, eps float64) *Value

RMSNorm returns a · w / √(mean(a², last axis) + eps), where w broadcasts against the last axis.

func (*Value) Rsqrt

func (a *Value) Rsqrt() *Value

Rsqrt returns 1/√a, computed by an honest kernel either directly or as a square root and a division.

func (*Value) Shape

func (v *Value) Shape() []int

Shape returns v's shape.

func (*Value) Silu

func (a *Value) Silu() *Value

Silu returns a·σ(a) = a/(1+e^-a).

func (*Value) Softmax

func (a *Value) Softmax(axis int) *Value

Softmax returns e^a / Σ e^a along axis. An honest kernel may shift the exponent by any value up to the largest magnitude in the row, including the running maximum of an online softmax.

func (*Value) Sqrt

func (a *Value) Sqrt() *Value

Sqrt returns √a.

func (*Value) Sub

func (a *Value) Sub(b *Value) *Value

Sub returns a - b.

func (*Value) Sum

func (a *Value) Sum(axis int) *Value

Sum returns the sum of a along axis, keeping the axis with size 1. A negative axis counts from the last. An honest kernel may add the terms in any order.

type Verdict

type Verdict int

A Verdict is the outcome of a check.

const (
	// Accept: every output element is within its honest bound.
	Accept Verdict = iota
	// Abstain: no element is outside its bound, but the bound is too
	// loose to tell an honest kernel from a cheating one, or some
	// elements could not be bounded. Abstain is not a pass.
	Abstain
	// Reject: some output element is outside its bound, so no honest
	// kernel at the declared precision could have produced it.
	Reject
)

func (Verdict) String

func (v Verdict) String() string

Directories

Path Synopsis
Package errboundcuda runs CUDA kernels as errbound.Kernel values, on a GPU through NVRTC or on the host CPU through cudahostemu, so that errbound.Check can certify them.
Package errboundcuda runs CUDA kernels as errbound.Kernel values, on a GPU through NVRTC or on the host CPU through cudahostemu, so that errbound.Check can certify them.
Package plant holds a corpus of CUDA kernels that cheat kernel correctness checks, with honest controls, for testing checkers such as github.com/tmc/lib/nvidia/x/obs/diag/errbound.
Package plant holds a corpus of CUDA kernels that cheat kernel correctness checks, with honest controls, for testing checkers such as github.com/tmc/lib/nvidia/x/obs/diag/errbound.

Jump to

Keyboard shortcuts

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