# max matrix size in matrix multiplication matrix example in programming guide

**URL:** <https://forums.developer.nvidia.com/t/max-matrix-size-in-matrix-multiplication-matrix-example-in-programming-guide/1765>\
**Category:** CUDA Programming and Performance\
**Created:** [November 4, 2007, 11:24pm UTC](https://forums.developer.nvidia.com/t/max-matrix-size-in-matrix-multiplication-matrix-example-in-programming-guide/1765 "2007-11-04T23:24:25Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![timtimac](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@timtimac](https://forums.developer.nvidia.com/u/timtimac)\
**Post date:** [November 4, 2007, 11:24pm UTC](https://forums.developer.nvidia.com/t/max-matrix-size-in-matrix-multiplication-matrix-example-in-programming-guide/1765/1 "2007-11-04T23:24:25Z")

</div>

Hi,

On page 64 of programming guide 1.0, it says “The maximum number of blocks that can run concurrently on a multiprocessor is 8” and “The maximum number of warps that can concurrently on a multiprocessor is 24”. Does it mean the maxiumum number of blocks is 8\*16=128 on a 8800 GTX? Then, it greatly limits the size of the matrix multiplication on page 59-61.

Using that algorithm, one block is 16_16 threads (and also the number of elements of submatrix), so even for A: 800_800 and B:800_800, it is too much. Because it has (800/16)_(800/16) blocks(that is 2500).

I tried it on the gpu, but it still produce the right answer. However, if I try 8000_8000 multiply 8000_8000, it produce all 0 and never stop.

I want to test the FLOPS of GPU, so I need a big matrix multiplication. But with the constraints mentioned above, I can only make wA bigger. Something like 128_800000 multiply 800000_96. In that case, it produces the right answer, but if I change wA to 960000, then it is segmentation fault. Any idea why?

Many thanks,

Timtimac

---

<div class="post-metadata">

**Author:** ![MisterAnderson42](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@MisterAnderson42](https://forums.developer.nvidia.com/u/MisterAnderson42)\
**Post date:** [November 5, 2007, 12:26am UTC](https://forums.developer.nvidia.com/t/max-matrix-size-in-matrix-multiplication-matrix-example-in-programming-guide/1765/2 "2007-11-05T00:26:54Z")

</div>

> [@](#):
>
> Hi,
> 
> On page 64 of programming guide 1.0, it says “The maximum number of blocks that can run concurrently on a multiprocessor is 8” and “The maximum number of warps that can concurrently on a multiprocessor is 24”. Does it mean the maxiumum number of blocks is 8\*16=128 on a 8800 GTX? Then, it greatly limits the size of the matrix multiplication on page 59-61.
> 
> Using that algorithm, one block is 16_16 threads (and also the number of elements of submatrix),&nbsp; so even for A: 800_800 and B:800_800, it is too much. Because it has (800/16)_(800/16) blocks(that is 2500).
> 
> I tried it on the gpu, but it still produce the right answer. However, if I try 8000_8000 multiply 8000_8000, it produce all 0 and never stop.
> 
> I want to test the FLOPS of GPU, so I need a big matrix multiplication. But with the constraints mentioned above, I can only make wA bigger. Something like 128_800000 multiply 800000_96. In that case, it produces the right answer, but if I change wA to 960000, then it is segmentation fault. Any idea why?
> 
> Many thanks,
> 
> Timtimac
> 
> [snapback]274964[/snapback]

The only limitation in the number of blocks that can be run is the grid dimensions (65535x 65535)… though I wouldn’t want to try and run such a big grid. The limit you quote from the guide is the maximum number that can run concurrently. That is, all of the warps are on a multiproc and being time sliced. The blocks are aren’t currently running sit in a scheduler pool or something and are started up on a multiproc when there is a slot.

For the matrix multiply example, you should be able to push the dimensions as big as there is memory for.

---

<div class="post-metadata">

**Author:** ![mfatica](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@mfatica](https://forums.developer.nvidia.com/u/mfatica)\
**Post date:** [November 5, 2007, 1:09am UTC](https://forums.developer.nvidia.com/t/max-matrix-size-in-matrix-multiplication-matrix-example-in-programming-guide/1765/3 "2007-11-05T01:09:24Z")

</div>

If you want to benchmark SGEMM, use the cublas library.  
It is faster and the size of the matrices is limited only by the amount of memory on the card. For best performance, the size should be a multiple of 32.

---

<div class="post-metadata">

**Author:** ![timtimac](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@timtimac](https://forums.developer.nvidia.com/u/timtimac)\
**Post date:** [November 5, 2007, 2:35am UTC](https://forums.developer.nvidia.com/t/max-matrix-size-in-matrix-multiplication-matrix-example-in-programming-guide/1765/4 "2007-11-05T02:35:15Z")

</div>

“About pushing dimensions as big as there is memory for”, since a thread block of 16_16 would use around 16_16_4_2=2kb of shared memory, and there is only 16kb per multiprocessor, does that mean I can only have 16/2 \* 16 = 128 blocks? Or I could have more than that because some sitting in the scheduler pool won’t count for the shared memory? (but we will not know for how long the blocks in the pool will wait, until the ones being time sliced all terminate?)

> [@](#):
>
> The only limitation in the number of blocks that can be run is the grid dimensions (65535x 65535)… though I wouldn’t want to try and run such a big grid. The limit you quote from the guide is the maximum number that can run concurrently. That is, all of the warps are on a multiproc and being time sliced. The blocks are aren’t currently running sit in a scheduler pool or something and are started up on a multiproc when there is a slot.
> 
> For the matrix multiply example, you should be able to push the dimensions as big as there is memory for.
> 
> [snapback]274983[/snapback]

---

<div class="post-metadata">

**Author:** ![timtimac](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@timtimac](https://forums.developer.nvidia.com/u/timtimac)\
**Post date:** [November 5, 2007, 2:51am UTC](https://forums.developer.nvidia.com/t/max-matrix-size-in-matrix-multiplication-matrix-example-in-programming-guide/1765/5 "2007-11-05T02:51:37Z")

</div>

on page 60 of programming guide,

```auto
__global__ void Muld(...) {

.......

for (int a = aBegin, b=bBegin; a<=aEnd; a+=aStep, b+=bStep) {

__shared__ float As[BLOCK_SIZE][BLOCK_SIZE];

__shared__ float Bs[BLOCK_SIZE][BLOCK_SIZE];

........

}

........

}

```

Does it matter whether I move the **shared** memory float array As and Bs before the for loop?

What I don’t understand here is that it seems to me every thread declare As and Bs many times instead of as a block declaration. Since shared memory is used by all block within the same multiprocessors, does anyone know how nvcc handle this kind of declaration?

> [@](#):
>
> The only limitation in the number of blocks that can be run is the grid dimensions (65535x 65535)… though I wouldn’t want to try and run such a big grid. The limit you quote from the guide is the maximum number that can run concurrently. That is, all of the warps are on a multiproc and being time sliced. The blocks are aren’t currently running sit in a scheduler pool or something and are started up on a multiproc when there is a slot.
> 
> For the matrix multiply example, you should be able to push the dimensions as big as there is memory for.
> 
> [snapback]274983[/snapback]

---

<div class="post-metadata">

**Author:** ![jordyvaneijk](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@jordyvaneijk](https://forums.developer.nvidia.com/u/jordyvaneijk)\
**Post date:** [November 5, 2007, 7:51am UTC](https://forums.developer.nvidia.com/t/max-matrix-size-in-matrix-multiplication-matrix-example-in-programming-guide/1765/6 "2007-11-05T07:51:23Z")

</div>

> [@](#):
>
> “About pushing dimensions as big as there is memory for”, since&nbsp; a thread block of 16_16 would use around 16_16_4_2=2kb of shared memory, and there is only 16kb per multiprocessor, does that mean I can only have 16/2 \* 16 = 128 blocks? Or I could have more than that because some sitting in the scheduler pool won’t count for the shared memory? (but we will not know for how long the blocks in the pool will wait, until the ones being time sliced all terminate?)
> 
> [snapback]275027[/snapback]

I think thats not completely true. You don’t load all the matrixes in the shared memory. then you have that limitation. This is good for submatrices i think.

Cheers, Jordy

---

<div class="post-metadata">

**Author:** ![timtimac](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@timtimac](https://forums.developer.nvidia.com/u/timtimac)\
**Post date:** [November 5, 2007, 10:28pm UTC](https://forums.developer.nvidia.com/t/max-matrix-size-in-matrix-multiplication-matrix-example-in-programming-guide/1765/7 "2007-11-05T22:28:34Z")

</div>

Jordy, I don’t think I understand what you mean.

A submatrix in C (calculated by a thread block of 16\*16) needs to load 1kb of submatrix of A and 1kb of submatrix of B into shared memory. So when there are 16kb shared memory per multiprocessors in GTX, and 16 multiprocessors, does it mean matrix C can only have 16/(1+1)\*16=128 blocks? also each block has only 16 by 16 elements, which means the size of the matrix multiplication is very limited. Am i right?

Many thanks,

Timtimac

> [@](#):
>
> I think thats not completely true. You don’t load all the matrixes in the shared memory. then you have that limitation. This is good for submatrices i think.
> 
> Cheers, Jordy
> 
> [snapback]275101[/snapback]
