cancel
Showing results for 
Search instead for 
Did you mean: 

Archives Discussions

dinaharchery
Journeyman III

Sum within a Output Stream

Custom Reduce

Hello All,

I got a quick question I hope someone can help with regarding summing values. I could use a reduction kernel but since the reduction factor would be so small (~3 - 7) the overhead would not be worth it.

I have a single Stream made up of the following values (y,x):

4, 4, 2, 16, 56, 0, 9, 5

I would like to sum the Stream as the following:

4    56 ----> 60

4    0 -------> 4

2    9 -------> 11

16    5 ------> 21

Can this be done? As you can see, using the standard reduction would become an overload.

Thanks.

0 Likes
4 Replies
gaurav_garg
Adept I

You can use a 2D gather stream and 1D output stream to do the same. Something like-

kernel sum(float input[][], out result<> )

{

    int j = instance().x;

    result = input[0] + input[1];
}

0 Likes

Thank you.

What if the "width" is passed as a constant to the kernel, given that it may be any width? Something like:

kernel sum(float input[][], int width, out result<> )

{

     int j = instance().x;

     int k = 0;

    for(k = 0; k < width; k = k + 1)

        result += input;

}

 

Would this work?

0 Likes

This should work.

0 Likes

Thank you for all the assistance

Everything works fine now.

0 Likes