# Max threads per block & Max thread dimensions

**URL:** <https://forums.developer.nvidia.com/t/max-threads-per-block-max-thread-dimensions/20771>\
**Category:** CUDA Programming and Performance\
**Created:** [January 29, 2011, 11:34pm UTC](https://forums.developer.nvidia.com/t/max-threads-per-block-max-thread-dimensions/20771 "2011-01-29T23:34:19Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jjosh7](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@jjosh7](https://forums.developer.nvidia.com/u/jjosh7)\
**Post date:** [January 29, 2011, 11:34pm UTC](https://forums.developer.nvidia.com/t/max-threads-per-block-max-thread-dimensions/20771/1 "2011-01-29T23:34:19Z")

</div>

Hi,

I am trying to do an example from the book “Cuda by Example”.

--------- This works fine when included with the rest of code ------------------

#define N 65535  
#define THREADS\_PER\_BLOCK 512

add\<\<\<((N/THREADS\_PER\_BLOCK)),THREADS\_PER\_BLOCK\>\>\>(dev\_a, dev\_b, dev\_c);

* * *

I ran another example from this book, which gave these numbers

Max threads per block: 512  
Max thread dimensions: (512, 512, 64)  
Max grid dimensions: (65535, 65535, 1)

How do these numbers ( Max threads per block, Max thread dimensions ,Max grid dimensions ) translate into these ( N, THREADS\_PER\_BLOCK ) ?

Does that mean, we can have N = 65535 \* 65535, THREADS\_PER\_BLOCK = 512 \* 512 \* 64

How are Max threads per block, Max thread dimensions ,Max grid dimensions related ?

Thanks.

---

<div class="post-metadata">

**Author:** ![kamsandh](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@kamsandh](https://forums.developer.nvidia.com/u/kamsandh)\
**Post date:** [January 30, 2011, 12:53pm UTC](https://forums.developer.nvidia.com/t/max-threads-per-block-max-thread-dimensions/20771/2 "2011-01-30T12:53:50Z")

</div>

Maximum threads per block is 512 It may be arranged in any ways , as one dimensional , in this case maximum 512 , or two dimensional , then Bx_By=512 is maximum , or three dimensional , Bx_By\*Bz=512 is maximum . Here maximum threads per dimension means , if we have a one dimensional block , it can have 512 elements and can be in Xdrection or Ydirecton . But if we have 3 dimensional block , the 3rd dimention should not exceed 64 , and obviously , the other dimensions are determined by the constraint of maximimum 512 .

So in principle , we can have 65535_65535_512 threads at a time .  
I think you are considering only one dimensional blocks . So N=65535, threadsperblock=512 are the maxima.

---

<div class="post-metadata">

**Author:** ![jjosh7](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@jjosh7](https://forums.developer.nvidia.com/u/jjosh7)\
**Post date:** [January 31, 2011, 2:53pm UTC](https://forums.developer.nvidia.com/t/max-threads-per-block-max-thread-dimensions/20771/3 "2011-01-31T14:53:31Z")

</div>

Thank you.

I was trying another example

* * *

#define N (2048 \* 2048)  
#define THREADS\_PER\_BLOCK 512

add\<\<\<((N/THREADS\_PER\_BLOCK)),THREADS\_PER\_BLOCK\>\> \>(dev\_a, dev\_b, dev\_c);

* * *

I am getting a stack overflow error. When I use N = 65535, it works fine.

Thanks.
