Skip to content

WIP: Game of Life example#3208

Draft
bkmgit wants to merge 1 commit into
google:masterfrom
bkmgit:gol
Draft

WIP: Game of Life example#3208
bkmgit wants to merge 1 commit into
google:masterfrom
bkmgit:gol

Conversation

@bkmgit

@bkmgit bkmgit commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Game of life example to demonstrate stencil computations and computations using arrays of bits.

std::vector(bool) cannot be used and so hw::AlignedVector(bool) cannot also be used.

Could possibly output results as uncompressed animated gif or animated Lottie json files

@jan-wassenberg jan-wassenberg left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a good framework :)
If you'd like to start vectorizing already, I think SlideUpLanesOr is a good way to get right neighbors, for up/down it's just loading previous row, and for left we can use LoadU(d, ptr-1).

const size_t nx = 60;
const size_t ny = 60;
const size_t iterations = 100;
bool* a = (bool*)malloc(nx*ny*sizeof(bool));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer AlignedFreeUniquePtr<uint8_t[]> ptr = AllocateAligned<uint8_t>(num); - this avoids leaks, and is vector-aligned.

@bkmgit

bkmgit commented Jul 17, 2026

Copy link
Copy Markdown
Contributor Author

A straight forward SIMD implementation is described at:
https://lemire.me/blog/2018/07/18/accelerating-conways-game-of-life-with-simd-instructions/

However, bit operations seem to be the way to go:
https://binary-banter.github.io/game-of-life/

This maybe a good extended example, but might not be quite so helpful for demonstrating stencil computations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants