none
Autovectorization and /Qvec-report:1 and 2

    Question

  • I have several c++ projects and I am trying to find out which loops in the projects are autovectorized and which aren't.  I set the /Qvec-report:1 command line switch so I can get a report of which loops are autovectorized.

    Doing so produced no listing in either of my C++ projects.

    I then switched to /Qvec-report:2

    This did produce some reports about several loops that were not autovectorized, but it did not produce a report for all the loops in my project, no did it produce a report for any loops that were autovectorized.

    I tried several examples off of the blog here http://blogs.msdn.com/b/nativeconcurrency/archive/2012/05/01/auto-vectorizer-in-visual-studio-11-rules-for-loop-header.aspx

    and they produced no reports one way or the other.

    Can anyone tell me what's going on?

    Friday, February 08, 2013 10:00 PM

All replies

  • If Qvec-report:1 spits out nothing and Qvec-report:2 has output, it means that no loops in your code could be vectorized (1 reports only successful, whereas 2 reports both successful and unsuccessful, so (2) - (1) = (2) means that all are not vectorizable). It is difficult to say what is up with the loops without looking at them, and the auto-vectorizer is reasonably frail itself (OTOH, auto-vec is a hard and as of yet unsolved problem so...). Are you using fp:precise? That prevents auto-vec from working since FP math is not associative, so it cannot guarantee consistency of results post aggregation of ops.
    Friday, February 08, 2013 11:37 PM
  • No I am using fpfast

    I am wonderng about the loops that reported nothing one way or the other, success or fail.  The documentation for Qvec-report:2 states that it reports for either occurrence.

    Friday, February 08, 2013 11:42 PM
  • And here is an example.  The loops in function main are being evaluated, but none of the loops in the other functions are evaluated, even though some of them are copy and paste duplicates.

    //only loops in main are being vectorized.

    int main()
    {
        int n;
    float a[100],b[100],c[100];
        for (n=0;n<100;++n){   //info C5001: loop vectorized
            a[n]=b[n]+c[n];
        }

        int z2=10;
        for (int z=0; z2<10;z++){  //info C5002: loop not vectorized due to reason '1305'
            z2++;}
        
        for (n=0;n<100;++n){a[n]+=1;}  // info C5001: loop vectorized

        return 0;
    }


    int test()
    {
        //3 loops copy and pasted from above (main) function, but no info is reported for these 3 loops...

        int n;
    float a[100],b[100],c[100];
        for (n=0;n<100;++n){  //no info
            a[n]=b[n]+c[n];
        }

        int z2=10;
        for (int z=0; z2<10;z++){  //no info
            z2++;}
        
        for (n=0;n<100;++n){a[n]+=1;}  //no info

        return 0;
    }

    void test2(){
        float a[100],b[100];
        int n;
        for (n=100;n<1;n--){a[n]=b[n];} //again, no info if this was vectorized or not.
    }

    Saturday, February 09, 2013 6:14 PM
  • Hmm, interesting. I'm away from the possibility of testing this immediately, but two ideas: if you call the three test functions in main, do they get evaluated for vectorization? Also, what happens if you mark them with inline?
    Saturday, February 09, 2013 8:35 PM
  • Interestingly, yes, calling the function from main does seem to cause it to evaluate, and no, it didn't have to be _inline'ed.

    This is a problem for me because all my C coding is for writing dlls.  I don't call anything from my main function in a dll.  all my functions are just exported to other programs.

    Saturday, February 09, 2013 9:44 PM
  • but this did work...

    //only loops in main are being evaluated for vectorization.
    //they are however evaluated if I call them from main.

    int test();
    void test2();


    int main()
    {
        int n;
    float a[100],b[100],c[100];
        for (n=0;n<100;++n){   //info C5001: loop vectorized
            a[n]=b[n]+c[n];
        }

        int z2=10;
        for (int z=0; z2<10;z++){  //info C5002: loop not vectorized due to reason '1305'
            z2++;}
        
        for (n=0;n<100;++n){a[n]+=1;}  // info C5001: loop vectorized

        test ();
        test2();

        return 0;
    }


     int test()

    {
        //3 loops copy and pasted from above (main) function, but no info is reported for these 3 loops...
        int n;
    float a[100],b[100],c[100];
        for (n=0;n<100;++n){  //no info
            a[n]=b[n]+c[n];
        }

        int z2=10;
        for (int z=0; z2<10;z++){  //it evaluated when called from main
            z2++;}
        
        for (n=0;n<100;++n){a[n]+=1;}  //it evaluated when called from main

        return 0;
    }

    void test2(){
        float a[100],b[100];
        int n;
        for (n=100;n<1;n--){a[n]=b[n];}//it evaluated when called from main.
    }


    • Edited by Dan Ritchie Saturday, February 09, 2013 9:48 PM
    Saturday, February 09, 2013 9:46 PM
  • Do you have link time code generation enabled? If not, could you try with it enabled? The auto-vectorizer might be a bit shy about passing boundaries to peek at dll imported functions.
    Monday, February 11, 2013 7:28 AM
  • Yes I did.

    Monday, February 11, 2013 7:14 PM
  • Hi Dan,

    When reasoning about messages from the auto-vectorizer, it is sometimes useful to think in terms of the compiler optimizer. In your example with test & test2 not being called, these two functions are never optimized; the compiler won't optimize a function if it can guarantee it will never be executed. If you marked test & test2() as, say, __declspec(dllexport), then you'll see we emit the loop messages.

    That explains what's going on in the examples in this thread, but it might not explain what's going on in your project. Do you have a solution or code snippets that you can share which shows this better?

    Wednesday, February 13, 2013 5:07 PM
  • I've avoided using __declspec(dllexport) because of the name mangling, which appears is not able to be defeated.  Instead I had my exports in a def file.

    Sunday, February 17, 2013 10:14 PM
  • I've added in the def file and so far it looks like the code in the examples is now being evaluated.  I had to add main as one of the exports as well.  I don't think I've had to do that before.

    Looks like I'll have to go back to my original code and start from scratch on why only a handful of functions are being evaluated.

    Monday, February 18, 2013 9:22 PM