'clean' way to do image operations? starting from float arrays redfining operators like addi

Hi guys

I’m currently developping code in the field of image processing.
Within my code i manipulate my images as float*, ie for a given MxN image, i store it in a 1D array of MxN floats.
What i would like to do is finding a clean way to perform operations such as elementwise addition for example.
To be more precise, let’s say we have 3 images A,B and C. For now , if i want to calculate the elementwise sum of those three images and store it in another image named ‘Result’, i call three times a function :

elementwiseAddition_kernel(Result, image2Add, M, N);
with image2Add in {A,B,C}.

Of course it works but for more complicated operations, it can be really ugly and long. Of course i could also code a function doing all that in one shot but again that wouldn’t be ‘optimal’. Eventually, it would be really nice to re-define the ‘+’ operator for objects of type float* like in C++ when defining a class and then write

Result = A + B + C;

Though according to what i saw on the net, it doesn’t seem possible here with device variables…

Has anyone managed to find a more elegant way to do so? or leading ideas on how to come closer to a approximated solution?

Thanks in advance and have a good day

Maybe Thrust can be of any help, which is already included with CUDA.

Example code for adding two vectors, examples without functors are on the Thrust website.

// templated functor to add numbers

template< typename T >

class add {


  T operator()(T a, T b) {

    return a + b;



int x = 10; int y = 20; int z;

add<int> func; // create an add functor for T=int

z = func(x,y); // invoke functor on x and y

float x = 10; float y = 20; float z;

add<float> func; // create an add functor for T=float

z = func(x,y); // invoke functor on x and y

I briefly looked at the doc, seems like that could do the trick.