Convolution with Wrapped Edges

Hi everyone,

I’m trying to implement a simple iterated convolution kernel with edge wrapping. I have a few questions about how to do this most effectively.

What is the best way to implement edge wrapping in a kernel? Should I use modulo? Should I limit my buffers to widths/heights that are powers of two and use a bitwise and? Or should I avoid this altogether and use a larger buffer and copy the left edge to the right side and vice versa? If so, what’s the best way to do this?

How about using a sampler variable that has CLK_ADDRESS_REPEAT set?

Paul is right if your input is an image. Just set the sampler to wrap. If you are using buffers and/or blocking into local memory you’ll have to handle it yourself. In the case of using local memory you can just load the extra data for the edges. In general you’ll want to have separate code-paths for the edge case/body case so you don’t pay the conditional/modulo overhead on every calculation.)


I’m in this situation. I work with buffers of 3D image (~maybe~ will working with image2D, 3D later) and I want to know if

  • using “gentype fmod (gentype x, gentype y)” will be fast enough? What"s the cost?
  • using array(local, or global) with border value will be better than fmod ?

Exemple for border value with image[5][8] :
arrayY[5]={0, 8, 16,24,32}

What is your knowledge/experience ?
Thank you!