aben20807 / mmul-anim

Visualization of cache-optimized matrix multiplication

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Visualization of cache-optimized matrix multiplication

The code in this repository generates animations visualizing algorithms for cache-optimized matrix multiplication. Generated animations are available on YouTube. One frame from the animation is shown below.

Example

To generate the animations, simply run make (legacy, only available at 379bf8).

Dependencies:

  • python3-cairo (pip install pycairo)
  • ffmpeg (choco install ffmpeg in windows)

How to run the modified version:

  • The default settings only perform a dry run and print the cache hit rate
  • Use -t pdf (fast) or -t mp4 (slow) to generate the visualization output
  • Use --L1 0 to utilize a one-level cache instead of a two-level cache
$ python matrix_mul.py --help
usage: matrix_mul.py [-h] [--matrix-size SIZE] [--transpose] [--cache-line SIZE] [--L1 SIZE]
                     [--L2 SIZE] [--func {,vc,v0,v1,v2,v3,v3_5}] [--block1 SIZE] [--block2 SIZE]
                     [--no-memory] [--title TITLE] [--subtitle SUBTITLE] [--output PATH]
                     [--type {dry,pdf,mp4}] [--max-frame NUM] [--no-auto-correct-extension]
                     [--framerate FRAMERATE]

Visualization of cache-optimized matrix multiplication

options:
  -h, --help            show this help message and exit
  --matrix-size SIZE    n of the n-by-n matrix (default: 16)
  --transpose           Transpose matrix B (default: False)
  --cache-line SIZE     number of elements for each cache line, must be power of 2 (default: 4)
  --L1 SIZE             number of cache lines in L1 cache (default: 4)
  --L2 SIZE             number of cache lines in L2 cache (default: 16)
  --func {,vc,v0,v1,v2,v3,v3_5}
                        Computing function (default: vc)
  --block1 SIZE         Inner block size (default: 16)
  --block2 SIZE         Outer block size (default: 8)
  --no-memory           Do not draw memory (default: False)
  --title TITLE
  --subtitle SUBTITLE
  --output PATH, -o PATH
                        Output file path (default: matrix_mul.pdf)
  --type {dry,pdf,mp4}, -t {dry,pdf,mp4}
                        The type of the output file (default: dry)
  --max-frame NUM       The max number of frames to be generated (default: None)
  --no-auto-correct-extension
                        Do not correct the extension automatically (default: False)
  --framerate FRAMERATE
                        mp4 framerate (default: 24)

About

Visualization of cache-optimized matrix multiplication

License:GNU General Public License v3.0


Languages

Language:Python 96.8%Language:Makefile 3.2%