简体   繁体   English

为什么MSVC12的自动矢量化程序无法分析功能模板?

[英]Why would function templates not be analyzed by MSVC12's auto-vectorizer?

Function templates are not seen by the auto-vectorization or the auto-parallelizer (/Qpar) engine in VS2013. VS2013中的自动矢量化或自动并行化器(/ Qpar)引擎看不到功能模板。

For example, this code: 例如,此代码:

void foo::someFunc(int a)
{
    int myArray[1000000];

    for (unsigned i = 0; i < 1000000; i++)
    {
       myArray[i] = i+1;
    }
}

seems to be recognized and I get the appropriate output from /Qvec-report:2 and /Qpar-report:2: 似乎可以识别,并且我从/ Qvec-report:2和/ Qpar-report:2获得了适当的输出:

foo.cpp

--- Analyzing function: void __cdecl foo::someFunc(int) __ptr64
c:\visual studio 2013\projects\autovectest\autovectest\foo.cpp(18) : info C5001: loop vectorized
c:\visual studio 2013\projects\autovectest\autovectest\foo.cpp(18) : info C5012: loop not parallelized due to reason '1007'
AutoVecTest.vcxproj -> c:\visual studio 2013\Projects\AutoVecTest\x64\Debug\AutoVecTest.dll

But, as soon as I turn someFunc() into a function template: 但是,一旦我将someFunc()变成函数模板:

template <class T>
void foo::someFunc(T a)
{
    int myArray[1000000];

    for (unsigned i = 0; i < 1000000; i++)
    {
        myArray[i] = i+1;
    }
}

I get nothing from the auto-vectorizer or the auto-parallelizer in the logs: 从日志中的自动矢量化器或自动并行化器,我什么也没得到:

foo.cpp
AutoVecTest.vcxproj -> c:\visual studio 2013\Projects\AutoVecTest\x64\Debug\AutoVecTest.dll

I am not using /GL as stated in Why would /Qvec-report:2 return nothing ? 我没有按照/ Qvec-report:2什么都不返回的说明使用/ GL (MSVC 2012) (MSVC 2012)

  1. As Retired Ninja pointed out, make sure your function template is actually called or instantiated. 正如退休忍者指出的那样,请确保您的功能模板实际上已被调用或实例化。

  2. Make sure the proper optimization compile flags are enabled. 确保启用了正确的优化编译标志。 YMMV here, but Visual Studio 2012's Auto-Vectorization Cookbook says /O2 or /O2 /GL will work. YMMV在这里,但是Visual Studio 2012的自动矢量化食谱/O2/O2 /GL可以工作。 Another user discovered /GL did not work for them ( Why would /Qvec-report:2 return nothing ? (MSVC 2012) ). 另一个用户发现/GL不适用于他们( 为什么/ Qvec-report:2什么也不返回?(MSVC 2012) )。 Using #pragma("gt", on) enabled the auto-vectorizer for me. 使用#pragma("gt", on)为我启用了自动矢量化程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM