High-performance cellular automata implementations in Mojo, featuring CPU (SIMD-vectorized) and native GPU execution paths. Four sub-projects cover 1D, 2D, 3D, and 4D automata with real-time visualization and comprehensive benchmarking.
Rule-based 1D automata (Rule 30, 110, 254, etc.) with pattern evolution from a single center cell. Supports massive grids (20KΓ10K) for deep pattern exploration.
Classic 2D simultaneous-update automaton with real-time pygame visualization at 1440p. Interactive controls for pause, reset, and GPU/CPU mode switching.
26-neighbor 3D cellular automaton (B6/S567) running on native GPU kernels. Renders a rotating voxel cube with a transparent gray grid on black background.
80-neighbor 4D extension of the cube rule (B6/S567) over WΓZΓYΓX (default 32Γ32Γ32Γ32). GPU-only with multiple render modes: single W slice, max-intensity projection, tiled slices, and render-off; modes cycle with a toggle key.
- Mojo-native implementation: Grid logic, rule engines, renderers, and compute modules organized into clean packages
- Multiple execution modes:
- Sequential CPU
- Parallel cells on CPU (multi-threaded)
- Parallel grids on CPU
- SIMD-vectorized CPU (AVX-512, 64-cell vectors)
- CuPy GPU (via Python interop)
- Native Mojo GPU kernels
- Real-time visualization: pygame-powered viewers with FPS counter and control overlays
- PNG export: Optional Pillow-based image generation for Row CA patterns
- Comprehensive benchmarking: Detailed timing stats (min/max/avg/stddev) with report generation
- Extensive test suites: 70+ unit tests covering grid operations, rules, CPU/GPU equivalence
- Linux environment (on Windows, run under WSL2)
- Pixi for dependency management
- Mojo 0.26+ (MAX nightly channel)
- CUDA-capable GPU (optional, for GPU acceleration)
| Package | Version |
|---|---|
| mojo | β₯0.26.1 |
| pillow | β₯12.0 |
| cupy | β₯13.6 |
| pygame | β₯2.5 |
.
βββ shared/ # Shared utilities
β βββ common.mojo # Global config (WIDTH, HEIGHT, flags)
β βββ benchmark.mojo # Benchmark suite utilities
β βββ logger.mojo # Timestamped logging
β βββ gpu_timing_result.mojo # GPU timing stats struct
β
βββ row/ # 1D Row cellular automata
β βββ main.mojo # Entry point (benchmark all modes)
β βββ grid.mojo # Grid struct + CPU/GPU generation
β βββ rule.mojo # Rule definition (3-neighbor patterns)
β βββ rule_container.mojo # Pre-defined rules (30, 110, 254)
β βββ gpu_kernels.mojo # Native Mojo GPU kernels
β βββ renderer.mojo # PNG export via Pillow
β βββ renderer/ # Interactive pygame viewer
β β βββ base.mojo # Renderer configuration
β β βββ python_module.mojo # Mojo-Python bridge
β β βββ viewer.py # Python-side rendering
β βββ run_tests.mojo # row test runner (Mojo + Python)
β βββ tests/ # 40+ unit tests
β
βββ grid/ # Grid Game of Life (2D)
β βββ main.mojo # Entry point (live viewer)
β βββ run_benchmark.mojo # Dedicated benchmark runner
β βββ grid.mojo # Double-buffered 2D grid
β βββ rules.mojo # B3/S23 rule implementation
β βββ cpu_compute.mojo # SIMD-vectorized CPU compute
β βββ gpu_compute.mojo # Persistent GPU buffer management
β βββ gpu_kernels.mojo # Native Mojo GPU kernels
β βββ renderer/ # pygame real-time renderer
β β βββ base.mojo # Display initialization
β β βββ python_module.mojo # Mojo-Python bridge
β β βββ viewer.py # Zero-copy numpy rendering
β βββ benchmark/ # Stats & reporting
β β βββ stats.mojo # Statistical calculations
β β βββ result.mojo # Result aggregation
β β βββ report.mojo # Console/file reports
β βββ tests/ # 70+ unit tests
β
βββ generated/ # PNG outputs
βββ pixi.toml / pixi.lock # Environment definition
βββ README.md
curl -fsSL https://pixi.sh/install.sh | shpixi installpixi run mojo grid/main.mojoControls:
SPACEβ Pause/ResumeRβ Reset (new random grid)Gβ Toggle GPU/CPU modeQ/ESCβ Quit
pixi run mojo row/renderer/main.mojoVisualizes the 20KΓ10K grid playback with pygame at 60 FPS. Use this for live viewing; pause/resume with SPACE, reset with R, quit with Q/ESC.
pixi run mojo row/main.mojoRuns all execution modes on a 20KΓ10K grid and prints timing comparison.
pixi run mojo grid/run_benchmark.mojoRuns 10,000 generations at 4K resolution, outputs detailed report to grid_benchmark.txt.
pixi run mojo cube/main.mojoControls: SPACE β Pause/Resume, R β Reset, Q/ESC β Quit
pixi run mojo hypercube/main.mojoControls: SPACE β Pause/Resume, R β Reset, T β Cycle render mode (Slice β Max β Tiled β Off), [ / ] β Move W slice (Slice mode), Q/ESC β Quit
Windows (WSL2) one-liner β run inside WSL, pointing to your repo:
wsl -e bash -lc "cd /mnt/c/Path/To/Cellatons && pixi run mojo cube/main.mojo"# All Row tests + renderer tests
pixi run mojo row/run_tests.mojo
# Grid Game of Life tests
pixi run mojo grid/run_tests.mojo
# Cube automaton tests
pixi run mojo cube/run_tests.mojo
# Hypercube automaton tests (GPU not required for grid checks)
pixi run mojo hypercube/run_tests.mojoalias WIDTH: Int = 20_000 # Grid width (cells)
alias HEIGHT: Int = 10_000 # Grid height (rows/generations)
alias PIXELS_PER_CELL: Int = 2 # PNG scale factor
alias RENDER_PNGS: Bool = False # Enable PNG generationalias DISPLAY_WIDTH: Int = 2560 # Display width (1440p)
alias DISPLAY_HEIGHT: Int = 1440 # Display height
alias INITIAL_DENSITY: Float64 = 0.15 # Random fill densityBoth sub-projects leverage:
- AVX-512 SIMD: 64-byte aligned buffers for vectorized processing
- Double-buffering: Ping-pong buffers for zero-copy generation swaps
- Native GPU kernels: Mojo's GPU programming model for direct CUDA execution
- Zero-copy rendering: numpy views over Mojo memory for efficient Python interop
Typical performance on RTX-class GPUs:
- Row CA: 200M+ cells generated in <1s
- grid: 8M+ cells/generation at 60+ FPS (GPU mode)
MIT