Blockdim for global function Change blockDim with function content ?

Hi :wave:

I tried to modify the SobelFilter example to average filter, or filter with coefficients fixed by user.

The function SobelTex, in SobelFilter_kernel.cu, uses a 3x3 matrix.

If I want to use a 5x5 matrix, I have to change the blockDim of the call from 384 to 128, otherwise it is not functional… :fear:

If I want to use a 7x7 matrix, I have to change the blockDim to 64.

Why ? What element affect the blockDim for wich it’s functional ?

Here my functions :

5x5 :

       SobelTex:
       unsigned char pix[25];

        int cpt = 0;

        unsigned char *pSobel = 

        (unsigned char *) (((char *) pSobelOriginal)+blockIdx.x*Pitch);

        for ( int i = threadIdx.x; i < w; i += blockDim.x ) 

        {

            for (int j = -2; j <= 2; j++)

                for (int k = -2; k <= 2; k++)

                {

                    p[cpt] = tex2D( tex, (float) i-k, (float) blockIdx.x-j );

                    cpt++;

                }

            pSobel[i] = ComputeSobel5(p);

            cpt = 0;

        }

ComputeSobel:

       float Sum = p[0]*mat5[0] + p[1]*mat5[1] + p[2]*mat5[2] + p[3]*mat5[3] + p[4]*mat5[4] +

                    p[5]*mat5[5] + p[6]*mat5[6] + p[7]*mat5[7] + p[8]*mat5[8] + p[9]*mat5[9] + 

                    p[10]*mat5[10] + p[11]*mat5[11] + p[12]*mat5[12] + p[13]*mat5[13] + p[14]*mat5[14] + 

                    p[15]*mat5[15] + p[16]*mat5[16] + p[17]*mat5[17] + p[18]*mat5[18] + p[19]*mat5[19] + 

                    p[20]*mat5[20] + p[21]*mat5[21] + p[22]*mat5[22] + p[23]*mat5[23] + p[24]*mat5[24];

	Sum = Sum/25.0f;

    	return ((short)Sum);

mat5 table contains coefficients. It’s the same thing for 7x7 matrix.

Thanks for reply :thumbup: