3 ms·
I have an 'art/game' project in Rust that uses vectorized expression evaluation to draw random images. It turns the expression tree into a stack machine then e
by gameswithgo 7y ago
I have an 'art/game' project in Rust that uses vectorized expression evaluation to draw random images. It turns the expression tree into a stack machine then evaluates the stack machine with SIMD instructions:
https://github.com/jackmott/evolution/blob/master/src/stack_machine.rs https://github.com/jackmott/evolution/blob/master/src/stack_...
The speedup is really big for this case sometimes because not only do you do math 4x/8x/16x faster (depending on instruction set) but you also traverse the stack machine (or tree if you are pure interpreting) 4x/8x/16x less often. The improvement when traversing a tree is extra extra big because of reduced memory hops.
I used a SIMD library I made in Rust, which lets me write the stack machine once, and then run it in SSE2/SSE41 or AVX2 mode. You can select either at runtime or compile time:
https://github.com/jackmott/simdeez https://github.com/jackmott/simdeez
- dahart 7y agoSounds cool, do you have a gallery? I had a similar sounding project inspired by Karl Sims’ genetic images that I haven’t touched for many years now, but I’ve been meaning to revive and compile to GLSL or CUDA to get (I expect) much faster eval than is possible with CPU AVX or SSE instructions. Have you considered that route?
- gameswithgo 7y agothe readme has some examples: https://github.com/jackmott/evolution https://github.com/jackmott/evolution Not really enough to show off the full range of possibilities but it is a start. The program is still a WIP I'll release it eventually.
- dahart 7y agoVery cool, thanks for the link! The cell & fbm primitives look really useful. The only complex primitive like that I included so far was Perlin turbulence. If you’re interested, here’s a sampling of mine, https://flickr.com/photos/biv4b/albums/576553 https://flickr.com/photos/biv4b/albums/576553 I haven’t gotten around to any vectorized evaluation yet, it’s pure CPU recursive eval, the closest thing I did was to use multiple threads, but it’s not particularly fast compared to what a GPU would do.
- gameswithgo 7y agothose look really nice, id be interested to know what primitives you have and how you compose them
- dahart 7y agoSure, I happen to have written those things up in a paper; it’s a fairly simple & constrained set. The composing part is also fairly standard though I came up with a couple of new mutation strategies that seemed useful. http://dahart.com/paper/hart_evomusart_2007_paper.pdf http://dahart.com/paper/hart_evomusart_2007_paper.pdf You can ignore most of that unless you’re interested in animating evolved expressions; the primitives & mutations are summed up in the first few pages.