advanced27 min studyLesson 520 in Engineering

Validate the analyzed domain, not just one compiled answer

Combine structural verification, guard-negative fixtures, differential oracles, floating-point tolerances, and bounded proof claims in a compiler validation plan.

On this page

What you’ll understand

  • Separate well-formed IR from semantic equivalence and backend correctness.
  • Define numerical, state, shape, and dispatch oracles over a declared domain.
  • Explain what random tests and bounded proofs can and cannot establish.

Compiler validation should challenge the assumptions that justified a transformation. A graph that parses, a kernel that runs, and one matching output are distinct observations with different limits. Begin by stating the input domain and observable behavior, then choose oracles capable of detecting the plausible failure modes. Shapes, layouts, aliases, effects, special values, and guard outcomes all matter. The goal is a reviewable chain from analysis premises to generated behavior, with explicit boundaries around both empirical evidence and any formal argument.

Use structural verification for structural obligations

An IR verifier can reject mismatched operand types, invalid region structure, or definitions that violate dominance. These checks are valuable because downstream passes rely on well-formed input. A verifier does not generally know whether replacing a multiply with an add preserves the original function, or whether a layout guard omitted a required stride condition. Keep structural tests alongside semantic tests rather than treating either as a complete replacement for the other.

Compatibility is another separate claim. A versioned portable representation can define which producers and consumers accept an artifact, while backend support and numerical behavior require additional checks. StableHLO's compatibility documentation states a versioned portability policy; it is not a promise that all devices execute every program with bit-identical floating-point results. Record producer, IR dialect or artifact version, backend, numerical flags, and relevant device conditions so a regression can be reproduced against the contract actually tested.

∀x∈D: Obs⁡(P,x)=Obs⁡(Q,x)\forall x\in D:\ \operatorname{Obs}(P,x)=\operatorname{Obs}(Q,x)
This schematic exact-equivalence goal quantifies over a declared domain D. Obs includes the outputs, state changes, errors, and effects specified by the contract. Approximate numerical contracts replace equality for selected numerical observations only; they do not silently weaken required dispatch, state, or error behavior.↔ Scroll wide equations horizontally.

Choose oracles that can expose the proposed mistake

A differential fixture compares a reference program with the transformed program under controlled initial state. Use noncontiguous two-dimensional views to test indexing, alias-positive and copy cases to test mutation, changed static values to test specialization, and nonuniform cotangents to test derivative reductions. Include expected rejected or fallback inputs. If an outside-domain call should not reach the specialized kernel, merely checking a numerically lucky result is weaker than verifying the dispatch event.

For supported finite numerical outputs, an absolute-plus-relative tolerance can handle small magnitudes and scale-dependent deviations. Specify which value supplies the scale and evaluate special values separately. NaN equality policy, infinities, signed zero, integer exactness, and state effects are not resolved by a single allclose call. A very large tolerance can conceal a wrong transpose or stale parameter, so derive acceptable error from the application and operations rather than increasing it until every test passes.

∣q−r∣≤atol⁡+rtol⁡∣r∣|q-r|\leq \operatorname{atol}+\operatorname{rtol}|r|
r is the finite reference value and q the finite candidate in the same unit. atol has that unit and rtol is dimensionless; both are nonnegative. The asymmetric reference scaling is deliberate. This criterion is not the policy for NaNs, infinities, signed-zero-sensitive operations, or nonnumerical effects.↔ Scroll wide equations horizontally.

Counterexamples and proofs have different scope

One valid counterexample disproves a universal equivalence claim over a domain containing that case. Passing many tests does not prove the universal statement. A bounded formal check can be powerful, but its result applies to the modeled operations, dimensions, value ranges, flags, and memory assumptions. A proof using mathematical integers does not automatically cover overflowing machine arithmetic; a proof excluding aliases does not cover an aliased input. Preserve those restrictions in the validation report instead of turning a bounded result into an unrestricted slogan.

