Hydraulic conductivity: Difference between revisions

From formulasearchengine
Jump to navigation Jump to search
en>Bibcode Bot
m Adding 0 arxiv eprint(s), 1 bibcode(s) and 0 doi(s). Did it miss something? Report bugs, errors, and suggestions at User talk:Bibcode Bot
 
en>Jwratner1
Line 1: Line 1:
Golda is what's written on my birth certification although it is not the title on my birth certificate. The preferred pastime for him and his kids is to perform lacross and he would by no means give it up. Distributing production has been his occupation for some time. Her family members lives in Alaska but her husband desires them to transfer.<br><br>Review my web blog :: psychic readers - [http://www.naadagam.com/profile.php?u=SuNFMS www.naadagam.com linked web-site] -
{{more footnotes|date=October 2010}}
{{for|vectorization as a programming idiom|Array programming}}
'''Automatic vectorization''', in [[parallel computing]], is a special case of automatic [[parallelization]], where a [[computer program]] is converted from a [[scalar (computing)|scalar]] implementation, which processes a single pair of [[operand]]s at a time, to a [[Array data structure|vector]] implementation which processes one operation on multiple pairs of operands at once. As an example, modern conventional computers (as well as specialized [[supercomputers]]) typically have [[vector processing|vector operations]] that perform, e.g. the four additions
 
:<math>\begin{align}
    c_1 & = a_1 + b_1 \\
    c_2 & = a_2 + b_2 \\
    c_3 & = a_3 + b_3 \\
    c_4 & = a_4 + b_4
\end{align}</math>
 
all at once. However, in most [[programming language]]s, one typically writes loops that perform additions on many numbers, e.g. (example in [[C (programming language)|C]]):
 
<source lang="c">
for (i=0; i<n; i++)
    c[i] = a[i] + b[i];
</source>
 
The goal of a vectorizing [[compiler]] is to transform such a loop into a sequence of vector operations, that perform additions on length-four (in our example) blocks of elements from the arrays <code>a</code>, <code>b</code> and <code>c</code>. Automatic vectorization is a major research topic in computer science.
 
==Background==
Early computers generally had one logic unit that sequentially executed one instruction on one operand pair at a time. Computer programs and [[programming language]]s were accordingly designed to execute sequentially. Modern computers can do many things at once. Many optimizing compilers feature auto-vectorization, a compiler feature where particular parts of sequential programs are transformed into equivalent parallel ones, to produce code which will well utilize a vector processor. For a compiler to produce such efficient code for a programming language intended for use on a vector-processor would be much simpler, but, as much real-world code is sequential, the optimization is of great utility.
 
'''Loop vectorization''' converts procedural loops that iterate over multiple pairs of data items and assigns a separate processing unit to each pair. Most programs spend most of their execution times within such loops. Vectorizing loops can lead to significant performance gains without programmer intervention, especially on large data sets. Vectorization can sometimes instead slow execution because of [[Pipeline (computing)|pipeline]] synchronization, data movement timing and other issues.
 
[[Intel]]'s [[MMX (instruction set)|MMX]], [[Streaming SIMD Extensions|SSE]], [[Advanced Vector Extensions|AVX]] and [[Power Architecture]]'s [[Altivec|AltiVec]] and [[ARM Holdings|ARM]]'s [[ARM NEON|NEON]] instruction sets support such vectorized loops.
 
Many constraints prevent or hinder vectorization. [[Loop dependence analysis]] identifies loops that can be vectorized, relying on the [[data dependence]] of the instructions inside loops.
 
==Guarantees==
Automatic vectorization, like any [[loop optimization]] or other compile-time optimization, must exactly preserve program behavior.
 
===Data dependencies===
All dependencies must be respected during execution to prevent incorrect outcomes.
 
In general, loop invariant dependencies and lexically forward dependencies can be easily vectorized, and lexically backward dependencies can be transformed into lexically forward. But these transformations must be done safely, in order to assure the dependence between '''all statements''' remain true to the original.
 
Cyclic dependencies must be processed independently of the vectorized instructions.
 
===Data precision===
[[Integer (computer science)|Integer]] [[Precision (computer science)|precision]] (bit-size) must be kept during vector instruction execution. The correct vector instruction must be chosen based on the size and behavior of the internal integers. Also, with mixed integer types, extra care must be taken to promote/demote them correctly without losing precision. Special care must be taken with [[sign extension]] (because multiple integers are packed inside the same register) and during shift operations, or operations with [[carry bit]]s that would otherwise be taken into account.
 
[[Floating-point]] precision must be kept as well, unless [[IEEE-754]] compliance is turned off, in which case operations will be faster but the results may vary slightly. Big variations, even ignoring IEEE-754 usually means programmer error. The programmer can also force constants and loop variables to single precision (default is normally double) to execute twice as many operations per instruction.
 
==Theory==
To vectorize a program, the compiler's optimizer must first understand the dependencies between statements and re-align them, if necessary. Once the dependencies are mapped, the optimizer must properly arrange the implementing instructions changing appropriate candidates to vector instructions, which operate on multiple data items.
 
===Building the dependency graph===
The first step is to build the [[dependency graph]], identifying which statements depend on which other statements. This involves examining each statement and identifying every  data item that the statement accesses, mapping array access modifiers to functions and checking every access' dependency to all others in all statements. [[Alias analysis]] can be used to certify that the different variables access (or intersects) the same region in memory.
 
The dependency graph contains all local dependencies with distance not greater than the vector size. So, if the vector register is 128 bits, and the array type is 32 bits, the vector size is 128/32 = 4. All other non-cyclic dependencies should not invalidate vectorization, since there won't be any concurrent access in the same vector instruction.
 
Suppose the vector size is the same as 4 ints:
 
<source lang="C">
for (i = 0; i < 128; i++) {
  a[i] = a[i-16]; // 16 > 4, safe to ignore
  a[i] = a[i-1]; // 1 < 4, stays on dependency graph
}
</source>
 
===Clustering===
Using the graph, the optimizer can then cluster the [[strongly connected components]] (SCC) and separate vectorizable statements from the rest.
 
