Reputation: 713
I work on an image processing code base that uses image2d_t
objects everywhere. These have their shape (width and height) formally declared which enables programmers to use built-in boundary checking and so on.
To speed-up a separable 2D convolution, I would like to transpose the image temporarily, so the two 1D convolutions access memory along lines. But since all the image2d_t
buffers have the same shape, I need to reshape 2 of them, while not reallocating them (if I need to realloc + transpose, then the speed-up adds up to almost nothing).
Is there a way to switch width and height properties in the image2d_t
object ?
Upvotes: 1
Views: 161
Reputation: 4595
There is no point in transposing image2d_t
objects.
image2d_t
objects represent texture memory. Texture memory is a special kind of memory that is hardware-optimized for situations where threads of a warp / wavefront access elements in nearby 2D locations (x and y).
By 'nearby 2D locations' I mean not necessarily on the same horizontal line (x) and not necessarily in discrete pixel locations.
The GPU hardware has special support for 'texture sampling' - allowing you to 'sample' the texture in non discrete locations and obtain interpolated pixel values.
The exact manner in which texture memory is implemented is vendor dependent, but the general idea is to have 2D regional tiles reside in the same physical line in memory.
Examples where using texture memory makes sense:
Texture mapping in computer graphics. Adjacent pixels in an object sample their color from adjacent 2D locations in an input image.
Image transformation in image processing - scaling, rotating, distorting and undistorting an image. Situations where you 'sample' an input image in an arbitrarily calculated location and write the sample to a target buffer / image.
For most cases in image processing applications, texture memory makes no sense.
Many image processing algorithms access memory in a known pattern, which can be better optimized using linear memory (opencl buffers), and have less overhead.
As for your specific question:
Is there a way to switch width and height properties in the image2d_t object?
No. image2d_t objects are 'immutable'. Their content can be changed however if you allocate them with appropriate flags and pass them to a kernel as __write_only
.
I suggest you switch to using buffer objects. Transposing them is possible to do efficiently and there are some good examples online.
Upvotes: 1