This bugzilla service is closed. All entries have been migrated to https://gitlab.com/libeigen/eigen
Bug 1331 - Alignment on 16 bytes, whereas AVX requires 32?
Summary: Alignment on 16 bytes, whereas AVX requires 32?
Status: RESOLVED INVALID
Alias: None
Product: Eigen
Classification: Unclassified
Component: Core - general (show other bugs)
Version: 3.3 (current stable)
Hardware: x86 - AVX Windows
: Highest Crash
Assignee: Nobody
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 3.3
  Show dependency treegraph
 
Reported: 2016-10-19 14:44 UTC by Thijs Withaar
Modified: 2019-12-04 16:27 UTC (History)
3 users (show)



Attachments

Description Thijs Withaar 2016-10-19 14:44:24 UTC
Using Eigen 3.3rc1 on windows 7, 64 bit with Visual Studio 2013,
and /arch:AVX

In:
Eigen\src\Core\util\Macros.h
EIGEN_IDEAL_MAX_ALIGN_BYTES is defined as 32 when AVX is enabled.

Somehow in 
Eigen\src\Core\util\Memory.h,

aligned_malloc() still takes the code path given by EIGEN_MALLOC_ALREADY_ALIGNED
which results in 16-byte aligned memory.

This results in a crash in an line like
Eigen::VectorXd x = Eigen::VectorXd::Zero(n)
which traces down to a pstore.

Could it be that line 52 of Memory.h should read:
 || (EIGEN_OS_WIN64 && (EIGEN_DEFAULT_ALIGN_BYTES == EIGEN_IDEAL_MAX_ALIGN_BYTES))   \

instead of:
 || (EIGEN_OS_WIN64 && (EIGEN_DEFAULT_ALIGN_BYTES == 16))   \
Comment 1 Christoph Hertzberg 2016-10-20 13:56:20 UTC
I'm not sure, especially since the gcc and clang paths have the same condition (i.e. `== 16`). And as far as I remember the essential unit tests all work with gcc and clang and AVX enabled (currently I'm on a non-AVX cpu, I'll try that when I get home).
Comment 2 Gael Guennebaud 2016-10-24 20:27:55 UTC
This is strange because EIGEN_MALLOC_ALREADY_ALIGNED is defined only if EIGEN_DEFAULT_ALIGN_BYTES == 16 (Memory.h, line 52), and in Macros.h line 772 we have:

#if EIGEN_IDEAL_MAX_ALIGN_BYTES > EIGEN_MAX_ALIGN_BYTES
#define EIGEN_DEFAULT_ALIGN_BYTES EIGEN_IDEAL_MAX_ALIGN_BYTES
#else
#define EIGEN_DEFAULT_ALIGN_BYTES EIGEN_MAX_ALIGN_BYTES
#endif

so in your case, EIGEN_DEFAULT_ALIGN_BYTES should be defined to 32, and thus EIGEN_MALLOC_ALREADY_ALIGNED would be disabled.

Are you sure you are using 3.3rc1? Could you check the value of EIGEN_DEFAULT_ALIGN_BYTES?
Comment 3 Thijs Withaar 2016-10-25 13:39:58 UTC
Using your suggestions:

EIGEN_DEFAULT_ALIGN_BYTES 
was set correctly (32) for the static lib of which the code is part.
The application itself, however, did not have the AVX instruction set enabled.
This caused the functions in the .lib to use the non-32 byte version of the allocation routines.
Comment 4 Nobody 2019-12-04 16:27:26 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to gitlab.com's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.com/libeigen/eigen/issues/1331.

Note You need to log in before you can comment on or make changes to this bug.