|
1 | | -EdgeFlow Compiler (CLI) |
2 | | -======================= |
| 1 | +EdgeFlow Compiler with Semantic Analysis |
| 2 | +========================================== |
3 | 3 |
|
4 | 4 | EdgeFlow is a domain-specific language (DSL) and compiler for optimizing TensorFlow Lite models for edge deployment. Users write simple `.ef` configuration files that describe optimization strategies (e.g., INT8 quantization), target devices, and goals like latency or size. The CLI parses these configs and runs the optimization pipeline. |
5 | 5 |
|
6 | | -Project Status: Day 1 CLI skeleton with tests and CI. Parser and optimizer are stubbed for integration by other teams. |
| 6 | +**NEW: Comprehensive Semantic Analysis System** - The compiler now includes a sophisticated semantic analyzer that validates DSL models for shape compatibility, parameter ranges, resource constraints, and device compatibility before code generation. |
| 7 | + |
| 8 | +Project Status: CLI with semantic analysis, tests, and CI. Parser and optimizer integration points ready. |
7 | 9 |
|
8 | 10 | Overview |
9 | 11 | -------- |
@@ -112,20 +114,80 @@ Parse a `.ef` config and run the (placeholder) optimization pipeline: |
112 | 114 | python edgeflowc.py path/to/config.ef |
113 | 115 | ``` |
114 | 116 |
|
| 117 | +## Semantic Analysis System |
| 118 | + |
| 119 | +The EdgeFlow compiler now includes a comprehensive semantic analysis system that validates DSL models before code generation. This ensures that generated models are correct, efficient, and compatible with target devices. |
| 120 | + |
| 121 | +### Key Features |
| 122 | + |
| 123 | +- **Shape Compatibility Validation**: Ensures tensor shapes match between connected layers |
| 124 | +- **Parameter Range Checking**: Validates that all layer parameters are within acceptable ranges |
| 125 | +- **Device Compatibility**: Checks if the model is compatible with target device constraints |
| 126 | +- **Resource Analysis**: Validates memory usage and computational requirements |
| 127 | +- **Forbidden Configuration Detection**: Identifies problematic layer sequences and configurations |
| 128 | +- **Graph Structure Validation**: Detects cycles, connectivity issues, and missing components |
| 129 | + |
| 130 | +### Quick Start with Semantic Analysis |
| 131 | + |
| 132 | +```python |
| 133 | +from semantic_analyzer import SemanticAnalyzer, IRGraph, semantic_check |
| 134 | +from semantic_analyzer import get_edge_device_config |
| 135 | + |
| 136 | +# Create or load your IR graph |
| 137 | +graph = create_your_model_graph() |
| 138 | + |
| 139 | +# Run semantic analysis |
| 140 | +config = get_edge_device_config() # For edge devices |
| 141 | +errors = semantic_check(graph, config) |
| 142 | + |
| 143 | +# Check results |
| 144 | +if errors.has_errors(): |
| 145 | + errors.print_summary() |
| 146 | +else: |
| 147 | + print("✅ Model validation passed!") |
| 148 | +``` |
| 149 | + |
| 150 | +### Example Error Output |
| 151 | + |
| 152 | +``` |
| 153 | +📊 Semantic Analysis Summary: |
| 154 | + Errors: 2 |
| 155 | + Warnings: 1 |
| 156 | + Info: 0 |
| 157 | + Fatal: 0 |
| 158 | +
|
| 159 | +📝 Detailed Report: |
| 160 | + [ERROR] at model.dsl:line 7: Expected input shape (1, 256), got (1, 28, 28, 3). |
| 161 | + Suggestion: Ensure the previous layer outputs shape (1, 256) |
| 162 | + [ERROR] at model.dsl:line 10: Dense layer requires Flatten layer after Conv2D |
| 163 | + Suggestion: Add a Flatten layer between the convolutional and dense layers |
| 164 | + [WARNING] at model.dsl:line 5: Kernel size 13 exceeds recommended maximum (11) for target device |
| 165 | +``` |
| 166 | + |
115 | 167 | ## Project Structure |
116 | 168 |
|
117 | 169 | Architecture |
118 | 170 | ------------ |
119 | 171 |
|
120 | 172 | ```bash |
121 | 173 | edgeFlow/ |
122 | | -├── edgeflowc.py # CLI entry point (this repo) |
123 | | -├── parser/ # ANTLR-generated modules + wrapper (__init__.py) |
124 | | -├── optimizer.py # Model optimization logic (Team B) |
| 174 | +├── edgeflowc.py # CLI entry point |
| 175 | +├── semantic_analyzer/ # 🆕 Semantic analysis system |
| 176 | +│ ├── __init__.py # Main exports |
| 177 | +│ ├── analyzer.py # Core semantic analyzer |
| 178 | +│ ├── error_types.py # Error definitions and collection |
| 179 | +│ ├── ir_nodes.py # IR graph and node structures |
| 180 | +│ ├── constraints.py # Parameter ranges and device constraints |
| 181 | +│ └── compiler_integration.py # Integration with compiler pipeline |
| 182 | +├── parser/ # ANTLR-generated modules + wrapper |
| 183 | +├── optimizer.py # Model optimization logic |
125 | 184 | ├── benchmarker.py # Performance measurement tools |
126 | 185 | ├── reporter.py # Report generation |
| 186 | +├── examples/ # 🆕 Semantic analysis examples |
| 187 | +│ └── semantic_analysis_examples.py |
127 | 188 | ├── tests/ # Unit tests |
128 | | -│ └── test_cli.py |
| 189 | +│ ├── test_cli.py |
| 190 | +│ └── test_semantic_analyzer.py # 🆕 Semantic analyzer tests |
129 | 191 | ├── .github/workflows/ci.yml # CI: lint, type, test, coverage badge |
130 | 192 | ├── requirements.txt # Runtime dependencies |
131 | 193 | ├── requirements-dev.txt # Dev/test dependencies |
|
0 commit comments