Hello All,

Can anybody help to understand, why to use three dimensional threads?

If i am able to do some job in single dimension, why should i do three dimensional tasks?

Like for matrix multiplication exmaple has been done in two dimension something like this -

**global** void MatrixMulKernel(int* Md, int* Nd, int* Pd, int Width)

{

```
// Pvalue is used to store the element of the matrix
// that is computed by the thread
int Pvalue = 0;
for (int k = 0; k < Width; ++k)
{
int Melement = Md[threadIdx.y*Width+k];
int Nelement = Nd[k*Width+threadIdx.x];
Pvalue += Melement * Nelement;
}
```

Pd[threadIdx.y*Width+threadIdx.x] = Pvalue;

}

with grid, block defns -

dim3 dimGrid(1, 1);

dim3 dimBlock(Width, Width);

But i can also do the same task by defining a single ddimensional block size -

dim3 blockDim(Width);

dim3 gridDim(Width);

and with kernel code -

**global** void matrixmultiplicationKernel(int *d_a,int *d_b,int M,int N,int P,int *d_f)

{

int j = blockIdx.x * blockDim.x + threadIdx.x;

```
// Perform multiplication
float sum = 0.0f;
for(int k = 0; k < N; ++k)
{
sum += d_a[k+blockIdx.x * blockDim.x]* d_b[ blockDim.x*k+threadIdx.x];
}
d_f[j] = sum;
```

}

Which is total a single dimensional block doing same task.

Please help me understand why dimensions are necessary.

Thanks in Advance,

Nabarun.