For example, consider a program fragment containing three statement groups inside a loop: (SCC1+SCC2), SCC3 and SCC4, in that order, in which only the second group (SCC3) can be vectorized. The final program will then contain three loops, one for each group, with only the middle one vectorized. The optimizer cannot join the first with the last without violating statement execution order, which would invalidate the necessary guarantees.
 
===Detecting idioms===
Some non-obvious dependencies can be further optimized based on specific idioms.
 
For instance, the following self-data-dependencies can be vectorized because the value of the right-hand values ([[Left-hand side and right-hand side of an equation|RHS]]) are fetched and then stored on the left-hand value, so there is no way the data will change within the assignment.
 
<source lang="C">
a[i] = a[i] + a[i+1];
</source>
 
Self-dependence by scalars can be vectorized by variable elimination.
 
==General framework==
The general framework for loop vectorization is split into four stages:
* '''Prelude''': Where the loop-independent variables are prepared to be used inside the loop. This normally involves moving them to vector registers with specific patterns that will be used in vector instructions. This is also the place to insert the run-time dependence check. If the check decides vectorization is not possible, branch to '''Cleanup'''.
* '''Loop(s)''': All vectorized (or not) loops, separated by SCCs clusters in order of appearance in the original code.
* '''Postlude''': Return all loop-independent variables, inductions and reductions.
* '''Cleanup''': Implement plain (non-vectorized) loops for iterations at the end of a loop that are not a multiple of the vector size or for when run-time checks prohibit vector processing.
 
==Run-time vs. compile-time==
Some vectorizations cannot be fully checked at compile time. Compile-time optimization requires an explicit array index. Library functions can also defeat optimization if the data they process is supplied by the caller. Even in these cases, run-time optimization can still vectorize loops on-the-fly.
 
This run-time check is made in the '''prelude''' stage and directs the flow to vectorized instructions if possible, otherwise reverting to standard processing, depending on the variables that are being passed on the registers or scalar variables.
 
The following code can easily be vectorized on compile time, as it doesn't have any dependence on external parameters. Also, the language guarantees that neither will occupy the same region in memory as any other variable, as they are local variables and live only in the execution [[stack (data structure)|stack]].
 
<source lang="C">
int a[128];
int b[128];
// initialize b
 
for (i = 0; i<128; i++)
  a[i] = b[i] + 5;
</source>
 
On the other hand, the code below has no information on memory positions, because the references are [[pointer (computer programming)|pointer]]s and the memory they point to lives in the [[Dynamic memory allocation|heap]].
 
<source lang="C">
int *a = malloc(128*sizeof(int));
int *b = malloc(128*sizeof(int));
// initialize b
 
for (i = 0; i<128; i++, a++, b++)
  *a = *b + 5;
// ...
// ...
// ...
free(b);
free(a);
</source>
 
A quick run-time check on the [[memory address|address]] of both ''a'' and ''b'', plus the loop iteration space (128) is enough to tell if the arrays overlap or not, thus revealing any dependencies.
 