The probability lab quantifies one testing limit under a deliberately hypothetical independent sampling model. Reset, set both defect-trigger probability p=0.1 and trials n=20, predict the no-trigger probability 0.9²⁰≈0.1216, then Play or Step. Reset and set both p=0.1,n=30 for about 0.0424. The displayed binomial bars are exact model probabilities; playback highlights outcomes rather than drawing samples. Real compiler bugs do not come with known independent trigger rates, so deliberate boundary fixtures remain necessary and this lab cannot certify equivalence.

Apply one declared finite-value tolerance

Use atol=0.000001 and rtol=0.00001 with reference scaling. Compare candidate q=1000.005 to reference r=1000, then candidate q=0.00005 to reference r=0. All values are finite, dimensionless scalars, and this tolerance is the declared numerical criterion only.

  1. For r=1000, the threshold is 0.000001+0.00001×1000=0.010001. The absolute difference is 0.005, so the first comparison passes.

  2. For r=0, the relative term vanishes and the threshold is 0.000001. The second absolute difference is 0.00005, fifty times the threshold, so it fails.

  3. Report both outcomes under this numerical criterion, then separately check shape, dispatch, supported special values, and effects. Passing the first tolerance test cannot establish that a guard or mutation analysis was correct.

The result

The large-magnitude comparison passes and the near-zero comparison fails. Reference-scaled numerical agreement is one oracle within a larger declared validation contract.

Explore the model

Interactive lab

Interactive lab · probability

Quantify a hypothetical random-test blind spot

Fresh Reset → set both p=0.1,n=20 predicts P(no trigger)≈0.1216; Reset → set both p=0.1,n=30 predicts ≈0.0424. Play or Step highlights exact binomial outcomes, not sampled tests. Known independent trigger probabilities are hypothetical and do not prove compiler correctness.

Quantify a hypothetical random-test blind spotThese are exact binomial probabilities for independent trials with one fixed success probability. Playback tours the distribution; it does not resample outcomes. Current readings: Mean · np: 5; Variance · np(1−p): 2.5; Total probability: 1. All parameters are adjustable with the labeled controls below.03581000.070.150.220.3Successes kP(X = k)k = 0 · P = 9.77e-4
Exact probabilityHighlighted outcomeMean np
Mean · np
5
Variance · np(1−p)
2.5
Total probability
1
t = 0 s

These are exact binomial probabilities for independent trials with one fixed success probability. Playback tours the distribution; it does not resample outcomes. Parameter changes pause playback and recompute the model at the current elapsed time. Reset restores both parameters and returns time to zero. Playback starts paused. Adjust either parameter, then choose Play or Step.

Look forRandom-test counts quantify evidence only under a justified sampling model; targeted domain tests remain essential.

Check your understanding

A bounded proof validates a rewrite for nonaliased [2,2] integer tensors without overflow. Which conclusion follows?

Try it yourself

A proposed layout rewrite passes one thousand contiguous-input comparisons but fails on one supported [2,3] view with strides [1,2]. The author proposes excluding that fixture from the random seed set. What does the counterexample establish, and what should change?

Take a moment to make a prediction or work it out on paper. Open a hint when you need one.

Give me a hint

The public input domain, rather than the frequency of the failing layout, determines whether the case contradicts the claim.

Compare with the solution

If the view lies in the declared domain, one failure disproves the claimed universal equivalence; a thousand successes do not outweigh it. Correct the indexing transformation, add an enforced guard with specified alternate behavior, or deliberately narrow the public contract only if that is an authorized API change. Preserve the failing view as a regression fixture with distinctive contents. Removing it from the seed set changes the evidence rather than repairing the implementation or its assumptions.

Take it with you

  • IR well-formedness, portability, semantic equivalence, and numerical agreement are separate claims.
  • Validation oracles must include the shapes, layouts, state, effects, and dispatch behavior promised by the contract.
  • Tests and bounded proofs should report their actual domains and assumptions.

Read further

Original sources and deeper explanations to follow at your own pace.

Optional progress, saved in this browser when available. Revisit any lesson at any time.

Lesson not marked complete.