How nyu-systems/cleave works
Cleave is an ML compiler for generating optimized GPU kernels. The principal workflow starts with a user-declared tensor program, traces it into a graph, searches for algebraically equivalent graphs, schedules those graphs, builds kernels, then validates and benchmarks candidates into a report. Separate branches cover dynamic-shape and paged-KV workloads, and the native superoptimizer supplies graph search and verification. The README documents the staged workflow; several Python implementations were not sampled, so their internal calls are not asserted here.
Main entry points: graph.py Tensor IR Graph · cleave.py Superoptimizer API · search.py Schedule Search · pipeline Pipeline Orchestration
Components 21
Program Frontend
- JIT and Trace
python/cleave/frontend - Program Builder
python/cleave/frontend/program.py
Graph Optimization
- Tensor IR Graph
python/cleave/ir/graph.py - IR Operations
python/cleave/ir/ops - Native Kernel Graph
src/superoptimizer/kernel/graph.cc - Symbolic Grouping
src/superoptimizer/symbolic/grouping_rules.cc - Graph Search
src/superoptimizer/search/search.cc - Candidate Verification
src/superoptimizer/search/verification/probabilistic_verifier.cc - Superoptimizer API
python/cleave/superoptimizer/cleave.py - Graph Lowering
python/cleave/lower
Kernel Generation
- Schedule Search
python/cleave/schedule/search.py - Default Schedule Policy
python/cleave/schedule/policy/default.py - Kernel Code Generation
python/cleave/codegen - Pipeline Orchestration
python/cleave/pipeline
Execution and Evaluation
- Target and Session
python/cleave/core/session.py - Compile and Run
python/cleave/runtime - Validation and Benchmark
python/cleave/runtime/evaluate.py - Candidate Report
python/cleave/pipeline/report.py
Dynamic Workloads
- Dynamic Workloads
python/cleave/dynamic - Paged-KV Builders
python/cleave/dynamic/paging/builders
Other components
- Kernel Author
Connections 20
- Kernel Author → JIT and Trace: declares program
README.md - JIT and Trace → Program Builder: traces program
README.md - Program Builder → Tensor IR Graph: produces graph
README.md - Tensor IR Graph → Superoptimizer API: input to search
README.md - Superoptimizer API → Native Kernel Graph: uses graph search
- Native Kernel Graph → Symbolic Grouping: symbolizes graph
src/superoptimizer/kernel/graph.cc - Graph Search → Candidate Verification: verifies candidates
src/superoptimizer/search/search.cc - Graph Search → Superoptimizer API: returns equivalents
README.md - Superoptimizer API → Graph Lowering: lowers graphs
README.md - Tensor IR Graph → IR Operations: uses operations
python/cleave/ir/ops/__init__.py - Graph Lowering → Schedule Search: provides graphs
README.md - Schedule Search → Default Schedule Policy: selects schedules
python/cleave/schedule/search.py - Schedule Search → Kernel Code Generation: scheduled plans
README.md - Kernel Code Generation → Pipeline Orchestration: builds kernels
README.md - Pipeline Orchestration → Target and Session: uses target settings
- Pipeline Orchestration → Compile and Run: compiles candidates
README.md - Compile and Run → Validation and Benchmark: validates and times
README.md - Validation and Benchmark → Candidate Report: produces results
README.md - Dynamic Workloads → Paged-KV Builders: includes paged builders
README.md - Paged-KV Builders → Tensor IR Graph: constructs graphs
python/cleave/dynamic/paging/builders/ragged.py