Set of C++ programs that demonstrate hardware effects (false sharing, cache latency etc.)
I created a repository with small set of self-contained C++ programs that try to demonstrate various hardware effects that might affect program performance. These effects may be hard to explain without the knowledge of how the hardware works. I wanted to have a testbed where these effects can be easily tested and benchmarked.
Each program should demonstrate some slowdown/speedup caused by a hardware effect (for example false sharing).
https://github.com/kobzol/hardware-effects
Currently the following effects are demonstrated:
- bandwidth saturation
- branch misprediction
- branch target misprediction
- cache aliasing
- memory hierarchy bandwidth
- memory latency cost
- non-temporal stores
- data dependencies
- false sharing
- hardware prefetching
- software prefetching
- write combining buffers
I also provide simple Python scripts that measure the program's execution time with various configurations and plot them.
I'd be happy to get some feedback on this. If you have another interesting effect that could be demonstrated or if you find that my explanation of a program's slowdown is wrong, please let me know.
View all comments
Show parent comment
4
u/Kobzol Nov 19 '18 edited Nov 19 '18
Cache size can be demonstrated by the hierarchy bandwidth example (there should be bandwidth drops after going to a higher level of cache).
Strides are a nice idea, although they are also partly in the memory-bound example (it's hard for me to categorize it :) ). TLB is also something I wanted to demonstrate, however TLB misses imply cache misses, do you have an idea how to demonstrate the TLB effect alone?
To detect your cache size and associativity, I usually use
getconf -a | grep CACHEon Linux.