Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hadd confusing #6

Open
fritterhoff opened this issue Nov 10, 2019 · 6 comments
Open

hadd confusing #6

fritterhoff opened this issue Nov 10, 2019 · 6 comments
Labels

Comments

@fritterhoff
Copy link
Contributor

The reduction method hadd is a bit confusing. In AVX2 this is used for a pairwise add so the result is also a vector not a scalar. Maybe there is the possibility to change the behavior for the other implementations?

MIPP/src/mipp.h

Line 1224 in 6be95bb

template <typename T> inline T hadd(const reg v) { return reduction<T,mipp::add<T>>::sapply(v); }

@kouchy
Copy link
Member

kouchy commented Nov 12, 2019

Hi @flori-uni,

In MIPP we chose that horizontal operations return a scalar (hadd, hmul, etc.). I'm not sure I want to modify this default behavior documented here: https://github.com/aff3ct/MIPP#reductions-horizontal-functions-.
But if you need a vector instead of a scalar, you can write mipp::Reduction<T,mipp::add<T>>::apply(v); (apply instead of sapply) in your code.

@fritterhoff
Copy link
Contributor Author

fritterhoff commented Nov 12, 2019

Well I plan to use the functionality for calculation on complex numbers. In detail for calculating real²+imaginary².

The real and imaginary part are in the same memory stored alternating. So I have re,im,re,im...

Maybe I'll implement some separated methods for my use-case. Later I probably need also the real and imaginary parts separate...

@fritterhoff
Copy link
Contributor Author

mipp::Reduction<T,mipp::add>::apply(v); actually does not result in the right data. I think i need to implement it on my own 😢

@kouchy
Copy link
Member

kouchy commented Nov 12, 2019

I'm not sure to understand, what is the result you expect? Could you give me an example?

@fritterhoff
Copy link
Contributor Author

fritterhoff commented Nov 12, 2019

Using AVX2 I'm able to do the following:

for (auto idx = 0u; idx < max - 3; idx += 4)
{
         auto item = _mm256_load_ps(&data[idx]);
         item = _mm256_mul_ps(item, item );
         auto mag = _mm256_hadd_ps(item, zeros);
         sum = _mm256_add_ps(sum, _mm256_sqrt_ps(mag));
}
auto totalSum = sum[0] + sum[1] + sum[4] + sum[5];       

So it calculates sqrt(x*x+y*y) for each complex pair. Afterwards i can calculate the mean of the sum and some other stuff

@fritterhoff
Copy link
Contributor Author

    [1,  2,  3,  4,  5,  6,  7,  8]
*   [1,  2,  3,  4,  5,  6,  7,  8]
    [1,  4,  9, 16, 25, 36, 49, 64]
hadd[5,  0, 25,  0, 61,  0,113, 0,]
sqrt[.............................]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants