Repository navigation
[wip] Align Struct fields to their natural alignment - #197
Open
szymonlopaciuk wants to merge 1 commit into
Open
szymonlopaciuk wants to merge 1 commit into
szymonlopaciuk wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This replaces
Struct's fixed 8-byte field padding with per-type_alignmentspec. Structs align each field individually and themselves take as alignment the maximum among their fields (forComplex64/Complex1284/8 bytes is used which is a natural alignment for x86_64/arm64 and on GPU they are defined asfloat[2]/double[2], respectively). Array elements follow their type’s alignment. Separately allocated objects also respect the context’s minimum alignment; fields within structs use only their type’s alignment.This alignment method follows the standard C struct alignment for x86_64, arm64, CUDA, and OpenCL (see the caveat about complex values as noted above, and some pointer peculiarities for OpenCL, which are not relevant for us). It should allow for less waste of space and lower memory pressure.
The alignment specified here is for Xobjects types, and is conceptually different to
Context.minimum_alignment: the latter governs the alignment of context buffers. This is generally the same, except on OpenCL, where, depending on the platform the alignment of pointers passed as kernel arguments can be required to be as large as 16 or even 32 bytes. As things stand, it is not always safe to pass Xobject pointers to kernels if they are not at the beginning of a buffer, or if they are not aligned to this boundary. However, this is already in theory a problem, and this PR doesn't make it better or worse. For beam elements in Xtrack, these are always reallocated when a tracker is built on a new context, and in the process each beam element is aligned to the context's minimum alignment. Some issues related to this are already known xsuite/xsuite#1021.This is [wip] because I still need to comprehensively test this on all contexts.
Checklist
Mandatory:
Optional: