Eigen库对齐问题:declspec(align('16')) 的形参将不被对齐
一:错误提示:error C2719: '_Val': formal parameter with __declspec(align('16')) won't be aligned
英文提示: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
在此不再重复表述。
三:我的解决方法:eigen 3.1.2有 bug, 重装Eigen;
关闭使用 预编译头;
关闭编译选项里面的16位对齐;
把Eigen::Vector4f 传值改为 传引用 Eigen::Vector4f &;
把结构体 传值 全部转换为 传引用。躲过对齐!!!
编译器选项:C/C++ ---代码生成---结构图成员对齐;
可恶:忘记了当初是怎么解决的!!!!!
四:对stl vector 进行修改:http://blog.csdn.net/pkueecser/article/details/8602656
产生问题的resize()方法,改为:
{ // determine new length, padding with _Val elements as needed
if (size() < _Newsize)
_Insert_n(end(), _Newsize - size(), _Val);
else if (_Newsize < size())
erase(begin() + _Newsize, end());
}
注意其中红色部分,将传值改为传参,避免在参数栈上创建被对齐的结构的对象。然后,在我们使用std::vector< Foo<5, float> >之前包含我们的foo_vector.hpp头文件,就可以正常使用了。 注意红色部分.....
是微软坑呢?还是Eigen坑?个人感觉微软更坑!!!
后记:
添加 修改为 869行为引用之后,引发2562行的错误,修改方式为 把第二个参数0去掉。
Eigen库对齐问题:declspec(align('16')) 的形参将不被对齐的更多相关文章
- 关于Eigen库在Visual Studio2013中传参对齐报错问题
Error as follow: 具体问题及解决办法描述如下: (引自http://www.fx114.net/qa-278-97757.aspx) /************************ ...
- Eigen库和STL容器冲突问题
博客参考:https://blog.csdn.net/huajun998/article/details/54311561 在程序中想使用类似于如下的容器 std::vector<Eigne:: ...
- NDK 开发实例二(添加 Eigen库)
上一篇,我已经阐述了如何创建一个简单的NDK实例: NDK 开发实例一(Android.mk环境配置下) 在上一篇的基础上,我们来添加Eigen库,然后做一个简单实例. Eigen是一个高层次的C + ...
- Eigen库矩阵运算使用方法
Eigen库矩阵运算使用方法 Eigen这个类库,存的东西好多的,来看一下主要的几个头文件吧: ——Core 有关矩阵和数组的类,有基本的线性代数(包含 三角形 和 自伴乘积 相关),还有相应对数组的 ...
- SVD分解的c++代码(Eigen 库)
使用Eigen 库:进行svd分解,形如 A = U * S * VT. JacobiSVD<MatrixXd> svd(J, ComputeThinU | ComputeThinV); ...
- C++ 矩阵计算库 :Eigen库
Eigen http://eigen.tuxfamily.org/index.php?title=Main_Page 下载http://bitbucket.org/eigen/eigen/get/3. ...
- Eigen库笔记整理(一)
首先熟悉Eigen库的用途,自行百度. 引入头文件: // Eigen 部分 #include <Eigen/Core> // 稠密矩阵的代数运算(逆,特征值等) #include < ...
- 如何安装Eigen库和Sophus库
* { font-family: "Tibetan Machine Uni", "sans-serif", STFangSong; outline: none ...
- C/C++编程笔记:C语言对齐问题【结构体、栈内存以及位域对齐】
引言 考虑下面的结构体定义: 假设这个结构体的成员在内存中是紧凑排列的,且c1的起始地址是0,则s的地址就是1,c2的地址是3,i的地址是4. 现在,我们编写一个简单的程序: 运行后输出: 为什么会这 ...
随机推荐
- JS 常用语法
通常,通过 JavaScript,您需要操作 HTML 元素. 1.通过 id 找到 HTML 元素 2.通过标签名找到 HTML 元素 3.通过类名找到 HTML 元素 提示:通过类名查找 HTML ...
- UNIX C 进程Part2
1.获取进程ID #include <unistd.h> pid_t getpid(void); //获取子进程id pid_t getppid(void);//获取父进程id 2.获取实 ...
- Problem 52
Problem 52 It can be seen that the number, 125874, and its double, 251748, contain exactly the same ...
- Ada boost学习
http://blog.csdn.net/dark_scope/article/details/14103983 据说在Deep Learning出来之前,SVM和Adaboost是效果最好的 两个算 ...
- UVA 10187 From Dusk Till Dawn /PC 110907
不吐槽.. #include <iostream> #include <map> #include <queue> //无语的水题.节哀吧.且这道题不严谨,因为没说 ...
- FaceBook推出的Android图片载入库-Fresco
欢迎关注ndroid-tech-frontier开源项目,定期翻译国外Android优质的技术.开源库.软件架构设计.測试等文章 原文链接:Introducing Fresco: A new imag ...
- Linux内核中网络数据包的接收-第二部分 select/poll/epoll
和前面文章的第一部分一样,这些文字是为了帮别人或者自己理清思路的.而不是所谓的源代码分析.想分析源代码的,还是直接debug源代码最好,看不论什么文档以及书都是下策. 因此这类帮人理清思路的文章尽可能 ...
- 使用makeself创建安装文件
Makeself.sh是一个小的Shell脚本.用于从一个文件夹中生成自解压的tar.gz压缩包. 结果文件以一个shell脚本显示(大多数以.run作为后缀名).能够自己主动执行.该文档会解压自己到 ...
- HDU 1754 I Hate it (线段树最大值模板)
思路:与我发表的上一遍求和的思想一样 仅仅是如今变成求最大值而已 AC代码: #include<iostream> #include<cstdio> #include< ...
- 【java项目实战】ThreadLocal封装Connection,实现同一线程共享资源
线程安全一直是程序员们关注的焦点.多线程也一直是比較让人头疼的话题,想必大家以前也遇到过各种各种的问题.我就不再累述了.当然,解决方案也有非常多,这篇博文给大家提供一种非常好的解决线程安全问题的思路. ...