Intel® oneAPI DPC++/C++ Compiler Developer Guide and Reference

ID 767253
Date 9/08/2022
Public

A newer version of this document is available. Customers should click here to go to the newest version.

Document Table of Contents

vector

Tells the compiler that the loop should be vectorized according to the argument keywords.

Syntax

#pragma vector {always[assert]|dynamic_align|nodynamic_align|temporal|nontemporal|[no]vecremainder|vectorlength(n1[, n2]...)}

#pragma vector nontemporal[(var1[, var2, ...])]

Arguments

always

Instructs the compiler to override any efficiency heuristic during the decision to vectorize or not, and vectorize non-unit strides or very unaligned memory accesses; controls the vectorization of the subsequent loop in the program; optionally takes the keyword assert.

dynamic_align

Instructs the compiler to perform dynamic alignment optimization for the loop.

nodynamic_align

Disables dynamic alignment optimization for the loop.

nontemporal

Instructs the compiler to use non-temporal (that is, streaming) stores on systems based on all supported architectures, unless otherwise specified; optionally takes a comma-separated list of variables.

When this pragma is specified, it is your responsibility to also insert any fences as required to ensure correct memory ordering within a thread or across threads. One typical way to do this is to insert a _mm_sfence intrinsic call just after the loops (such as the initialization loop) where the compiler may insert streaming store instructions.

temporal

Instructs the compiler to use temporal (that is, non-streaming) stores on systems based on all supported architectures, unless otherwise specified.

vecremainder

Instructs the compiler to vectorize the remainder loop when the original loop is vectorized.

novecremainder

Instructs the compiler not to vectorize the remainder loop when the original loop is vectorized.

vectorlength (n1[, n2]...)

Instructs the vectorizer which vector length/factor to use when generating the main vector loop.

Description

The vector pragma indicates that the loop should be vectorized, if it is legal to do so, ignoring normal heuristic decisions about profitability. The vector pragma takes several argument keywords to specify the kind of loop vectorization required. The compiler does not apply the vector pragma to nested loops, each nested loop needs a preceding pragma statement. Place the pragma before the loop control statement.

The vector pragma is supported in host code only.

Using the always keyword

When the always argument keyword is used, the pragma will ignore compiler efficiency heuristics for the subsequent loop. When assert is added, the compiler will generate a diagnostic message if the loop cannot be vectorized for any reason.

Using the dynamic_align and nodynamic_align keywords

Dynamic alignment is an optimization the compiler can perform to improve alignment of memory references inside the loop. It involves peeling iterations from the vector loop into a scalar loop (which may, in turn, also be vectorized) before the vector loop so that the vector loop aligns with a particular memory reference. Specifying dynamic_align enables the optimization to be performed, but the compiler will still use efficiency heuristics to determine whether the optimization will be applied to the loop. Specifying nodynamic_align disables the optimization. By default, the compiler does not perform optimization.

Using the nontemporal and temporal keywords

The nontemporal and temporal argument keywords are used to control how the "stores" of register contents to storage are performed (streaming versus non-streaming) on systems based on Intel® 64 architectures.

By default, the compiler automatically determines whether a streaming store should be used for each variable.

Streaming stores may cause significant performance improvements over non-streaming stores for large numbers on certain processors. However, the misuse of streaming stores can significantly degrade performance.

Using the [no]vecremainder keyword

If keyword vecremainder is specified, the compiler tries to vectorize the remainder loop when the main loop is vectorized. Even if the always keyword is specified, the remainder loop vectorization is still a subject of compiler efficiency heuristics.

If keyword novecremainder is specified, the compiler vectorizes the main loop, but it does not vectorize the remainder loop.

Using the vectorlength keyword

n is an integer power of 2; the value must be 2, 4, 6, 8, 16, 32, or 64. If more than one value is specified, the vectorizer will choose one of the specified vector lengths based on a cost model decision.

NOTE:

The pragma vector should be used with care.

Overriding the efficiency heuristics of the compiler should only be done if the programmer is absolutely sure that vectorization will improve performance.