title: Smooth convolution in CUDA C++
body: <p>I'm new at CUDA and I'm trying to implement smooth convolution on an image and so far I have this, but the result is wrong.
  not sure if I did the offset movement correct. Any help?</p>
  <pre><code>
  __global__ void smooth(unsigned char* device_out_image, float kernel_size, unsigned char* device_input_imag, int height, int width)
  {
      int pos_x = threadIdx.x + blockIdx.x * blockDim.x;//x coordinate of pixel
      int pos_y = threadIdx.y + blockIdx.y * blockDim.y;//y coordinate of pixel
  
      if (pos_x &lt; width &amp;&amp; pos_y &lt; height)
      {
          unsigned char r = device_input_imag[pos_y * width + pos_x];//absolute pixel position
          unsigned char g = device_input_imag[(height + pos_y) * width + pos_x];
          unsigned char b = device_input_imag[(height * 2 + pos_y) * width + pos_x];
          //also mix value with the intensity instead of the range x
          float sumR = float(0.0f);
          float sumG = float(0.0f);
          float sumB = float(0.0f);
          for (int i = (-1 * 15); i &lt;= 15; i++)
              for (int j = (-1 *15); j &lt;= 15; j++)
              {
                  if (pos_x + j &gt; 0 &amp;&amp; pos_y + i &gt; 0 &amp;&amp; pos_x + j &lt;= width &amp;&amp; pos_y + i &lt;= height)
                  {
                      sumR += (float)device_input_imag[(pos_y + i) * width + (pos_x + j)]/255.0;
                      sumG += (float)device_input_imag[(height + (pos_y + i)) * width + (pos_x + j)]/255.0;
                      sumB += (float)device_input_imag[(height * 2 + (pos_y + i)) * width + (pos_x + j)]/255.0;
                  }   
              }
          sumR = sumR / (15 * 15);
          sumG = sumG / (15 * 15);
          sumB = sumB / (15 * 15);
          device_out_image[pos_y * width + pos_x] = (unsigned char)(sumR * 255.0);
          device_out_image[(height + pos_y) * width + pos_x] = (unsigned char)(sumG * 255.0) ;
          device_out_image[(height * 2 + pos_y) * width + pos_x] = (unsigned char)(sumB *255.0 );
          if (device_out_image[pos_y * width + pos_x] &gt; 255)
              device_out_image[pos_y * width + pos_x] = 255;
          if (device_out_image[(height + pos_y) * width + pos_x] &gt; 255)
              device_out_image[(height + pos_y) * width + pos_x] = 255;
          if (device_out_image[(height * 2 + pos_y) * width + pos_x] &gt; 255)
              device_out_image[(height * 2 + pos_y) * width + pos_x] = 255;   
      }
  }
  </code></pre>