-
Notifications
You must be signed in to change notification settings - Fork 205
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
Fix undefined behaviour in dot product kernels #655
Conversation
7c7b097
to
946259f
Compare
The test failure is unrelated; it's due to #646. |
On my machine I can get away with an absolute tolerance of |
@argilo you could convert this PR into a draft. This would clearly indicate that it is still being worked on. |
d2e8603
to
43d8980
Compare
Aha! The volk/kernels/volk/volk_32fc_32f_dot_prod_32fc.h Lines 64 to 65 in a26a1b8
I got rid of the float array and replaced it with Tests now pass on all platforms, even with the tighter |
The test failures are unrelated; both are due to #646. |
|
GNU Radio uses both |
Actually, I'll throw it in here because it will also need the new absolute tolerance code. |
43d8980
to
d4c8688
Compare
The test failure in the latest run is due to #650. At least there's some variety. 😄 |
Some information about why casting from https://stackoverflow.com/questions/23198943/is-it-legal-to-cast-float-to-stdcomplexfloat |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Almost LGTM. Only a very few comments. Thanks!
@@ -147,8 +147,7 @@ static inline void volk_16i_32fc_dot_prod_32fc_u_sse(lv_32fc_t* result, | |||
unsigned int number = 0; | |||
const unsigned int sixteenthPoints = num_points / 8; | |||
|
|||
float res[2]; | |||
float *realpt = &res[0], *imagpt = &res[1]; | |||
lv_32fc_t returnValue; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Compilers would potentially complain about uninitialized variables here.
I suggest: lv_32fc_t returnValue = lv_cmake(0.0f, 0.0f);
I'd update the other occurrences as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure compilers would be confused by this particular case, but it would make the code easier to understand for humans. I'll add initializations and change all the updates to +=
.
794ca91
to
56fba31
Compare
Signed-off-by: Clayton Smith <argilo@gmail.com>
Signed-off-by: Clayton Smith <argilo@gmail.com>
Signed-off-by: Clayton Smith <argilo@gmail.com>
56fba31
to
221138a
Compare
Updated, and rebased on main. It might be a while until CI catches up. 😄 |
CI has now caught up. ✅ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Fix undefined behaviour in dot product kernels
Fixes #651.
Fixes #659.
In tests, the dot product is a summation of 131071 terms,
so a fair amount of error can accumulate. From the past CI failures it can be seen that the error can reach a magnitude of 2, so I've set a tolerance of 10 to leave a safe margin.Since the summation can be close to zero, it makes sense to check the absolute error instead of the relative error. The
ccompare
function did not have an absolute mode, so I added one.Update: The test failures and large errors identified in #651 were due to undefined behaviour in the dot product kernels, which sometimes manifested in trailing samples/taps not being included in the calculation. I've updated the pull request to include fixes for that problem.