 # Porting suggestion!

I need some preposition for porting some code with cuda. I have this function:

``````void GaussianBlur(float sigma)

{

float x, kernel, sum = 0.0, GaussTruncate = 4.0;

int ksize, i;

/* The Gaussian kernel is truncated at GaussTruncate sigmas from

center.  The kernel size should be odd.

*/

//GaussTruncate is constant

ksize = (int)(2.0 * GaussTruncate * sigma + 1.0);

ksize = MAX(3, ksize);    /* Kernel must be at least 3. */

if (ksize % 2 == 0)       /* Make kernel size odd. */

ksize++;

assert(ksize < 100);

/* Fill in kernel values. */

for (i = 0; i <= ksize; i++) {

x = i - ksize / 2;

kernel[i] = exp(- x * x / (2.0 * sigma * sigma));

sum += kernel[i];

}

/* Normalize kernel values to sum to 1.0. */

for (i = 0; i < ksize; i++)

kernel[i] /= sum;

}
``````

My kernel would be like this: (pseudo code)

``````first for loop:

__global__ kernelGauss1 (int ksize, float sigma) {

//calculate idx

x = i - ksize / 2;

kernel[idx] = exp(- x * x / (2.0 * sigma * sigma));

sum += kernel[idx];

write to global mem kernel array and sum

}

2nd for loop:

__global__ kernelGauss2 (int ksize, input from glob mem kernel array and sum) {

//calculate idx

kernel[idx]=kernel[idx] / sum

write results in glob mem

}
``````

``````   ksize = (int)(2.0 * GaussTruncate * sigma + 1.0);

ksize = MAX(3, ksize);    /* Kernel must be at least 3. */

if (ksize % 2 == 0)       /* Make kernel size odd. */

ksize++;

assert(ksize < 100);
``````

Can I pass that to gpu and make another kernel which will calculate this and then pass ksize to kernelGauss1 or just to calculate ksize on cpu and then use only kernelGauss1 and kernelGauss2???

Any suggestions?

Thanks, Petar :)