outputcontract

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: 4 Imported by: 0 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 outputcontract defines pure-stdlib recorded output contracts, two-fill write-domain classification, and bounded FP32 comparison policies shared between nvidia/x/cuda/cudatest and nvidia/x/isa/ptx.

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidCUDAOutput = errors.New("invalid CUDA output comparison")

ErrInvalidCUDAOutput distinguishes a malformed policy or readback from a numerical mismatch. An empty domain is valid only when Elements is zero and both buffers are empty.

Functions

func CompareCUDAOutputFP32

func CompareCUDAOutputFP32(actual, expected []float32, p CUDAOutputPolicy) error

CompareCUDAOutputFP32 checks every declared logical element. It does not normalize buffers, establish that elements were written, or replace trace hashing. Invalid reference values under the chosen policy are input errors; invalid actual values are mismatches.

func IsDigest

func IsDigest(s string) bool

IsDigest reports whether s is a 64-character lowercase hexadecimal SHA-256 digest.

func ValidateTwoFill

func ValidateTwoFill(t TwoFill) error

ValidateTwoFill checks admission invariants for a two-fill spec before running or classifying readbacks.

Types

type CUDAOutputMismatch

type CUDAOutputMismatch struct {
	Index                    int
	Actual, Expected         float32
	ActualBits, ExpectedBits uint32
	Policy                   CUDAOutputPolicy
}

CUDAOutputMismatch retains the first bad logical index, FP32 values and bits, and the policy identities. It reports output disagreement, not bad input.

func (*CUDAOutputMismatch) Error

func (m *CUDAOutputMismatch) Error() string

Error describes the first disagreement including its reproducible identities.

type CUDAOutputPolicy

type CUDAOutputPolicy struct {
	Target, DType, MathMode   string
	SourceDigest, InputDigest string
	Elements                  int
	Absolute, Relative        float64
	NaN, Infinity, Zero       string
}

CUDAOutputPolicy identifies a bounded CUDA FP32 comparison. Its zero value is invalid. SourceDigest and InputDigest are lowercase SHA-256 receipts; Target and MathMode describe the actual compiled consumer, not a default. NaN is "reject" or "semantic" (both values NaN, without payload equality). Infinity is "reject" or "same-sign". Zero is "equal" or "bits". Finite values pass when abs(actual-expected) <= Absolute + Relative * max(abs(actual), abs(expected)). The implementation rearranges this formula to avoid overflowing a tolerance product or sum.

type Contract

type Contract struct {
	Buffer            string
	Elements          int
	Domain            []Range
	Kind              Kind
	Atomic, Reduction bool
	ExpectedWriters   uint64
	Deterministic     bool
}

Contract declares a buffer's write domain and writer semantics. Elements includes padding; Domain excludes it and must be sorted, nonoverlapping and nonempty. Atomic and Reduction require WriterCount or Accumulated.

func (Contract) Validate

func (c Contract) Validate() error

Validate rejects malformed domains and contradictory writer contracts.

type CoverageReport

type CoverageReport struct {
	Contract                                    Contract
	Arm                                         string
	Geometry                                    Geometry
	Unwritten, Nondeterministic                 []Range
	SourceDigest, InputDigest, Target, MathMode string
}

CoverageReport separates write-domain failures from nondeterministic readbacks. Numerical correctness must be checked independently.

func ClassifyTwoFill

func ClassifyTwoFill(t TwoFill) (CoverageReport, error)

ClassifyTwoFill checks recorded readbacks without touching hardware. Invalid admission is an error, never an empty successful report.

type Geometry

type Geometry struct{ Grid, Block [3]uint32 }

Geometry records the admitted launch dimensions, rather than deriving them from the logical domain.

type Kind

type Kind string

Kind identifies a closed write-contract policy.

const (
	ExactlyOnce Kind = "exactly_once"
	AtLeastOnce Kind = "at_least_once"
	WriterCount Kind = "writer_count"
	Accumulated Kind = "accumulated"
)

type PairedReport

type PairedReport struct {
	Written           CoverageReport
	NumericalMismatch *CUDAOutputMismatch
}

PairedReport keeps written-domain and numerical findings separate. A nil NumericalMismatch means the admitted numerical comparison passed; it says nothing about whether the launch wrote the output.

func CheckOutput

func CheckOutput(t TwoFill, ordinary []uint32, p CUDAOutputPolicy) (PairedReport, error)

CheckOutput checks a recorded ordinary readback numerically using the integrated CUDA output policy and checks the two-fill readbacks for writes. Policy.Elements is the number of domain elements, excluding declared padding. All execution identities must match. NumericalMismatch.Index is the logical buffer index, not a flattened-domain index.

type Range

type Range struct{ Start, End int }

Range is a half-open logical element interval [Start, End).

type RecordedOutput

type RecordedOutput struct {
	PTXDigest string
	TwoFill   TwoFill
	Ordinary  []uint32
	Policy    CUDAOutputPolicy
}

RecordedOutput retains the completed readbacks and policy used to check a campaign run. PTXDigest identifies the runner's loaded PTX; SourceDigest in TwoFill identifies the CUDA source. Neither digest substitutes for the other. These are producer claims, not independent device or process attestation. A campaign snapshots its slices when the runner returns. The runner must complete device work before returning and must not mutate evidence concurrently.

type TwoFill

type TwoFill struct {
	Contract                        Contract
	FillA, FillB                    uint32
	Reference, ReadbackA, ReadbackB []uint32
	Geometry                        Geometry
	SourceDigest, InputDigest       string
	Target, MathMode                string
}

TwoFill records reference and readback bits from two executions with the same admitted inputs, artifact, launch geometry and contract.

Jump to

Keyboard shortcuts

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