How __shared__ is working in the following code?
<p>I am not getting line no 9 and 10; the index being used and calculated via the formula <code>Col + (m*TILE_WIDTH + ty)*Width</code>.</p>

<p>Can someone help me in understanding this code, i.e. the use of <code>__shared__</code>?</p>

<pre><code>__global__ void MatrixMulKernel(float* Md, float* Nd, float* Pd, int Width) 
{ 
 __shared__float Mds[TILE_WIDTH][TILE_WIDTH];
 __shared__float Nds[TILE_WIDTH][TILE_WIDTH];
 3.  int bx = blockIdx.x;  int by = blockIdx.y; 
 4.  int tx = threadIdx.x; int ty = threadIdx.y;
 // Identify the row and column of the Pd element to work on 
 5.  int Row = by * TILE_WIDTH + ty; 
 6.  int Col = bx * TILE_WIDTH + tx; 
 7.   float Pvalue = 0; ; 
 // Loop over the Md and Nd tiles required to compute the Pd element  
 8.   for (int m = 0; m &lt; Width/TILE_WIDTH; ++m) {
 // Coolaborative loading of Md and Nd tiles into shared memory 
 9.Mds[ty][tx] = Md[Row*Width + (m*TILE_WIDTH + tx)];
 10.Nds[ty][tx] = Nd[Col + (m*TILE_WIDTH + ty)*Width]; 
 11.__syncthreads();
 11.   for (int k = 0; k &lt; TILE_WIDTH; ++k) 
 12.Pvalue += Mds[ty][k] * Nds[k][tx];
 13.   Synchthreads();
  }
  Pd[Row*Width+Col] = Pvalue; 
  }
</code></pre>