# Block dim discussion 1D vs 2D

**URL:** <https://forums.developer.nvidia.com/t/block-dim-discussion-1d-vs-2d/1224>\
**Category:** CUDA Programming and Performance\
**Created:** [July 30, 2007, 10:35am UTC](https://forums.developer.nvidia.com/t/block-dim-discussion-1d-vs-2d/1224 "2007-07-30T10:35:46Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![clement\_k](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@clement\_k](https://forums.developer.nvidia.com/u/clement_k)\
**Post date:** [July 30, 2007, 10:35am UTC](https://forums.developer.nvidia.com/t/block-dim-discussion-1d-vs-2d/1224/1 "2007-07-30T10:35:46Z")

</div>

I’ve tested my kernels and saw that the same code running on 2D blocks went faster than 1D blocks, when the blocks have the same number of threads.  
My question is why ? (if any has the answer)

---

<div class="post-metadata">

**Author:** ![Jeff\_hagen](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@Jeff\_hagen](https://forums.developer.nvidia.com/u/Jeff_hagen)\
**Post date:** [July 30, 2007, 11:53pm UTC](https://forums.developer.nvidia.com/t/block-dim-discussion-1d-vs-2d/1224/2 "2007-07-30T23:53:02Z")

</div>

I have not seen any difference in any of the kernels I’ve tested.

Are your kernels compute or memory bound?

---

<div class="post-metadata">

**Author:** ![clement\_k](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@clement\_k](https://forums.developer.nvidia.com/u/clement_k)\
**Post date:** [July 31, 2007, 7:15am UTC](https://forums.developer.nvidia.com/t/block-dim-discussion-1d-vs-2d/1224/3 "2007-07-31T07:15:28Z")

</div>

> [@](#):
>
> Are your kernels compute or memory bound?
> 
> [snapback]230593[/snapback]

They spent most of their time doing computing, with some memory accesses.

They follow the MatrixMul example pattern : loading data into shared memory, computing the results, writing it back to global memory.

---

<div class="post-metadata">

**Author:** ![PINS](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@PINS](https://forums.developer.nvidia.com/u/PINS)\
**Post date:** [July 31, 2007, 7:38am UTC](https://forums.developer.nvidia.com/t/block-dim-discussion-1d-vs-2d/1224/4 "2007-07-31T07:38:10Z")

</div>

Are you reading data from texture to shared memory? Since texture memory is optimized for 2D locality, the hardware architecture might give you a better cache utilization with 2D blocks. Specially if you have several stages like: reading to shared memory, computing and uploading back to texture memory.

Although I’m not sure if it should improve your writes to texture memory as well…

---

<div class="post-metadata">

**Author:** ![clement\_k](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@clement\_k](https://forums.developer.nvidia.com/u/clement_k)\
**Post date:** [July 31, 2007, 12:43pm UTC](https://forums.developer.nvidia.com/t/block-dim-discussion-1d-vs-2d/1224/5 "2007-07-31T12:43:42Z")

</div>

> [@](#):
>
> Are you reading data from texture to shared memory? [snapback]230745[/snapback]

Yeah, I use texture memory. First, I did not notice any speed up when using 1D blocks. But with 2D blocks, the hardware architecture is involved, for sure. But I haven’t tried to right back into texture memory, I use the global memory pointer instead.

Good idea to test, thanx for the suggestion…

---

<div class="post-metadata">

**Author:** ![PINS](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@PINS](https://forums.developer.nvidia.com/u/PINS)\
**Post date:** [August 5, 2007, 8:44pm UTC](https://forums.developer.nvidia.com/t/block-dim-discussion-1d-vs-2d/1224/6 "2007-08-05T20:44:50Z")

</div>

> [@](#):
>
> Although I’m not sure if it should improve your writes to texture memory as well…
> 
> [snapback]230745[/snapback]

Sorry clement, I meant to say global memory instead of texture memory, which is read only (as you may already know) :blink:

The reasoning I was talking about would be that the texture cache would alleviate the memory bus from reads and, therefore, you would get a better performance when writing to global memory.

---

<div class="post-metadata">

**Author:** ![clement\_k](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@clement\_k](https://forums.developer.nvidia.com/u/clement_k)\
**Post date:** [August 7, 2007, 7:28am UTC](https://forums.developer.nvidia.com/t/block-dim-discussion-1d-vs-2d/1224/7 "2007-08-07T07:28:56Z")

</div>

Ok, thank you dude !

---

<div class="post-metadata">

**Author:** ![Archer](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@Archer](https://forums.developer.nvidia.com/u/Archer)\
**Post date:** [August 14, 2007, 5:49am UTC](https://forums.developer.nvidia.com/t/block-dim-discussion-1d-vs-2d/1224/8 "2007-08-14T05:49:48Z")

</div>

> [@](#):
>
> I’ve tested my kernels and saw that the same code running on 2D blocks went faster than 1D blocks, when the blocks have the same number of threads.
> 
> My question is why ? (if any has the answer)
> 
> [snapback]230206[/snapback]

Can you tell us how much performance improvement you get using 2D blocks instead 1D block?

---

<div class="post-metadata">

**Author:** ![clement\_k](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@clement\_k](https://forums.developer.nvidia.com/u/clement_k)\
**Post date:** [August 14, 2007, 7:43am UTC](https://forums.developer.nvidia.com/t/block-dim-discussion-1d-vs-2d/1224/9 "2007-08-14T07:43:07Z")

</div>

On a run with 65536 cells, it took 75s instead of 90s (17% faster). I haven’t tested with a higher number of cells (because other problems appeared), but I think larger domain would give better improvement.

I wonder if using 16x16 blocks makes less bank acess conflicts than 256x1 blocks…
