This project explores various implementations of Conway's Game of Life, each optimized using different computational approaches. The goal is to compare their performance characteristics across different problem sizes.
- File:
src/basic_gol.py
- Description: A straightforward Python implementation using nested loops for cell updates.
- Strengths: Simple to understand, no external dependencies.
- Weaknesses: Poor performance for large grids due to Python's interpreted nature.
- File:
src/conv_gol.py
- Description: Uses NumPy's convolution operation to compute neighbor counts.
- Strengths: Vectorized operations, better performance than basic Python.
- Weaknesses: Memory intensive for very large grids.
- File:
src/numba_gol.py
- Description: Uses Numba's JIT compilation to optimize the basic implementation.
- Strengths: Significant speedup over pure Python with minimal code changes.
- Weaknesses: Still runs on CPU, limited by single-threaded performance.
- File:
src/cuda_gol.py
- Description: GPU-accelerated implementation using Numba's CUDA capabilities.
- Strengths: Massive parallelization, best performance for large grids.
- Weaknesses: Requires CUDA-capable GPU, more complex implementation.
Approach | Mean Time per Iteration (s) | Relative Speed |
---|---|---|
Convolution | 30.84 | 1.0x (baseline) |
Numba | 0.76 | 40.6x faster |
CUDA | 0.43 | 71.7x faster |
Note: Basic implementaiton is not listed because it is too slow to run for the largest grid size.
-
Convolution vs Optimized Implementations:
- The convolution approach, while vectorized, is significantly slower than both Numba and CUDA implementations.
- This demonstrates the overhead of the convolution operation compared to direct neighborhood computation.
-
Numba Performance:
- Provides excellent speedup (40x) over the convolution approach.
- Performance scales linearly with problem size.
- Ideal for systems without GPU acceleration.
-
CUDA Performance:
- Delivers the best performance (71.7x faster than convolution).
- Shows superior scaling for larger problem sizes.
- The performance gap widens as the grid size increases.
- Shows performance across different grid sizes with logarithmic axes.
- Demonstrates the scaling behavior of each approach.
- Shows absolute performance differences between implementations.
- Makes it easier to see the performance gap at different scales.
- Direct comparison between the two fastest implementations.
- Highlights the advantage of GPU acceleration for this problem.
-
Performance Scaling:
- All implementations show roughly linear scaling with problem size.
- CUDA shows the most consistent performance improvements at larger scales.
-
Crossover Points:
- For very small grids, the overhead of GPU initialization makes the difference less significant.
- The performance advantage of CUDA becomes more pronounced as the grid size increases.
-
Practical Implications:
- For small to medium grids, Numba provides an excellent balance of performance and simplicity.
- For large-scale simulations, CUDA is the clear winner in terms of raw performance.
- Python 3.7+
- NumPy
- Numba
- CUDA Toolkit (for CUDA implementation)
- Matplotlib (for generating plots)
-
Install dependencies:
pip install numpy numba matplotlib
-
Run the performance benchmark:
cd src python run_exp.sh
-
Generate performance plots:
cd analysis python plot_performance.py output.csv
This project demonstrates how different computational approaches can significantly impact the performance of the Game of Life simulation. The choice of implementation should be based on the specific requirements of your application, considering factors like grid size, hardware availability, and development complexity.