Drawing GPU Blocks and Threads with TikZ

Although I only know the very basics of TikZ, I like what it can do and how it does it, so I try to use it whenever I can. Some time ago I used it in a paper to explain how the processing was divided between blocks and threads of a GPU and I was happy with the result, so I would like to share it here.

I wanted to express the idea that one GPU block would be responsible to process a line of a matrix and that the threads in the block would operate over the elements of this line. I tried to represent a block as a square, but I think it loses a bit of the idea that the blocks can have more than two dimensions. So the decision was to use a cube to represent a GPU block.

The cube I ended up using was found in an answer from StackExchange and I take no credit for it. The author made it easy to create a cube by using a macro (tikzcuboid) that I modified a bit (the complete source is available at GitHub):

        emphstyle=ultra thin,

Although there are a few more options to change (scale, dimensions, etc), with this macro you call it by simply passing a color:


The result should be like this picture:


Recently I found a simpler way to draw a cube from another answer from StackExchange:

      \shade[yslant=-0.5,right color=gray!10, left color=black!50]
      (0,0) rectangle +(3,3);
      \draw[yslant=-0.5] (0,0) grid (3,3);
      \shade[yslant=0.5,right color=gray!70,left color=gray!10]
      (3,-3) rectangle +(3,3);
      \draw[yslant=0.5] (3,-3) grid (6,0);
      \shade[yslant=0.5,xslant=-1,bottom color=gray!10,
        top color=black!80] (6,3) rectangle +(-3,-3);
      \draw[yslant=0.5,xslant=-1] (3,0) grid (6,3);

To insert this second cube, you can call this macro by passing the size (in pt). This may not be the best way to resize it, but it works for this example:


The result is a cube a bit different from the other (it’s a bit rotated for example):


As for drawing a thread, I used my elementary TikZ skills to bend a line a few times:

      \draw[very thick,color=#1] plot [smooth,tension=1.5] coordinates{(0.3,0.5) (0.25,0.37) (0.3,0.25) (0.25,0.12)};

To call it you also just pass the color:


The result looks like a thread (at least in my eyes):


By drawing these figures on the side of a matrix I believe it helped explain how the processing is done in a better way:

Screen Shot 2016-10-07 at 21.34.04.png

I think there are other ways to explain this idea in a paper or other ways to draw it, and the comments are open for suggestions.

As mentioned, the code used in the examples is available at GitHub.



Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s