您的位置:首页 > 其它

编译器错误 C2719 & Eigen库出现的对齐问题

2013-02-22 16:57 651 查看


注意收集错误信息,通过“输出”窗口,定位到具体代码行!!!

解决方案:

http://eigen.tuxfamily.org/dox/TopicStlContainers.html



eigen 3.1.2有 bug,   

更新daily build版本: (官网 https://bitbucket.org/eigen/eigen/)
hg clone https://bitbucket.org/eigen/eigen/


并修改   RealScalar p => const RealScalar& p

关于为何更改的网页找不到了。。。 大致意思是这个: http://eigen.tuxfamily.org/bz/show_bug.cgi?id=83

msvc2008才会出现此错误,2010没有。



解释大致为:





error C2719: '_Val': formal parameter with __declspec(align('16')) won't be aligned?

It is a known issue that stl::vector
cannot properly contain aligned data, such as D3DXMATRIXA16. One poster pinned
the root cause (or at least, one of them?): the declaration of vector::resize passes the aligned data by value, and not as const reference. Several workarounds were suggested in that thread, the safest being dropping
stl::vector altogether. You might also want to fix the stl headers yourself and recompile - this actually may be easier than it sounds, but I haven't done so myself.

EDIT: links are now broken (thanks @David Menard), here's an
alternative, more elaborate answer.

The issue is fixed in VS2012RC - here's a link to a
corresponding connect issue. Turns out it was actually an issue in the C++ standard itself, fixed in 2008.

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

(zz)使用Eigen库出现的对齐问题。

2012-03-13 19:34:36| 分类:reproduct|
标签:eigenvs2010|字号大中小订阅

error C2719: '_Val': formal parameter with __declspec(align('16')) won't be aligned

2012-02-09 12:42
英文提示:error C2719: 'p': formal parameter with __declspec(align('16')) won't be aligned
中文提示:error C2719: “p”: 具有 __declspec(align('16')) 的形参将不被对齐
导致整个现象的主要原因是使用了Eigen库,Eigen为了使用SSE加速,所以内存分配上使用了128位的指针。
更加准确的说法:
“First, "fixed-size" should be clear: an
Eigen object has fixed size if its number of rows and its number of columns are fixed at compile-time. So for example Matrix3f has fixed size, but MatrixXf doesn't (the opposite of fixed-size is dynamic-size).

The array of coefficients of a fixed-size
Eigen object is a plain "static array", it is not dynamically allocated. For example, the data behind a Matrix4f is just a "float array[16]".
Fixed-size objects are typically very small, which means that we want to handle them with zero runtime overhead -- both in terms of memory usage and of speed.
Now, vectorization (both SSE and AltiVec) works with 128-bit packets. Moreover, for performance reasons, these packets need to be have 128-bit alignment.
So it turns out that the only way that fixed-size
Eigen objects can be vectorized, is if their size is a multiple of 128 bits, or 16 bytes.Eigen will then request
16-byte alignment for these objects, and henceforth rely on these objects being aligned so no runtime check for alignment is performed.”

解决方案:
分为四种情况:

Cause 1: Structures having Eigen objects as members
Cause 2: STL Containers
Cause 3: Passing Eigen objects by value
Cause 4: Compiler making a wrong assumption on stack alignment (for instance GCC on Windows)

每种情况可以对照官方的说法。可以参考如下链接
http://eigen.tuxfamily.org/dox/TopicUnalignedArrayAssert.html
在此不再重复表述。
http://eigen.tuxfamily.org/dox/TopicUnalignedArrayAssert.html#c3

Table of contents

Where in my own code is the cause of the problem?
Cause 1: Structures having Eigen objects as members
Cause 2: STL Containers
Cause 3: Passing Eigen objects by value
Cause 4: Compiler making a wrong assumption on stack alignment (for instance GCC on Windows)
Explanation
I don't care about vectorization, how do I get rid of that stuff?

编译器错误 C2719

Visual Studio 2008

其他版本



Visual Studio 2012
Visual Studio 2010
Visual Studio 2005

此主题尚未评级-评价此主题

更新:2007 年 11 月

错误消息

“parameter”: 具有 __declspec(align('#')) 的形参将不被对齐

函数参数中不允许使用
align__declspec 修饰符。

下面的示例生成 C2719:

复制

// C2719.cpp
void func(int __declspec(align(32)) i);   // C2719
// try the following line instead
// void func(int i);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