[llvm-dev] Jacobi 5 Point Stencil Code not Vectorizing

Hal Finkel via llvm-dev llvm-dev at lists.llvm.org
Sun Jul 2 01:28:40 PDT 2017


On 07/01/2017 05:33 PM, hameeza ahmed wrote:
> I am able to vectorize it with the following code;
>
> #include <stdio.h>
> #define N 100351
> // This function computes 2D-5 point Jacobi stencil
> void stencil(int a[][N], int b[][N])
> {
>    int i, j, k;
>    for (k = 0; k < N; k++) {
>        for (i = 1; i <= N-2; i++)
>            for (j = 1; j <= N-2; j++)
> b[i][j] = 0.25 * (a[i][j] + a[i-1][j] + a[i+1][j] + a[i][j-1] + 
> a[i][j+1]);
>
> for (i = 1; i <= N-2; i++)
> for (j = 1; j <= N-2; j++)
>  a[i][j] = b[i][j];
> }
> }
>
> I removed restrict over here.

That seems odd. Can you please file a bug report?

  -Hal

>
> On Sun, Jul 2, 2017 at 3:11 AM, hameeza ahmed <hahmed2305 at gmail.com 
> <mailto:hahmed2305 at gmail.com>> wrote:
>
>     further i modified the code to the following;
>
>     #include <stdio.h>
>     #define N 100351
>     // This function computes 2D-5 point Jacobi stencil
>     void stencil(int a[restrict][N], int b[restrict][N])
>     {
>        int i, j, k;
>        for (k = 0; k < N; k++) {
>            for (i = 1; i <= N-2; i++)
>                for (j = 1; j <= N-2; j++)
>     b[i][j] = 0.25 * (a[i][j] + a[i-1][j] + a[i+1][j] + a[i][j-1] +
>     a[i][j+1]);
>
>     for (i = 1; i <= N-2; i++)
>     for (j = 1; j <= N-2; j++)
>      a[i][j] = b[i][j];
>     }
>     }
>
>        but still no vectorization in IR. Also, when I set vector width
>     explicitly to 64, it gives the following error:
>
>     remark: <unknown>:0:0: loop not vectorized: call instruction
>     cannot be vectorized
>     remark: <unknown>:0:0: loop not vectorized: value that could not
>     be identified as reduction is used outside the loop
>
>     I need serious help on this. Please guide me.
>
>     On Sun, Jul 2, 2017 at 1:54 AM, hameeza ahmed
>     <hahmed2305 at gmail.com <mailto:hahmed2305 at gmail.com>> wrote:
>
>         Does it happen due to loop carried dependence? if yes what is
>         the solution to vectorize such codes?
>
>
>         please reply. i m waiting.
>
>         On Jul 1, 2017 12:30 PM, "hameeza ahmed" <hahmed2305 at gmail.com
>         <mailto:hahmed2305 at gmail.com>> wrote:
>
>             I even tried polly but still my llvm IR does not contain
>             vector instructions. i used the following command;
>
>             clang  -S -emit-llvm stencil.c -march=knl -O3 -mllvm
>             -polly -mllvm -polly-vectorizer=stripmine -o stencil_poly.ll
>
>             Please specify what is wrong with my code?
>
>
>             On Sat, Jul 1, 2017 at 4:08 PM, hameeza ahmed
>             <hahmed2305 at gmail.com <mailto:hahmed2305 at gmail.com>> wrote:
>
>                 Hello,
>
>                 I am trying to vectorize following stencil code;
>
>                 #include <stdio.h>
>                 #define N 100351
>                 // This function computes 2D-5 point Jacobi stencil
>                 void stencil(int a[restrict][N])
>                 {
>                    int i, j, k;
>                    for (k = 0; k < 100; k++)
>                      {  for (i = 1; i <= N-2; i++)
>                          {  for (j = 1; j <= N-2; j++)
>                 { a[i][j] = 0.25 * (a[i][j] + a[i-1][j] + a[i+1][j] +
>                 a[i][j-1] + a[i][j+1]);
>                               }
>                 }
>                 }}
>
>                 I have used the following commands
>
>                 clang  -S -emit-llvm stencil.c -march=knl -O3 -mllvm
>                 -disable-llvm-optzns -o stencil.ll
>
>                 opt  -S -O3 stencil.ll -o stencil_o3.ll
>
>                 llc -x86-asm-syntax=intel stencil_o3.ll -o stencil.s
>
>                 But the code is not vectorized. It still uses the
>                 scalar instructions;
>
>                 Please correct me.
>
>                 Thank You
>
>
>
>
>
>
>

-- 
Hal Finkel
Lead, Compiler Technology and Programming Languages
Leadership Computing Facility
Argonne National Laboratory

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20170702/a00748f2/attachment.html>


More information about the llvm-dev mailing list