# three dimensional indexing!

**URL:** <https://forums.developer.nvidia.com/t/three-dimensional-indexing/20544>\
**Category:** CUDA Programming and Performance\
**Created:** [January 14, 2011, 1:01pm UTC](https://forums.developer.nvidia.com/t/three-dimensional-indexing/20544 "2011-01-14T13:01:17Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![shadab](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@shadab](https://forums.developer.nvidia.com/u/shadab)\
**Post date:** [January 14, 2011, 1:01pm UTC](https://forums.developer.nvidia.com/t/three-dimensional-indexing/20544/1 "2011-01-14T13:01:17Z")

</div>

I am trying to set up three dimensional indexing using 2-D grid and 3-D blocks.

Following is indexing scheme used in my code:

```auto
LX=80; LY=80; LZ=32;

  TILE_I=8; TILE_J=8; TILE_K=4; 

dim3 grid = dim3(LX/TILE_I, LY/TILE_J);

  dim3 block = dim3(TILE_I, TILE_J, TILE_K );

int x = blockIdx.x*TILE_I + threadIdx.x;

  int y = blockIdx.y*TILE_J + threadIdx.y;

  int z = blockIdx.z*TILE_K + threadIdx.z;

  int idx= x+ y*LX+ z*LX*LY;

idx is global indexing for any thread.

```

It is important for me to know each thread in (x,y,z) co-ordinate.

This indexing scheming works ok for first 6400 (80x80) elements, for the 2-D indexing, but something

is wrong with indexing in Z direction.

Could you please help me debug this indexing problem.

Thanks

---

<div class="post-metadata">

**Author:** ![avidday](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/avidday/32/59219_2.png) [@avidday](https://forums.developer.nvidia.com/u/avidday)\
**Post date:** [January 14, 2011, 2:07pm UTC](https://forums.developer.nvidia.com/t/three-dimensional-indexing/20544/2 "2011-01-14T14:07:56Z")

</div>

Grids are only two dimensional in CUDA at present.

---

<div class="post-metadata">

**Author:** ![shadab](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@shadab](https://forums.developer.nvidia.com/u/shadab)\
**Post date:** [January 14, 2011, 2:17pm UTC](https://forums.developer.nvidia.com/t/three-dimensional-indexing/20544/3 "2011-01-14T14:17:58Z")

</div>

> [@](#):
>
> Grids are only two dimensional in CUDA at present.

I am using 2-D grid

dim3 grid = dim3(LX/TILE\_I, LY/TILE\_J);

---

<div class="post-metadata">

**Author:** ![avidday](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/avidday/32/59219_2.png) [@avidday](https://forums.developer.nvidia.com/u/avidday)\
**Post date:** [January 14, 2011, 2:37pm UTC](https://forums.developer.nvidia.com/t/three-dimensional-indexing/20544/4 "2011-01-14T14:37:30Z")

</div>

Your code shows you are trying to index using blockIdx.z. That isn’t presently used.

---

<div class="post-metadata">

**Author:** ![Ailleur](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@Ailleur](https://forums.developer.nvidia.com/u/Ailleur)\
**Post date:** [January 14, 2011, 3:13pm UTC](https://forums.developer.nvidia.com/t/three-dimensional-indexing/20544/5 "2011-01-14T15:13:35Z")

</div>

I find using a big linear index and then striding it is easier. Heres how I do it:

> **[NVIDIA Official Forums](https://www.nvidia.com/en-us/forums/)**
>
> Keep up to date with the latest announcements & discussions on the hot topics.
