- 
                Notifications
    You must be signed in to change notification settings 
- Fork 15k
[OpenMP] Fix various alignment issues #142376
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|  | @@ -73,7 +73,7 @@ static void bectl(kmp_info_t *th, bget_compact_t compact, | |||||
| /* On IA-32 architecture with Linux* OS, malloc() does not | ||||||
| ensure 16 byte alignment */ | ||||||
|  | ||||||
| #if KMP_ARCH_X86 || !KMP_HAVE_QUAD | ||||||
| #if KMP_ARCH_X86 || KMP_ARCH_SPARC || !KMP_HAVE_QUAD | ||||||
|  | ||||||
| #define SizeQuant 8 | ||||||
| #define AlignType double | ||||||
|  | @@ -1861,7 +1861,7 @@ typedef struct kmp_mem_desc { // Memory block descriptor | |||||
| void *ptr_align; // Pointer to aligned memory, returned | ||||||
| kmp_allocator_t *allocator; // allocator | ||||||
| } kmp_mem_desc_t; | ||||||
| static int alignment = sizeof(void *); // align to pointer size by default | ||||||
| static int alignment = SizeQuant; | ||||||
|          | ||||||
| static int alignment = SizeQuant; | |
| constexpr size_t alignment = SizeQuant; | 
It is only used once down below in the __kmp_alloc() function (line 1929).
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.
Do we want to add anything to the comment above this?
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 found this is complete mess:
glibcsysdeps/i386/malloc-alignment.does#define MALLOC_ALIGNMENT 16, contrary to the comment (haven't checked if this has changed historically). Besides,KMP_HAVE_QUADis a complete misnomer: it's only defined on x86 targets, so should probably be renamed toKMP_X86_HAVE_QUADto reflect that.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've updated this comment now, removing the incorrect Linux reference.
As it turns out,
mallocalignment is a total can of worms:alignof(max_align_t).libcmalloconly uses 8-byte alignment. At the time this was introduced,__float128didn't exist on x86 yet and it was considered too risky to raise this later for fear of breaking binary compatiblity. Similarly, SPARC uses 8-byte alignment, too, although one could argue that this should be 16 bytes due to the use of 128-bit long double.mallocimplementions that often differ from the one inlibc.That said, it might be prudent to switch to one of
memalign,posix_memalign, or_aligned_malloc. GCC'slibgomp(inlibgomp/alloc.c:gomp_aligned_alloc) went that route, e.g.