Architecture Overview
Shrew is built as a modular set of Rust crates. The architecture is designed to separate the frontend language (DSL) from the backend execution engines, with a middle layer for Intermediate Representation (IR) and optimization.
High-Level Flow
- Frontend: The
shrew-ircrate parses the.swsource code into an Abstract Syntax Tree (AST) and then lowers it into a High-Level IR (Graph). - Optimization: The
shrew-optimcrate applies graph transformations (e.g., constant folding, operator fusion) to the IR. - Execution: The
shrew-corecrate orchestrates execution, dispatching tensor operations to specific backends (shrew-cpu,shrew-cuda).
Diagram
graph TD
Source[.sw File] --> Parser[shrew-ir: Parser]
Parser --> AST[AST]
AST --> Lower[shrew-ir: Lowering]
Lower --> IR[Graph IR]
IR --> Optim[shrew-optim]
Optim --> Exec[shrew-core: Executor]
Exec --> CPU[shrew-cpu]
Exec --> CUDA[shrew-cuda]