10000 Force alignment of arrays in memory by navjotk · Pull Request #20 · devitocodes/devito · GitHub
[go: up one dir, main page]

Skip to content

Force alignment of arrays in memory #20

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 2 commits into from
May 23, 2016
Merged

Force alignment of arrays in memory #20

merged 2 commits into from
May 23, 2016

Conversation

navjotk
Copy link
Member
@navjotk navjotk commented May 23, 2016

No description provided.

@mlange05
Copy link

Neat, looks good. Feel free to merge.

@navjotk
Copy link
Member Author
navjotk commented May 23, 2016

Numpy provides a setflags method on arrays which has an alignment option. Changing this doesn't actually change anything in the underlying array. It only changes how numpy looks at it.

It also provides a require method which makes sure an array is aligned. However the size of alignment in this case is internal and quite arbitrary. Reading the discussions here it seems like the alignment is to 16 bytes. This seems like it might be aligning for improving SIMD performance. Alignment for optimal cache performance seems like a huge issue for numpy and they don't seem to have fixed this yet.

@navjotk
Copy link
Member Author
navjotk commented May 23, 2016

Assuming we need to be able to align to any arbitrary number of bytes, this needs to be implemented ourselves. Implementing this in python is fairly trivial. To implement this in C, we would need to create our own data structures to implement the buffer protocol required by python, which seems to be a very tedious affair. Making these data structures interoperable with numpy might require additional work.

@mlange05
Copy link

I agree, the Python trick you linked might be the quickest and easiest to implement for now, and for our current benchmark purposes we might just want to do this. If we have more complicated data layouts on top of custom alignment I would hope that we might use some Cython magic to make this a little less tedious, but that would require adding a small Cython compilation setup. However, if we end up having to go through the buffer protocol and NumPy array API, I would recommend looking at petsc4py, in particular this code for an example.

@navjotk navjotk merged commit 7022239 into master May 23, 2016
@navjotk navjotk deleted the memory_align branch May 23, 2016 17:26
@navjotk navjotk mentioned this pull request Oct 13, 2016
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
0