Skip to content

Commit 0c742d5

Browse files
committed
Fix crash due to incorrect alignment when building Eigen with AVX extensions
Consequentially, we now use 32-byte alignment when building with eigen if __AVX__ is set.
1 parent 4393455 commit 0c742d5

File tree

5 files changed

+22
-2
lines changed

5 files changed

+22
-2
lines changed

doc/ReleaseNotes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ This issue fixes several bugs that were still found in 1.9.2.
5353
* Fix back-to-front sorting when gl-coordinate-system is changed
5454
* Now also compiles on older Linux distros (eg. CentOS 5 / manylinux1)
5555
* get_keyboard_map now includes keys on layouts with special characters
56+
* Fix crash due to incorrect alignment when compiling Eigen with AVX
5657

5758
------------------------ RELEASE 1.9.2 ------------------------
5859

dtool/src/dtoolbase/deletedBufferChain.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,11 @@ class EXPCL_DTOOL DeletedBufferChain {
105105

106106
#elif defined(LINMATH_ALIGN)
107107
// With SSE2 alignment, we need all 16 bytes to preserve alignment.
108+
#ifdef __AVX__
109+
static const size_t flag_reserved_bytes = 32;
110+
#else
108111
static const size_t flag_reserved_bytes = 16;
112+
#endif
109113

110114
#else
111115
// Otherwise, we only need enough space for the Integer itself.

dtool/src/dtoolbase/dlmalloc_src.cxx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,8 +453,13 @@ DEFAULT_MMAP_THRESHOLD default: 256K
453453
// drose: We require 16-byte alignment of certain structures, to
454454
// support SSE2. We don't strictly have to align *everything*, but
455455
// it's just easier to do so.
456+
#ifdef __AVX__
457+
// Eigen requires 32-byte alignment when using AVX instructions.
458+
#define MALLOC_ALIGNMENT ((size_t)32U)
459+
#else
456460
#define MALLOC_ALIGNMENT ((size_t)16U)
457461
#endif
462+
#endif
458463

459464
#ifndef WIN32
460465
#ifdef _WIN32

dtool/src/dtoolbase/dtoolbase.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@
372372
// enforce alignment externally.
373373
#define MEMORY_HOOK_DO_ALIGN 1
374374

375-
#elif defined(IS_OSX) || defined(_WIN64)
375+
#elif (defined(IS_OSX) || defined(_WIN64)) && !defined(__AVX__)
376376
// The OS-provided malloc implementation will do the required
377377
// alignment.
378378
#undef MEMORY_HOOK_DO_ALIGN

dtool/src/dtoolbase/memoryHook.I

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,12 @@ get_memory_alignment() {
5555
// We require 16-byte alignment of certain structures, to support
5656
// SSE2. We don't strictly have to align *everything*, but it's just
5757
// easier to do so.
58+
#ifdef __AVX__
59+
// Eigen requires 32-byte alignment when using AVX instructions.
60+
const size_t alignment_size = 32;
61+
#else
5862
const size_t alignment_size = 16;
63+
#endif
5964
#else
6065
// Otherwise, use word alignment.
6166
const size_t alignment_size = sizeof(void *);
@@ -79,7 +84,12 @@ get_header_reserved_bytes() {
7984
#ifdef LINMATH_ALIGN
8085
// If we're doing SSE2 alignment, we must reserve a full 16-byte
8186
// block, since anything less than that will spoil the alignment.
82-
static const size_t header_reserved_bytes = 16;
87+
#ifdef __AVX__
88+
// Eigen requires 32-byte alignment when using AVX instructions.
89+
const size_t header_reserved_bytes = 32;
90+
#else
91+
const size_t header_reserved_bytes = 16;
92+
#endif
8393

8494
#elif defined(MEMORY_HOOK_DO_ALIGN)
8595
// If we're just aligning to words, we reserve a block as big as two

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy