# Example of Matrix multiplication

**URL:** <https://forums.developer.nvidia.com/t/example-of-matrix-multiplication/15177>\
**Category:** CUDA Programming and Performance\
**Created:** [February 26, 2010, 3:18pm UTC](https://forums.developer.nvidia.com/t/example-of-matrix-multiplication/15177 "2010-02-26T15:18:07Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![kemu](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@kemu](https://forums.developer.nvidia.com/u/kemu)\
**Post date:** [February 26, 2010, 3:18pm UTC](https://forums.developer.nvidia.com/t/example-of-matrix-multiplication/15177/1 "2010-02-26T15:18:07Z")

</div>

hi all,

i have a question about data teiling in the Matrix muliplication SDK.  
The Code for data tiling from device memory to shared memory is following:

//code from SDK  
for (int a = aBegin, b = bBegin;a \<= aEnd;a += aStep, b += bStep) {  
**shared** float As[BLOCK\_SIZE][BLOCK\_SIZE]; //Block\_size = 3  
**shared** float Bs[BLOCK\_SIZE][BLOCK\_SIZE];

```
    AS(ty, tx) = A[a + wA * ty + tx];
    BS(ty, tx) = B[b + wB * ty + tx];

    __syncthreads();
    ....
}

```

In the example the same amount tiling data from both matrix, A and B, is copied. Now I want to copy for example a 3_3 Block from A, but 5_5 Block from B each time. The both tilings have the same centre.  
How can i execute now the threads? I’m some deluded with the threadIDs…

This is a figure about the question:

 ![matrixQ.png](https://global.discourse-cdn.com/nvidia/original/2X/e/e574d136b7909f650429a45793bc0c175c58ad01.png)

---

<div class="post-metadata">

**Author:** ![kemu](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@kemu](https://forums.developer.nvidia.com/u/kemu)\
**Post date:** [February 26, 2010, 3:28pm UTC](https://forums.developer.nvidia.com/t/example-of-matrix-multiplication/15177/2 "2010-02-26T15:28:55Z")

</div>

i think, maybe i need tow loops, which have different “begin” and “end” like:

for (int a = aBegin;a \<= aEnd;a += aStep) {  
**shared** float As[BLOCK\_SIZE\_A][BLOCK\_SIZE\_A]; //Block\_size\_A = 3

```
    AS(ty, tx) = A[a + wA * ty + tx];

    __syncthreads();
    ....
}

```

for (int b = bBegin;b \<= bEnd; b += bStep) {  
**shared** float As[BLOCK\_SIZE\_B][BLOCK\_SIZE\_B]; //Block\_size\_B = 5

```
    BS(ty, tx) = B[b + wB * ty + tx];

    __syncthreads();
    ....
}

```

Is that right?
