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

Vfmadd #289

Merged
merged 8 commits into from
Sep 16, 2021
Merged

Vfmadd #289

merged 8 commits into from
Sep 16, 2021

Conversation

P1K
Copy link
Member

@P1K P1K commented Dec 17, 2019

Tentatively solving issue #274 (plus some minor change in fflas_fscal.inl)

This is mostly a duplication of fflas_fscal.inl into fflas_faxpy.inl and replacing muls by muladds.
Tested with and without vectorisation enabled on albaron (AVX2) and retourdest (AVX512)

}
else
{
typename Field::Element_ptr Xc = fflas_new (F,N) ;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If only one of X or Y has an inc !=1 then this code copies both vectors anyway!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks indeed wasteful

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be fixed in latest commit

typename Field::ConstElement_ptr Xi = X;
typename Field::Element_ptr Yi=Y;
for (; Xi < X+n*incX; Xi+=incX, Yi+=incY )
*Yi = reduce(a*(*Xi) + (*Yi), H);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we sure that the infix operators + and * are legit for this field?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should come from support_fast_mod (also implied by support_simd_mod)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. At some point, one should consider cleaning up these traits. This is #304

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This axpyp should also not be in the namespace vectorised as it does not use vectorization

typename Field::Element_ptr Yc = fflas_new (F,N) ;
fassign(F,N,X,incX,Xc,1);
fassign(F,N,Y,incY,Yc,1);
faxpy(F,N,a,Xc,1,Yc,1,FieldCategories::ModularTag());
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From JGD: why not a call to vectorised::axpyp directly?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be fixed in latest commit

@P1K
Copy link
Member Author

P1K commented Feb 20, 2020

Tests passed on retourdestbut failed on albaron, so probably not ready

@P1K
Copy link
Member Author

P1K commented Feb 25, 2020

There is still at least one bug in this branch w.r.t. the current master, but I believe it's due to recent changes in cardinality bounds.
Essentially, the "fast" reduce on int64_t gives erroneous results when the to-be-reduced input overflowed as a product into a negative number (which is undefined behaviour, if I'm not wrong). (Then even if the overflow did not technically result in a loss of information, the computed result will be wrong due to difference between signed/unsigned division used in the reduce function.)
Example (from a real test):

int64_t a = 3315567202
int64_t b = 3606843909
int64_t c = a*b == -6488010706295678998 // unsigned would be 11958733367413872618 < 2**64-1

In short, I believe that the cardinality bound is incorrect and that no modulus should make such an overflow possible.

Note: Even if I encountered this problem while testing this branch, I see no reason why the same bug would not be currently present on master. Maybe it's simply better hidden.

@cyrilbouvier , @ClementPernet do you have an opinion on this?

@P1K
Copy link
Member Author

P1K commented Mar 12, 2020

The bug from my previous comment actually came from a not-up-to-date master (I am apparently too distracted and/or not skilful enough to actually merge master into branches).
Everything seems to be fine now except a fail on test-fger, but that one also happens on master (cf. #307)

@cyrilbouvier cyrilbouvier mentioned this pull request Nov 6, 2020
}
else
{
Yc = const_cast<typename Field::Element_ptr>(Y);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for const_cast as Y is not const

}
else
{
Ac = const_cast<typename Field::Element_ptr>(A); // Oh the horror
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here: A is not const, so why a const_cast

else
{
typename Field::Element_ptr Ac;
typename Field::Element_ptr Bc;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need Bc to be Element_ptr and not ConstElement_ptr, which would then remove the need for const_cast

fassign(F,N,Yc,1,Y,incY);
fflas_delete(Xc);
fflas_delete(Yc);
typename Field::Element_ptr Xc;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Define Xc as ConstElement_ptr instead, which will remove the need for const_cast

Copy link
Member Author

@P1K P1K Mar 30, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cf. our offline discussion, the const_cast is needed for compatibility with the signature of faxpy. The proposed fix doesn't work (as is) since there is a branch where Xc is assigned

@P1K
Copy link
Member Author

P1K commented Mar 31, 2021

The bug from my previous comment actually came from a not-up-to-date master (I am apparently too distracted and/or not skilful enough to actually merge master into branches).
Everything seems to be fine now except a fail on test-fger, but that one also happens on master (cf. #307)

All tests now passing with master (2.5.0rc0) on albaron (AVX2) and retourdest (AVX512)

@ClementPernet
Copy link
Member

Back to it. LGTM

@ClementPernet ClementPernet merged commit 83550b2 into master Sep 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants