在视觉工作室2012年对矢量的特征类型的自动矢量化表现不佳 [英] Auto-vectorization in visual studio 2012 on vectors of Eigen type is not performing well

查看:269
本文介绍了在视觉工作室2012年对矢量的特征类型的自动矢量化表现不佳的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有stig :: vector的Eigen :: vector3d类型,当我编译此代码使用Microsoft Visual Studio 2012具有用于报告向量化细节的 / Qvec-report:2 标志。它显示循环未向量化由于原因1304(循环包含不同类型的分配)在msdn页面上指定 - https://msdn.microsoft.com/en-us/library/jj658585.aspx

I have std::vector of Eigen::vector3d types and when i am compiling this code using Microsoft Visual Studio 2012 having the /Qvec-report:2 flag on for reporting vectorization details. It's showing Loop not vectorized due to reason 1304 (Loop contains assignments that are of different types) as specified on the msdn page -https://msdn.microsoft.com/en-us/library/jj658585.aspx

我的代码如下:

#include <iostream>
#include <vector>
#include <time.h>
#include<Eigen/StdVector>
int main(char *argv[], int argc)
{
    int tempSize=100;
/** I am aligning these vectors as specfied on http://eigen.tuxfamily.org/dox/group__TopicStlContainers.html */
    std::vector<Eigen::Vector3d,Eigen::aligned_allocator<Eigen::Vector3d>> eiVec(tempSize);
    std::vector<Eigen::Vector3d,Eigen::aligned_allocator<Eigen::Vector3d>> eiVec1(tempSize);
    std::vector<Eigen::Vector3d,Eigen::aligned_allocator<Eigen::Vector3d>> eiVec2(tempSize);

    for(int i=0;i<100;i++)
    {
        eiVec1[i] = Eigen::Vector3d::Zero();
        eiVec2[i] = Eigen::Vector3d::Zero();
    }

    Eigen::Vector3d *eV = &eiVec.front();
    const Eigen::Vector3d *eV1 = &eiVec1.front();
    const Eigen::Vector3d *eV2 = &eiVec2.front();

/** Below loop is not vectorized due to code 1304  */
    for(int i=0;i<100;i++)
    {
        eV[i] = eV1[i] - eV2[i];
    }
    return 0;
}

所以我不能理解如何告诉编译器,这是固定大小的数据和固定大小的分配将在这里发生。

So i am not able to understand that how to tell compiler, this is the fixed size data and fixed size assignment will happen here.

推荐答案

Eigen文档


例如 operator + 不会自己执行任何计算,它们只是返回描述要执行的计算的表达式对象。实际计算发生在稍后,当整个表达式被计算时,通常在operator =

In Eigen, arithmetic operators such as operator+ don't perform any computation by themselves, they just return an "expression object" describing the computation to be performed. The actual computation happens later, when the whole expression is evaluated, typically in operator=

因此 eV1 [i ] - eV2 [i] 不返回 Eigen :: Vector3d - 所以原因1304适用。你可能能够投射它 - 但我不打赌它。

So eV1[i] - eV2[i] is not returning an Eigen::Vector3d - so reason 1304 applies. You might be able to cast it - but I wouldn't bet on it.

这篇关于在视觉工作室2012年对矢量的特征类型的自动矢量化表现不佳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