Two implementations of "Generalization of Conway's "Game of Life" to a continuous domain - SmoothLife" written in Swift for the iPhone. Firstly, this repository contains a CPU implementation using vDSP for optimized matrix arithmetic and FFT. Secondly, the repository contains a GPU implementation written fully in Metal shading language, including the FFT.
I started this project to learn a bit about numeric computation on the GPU and other specialized hardware in a fun way. And also, I think looking at SmoothLife is just mesmerizing.
My implementation took inspiration from the original C++ implementation by the paper's author Stephan Rafler, a Python implementation by Sean Murphy, and a Dart/WebGL implementation by Robert Muth (live version, blog article). This blogpost by Mikola Lysenko was a great help as well.
The codebase also includes a simple implementation of the orignal Game of Life written in Metal shading language.
Written in Swift 5.3.2 using Xcode 12.3 for iOS 14.3.
The original SmoothLife C++ implementation has a configuration file in which you can specify certain paramters. This implementation defaults to the same parameters used by Robert Muth in his implementation. Resulting in nice gliders and wires.
2 2 12.0 4.0 12.0 0.100 0.254 0.312 0.340 0.518 2 0 0 0.0 0.0
An important part of the implementation is the quick application of convolutions by multiplying in the frequency domain. This requires transforming a representation to the frequency domain and back again using the fast Fourier transform. Using this trick we can apply convolutions in O(n log(n))
instead of O(n^2)
. Generally, FFT algorithms have the constraint that n
needs to be a power of 2, e.g. 2^8 = 256
. This is why our field's dimenstions are a power of two.
For the GPU implementation I needed to write an FFT in Metal shading language. This allows running the full SmoothLife algorithm on the GPU without going back for the CPU to call vDSP. You can find the standalone Metal FFT implementation here.