title: How much memory can I declare as tile_static?
body: <p>I am currently in the process of tiling my c++ AMP Code. For each tile, I have 4096 bytes of data which are read from frequently, so I would like to declare this as tile_static. It is not practical to divide this into multiple tiles, as each thread requires access to all of the data. My tiles consist of 128 threads, so they should take up 2-4 warps on Nvidia/AMD GPUs.</p>
  
  <p>I just read the following article, which seems to suggest that I can only use 1024 bits in tile_static per warp:
  <a href="http://blogs.msdn.com/b/nativeconcurrency/archive/2012/08/14/avoid-bank-conflicts-on-tile-static-memory-with-c-amp.aspx" rel="nofollow noreferrer">http://blogs.msdn.com/b/nativeconcurrency/archive/2012/08/14/avoid-bank-conflicts-on-tile-static-memory-with-c-amp.aspx</a></p>
  
  <blockquote>
    <p>On some modern GPUs, tile_static memory consists of “n” equally sized
    memory banks which can be accessed simultaneously, and successive
    “m”-bit words are mapped to successive memory banks. The exact
    organization of tile_static memory (i.e. n and m) is hardware
    dependent. For example, on an Nvidia GTX 580 card or an ATI HD 5870
    card, tile_static memory has <strong>32 banks (n = 32) that are organized such
    that successive 32-bit words (m = 32) map to successive memory banks</strong>.
    Note that n might be different from hardware to hardware, m is usually
    32. In the rest of the post, I will assume m is 32.</p>
  </blockquote>
  
  <p>Does this mean that I can declare up to 1024bits per warp, or per thread? Are all tile_static variables shared between warps, or does each warp have its own copy? </p>
  
  <p>How much of these questions are hardware-dependent, and if so, how can I find out the limitations at runtime? </p>
  
  <p>I have read <a href="https://rads.stackoverflow.com/amzn/click/com/0735664730" rel="nofollow noreferrer" rel="nofollow noreferrer">a c++ AMP book cover to cover</a>, and while I am thankful to the authors for introducing me to the subject, it did not seem to address this question (or if it did, I didn't understand it).</p>
  
  <p>There is a wealth of info online about how to use tile_static memory (this one is a good start: <a href="http://www.danielmoth.com/Blog/tilestatic-Tilebarrier-And-Tiled-Matrix-Multiplication-With-C-AMP.aspx" rel="nofollow noreferrer">http://www.danielmoth.com/Blog/tilestatic-Tilebarrier-And-Tiled-Matrix-Multiplication-With-C-AMP.aspx</a>) but no one seems to talk about how much we can declare, making it impossible to actually implement any of this stuff! That last link gives the following example:</p>
  
  <pre><code>01: void MatrixMultiplyTiled(vector&lt;float&gt;&amp; vC, 
           const vector&lt;float&gt;&amp; vA, 
           const vector&lt;float&gt;&amp; vB, int M, int N, int W)
  02: {
  03:   static const int TS = 16;
  
  04:   array_view&lt;const float,2&gt; a(M, W, vA);
  05:   array_view&lt;const float,2&gt; b(W, N, vB);
  06:   array_view&lt;float,2&gt; c(M,N,vC); c.discard_data();
  
  07:   parallel_for_each(c.extent.tile&lt; TS, TS &gt;(),
  08:   [=] (tiled_index&lt; TS, TS&gt; t_idx) restrict(amp) 
  09:   {
  10:     int row = t_idx.local[0]; int col = t_idx.local[1];
  11:     float sum = 0.0f;
  
  12:     for (int i = 0; i &lt; W; i += TS) {
  13:        tile_static float locA[TS][TS], locB[TS][TS];
  14:        locA[row][col] = a(t_idx.global[0], col + i);
  15:        locB[row][col] = b(row + i, t_idx.global[1]);
  16:        t_idx.barrier.wait();
  
  17:        for (int k = 0; k &lt; TS; k++)
  18:          sum += locA[row][k] * locB[k][col];
  
  19:        t_idx.barrier.wait();
  20:     }
  
  21:     c[t_idx.global] = sum;
  22:   });
  23: }
  </code></pre>
  
  <p>Note that line 13 declares 2x 1024 bits, which makes me hopeful that my 4096 bits isn't too much to ask for.... If anyone with some experience in c++ amp or GPU programming in general could help me out that would be great - I imagine these questions are more dependent on hardware/implementation than the AMP language extension itself...</p>