# gautam1858/tiny-gpu-compiler architecture

> Architecture diagram of the GitHub repository gautam1858/tiny-gpu-compiler, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-21). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/gautam1858/tiny-gpu-compiler
- Repository: https://github.com/gautam1858/tiny-gpu-compiler

## Overview

tiny-gpu-compiler is an MLIR-based GPU-kernel compiler with a browser visualizer and cycle-accurate simulator. Users edit or select a .tgc kernel; the compiler parses it, generates TinyGPU IR, optimizes and allocates registers, then emits instructions and analysis for visualization and simulation. The graph includes the documented optimization and shared-memory capabilities. The native pipeline and browser wiring are evidenced by excerpts; browser-internal details not sampled are represented only where the README or shown imports support them.

Main entry points: [`lib/Pipeline/Pipeline.cpp`](https://github.com/gautam1858/tiny-gpu-compiler/blob/main/lib/Pipeline/Pipeline.cpp) (Compilation pipeline), [`web/src/App.tsx`](https://github.com/gautam1858/tiny-gpu-compiler/blob/main/web/src/App.tsx) (Workbench coordinator), [`web/src/compiler/types.ts`](https://github.com/gautam1858/tiny-gpu-compiler/blob/main/web/src/compiler/types.ts) (Trace and state types), [`web/src/components/GPUSimulator.tsx`](https://github.com/gautam1858/tiny-gpu-compiler/blob/main/web/src/components/GPUSimulator.tsx) (Simulator controls)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Kernel Frontend"]
  node_lexer["Lexer<br/>[Lexer.cpp]"]
  node_parser["Parser and AST<br/>[Parser.cpp]"]
  node_mlirgen["MLIR generation<br/>[MLIRGen.cpp]"]
end

subgraph group_compiler["Compiler Backend"]
  node_dialect["TinyGPU dialect<br/>[TinyGPUOps.cpp]"]
  node_pipeline["Compilation pipeline<br/>[Pipeline.cpp]"]
  node_optimizations["Optimization passes<br/>[Passes.cpp]"]
  node_allocator["Register allocator"]
  node_emitter["Instruction emitter<br/>[TinyGPUEmitter.cpp]"]
end

subgraph group_browser["Browser Workbench"]
  node_editor["Kernel editor<br/>[Editor.tsx]"]
  node_app["Workbench coordinator<br/>[App.tsx]"]
  node_pipelineview["IR stage viewer<br/>[PipelineView.tsx]"]
  node_binaryview["Binary viewer<br/>[BinaryView.tsx]"]
  node_trace_types["Trace and state types<br/>[types.ts]"]
end

subgraph group_execution["Simulation and Analysis"]
  node_analysis["Analysis panel<br/>[AnalysisPanel.tsx]"]
  node_simcomponent["Simulator controls<br/>[GPUSimulator.tsx]"]
  node_simulator["GPU simulator<br/>[TinyGPUSim.ts]"]
end

node_user(("Kernel author"))

node_user -->|"enters kernel"| node_editor
node_editor -->|"reports edits"| node_app
node_app -->|"compiles source"| node_pipeline
node_pipeline -->|"tokenizes source"| node_lexer
node_pipeline -->|"parses tokens"| node_parser
node_parser -->|"requests tokens"| node_lexer
node_pipeline -->|"generates IR"| node_mlirgen
node_mlirgen -->|"emits operations"| node_dialect
node_pipeline -->|"runs passes"| node_optimizations
node_pipeline -->|"allocates registers"| node_allocator
node_pipeline -->|"emits instructions"| node_emitter
node_app -->|"renders stages"| node_pipelineview
node_app -->|"renders instructions"| node_binaryview
node_app -->|"renders analysis"| node_analysis
node_app -->|"configures simulation"| node_simcomponent
node_simcomponent -->|"executes instructions"| node_simulator
node_simcomponent -->|"reports cycle state"| node_app
node_app -->|"uses trace state"| node_trace_types
node_pipelineview -->|"displays stages"| node_trace_types
node_binaryview -->|"displays instructions"| node_trace_types
node_analysis -->|"displays metrics"| node_trace_types
node_simulator -->|"uses execution state"| node_trace_types
node_emitter -.->|"returns trace"| node_pipeline

click node_editor "https://github.com/gautam1858/tiny-gpu-compiler/blob/main/web/src/components/Editor.tsx"
click node_app "https://github.com/gautam1858/tiny-gpu-compiler/blob/main/web/src/App.tsx"
click node_lexer "https://github.com/gautam1858/tiny-gpu-compiler/blob/main/lib/Frontend/Lexer.cpp"
click node_parser "https://github.com/gautam1858/tiny-gpu-compiler/blob/main/lib/Frontend/Parser.cpp"
click node_mlirgen "https://github.com/gautam1858/tiny-gpu-compiler/blob/main/lib/Frontend/MLIRGen.cpp"
click node_dialect "https://github.com/gautam1858/tiny-gpu-compiler/blob/main/lib/Dialect/TinyGPU/TinyGPUOps.cpp"
click node_pipeline "https://github.com/gautam1858/tiny-gpu-compiler/blob/main/lib/Pipeline/Pipeline.cpp"
click node_optimizations "https://github.com/gautam1858/tiny-gpu-compiler/blob/main/lib/Passes/Passes.cpp"
click node_allocator "https://github.com/gautam1858/tiny-gpu-compiler/blob/main/lib/CodeGen/RegisterAllocator.cpp"
click node_emitter "https://github.com/gautam1858/tiny-gpu-compiler/blob/main/lib/CodeGen/TinyGPUEmitter.cpp"
click node_pipelineview "https://github.com/gautam1858/tiny-gpu-compiler/blob/main/web/src/components/PipelineView.tsx"
click node_binaryview "https://github.com/gautam1858/tiny-gpu-compiler/blob/main/web/src/components/BinaryView.tsx"
click node_analysis "https://github.com/gautam1858/tiny-gpu-compiler/blob/main/web/src/components/AnalysisPanel.tsx"
click node_simcomponent "https://github.com/gautam1858/tiny-gpu-compiler/blob/main/web/src/components/GPUSimulator.tsx"
click node_simulator "https://github.com/gautam1858/tiny-gpu-compiler/blob/main/web/src/simulator/TinyGPUSim.ts"
click node_trace_types "https://github.com/gautam1858/tiny-gpu-compiler/blob/main/web/src/compiler/types.ts"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_lexer,node_parser,node_mlirgen toneBlue
class node_dialect,node_pipeline,node_optimizations,node_allocator,node_emitter toneAmber
class node_editor,node_app,node_pipelineview,node_binaryview,node_trace_types toneMint
class node_analysis,node_simcomponent,node_simulator toneRose
class node_user toneIndigo
```

## Components

### Kernel Frontend

- [Lexer](https://github.com/gautam1858/tiny-gpu-compiler/blob/main/lib/Frontend/Lexer.cpp): `lib/Frontend/Lexer.cpp`
- [Parser and AST](https://github.com/gautam1858/tiny-gpu-compiler/blob/main/lib/Frontend/Parser.cpp): `lib/Frontend/Parser.cpp`
- [MLIR generation](https://github.com/gautam1858/tiny-gpu-compiler/blob/main/lib/Frontend/MLIRGen.cpp): `lib/Frontend/MLIRGen.cpp`

### Compiler Backend

- [TinyGPU dialect](https://github.com/gautam1858/tiny-gpu-compiler/blob/main/lib/Dialect/TinyGPU/TinyGPUOps.cpp): `lib/Dialect/TinyGPU/TinyGPUOps.cpp`
- [Compilation pipeline](https://github.com/gautam1858/tiny-gpu-compiler/blob/main/lib/Pipeline/Pipeline.cpp): `lib/Pipeline/Pipeline.cpp`
- [Optimization passes](https://github.com/gautam1858/tiny-gpu-compiler/blob/main/lib/Passes/Passes.cpp): `lib/Passes/Passes.cpp`
- [Register allocator](https://github.com/gautam1858/tiny-gpu-compiler/blob/main/lib/CodeGen/RegisterAllocator.cpp): `lib/CodeGen/RegisterAllocator.cpp`
- [Instruction emitter](https://github.com/gautam1858/tiny-gpu-compiler/blob/main/lib/CodeGen/TinyGPUEmitter.cpp): `lib/CodeGen/TinyGPUEmitter.cpp`

### Browser Workbench

- [Kernel editor](https://github.com/gautam1858/tiny-gpu-compiler/blob/main/web/src/components/Editor.tsx): `web/src/components/Editor.tsx`
- [Workbench coordinator](https://github.com/gautam1858/tiny-gpu-compiler/blob/main/web/src/App.tsx): `web/src/App.tsx`
- [IR stage viewer](https://github.com/gautam1858/tiny-gpu-compiler/blob/main/web/src/components/PipelineView.tsx): `web/src/components/PipelineView.tsx`
- [Binary viewer](https://github.com/gautam1858/tiny-gpu-compiler/blob/main/web/src/components/BinaryView.tsx): `web/src/components/BinaryView.tsx`
- [Trace and state types](https://github.com/gautam1858/tiny-gpu-compiler/blob/main/web/src/compiler/types.ts): `web/src/compiler/types.ts`

### Simulation and Analysis

- [Analysis panel](https://github.com/gautam1858/tiny-gpu-compiler/blob/main/web/src/components/AnalysisPanel.tsx): `web/src/components/AnalysisPanel.tsx`
- [Simulator controls](https://github.com/gautam1858/tiny-gpu-compiler/blob/main/web/src/components/GPUSimulator.tsx): `web/src/components/GPUSimulator.tsx`
- [GPU simulator](https://github.com/gautam1858/tiny-gpu-compiler/blob/main/web/src/simulator/TinyGPUSim.ts): `web/src/simulator/TinyGPUSim.ts`

### Other components

- **Kernel author**

## Connections

- Kernel author → Kernel editor: enters kernel (evidence: `README.md`)
- Kernel editor → Workbench coordinator: reports edits (evidence: `web/src/App.tsx`)
- Workbench coordinator → Compilation pipeline: compiles source (evidence: `README.md`)
- Compilation pipeline → Lexer: tokenizes source (evidence: `lib/Pipeline/Pipeline.cpp`)
- Compilation pipeline → Parser and AST: parses tokens (evidence: `lib/Pipeline/Pipeline.cpp`)
- Parser and AST → Lexer: requests tokens
- Compilation pipeline → MLIR generation: generates IR (evidence: `lib/Pipeline/Pipeline.cpp`)
- MLIR generation → TinyGPU dialect: emits operations (evidence: `lib/Frontend/MLIRGen.cpp`)
- Compilation pipeline → Optimization passes: runs passes (evidence: `lib/Pipeline/Pipeline.cpp`)
- Compilation pipeline → Register allocator: allocates registers (evidence: `lib/Pipeline/Pipeline.cpp`)
- Compilation pipeline → Instruction emitter: emits instructions (evidence: `lib/Pipeline/Pipeline.cpp`)
- Workbench coordinator → IR stage viewer: renders stages (evidence: `web/src/App.tsx`)
- Workbench coordinator → Binary viewer: renders instructions (evidence: `web/src/App.tsx`)
- Workbench coordinator → Analysis panel: renders analysis (evidence: `web/src/App.tsx`)
- Workbench coordinator → Simulator controls: configures simulation (evidence: `web/src/App.tsx`)
- Simulator controls → GPU simulator: executes instructions (evidence: `web/src/components/GPUSimulator.tsx`)
- Simulator controls → Workbench coordinator: reports cycle state (evidence: `web/src/App.tsx`)
- Workbench coordinator → Trace and state types: uses trace state (evidence: `web/src/App.tsx`)
- IR stage viewer → Trace and state types: displays stages (evidence: `web/src/components/PipelineView.tsx`)
- Binary viewer → Trace and state types: displays instructions (evidence: `web/src/components/BinaryView.tsx`)
- Analysis panel → Trace and state types: displays metrics (evidence: `web/src/components/AnalysisPanel.tsx`)
- GPU simulator → Trace and state types: uses execution state (evidence: `web/src/simulator/TinyGPUSim.ts`)
- Instruction emitter → Compilation pipeline: returns trace
