Intel® C++ Compiler
Support and discussions for creating C++ code that runs on platforms based on Intel® processors.
7650 Discussions

A SIMD loop performs memory references unconditionally.

mikeitexpert
New Contributor II
352 Views

I am just learning vector programming using ICL and come across the following tip/statement regarding Loop Vectorization which is not clear to me. Saying ....

 

"

  • A SIMD loop performs memory references unconditionally. Therefore, all address computations must result in valid memory addresses, even though such locations may not be accessed if the loop is executed sequentially

    "

    What does the author imply by "unconditionally"?

    I would like an expert to kindly elaborate on that please. Because, it can give debugging headaches if I don't take all details into consideration. 

    Much appreciate it.

     

    Here is the web link for further details.

    mikeitexpert_0-1617371343991.png

     

     

     

     

     

     

    0 Kudos
    1 Solution
    jimdempseyatthecove
    Black Belt
    313 Views

    Take for example (sketch code):

       if(condition) A(i) = A(i) + K(j)

    Where "condition" specifies not only that not only that you want to perform the statement, but also that the statement contains an invalid address, which, may be mapped inside your VM address space .OR. represent an invalid address. Bare in mind that such SIMD coded statements fetch the arguments first, then perform the conditional operation (as opposed to scalar code possibly bypassing the fetch, though in some cases the compiler optimization may perform the fetch, operation and then conditional move).

    In the case of a gather/scatter though the CPU may (should) inhibit memory trap to invalid address (while performing the fetch on the valid addresses even when the condition is false).

    Jim Dempsey

    View solution in original post

    4 Replies
    AwesomeScottB
    Beginner
    344 Views

    The simd pragma is used to guide the compiler to vectorize more loops. Vectorization using the simd pragma complements (but does not replace) the fully automatic approach.

    Without explicit vectorlength() and vectorlengthfor() clauses, compiler will choose a vectorlength using its own cost model. Misclassification of variables into private, firstprivate, lastprivate, linear, and reduction, or lack of appropriate classification of variables may lead to unintended consequences such as runtime failures and/or incorrect result.

    You can only specify a particular variable in at most one instance of a private, linear, or reduction clause.

    If the compiler is unable to vectorize a loop, a warning will be emitted (use assert clause to make it an error).

    If the vectorizer has to stop vectorizing a loop for some reason, the fast floating-point model is used for the SIMD loop.

    Note that the simd pragma may not affect all auto-vectorizable loops. Some of these loops do not have a way to describe the SIMD vector semantics.

    The following restrictions apply to the simd pragma:

    • The countable loop for the simd pragma has to conform to the for-loop style of an OpenMP worksharing loop construct. Additionally, the loop control variable must be a signed integer type.

    • The vector values must be signed 8-, 16-, 32-, or 64-bit integers, single or double-precision floating point numbers, or single or double-precision complex numbers.

    • A SIMD loop may contain another loop (for, while, do-while) in it. Goto out of such inner loops are not supported. Break and continue are supported. Note that inlining can create such an inner loop, which may not be obvious at the source level.

    • A SIMD loop performs memory references unconditionally. Therefore, all address computations must result in valid memory addresses, even though such locations may not be accessed if the loop is executed sequentially.

    To disable transformations that enables more vectorization, specify options -no-vec -no-simd (Linux* and Mac OS* X) or /Qvec- /Qsimd- (Windows*)

    User-mandated vectorization, also called SIMD vectorization can assert or not assert an error if a #pragma simd annotated loop fails to vectorize. By default #pragma simd is set to noassert, and the compiler will issue a warning if the loop fails to vectorize. To direct the compiler to assert an error when the #pragma simd annotated loop fails to vectorize, add the assert clause to the #pragma simd. If a #pragma simd annotated loop is not vectorized by the compiler, the loop holds its serial semantics.

    I hope this was at least somewhat helpful.

    mikeitexpert
    New Contributor II
    330 Views

    And what does the below statement mean ? Can you please elaborate on that too?

    "A SIMD loop performs memory references unconditionally. "

    Regards,

     

    jimdempseyatthecove
    Black Belt
    314 Views

    Take for example (sketch code):

       if(condition) A(i) = A(i) + K(j)

    Where "condition" specifies not only that not only that you want to perform the statement, but also that the statement contains an invalid address, which, may be mapped inside your VM address space .OR. represent an invalid address. Bare in mind that such SIMD coded statements fetch the arguments first, then perform the conditional operation (as opposed to scalar code possibly bypassing the fetch, though in some cases the compiler optimization may perform the fetch, operation and then conditional move).

    In the case of a gather/scatter though the CPU may (should) inhibit memory trap to invalid address (while performing the fetch on the valid addresses even when the condition is false).

    Jim Dempsey

    RahulV_intel
    Moderator
    294 Views

    Hi,

     

    Since @jimdempseyatthecove's answer has been marked as the solution, I will go ahead and close this thread from my end. Intel will no longer monitor this thread. Further discussions on this thread will be considered community only.

     

    Thanks,

    Rahul

    Reply