8000 MAINT: Further fixups to uint alignment checks by ahaldane · Pull Request #12677 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

MAINT: Further fixups to uint alignment checks #12677

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

Merged
merged 1 commit into from
Jan 8, 2019

Conversation

ahaldane
Copy link
Member
@ahaldane ahaldane commented Jan 6, 2019

A few more fixes following on #12626, based on testing on a ppc64be system.

First, on this system some einsum tests failed due typo in that PR: ; should have been &&. This wasn't caught by x64 unit tests, so I've added a test that should cover those code paths.

Second, I figured out that some of the fix in #12626 wasn't quite right: I had misunderstood what the NPY_ITER_ALIGNED flag is supposed to do. My understanding now is that is a request to guarantee that the nditer buffers are "true" aligned. (uint alignment is only an internal numpy thing which users shouldn't know about), which nditer it does by forcing a buffer/cast if that flag is requested, since all new buffers are true aligned. With that understanding, it now seems that the NPY_OP_ITFLAG_ALIGNED flag is not needed: Its only use was as a precalculated computation of the aligned parameter of PyArray_GetDTypeTransferFunction, but that is more safely computed on the spot, based on both uint and true alignment of the op. So I've removed all uses of NPY_OP_ITFLAG_ALIGNED.

This latter change was indirectly discovered from staring at the code while trying to bug-hunt failed alignment asserts on ppc64be. But those turned out to be irrelevant glibc problems from #10491. At least it got me to read a lot of code over more thoroughly: I also made sure that the ufunc code doesn't need alignment fixes.

*/
if (IsUintAligned(op[iop])) {
op_itflags[iop] |= NPY_OP_ITFLAG_ALIGNED;
}
Copy link
Member

Choose a reason for hiding this comment

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

Are there "aligned optimizations" (as mentioned in the comment) beyond the call to PyArray_GetDTypeTransferFunction?

Copy link
Member Author

Choose a reason for hiding this comment

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

No, grepping showed that it was only used there.

* needs uint-alignment in addition.
*/
if (IsUintAligned(out)) {
op_itflags[iop] |= NPY_OP_ITFLAG_ALIGNED;
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm confused why we don't simply revert to the code pre-#12626, and set OP_ITFLAG_ALIGNED unconditionally (and then use it in the transfer function if statements - it seems the least amount of churn and keeps the flag.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fair enough, will do

Copy link
Contributor
@mhvk mhvk left a comment

Choose a reason for hiding this comment

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

@ahaldane - as I had been looking at the iterator for the reductions, I thought I'd have a look here too. I ended up going back to #12626 and left some comments there. Here, there's only the one in-line one: why not keep using the OP_ITFLAG_ALIGNED flag - it seems that was in fact fine.

@ahaldane ahaldane force-pushed the fix_more_uint_aln branch 2 times, most recently from 2886c88 to 9dd6bdb Compare January 6, 2019 17:36
@charris
Copy link
Member
charris commented Jan 6, 2019

The coverage test has gone bonkers. Might be related to the pytest 4.1.0 release in the last 22 hours.

@charris
Copy link
Member
charris commented Jan 6, 2019

See pytest-dev/pytest#4606.

@charris
Copy link
Member
charris commented Jan 7, 2019

@ahaldane Do you feel done with this? I can follow the code, but cannot judge its correctness without a bigger context. Perhaps some comments would help.

EDIT: Particularly regarding big vs little alignment. I assume the use of the strides is to guarantee that alignment stays good while indexing through the array.

@charris
Copy link
Member
charris commented Jan 8, 2019

I'm going to put this in for testing purposes. @ahaldane More documentation explaining the purpose of the new function would be desirable.

@charris charris merged commit 4d07322 into numpy:master Jan 8, 2019
@charris
Copy link
Member
charris commented Jan 8, 2019

Thanks Allan.

@ahaldane
Copy link
Member Author
ahaldane commented Jan 8, 2019

@charris, will do. Just busy today.

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

Successfully merging this pull request may close these issues.

4 participants
0