lean

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: 14 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 lean provides a fail-closed 1-to-1 Tile IR to Lean 4 exporter and formal obligation verifier.

ExportTileIR lowers a validated subset of a *tileir.Module together with a contract.LaunchContract into a self-contained, deterministic Lean 4 source file containing `TileFunc`, `ControlFlowCfg`, `LaunchContract`, and concrete theorem obligations for each requested contract.Clause with zero `sorry` / `sorryAx`. Unsupported operations fail closed with ErrUnsupportedOp.

CheckClauses runs the structural obligation checker in Go. Verify combines ExportTileIR, CheckClauses, and (when Lean 4 is available and enabled) machine-checked verification via the `lean` binary, stamping a contract.ProofCertificate with either contract.ProverLean4 (only when Lean succeeds with zero `sorryAx`) or contract.ProverStructural.

This package is outside the compatibility promise of github.com/tmc/lib/nvidia. Its API may change or be removed in patch releases.

Index

Examples

Constants

This section is empty.

Variables

View Source
var ErrAxiomAudit = errors.New("lean: axiom audit")

ErrAxiomAudit reports that a Lean proof did not pass the axiom audit.

View Source
var ErrUnsupportedOp = errors.New("lean: unsupported tileir operation")

ErrUnsupportedOp is returned when ExportTileIR or CheckClauses encounters a Tile IR operation outside the verified subset.

Functions

func CheckClauses

func CheckClauses(mod *tileir.Module, c contract.LaunchContract) error

CheckClauses runs the fail-closed structural obligation checker for every clause declared in c against mod.

func Verify

Verify runs the fail-closed 1-to-1 Tile IR -> Lean 4 exporter and structural checker, then invokes Lean 4 when available and enabled. It returns a digest-bound contract.ProofCertificate stamped with contract.ProverLean4 only if Lean 4 succeeds with zero sorryAx; otherwise it stamps contract.ProverStructural.

Example
package main

import (
	"context"
	"fmt"

	"github.com/tmc/lib/nvidia/x/ir/contract"
	"github.com/tmc/lib/nvidia/x/ir/lean"
	"github.com/tmc/lib/nvidia/x/isa/tileir"
)

func main() {
	tvC := &tileir.TensorViewType{Shape: []int64{256, 256}, Strides: []int64{256, 1}, ElementType: tileir.BFloat16}
	pvC := &tileir.PartitionViewType{TileShape: []int64{128, 128}, View: tvC, Padding: tileir.PadZero}

	mod := &tileir.Module{
		Name: "example_mod",
		Functions: []*tileir.Function{
			{
				Name:  "fill_c",
				Entry: true,
				Operations: []*tileir.Operation{
					{Results: []string{"%bx", "%by", "%bz"}, OpCode: "cuda_tile.get_tile_block_id"},
					{Results: []string{"%t0"}, OpCode: "cuda_tile.make_token"},
					{Results: []string{"%tvC"}, OpCode: "cuda_tile.make_tensor_view", TypeVal: tvC},
					{Results: []string{"%pvC"}, OpCode: "cuda_tile.make_partition_view", Operands: []string{"%tvC"}, TypeVal: pvC},
					{Results: []string{"%z"}, OpCode: "cuda_tile.constant", Attributes: "{value = 0.0}"},
					{Results: []string{"%t1"}, OpCode: "cuda_tile.store_view_tko", Operands: []string{"%z", "%pvC", "%bx", "%by", "%t0"}},
					{OpCode: "cuda_tile.return"},
				},
			},
		},
	}

	c := contract.LaunchContract{
		KernelName: "fill_c",
		TargetArch: "sm_103a",
		Grid:       contract.DimBounds{Min: contract.Dim3{X: 2, Y: 2, Z: 1}, Max: contract.Dim3{X: 2, Y: 2, Z: 1}},
		Block:      contract.DimBounds{Min: contract.Dim3{X: 128, Y: 1, Z: 1}, Max: contract.Dim3{X: 128, Y: 1, Z: 1}},
		Tensors: []contract.TensorDesc{
			{Name: "C", Role: contract.RoleOutput, Shape: []int64{256, 256}, Strides: []int64{256, 1}, TileShape: []int64{128, 128}, ElemBytes: 2, TMA: true},
		},
		Clauses: []contract.Clause{
			contract.ClauseNoOOB,
			contract.ClauseTMA16BAligned,
			contract.ClauseDisjointWrites,
			contract.ClauseWritesAllElems,
		},
	}

	cert, err := lean.Verify(context.Background(), mod, c, lean.VerifyOptions{DisableLean: true})
	if err != nil {
		fmt.Println("error:", err)
		return
	}
	fmt.Println("kernel:", cert.KernelName, "prover:", cert.Prover, "clauses:", len(cert.Clauses))
}
Output:
kernel: fill_c prover: structural clauses: 4

Types

type ExportResult

type ExportResult struct {
	KernelName         string
	LeanSource         string
	IRSHA256           string
	Theorems           []string
	OpCount            int
	CFGNodeCount       int
	ObligationEvidence []contract.ObligationEvidence
}

ExportResult holds the deterministic Lean 4 module emitted from a Tile IR entry function and its launch contract.

func ExportTileIR

func ExportTileIR(mod *tileir.Module, c contract.LaunchContract) (*ExportResult, error)

ExportTileIR lowers the target entry function of mod and launch contract c into a deterministic, self-contained Lean 4 source file with zero sorry. Unsupported operations or invalid contracts fail closed.

type VerifyOptions

type VerifyOptions struct {
	// RequireLean fails verification if the lean binary is unavailable.
	RequireLean bool

	// DisableLean skips invoking the lean binary even when installed, returning
	// a structural pre-check certificate (Prover: "structural").
	DisableLean bool

	// LeanPath overrides PATH lookup for the lean binary.
	LeanPath string

	// BindContract emits v2 certificate metadata even for a v1 contract.
	BindContract bool

	// Cubin optionally binds a compiled cubin digest into the certificate.
	Cubin []byte

	// PTX is the emitted entry whose instruction sites the obligations name.
	PTX []byte
}

VerifyOptions configures how Verify checks a Tile IR module and stamps a contract.ProofCertificate.

Jump to

Keyboard shortcuts

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