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. 现在,我们编写一个简单的程序: 运行后输出: 为什么会这 ...
随机推荐
- 多重循环、缓冲区管理、数组(day06)
无法预知的数字叫随机数 rand标准函数可以用来获得随机数 为了使用这个标准函数需要包含stdlib.h头文件 srand标准函数用来设置随机数种子 这个函数把一个整数作为种子使用 不同的种子产生的随 ...
- 最小化安装CentOS-7-x86_64-Minimal-1511图文教程
说明: 虚拟机产品:VMware® Workstation 12 Pro,版本:12.5.0 build-4352439 系统镜像:CentOS-7-x86_64-Minimal-1511.iso 操 ...
- <a>标签中的href伪协议 标签: html 2016-12-24 22:38 365人阅读 评论(0)
<a id="jsPswEdit" class="set-item" href="javascript:;">修改密码</ ...
- Drop a database in MongoDB
http://www.linuxask.com/questions/drop-a-database-in-mongodb Drop a database in MongoDB Answer: Assu ...
- Atomic operations on the x86 processors
On the Intel type of x86 processors including AMD, increasingly there are more CPU cores or processo ...
- Tomcat日志配置远程Syslog采集
http://blog.csdn.net/leizi191110211/article/details/51593748
- Docker入门介绍
Docker是一种虚拟化技术 刚開始看Docker,感觉非常抽象"An open platform for distributed applications for develo ...
- Android传统HTTP请求get----post方式提交数据(包括乱码问题)
1.模仿登入页面显示(使用传统方式是面向过程的) 使用Apache公司提供的HttpClient API是面向对象的 (文章底部含有源码的连接,包括了使用async框架) (解决中文乱码的问题.主要 ...
- 【软件project】之第五、六章总结
软件project的前几章各自是软件计划.需求分析.软件设计.整体的都规划好了以后,就该着手去实践了. 所谓的理论体系足够强大了以后,实践就显得尤为轻松.我们设计软件,实践当然就是用我已经计划好的语言 ...
- 安装10gR2的硬件要求
1.至少1G的RAM. 2.RAM与swap关系: RAM swap 512M以上 2*RAM (非常奇怪.至少1G的RAM.还写512的 ...