There exist some tools to dynamically analyze existing applications to assess the inherent latent potential for SIMD parallelism, exploitable through further compiler advances and/or via manual code changes. <ref>[http://dl.acm.org/citation.cfm?id=2254108&CFID=305005555&CFTOKEN=26320981]</ref>
 
==Techniques==
An example would be a program to multiply two vectors of numeric data.  A scalar approach would be something like:
 
<source lang="C">
for (i = 0; i < 1024; i++)
    C[i] = A[i]*B[i];
</source>
 
This could be vectorized to look something like:
 
<source lang="C">
  for (i = 0; i < 1024; i+=4)
    C[i:i+3] = A[i:i+3]*B[i:i+3];
</source>
 
Here, C[i:i+3] represents the four array elements from C[i] to C[i+3] and the vector processor can perform four operations for a single vector instruction. Since the four vector operations complete in roughly the same time as one scalar instruction, the vector approach can run up to four times faster than the original code.
 
There are two distinct compiler approaches: one based on the conventional vectorization technique and the other based on [[loop unwinding|loop unrolling]].
 
===Loop-level automatic vectorization===
This technique, used for conventional vector machines, tries to find and exploit [[SIMD]] parallelism at the loop level. It consists of two major steps as follows.
 
# Find an innermost loop that can be vectorized
# Transform the loop and generate vector codes
 
In the first step, the compiler looks for obstacles that can prevent vectorization. A major obstacle for vectorization is [[Instruction level parallelism|true data dependency]] shorter than the vector length. Other obstacles include function calls and short iteration counts.
 
Once the loop is determined to be vectorizable, the loop is stripmined by the vector length and each scalar instruction within the loop body is replaced with the corresponding vector instruction. Below, the component transformations for this step are shown using the above example.
* After stripmining
 
<source lang="C">
for (i = 0; i < 1024; i+=4)
    for (ii = 0; ii < 4; ii++)
      C[i+ii] = A[i+ii]*B[i+ii];
</source>
* After loop distribution using temporary arrays
 
<source lang="C">
  for (i = 0; i < 1024; i+=4)
  {
    for (ii = 0; ii < 4; ii++) tA[ii] = A[i+ii];
    for (ii = 0; ii < 4; ii++) tB[ii] = B[i+ii];
    for (ii = 0; ii < 4; ii++) tC[ii] = tA[ii]*tB[ii];
    for (ii = 0; ii < 4; ii++) C[i+ii] = tC[ii];
  }
</source>
* After replacing with vector codes
 
<source lang="C">for (i = 0; i < 1024; i+=4)
  {
    vA = vec_ld( &A[i] );
    vB = vec_ld( &B[i] );
    vC = vec_mul( vA, vB );
    vec_st( vC, &C[i] );
  }
</source>
 
===Basic block level automatic vectorization===
This relatively new technique specifically targets modern SIMD architectures with short vector lengths.<ref>{{Cite journal | last1=Larsen | first1=S. | last2=Amarasinghe | first2=S. | contribution=Exploiting superword level parallelism with multimedia instruction sets | pages=145–156 | title=Proceedings of the ACM SIGPLAN conference on Programming language design and implementation | year=2000 | doi=10.1145/358438.349320 | journal=ACM SIGPLAN Notices | volume=35 | issue=5
}}</ref> Although loops can be unrolled to increase the amount of SIMD parallelism in basic blocks, this technique exploits SIMD parallelism within basic blocks rather than loops. The two major steps are as follows.
 
# The innermost loop is unrolled by a factor of the vector length to form a large loop body.
# Isomorphic scalar instructions (that perform the same operation) are packed into a vector instruction if dependencies do not prevent doing so.
 
To show step-by-step transformations for this approach, the same example is used again.
* After loop unrolling (by the vector length, assumed to be 4 in this case)
 
<source lang=c>
for (i = 0; i < 1024; i+=4)
  {
    sA0 = ld( &A[i+0] );
    sB0 = ld( &B[i+0] );
    sC0 = sA0 * sB0;
    st( sC0, &C[i+0] );
          ...
    sA3 = ld( &A[i+3] );
    sB3 = ld( &B[i+3] );
    sC3 = sA3 * sB3;
    st( sC3, &C[i+3] );
  }
</source>
* After packing
 
<source lang=c>
for (i = 0; i < 1024; i+=4)
  {
    (sA0,sA1,sA2,sA3) = ld( &A[i+0:i+3] );
    (sB0,sB1,sB2,sB3) = ld( &B[i+0:i+3] );
    (sC0,sC1,sC2,sC3) = (sA0,sA1,sA2,sA3) * (sB0,sB1,sB2,sB3);
    st( (sC0,sC1,sC2,sC3), &C[i+0:i+3] );
  }
</source>
* After code generation
 
<source lang=c>
for (i = 0; i < 1024; i+=4)
  {
    vA = vec_ld( &A[i] );
    vB = vec_ld( &B[i] );
    vC = vec_mul( vA, vB );
    vec_st( vC, &C[i] );
  }
</source>
Here, sA1, sB1, ... represent scalar variables and vA, vB, and vC represent vector variables.
 
Most automatically vectorizing commercial compilers use the conventional loop-level approach except the IBM XL Compiler,<ref name=ibm/> which uses both.
 
===In the presence of control flow===
The presence of if-statements in the loop body requires the execution of instructions in all control paths to merge the multiple values of a variable. One general approach is to go through a sequence of code transformations: predication → vectorization(using one of the above methods) → remove vector predicates → remove scalar predicates.<ref>{{Cite journal | last1=Shin | first1=J. | last2=Hall | first2=M. W. | last3=Chame | first3=J. | contribution=Superword-Level Parallelism in the Presence of Control Flow | pages=165–175
| title=Proceedings of the international symposium on Code generation and optimization | year=2005
| doi=10.1109/CGO.2005.33 |isbn=0-7695-2298-X}}</ref> If the following code is used as an example to show these transformations;
 
<source lang=c>
for (i = 0; i < 1024; i++)
    if (A[i] > 0)
      C[i] = B[i];
    else
      D[i] = D[i-1];
</source>
* After predication
 
<source lang=c>
for (i = 0; i < 1024; i++)
  {
    P = A[i] > 0;
    NP = !P;
    C[i] = B[i];    (P)
    D[i] = D[i-1];  (NP)
  }
</source>
where (P) denotes a predicate guarding the statement.
* After vectorization
 
<source lang=c>
for (i = 0; i < 1024; i+=4)
  {
    vP  = A[i:i+3] > (0,0,0,0);
    vNP = vec_not(vP);
    C[i:i+3] = B[i:i+3];    (vP)
    (NP1,NP2,NP3,NP4) = vNP;
    D[i+3] = D[i+2];        (NP4)
    D[i+2] = D[i+1];        (NP3)
    D[i+1] = D[i];          (NP2)
    D[i]    = D[i-1];        (NP1)
  }
</source>
* After removing vector predicates
 
<source lang=c>
for (i = 0; i < 1024; i+=4)
  {
    vP  = A[i:i+3] > (0,0,0,0);
    vNP = vec_not(vP);
    C[i:i+3] = vec_sel(C[i:i+3],B[i:i+3],vP);
    (NP1,NP2,NP3,NP4) = vNP;
    D[i+3] = D[i+2];        (NP4)
    D[i+2] = D[i+1];        (NP3)
    D[i+1] = D[i];          (NP2)
    D[i]    = D[i-1];        (NP1)
  }
</source>
* After removing scalar predicates
 
<source lang=c>
for (i = 0; i < 1024; i+=4)
  {
    vP  = A[i:i+3] > (0,0,0,0);
    vNP = vec_not(vP);
    C[i:i+3] = vec_sel(C[i:i+3],B[i:i+3],vP);
    (NP1,NP2,NP3,NP4) = vNP;
    if (NP4) D[i+3] = D[i+2];
    if (NP3) D[i+2] = D[i+1];
    if (NP2) D[i+1] = D[i];
    if (NP1) D[i]  = D[i-1];
  }
</source>
 
===Reducing vectorization overhead in the presence of control flow===
Having to execute the instructions in all control paths in vector code has been one of the major factors that slow down the vector code with respect to the scalar baseline. The more complex the control flow becomes and the more instructions are bypassed in the scalar code the larger the vectorization overhead grows. To reduce this vectorization overhead, vector branches can be inserted to bypass vector instructions similar to the way scalar branches bypass scalar instructions.<ref>{{Cite journal | last=Shin | first=J. | contribution=Introducing Control Flow into Vectorized Code | pages=280–291 | title=Proceedings of the 16th International Conference on Parallel Architecture and Compilation Techniques | year=2007 | doi=10.1109/PACT.2007.41}}</ref> Below, AltiVec predicates are used to show how this can be achieved.
* Scalar baseline (original code)
 
<source lang=c>
for (i = 0; i < 1024; i++)
  {
    if (A[i] > 0)
    {
      C[i] = B[i];
      if (B[i] < 0)
        D[i] = E[i];
    }
  }
</source>
* After vectorization in the presence of control flow
 
<source lang=c>
for (i = 0; i < 1024; i+=4)
  {
    vPA = A[i:i+3] > (0,0,0,0);
    C[i:i+3] = vec_sel(C[i:i+3],B[i:i+3],vPA);
    vT = B[i:i+3] < (0,0,0,0);
    vPB = vec_sel((0,0,0,0), vT, vPA);
    D[i:i+3] = vec_sel(D[i:i+3],E[i:i+3],vPB);
  }
</source>
* After inserting vector branches
 
<source lang=c>
for (i = 0; i < 1024; i+=4)
    if (vec_any_gt(A[i:i+3],(0,0,0,0)))
    {
        vPA = A[i:i+3] > (0,0,0,0);
        C[i:i+3] = vec_sel(C[i:i+3],B[i:i+3],vPA);
        vT = B[i:i+3] < (0,0,0,0);
        vPB = vec_sel((0,0,0,0), vT, vPA);
        if (vec_any_ne(vPB,(0,0,0,0)))
          D[i:i+3] = vec_sel(D[i:i+3],E[i:i+3],vPB);
    }
</source>
There are two things to note in the final code with vector branches; First, the predicate defining instruction for vPA is also included within the body of the outer vector branch by using vec_any_gt. Second, the profitability of the inner vector branch for vPB depends on the conditional probability of vPB having false values in all fields given vPA has false values in all fields.
 
Consider an example where the outer branch in the scalar baseline is always taken, bypassing most instructions in the loop body.  The intermediate case above, without vector branches, executes all vector instructions. The final code, with vector branches, executes both the comparison and the branch in vector mode, potentially gaining performance over the scalar baseline.
 
==See also==
* [[Chaining (vector processing)]]
 
==References==
{{Reflist|refs
<ref name=ibm>{{cite web
|url=http://www.ess.uci.edu/esmf/ibm_compiler_docs/xl_optimization.pdf
|title=Code Optimization with IBM XL Compilers
|date=June 2004
|accessdate=May 2010
}}</ref>
}}
 
{{DEFAULTSORT:Vectorization (Computer Science)}}
[[Category:Compiler optimizations]]
[[Category:Distributed computing problems]]
 
[[de:Vektorisierung]]
[[lt:Vektorizacija]]
[[ja:ベクトル化]]

Revision as of 08:39, 4 January 2014

Template:More footnotes 28 year-old Painting Investments Worker Truman from Regina, usually spends time with pastimes for instance interior design, property developers in new launch ec Singapore and writing. Last month just traveled to City of the Renaissance. Automatic vectorization, in parallel computing, is a special case of automatic parallelization, where a computer program is converted from a scalar implementation, which processes a single pair of operands at a time, to a vector implementation which processes one operation on multiple pairs of operands at once. As an example, modern conventional computers (as well as specialized supercomputers) typically have vector operations that perform, e.g. the four additions

all at once. However, in most programming languages, one typically writes loops that perform additions on many numbers, e.g. (example in C):

for (i=0; i<n; i++)
    c[i] = a[i] + b[i];

The goal of a vectorizing compiler is to transform such a loop into a sequence of vector operations, that perform additions on length-four (in our example) blocks of elements from the arrays a, b and c. Automatic vectorization is a major research topic in computer science.

Background

Early computers generally had one logic unit that sequentially executed one instruction on one operand pair at a time. Computer programs and programming languages were accordingly designed to execute sequentially. Modern computers can do many things at once. Many optimizing compilers feature auto-vectorization, a compiler feature where particular parts of sequential programs are transformed into equivalent parallel ones, to produce code which will well utilize a vector processor. For a compiler to produce such efficient code for a programming language intended for use on a vector-processor would be much simpler, but, as much real-world code is sequential, the optimization is of great utility.

Loop vectorization converts procedural loops that iterate over multiple pairs of data items and assigns a separate processing unit to each pair. Most programs spend most of their execution times within such loops. Vectorizing loops can lead to significant performance gains without programmer intervention, especially on large data sets. Vectorization can sometimes instead slow execution because of pipeline synchronization, data movement timing and other issues.

Intel's MMX, SSE, AVX and Power Architecture's AltiVec and ARM's NEON instruction sets support such vectorized loops.

Many constraints prevent or hinder vectorization. Loop dependence analysis identifies loops that can be vectorized, relying on the data dependence of the instructions inside loops.

Guarantees

Automatic vectorization, like any loop optimization or other compile-time optimization, must exactly preserve program behavior.

Data dependencies

All dependencies must be respected during execution to prevent incorrect outcomes.

In general, loop invariant dependencies and lexically forward dependencies can be easily vectorized, and lexically backward dependencies can be transformed into lexically forward. But these transformations must be done safely, in order to assure the dependence between all statements remain true to the original.

Cyclic dependencies must be processed independently of the vectorized instructions.

Data precision

Integer precision (bit-size) must be kept during vector instruction execution. The correct vector instruction must be chosen based on the size and behavior of the internal integers. Also, with mixed integer types, extra care must be taken to promote/demote them correctly without losing precision. Special care must be taken with sign extension (because multiple integers are packed inside the same register) and during shift operations, or operations with carry bits that would otherwise be taken into account.

Floating-point precision must be kept as well, unless IEEE-754 compliance is turned off, in which case operations will be faster but the results may vary slightly. Big variations, even ignoring IEEE-754 usually means programmer error. The programmer can also force constants and loop variables to single precision (default is normally double) to execute twice as many operations per instruction.

Theory

To vectorize a program, the compiler's optimizer must first understand the dependencies between statements and re-align them, if necessary. Once the dependencies are mapped, the optimizer must properly arrange the implementing instructions changing appropriate candidates to vector instructions, which operate on multiple data items.

Building the dependency graph

The first step is to build the dependency graph, identifying which statements depend on which other statements. This involves examining each statement and identifying every data item that the statement accesses, mapping array access modifiers to functions and checking every access' dependency to all others in all statements. Alias analysis can be used to certify that the different variables access (or intersects) the same region in memory.

The dependency graph contains all local dependencies with distance not greater than the vector size. So, if the vector register is 128 bits, and the array type is 32 bits, the vector size is 128/32 = 4. All other non-cyclic dependencies should not invalidate vectorization, since there won't be any concurrent access in the same vector instruction.

Suppose the vector size is the same as 4 ints:

for (i = 0; i < 128; i++) {
  a[i] = a[i-16]; // 16 > 4, safe to ignore
  a[i] = a[i-1]; // 1 < 4, stays on dependency graph
}

Clustering

Using the graph, the optimizer can then cluster the strongly connected components (SCC) and separate vectorizable statements from the rest.

For example, consider a program fragment containing three statement groups inside a loop: (SCC1+SCC2), SCC3 and SCC4, in that order, in which only the second group (SCC3) can be vectorized. The final program will then contain three loops, one for each group, with only the middle one vectorized. The optimizer cannot join the first with the last without violating statement execution order, which would invalidate the necessary guarantees.

Detecting idioms

Some non-obvious dependencies can be further optimized based on specific idioms.

For instance, the following self-data-dependencies can be vectorized because the value of the right-hand values (RHS) are fetched and then stored on the left-hand value, so there is no way the data will change within the assignment.

a[i] = a[i] + a[i+1];

Self-dependence by scalars can be vectorized by variable elimination.

General framework

The general framework for loop vectorization is split into four stages:

  • Prelude: Where the loop-independent variables are prepared to be used inside the loop. This normally involves moving them to vector registers with specific patterns that will be used in vector instructions. This is also the place to insert the run-time dependence check. If the check decides vectorization is not possible, branch to Cleanup.
  • Loop(s): All vectorized (or not) loops, separated by SCCs clusters in order of appearance in the original code.
  • Postlude: Return all loop-independent variables, inductions and reductions.
  • Cleanup: Implement plain (non-vectorized) loops for iterations at the end of a loop that are not a multiple of the vector size or for when run-time checks prohibit vector processing.

Run-time vs. compile-time

Some vectorizations cannot be fully checked at compile time. Compile-time optimization requires an explicit array index. Library functions can also defeat optimization if the data they process is supplied by the caller. Even in these cases, run-time optimization can still vectorize loops on-the-fly.

This run-time check is made in the prelude stage and directs the flow to vectorized instructions if possible, otherwise reverting to standard processing, depending on the variables that are being passed on the registers or scalar variables.

The following code can easily be vectorized on compile time, as it doesn't have any dependence on external parameters. Also, the language guarantees that neither will occupy the same region in memory as any other variable, as they are local variables and live only in the execution stack.

int a[128];
int b[128];
// initialize b

for (i = 0; i<128; i++)
  a[i] = b[i] + 5;

On the other hand, the code below has no information on memory positions, because the references are pointers and the memory they point to lives in the heap.

int *a = malloc(128*sizeof(int));
int *b = malloc(128*sizeof(int));
// initialize b

for (i = 0; i<128; i++, a++, b++)
  *a = *b + 5;
// ... 
// ...
// ...
free(b);
free(a);

A quick run-time check on the address of both a and b, plus the loop iteration space (128) is enough to tell if the arrays overlap or not, thus revealing any dependencies.

There exist some tools to dynamically analyze existing applications to assess the inherent latent potential for SIMD parallelism, exploitable through further compiler advances and/or via manual code changes. [1]

Techniques

An example would be a program to multiply two vectors of numeric data. A scalar approach would be something like:

 for (i = 0; i < 1024; i++)
    C[i] = A[i]*B[i];

This could be vectorized to look something like:

  for (i = 0; i < 1024; i+=4)
     C[i:i+3] = A[i:i+3]*B[i:i+3];

Here, C[i:i+3] represents the four array elements from C[i] to C[i+3] and the vector processor can perform four operations for a single vector instruction. Since the four vector operations complete in roughly the same time as one scalar instruction, the vector approach can run up to four times faster than the original code.

There are two distinct compiler approaches: one based on the conventional vectorization technique and the other based on loop unrolling.

Loop-level automatic vectorization

This technique, used for conventional vector machines, tries to find and exploit SIMD parallelism at the loop level. It consists of two major steps as follows.

  1. Find an innermost loop that can be vectorized
  2. Transform the loop and generate vector codes

In the first step, the compiler looks for obstacles that can prevent vectorization. A major obstacle for vectorization is true data dependency shorter than the vector length. Other obstacles include function calls and short iteration counts.

Once the loop is determined to be vectorizable, the loop is stripmined by the vector length and each scalar instruction within the loop body is replaced with the corresponding vector instruction. Below, the component transformations for this step are shown using the above example.

  • After stripmining
for (i = 0; i < 1024; i+=4)
    for (ii = 0; ii < 4; ii++)
       C[i+ii] = A[i+ii]*B[i+ii];
  • After loop distribution using temporary arrays
  for (i = 0; i < 1024; i+=4)
  {
    for (ii = 0; ii < 4; ii++) tA[ii] = A[i+ii];
    for (ii = 0; ii < 4; ii++) tB[ii] = B[i+ii];
    for (ii = 0; ii < 4; ii++) tC[ii] = tA[ii]*tB[ii];
    for (ii = 0; ii < 4; ii++) C[i+ii] = tC[ii];
  }
  • After replacing with vector codes
for (i = 0; i < 1024; i+=4)
  {
    vA = vec_ld( &A[i] );
    vB = vec_ld( &B[i] );
    vC = vec_mul( vA, vB );
    vec_st( vC, &C[i] );
  }

Basic block level automatic vectorization

This relatively new technique specifically targets modern SIMD architectures with short vector lengths.[2] Although loops can be unrolled to increase the amount of SIMD parallelism in basic blocks, this technique exploits SIMD parallelism within basic blocks rather than loops. The two major steps are as follows.

  1. The innermost loop is unrolled by a factor of the vector length to form a large loop body.
  2. Isomorphic scalar instructions (that perform the same operation) are packed into a vector instruction if dependencies do not prevent doing so.

To show step-by-step transformations for this approach, the same example is used again.

  • After loop unrolling (by the vector length, assumed to be 4 in this case)
for (i = 0; i < 1024; i+=4)
  {
     sA0 = ld( &A[i+0] );
     sB0 = ld( &B[i+0] );
     sC0 = sA0 * sB0;
     st( sC0, &C[i+0] );
           ...
     sA3 = ld( &A[i+3] );
     sB3 = ld( &B[i+3] );
     sC3 = sA3 * sB3;
     st( sC3, &C[i+3] );
  }
  • After packing
for (i = 0; i < 1024; i+=4)
  {
     (sA0,sA1,sA2,sA3) = ld( &A[i+0:i+3] );
     (sB0,sB1,sB2,sB3) = ld( &B[i+0:i+3] );
     (sC0,sC1,sC2,sC3) = (sA0,sA1,sA2,sA3) * (sB0,sB1,sB2,sB3);
     st( (sC0,sC1,sC2,sC3), &C[i+0:i+3] );
  }
  • After code generation
for (i = 0; i < 1024; i+=4)
  {
    vA = vec_ld( &A[i] );
    vB = vec_ld( &B[i] );
    vC = vec_mul( vA, vB );
    vec_st( vC, &C[i] );
  }

Here, sA1, sB1, ... represent scalar variables and vA, vB, and vC represent vector variables.

Most automatically vectorizing commercial compilers use the conventional loop-level approach except the IBM XL Compiler,[3] which uses both.

In the presence of control flow

The presence of if-statements in the loop body requires the execution of instructions in all control paths to merge the multiple values of a variable. One general approach is to go through a sequence of code transformations: predication → vectorization(using one of the above methods) → remove vector predicates → remove scalar predicates.[4] If the following code is used as an example to show these transformations;

for (i = 0; i < 1024; i++)
     if (A[i] > 0)
       C[i] = B[i];
     else
       D[i] = D[i-1];
  • After predication
for (i = 0; i < 1024; i++)
  {
     P = A[i] > 0;
     NP = !P;
     C[i] = B[i];     (P)
     D[i] = D[i-1];   (NP)
  }

where (P) denotes a predicate guarding the statement.

  • After vectorization
for (i = 0; i < 1024; i+=4)
  {
     vP  = A[i:i+3] > (0,0,0,0);
     vNP = vec_not(vP);
     C[i:i+3] = B[i:i+3];     (vP)
     (NP1,NP2,NP3,NP4) = vNP;
     D[i+3] = D[i+2];         (NP4)
     D[i+2] = D[i+1];         (NP3)
     D[i+1] = D[i];           (NP2)
     D[i]     = D[i-1];         (NP1)
  }
  • After removing vector predicates
for (i = 0; i < 1024; i+=4)
  {
     vP  = A[i:i+3] > (0,0,0,0);
     vNP = vec_not(vP);
     C[i:i+3] = vec_sel(C[i:i+3],B[i:i+3],vP);
     (NP1,NP2,NP3,NP4) = vNP;
     D[i+3] = D[i+2];         (NP4)
     D[i+2] = D[i+1];         (NP3)
     D[i+1] = D[i];           (NP2)
     D[i]     = D[i-1];         (NP1)
  }
  • After removing scalar predicates
for (i = 0; i < 1024; i+=4)
  {
     vP  = A[i:i+3] > (0,0,0,0);
     vNP = vec_not(vP);
     C[i:i+3] = vec_sel(C[i:i+3],B[i:i+3],vP);
     (NP1,NP2,NP3,NP4) = vNP;
     if (NP4) D[i+3] = D[i+2];
     if (NP3) D[i+2] = D[i+1];
     if (NP2) D[i+1] = D[i];
     if (NP1) D[i]   = D[i-1];
  }

Reducing vectorization overhead in the presence of control flow

Having to execute the instructions in all control paths in vector code has been one of the major factors that slow down the vector code with respect to the scalar baseline. The more complex the control flow becomes and the more instructions are bypassed in the scalar code the larger the vectorization overhead grows. To reduce this vectorization overhead, vector branches can be inserted to bypass vector instructions similar to the way scalar branches bypass scalar instructions.[5] Below, AltiVec predicates are used to show how this can be achieved.

  • Scalar baseline (original code)
for (i = 0; i < 1024; i++)
  {
     if (A[i] > 0)
     {
       C[i] = B[i];
       if (B[i] < 0)
         D[i] = E[i];
     }
  }
  • After vectorization in the presence of control flow
for (i = 0; i < 1024; i+=4)
  {
     vPA = A[i:i+3] > (0,0,0,0);
     C[i:i+3] = vec_sel(C[i:i+3],B[i:i+3],vPA);
     vT = B[i:i+3] < (0,0,0,0);
     vPB = vec_sel((0,0,0,0), vT, vPA);
     D[i:i+3] = vec_sel(D[i:i+3],E[i:i+3],vPB);
  }
  • After inserting vector branches
for (i = 0; i < 1024; i+=4)
     if (vec_any_gt(A[i:i+3],(0,0,0,0)))
     {
        vPA = A[i:i+3] > (0,0,0,0);
        C[i:i+3] = vec_sel(C[i:i+3],B[i:i+3],vPA);
        vT = B[i:i+3] < (0,0,0,0);
        vPB = vec_sel((0,0,0,0), vT, vPA);
        if (vec_any_ne(vPB,(0,0,0,0)))
           D[i:i+3] = vec_sel(D[i:i+3],E[i:i+3],vPB);
     }

There are two things to note in the final code with vector branches; First, the predicate defining instruction for vPA is also included within the body of the outer vector branch by using vec_any_gt. Second, the profitability of the inner vector branch for vPB depends on the conditional probability of vPB having false values in all fields given vPA has false values in all fields.

Consider an example where the outer branch in the scalar baseline is always taken, bypassing most instructions in the loop body. The intermediate case above, without vector branches, executes all vector instructions. The final code, with vector branches, executes both the comparison and the branch in vector mode, potentially gaining performance over the scalar baseline.

See also

References

43 year old Petroleum Engineer Harry from Deep River, usually spends time with hobbies and interests like renting movies, property developers in singapore new condominium and vehicle racing. Constantly enjoys going to destinations like Camino Real de Tierra Adentro.

de:Vektorisierung lt:Vektorizacija ja:ベクトル化

  1. [1]
  2. One of the biggest reasons investing in a Singapore new launch is an effective things is as a result of it is doable to be lent massive quantities of money at very low interest rates that you should utilize to purchase it. Then, if property values continue to go up, then you'll get a really high return on funding (ROI). Simply make sure you purchase one of the higher properties, reminiscent of the ones at Fernvale the Riverbank or any Singapore landed property Get Earnings by means of Renting

    In its statement, the singapore property listing - website link, government claimed that the majority citizens buying their first residence won't be hurt by the new measures. Some concessions can even be prolonged to chose teams of consumers, similar to married couples with a minimum of one Singaporean partner who are purchasing their second property so long as they intend to promote their first residential property. Lower the LTV limit on housing loans granted by monetary establishments regulated by MAS from 70% to 60% for property purchasers who are individuals with a number of outstanding housing loans on the time of the brand new housing purchase. Singapore Property Measures - 30 August 2010 The most popular seek for the number of bedrooms in Singapore is 4, followed by 2 and three. Lush Acres EC @ Sengkang

    Discover out more about real estate funding in the area, together with info on international funding incentives and property possession. Many Singaporeans have been investing in property across the causeway in recent years, attracted by comparatively low prices. However, those who need to exit their investments quickly are likely to face significant challenges when trying to sell their property – and could finally be stuck with a property they can't sell. Career improvement programmes, in-house valuation, auctions and administrative help, venture advertising and marketing, skilled talks and traisning are continuously planned for the sales associates to help them obtain better outcomes for his or her shoppers while at Knight Frank Singapore. No change Present Rules

    Extending the tax exemption would help. The exemption, which may be as a lot as $2 million per family, covers individuals who negotiate a principal reduction on their existing mortgage, sell their house short (i.e., for lower than the excellent loans), or take part in a foreclosure course of. An extension of theexemption would seem like a common-sense means to assist stabilize the housing market, but the political turmoil around the fiscal-cliff negotiations means widespread sense could not win out. Home Minority Chief Nancy Pelosi (D-Calif.) believes that the mortgage relief provision will be on the table during the grand-cut price talks, in response to communications director Nadeam Elshami. Buying or promoting of blue mild bulbs is unlawful.

    A vendor's stamp duty has been launched on industrial property for the primary time, at rates ranging from 5 per cent to 15 per cent. The Authorities might be trying to reassure the market that they aren't in opposition to foreigners and PRs investing in Singapore's property market. They imposed these measures because of extenuating components available in the market." The sale of new dual-key EC models will even be restricted to multi-generational households only. The models have two separate entrances, permitting grandparents, for example, to dwell separately. The vendor's stamp obligation takes effect right this moment and applies to industrial property and plots which might be offered inside three years of the date of buy. JLL named Best Performing Property Brand for second year running

    The data offered is for normal info purposes only and isn't supposed to be personalised investment or monetary advice. Motley Fool Singapore contributor Stanley Lim would not personal shares in any corporations talked about. Singapore private home costs increased by 1.eight% within the fourth quarter of 2012, up from 0.6% within the earlier quarter. Resale prices of government-built HDB residences which are usually bought by Singaporeans, elevated by 2.5%, quarter on quarter, the quickest acquire in five quarters. And industrial property, prices are actually double the levels of three years ago. No withholding tax in the event you sell your property. All your local information regarding vital HDB policies, condominium launches, land growth, commercial property and more

    There are various methods to go about discovering the precise property. Some local newspapers (together with the Straits Instances ) have categorised property sections and many local property brokers have websites. Now there are some specifics to consider when buying a 'new launch' rental. Intended use of the unit Every sale begins with 10 p.c low cost for finish of season sale; changes to 20 % discount storewide; follows by additional reduction of fiftyand ends with last discount of 70 % or extra. Typically there is even a warehouse sale or transferring out sale with huge mark-down of costs for stock clearance. Deborah Regulation from Expat Realtor shares her property market update, plus prime rental residences and houses at the moment available to lease Esparina EC @ Sengkang
  3. Cite error: Invalid <ref> tag; no text was provided for refs named ibm
  4. One of the biggest reasons investing in a Singapore new launch is an effective things is as a result of it is doable to be lent massive quantities of money at very low interest rates that you should utilize to purchase it. Then, if property values continue to go up, then you'll get a really high return on funding (ROI). Simply make sure you purchase one of the higher properties, reminiscent of the ones at Fernvale the Riverbank or any Singapore landed property Get Earnings by means of Renting

    In its statement, the singapore property listing - website link, government claimed that the majority citizens buying their first residence won't be hurt by the new measures. Some concessions can even be prolonged to chose teams of consumers, similar to married couples with a minimum of one Singaporean partner who are purchasing their second property so long as they intend to promote their first residential property. Lower the LTV limit on housing loans granted by monetary establishments regulated by MAS from 70% to 60% for property purchasers who are individuals with a number of outstanding housing loans on the time of the brand new housing purchase. Singapore Property Measures - 30 August 2010 The most popular seek for the number of bedrooms in Singapore is 4, followed by 2 and three. Lush Acres EC @ Sengkang

    Discover out more about real estate funding in the area, together with info on international funding incentives and property possession. Many Singaporeans have been investing in property across the causeway in recent years, attracted by comparatively low prices. However, those who need to exit their investments quickly are likely to face significant challenges when trying to sell their property – and could finally be stuck with a property they can't sell. Career improvement programmes, in-house valuation, auctions and administrative help, venture advertising and marketing, skilled talks and traisning are continuously planned for the sales associates to help them obtain better outcomes for his or her shoppers while at Knight Frank Singapore. No change Present Rules

    Extending the tax exemption would help. The exemption, which may be as a lot as $2 million per family, covers individuals who negotiate a principal reduction on their existing mortgage, sell their house short (i.e., for lower than the excellent loans), or take part in a foreclosure course of. An extension of theexemption would seem like a common-sense means to assist stabilize the housing market, but the political turmoil around the fiscal-cliff negotiations means widespread sense could not win out. Home Minority Chief Nancy Pelosi (D-Calif.) believes that the mortgage relief provision will be on the table during the grand-cut price talks, in response to communications director Nadeam Elshami. Buying or promoting of blue mild bulbs is unlawful.

    A vendor's stamp duty has been launched on industrial property for the primary time, at rates ranging from 5 per cent to 15 per cent. The Authorities might be trying to reassure the market that they aren't in opposition to foreigners and PRs investing in Singapore's property market. They imposed these measures because of extenuating components available in the market." The sale of new dual-key EC models will even be restricted to multi-generational households only. The models have two separate entrances, permitting grandparents, for example, to dwell separately. The vendor's stamp obligation takes effect right this moment and applies to industrial property and plots which might be offered inside three years of the date of buy. JLL named Best Performing Property Brand for second year running

    The data offered is for normal info purposes only and isn't supposed to be personalised investment or monetary advice. Motley Fool Singapore contributor Stanley Lim would not personal shares in any corporations talked about. Singapore private home costs increased by 1.eight% within the fourth quarter of 2012, up from 0.6% within the earlier quarter. Resale prices of government-built HDB residences which are usually bought by Singaporeans, elevated by 2.5%, quarter on quarter, the quickest acquire in five quarters. And industrial property, prices are actually double the levels of three years ago. No withholding tax in the event you sell your property. All your local information regarding vital HDB policies, condominium launches, land growth, commercial property and more

    There are various methods to go about discovering the precise property. Some local newspapers (together with the Straits Instances ) have categorised property sections and many local property brokers have websites. Now there are some specifics to consider when buying a 'new launch' rental. Intended use of the unit Every sale begins with 10 p.c low cost for finish of season sale; changes to 20 % discount storewide; follows by additional reduction of fiftyand ends with last discount of 70 % or extra. Typically there is even a warehouse sale or transferring out sale with huge mark-down of costs for stock clearance. Deborah Regulation from Expat Realtor shares her property market update, plus prime rental residences and houses at the moment available to lease Esparina EC @ Sengkang
  5. One of the biggest reasons investing in a Singapore new launch is an effective things is as a result of it is doable to be lent massive quantities of money at very low interest rates that you should utilize to purchase it. Then, if property values continue to go up, then you'll get a really high return on funding (ROI). Simply make sure you purchase one of the higher properties, reminiscent of the ones at Fernvale the Riverbank or any Singapore landed property Get Earnings by means of Renting

    In its statement, the singapore property listing - website link, government claimed that the majority citizens buying their first residence won't be hurt by the new measures. Some concessions can even be prolonged to chose teams of consumers, similar to married couples with a minimum of one Singaporean partner who are purchasing their second property so long as they intend to promote their first residential property. Lower the LTV limit on housing loans granted by monetary establishments regulated by MAS from 70% to 60% for property purchasers who are individuals with a number of outstanding housing loans on the time of the brand new housing purchase. Singapore Property Measures - 30 August 2010 The most popular seek for the number of bedrooms in Singapore is 4, followed by 2 and three. Lush Acres EC @ Sengkang

    Discover out more about real estate funding in the area, together with info on international funding incentives and property possession. Many Singaporeans have been investing in property across the causeway in recent years, attracted by comparatively low prices. However, those who need to exit their investments quickly are likely to face significant challenges when trying to sell their property – and could finally be stuck with a property they can't sell. Career improvement programmes, in-house valuation, auctions and administrative help, venture advertising and marketing, skilled talks and traisning are continuously planned for the sales associates to help them obtain better outcomes for his or her shoppers while at Knight Frank Singapore. No change Present Rules

    Extending the tax exemption would help. The exemption, which may be as a lot as $2 million per family, covers individuals who negotiate a principal reduction on their existing mortgage, sell their house short (i.e., for lower than the excellent loans), or take part in a foreclosure course of. An extension of theexemption would seem like a common-sense means to assist stabilize the housing market, but the political turmoil around the fiscal-cliff negotiations means widespread sense could not win out. Home Minority Chief Nancy Pelosi (D-Calif.) believes that the mortgage relief provision will be on the table during the grand-cut price talks, in response to communications director Nadeam Elshami. Buying or promoting of blue mild bulbs is unlawful.

    A vendor's stamp duty has been launched on industrial property for the primary time, at rates ranging from 5 per cent to 15 per cent. The Authorities might be trying to reassure the market that they aren't in opposition to foreigners and PRs investing in Singapore's property market. They imposed these measures because of extenuating components available in the market." The sale of new dual-key EC models will even be restricted to multi-generational households only. The models have two separate entrances, permitting grandparents, for example, to dwell separately. The vendor's stamp obligation takes effect right this moment and applies to industrial property and plots which might be offered inside three years of the date of buy. JLL named Best Performing Property Brand for second year running

    The data offered is for normal info purposes only and isn't supposed to be personalised investment or monetary advice. Motley Fool Singapore contributor Stanley Lim would not personal shares in any corporations talked about. Singapore private home costs increased by 1.eight% within the fourth quarter of 2012, up from 0.6% within the earlier quarter. Resale prices of government-built HDB residences which are usually bought by Singaporeans, elevated by 2.5%, quarter on quarter, the quickest acquire in five quarters. And industrial property, prices are actually double the levels of three years ago. No withholding tax in the event you sell your property. All your local information regarding vital HDB policies, condominium launches, land growth, commercial property and more

    There are various methods to go about discovering the precise property. Some local newspapers (together with the Straits Instances ) have categorised property sections and many local property brokers have websites. Now there are some specifics to consider when buying a 'new launch' rental. Intended use of the unit Every sale begins with 10 p.c low cost for finish of season sale; changes to 20 % discount storewide; follows by additional reduction of fiftyand ends with last discount of 70 % or extra. Typically there is even a warehouse sale or transferring out sale with huge mark-down of costs for stock clearance. Deborah Regulation from Expat Realtor shares her property market update, plus prime rental residences and houses at the moment available to lease Esparina EC @ Sengkang