hameeza ahmed via llvm-dev
2018-Mar-14 22:05 UTC
[llvm-dev] LLVM opt unable to vectorize PolyBench code
Hello, I m unable to vectorize following kernel by opt tool; for (i = 0; i < _PB_NI; i++) for (j = 0; j < _PB_NJ; j++) { tmp[i][j] = 0; for (k = 0; k < _PB_NK; ++k) tmp[i][j] += alpha * A[i][k] * B[k][j]; } for (i = 0; i < _PB_NI; i++) for (j = 0; j < _PB_NL; j++) { D[i][j] *= beta; for (k = 0; k < _PB_NJ; ++k) D[i][j] += tmp[i][k] * C[k][j]; } i m using following command $opt -S -O3 -force-vector-width=64 -pass-remarks=loop-vectorize -enable-load-pre=0 2mm.ll -o 2mm-64_o3.ll what is wrong here? what should i do? Please help.. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20180315/6bfc58d8/attachment.html>
Craig Topper via llvm-dev
2018-Mar-14 22:31 UTC
[llvm-dev] LLVM opt unable to vectorize PolyBench code
It would help if you sent the IR you're giving to opt or at least a complete C function and your clang command line. ~Craig On Wed, Mar 14, 2018 at 3:05 PM, hameeza ahmed <hahmed2305 at gmail.com> wrote:> Hello, > > I m unable to vectorize following kernel by opt tool; > > for (i = 0; i < _PB_NI; i++) > for (j = 0; j < _PB_NJ; j++) > { > tmp[i][j] = 0; > for (k = 0; k < _PB_NK; ++k) > tmp[i][j] += alpha * A[i][k] * B[k][j]; > } > for (i = 0; i < _PB_NI; i++) > for (j = 0; j < _PB_NL; j++) > { > D[i][j] *= beta; > for (k = 0; k < _PB_NJ; ++k) > D[i][j] += tmp[i][k] * C[k][j]; > } > > i m using following command > $opt -S -O3 -force-vector-width=64 -pass-remarks=loop-vectorize > -enable-load-pre=0 2mm.ll -o 2mm-64_o3.ll > > what is wrong here? what should i do? > > Please help.. > >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20180314/cd6794d6/attachment.html>
hameeza ahmed via llvm-dev
2018-Mar-14 22:33 UTC
[llvm-dev] LLVM opt unable to vectorize PolyBench code
C- Code; /** * 2mm.c: This file is part of the PolyBench/C 3.2 test suite. * * * Contact: Louis-Noel Pouchet <pouchet at cse.ohio-state.edu> * Web address: http://polybench.sourceforge.net */ #include <stdio.h> #include <unistd.h> #include <string.h> #include <math.h> /* Include polybench common header. */ #include <polybench.h> /* Include benchmark-specific header. */ /* Default data type is double, default size is 4000. */ #include "2mm.h" /* Array initialization. */ static void init_array(int ni, int nj, int nk, int nl, DATA_TYPE *alpha, DATA_TYPE *beta, DATA_TYPE POLYBENCH_2D(A,NI,NK,ni,nl), DATA_TYPE POLYBENCH_2D(B,NK,NJ,nk,nj), DATA_TYPE POLYBENCH_2D(C,NL,NJ,nl,nj), DATA_TYPE POLYBENCH_2D(D,NI,NL,ni,nl)) { int i, j; *alpha = 32412; *beta = 2123; for (i = 0; i < ni; i++) for (j = 0; j < nk; j++) A[i][j] = ((DATA_TYPE) i*j) / ni; for (i = 0; i < nk; i++) for (j = 0; j < nj; j++) B[i][j] = ((DATA_TYPE) i*(j+1)) / nj; for (i = 0; i < nl; i++) for (j = 0; j < nj; j++) C[i][j] = ((DATA_TYPE) i*(j+3)) / nl; for (i = 0; i < ni; i++) for (j = 0; j < nl; j++) D[i][j] = ((DATA_TYPE) i*(j+2)) / nk; } /* DCE code. Must scan the entire live-out data. Can be used also to check the correctness of the output. */ static void print_array(int ni, int nl, DATA_TYPE POLYBENCH_2D(D,NI,NL,ni,nl)) { int i, j; for (i = 0; i < ni; i++) for (j = 0; j < nl; j++) { fprintf (stderr, DATA_PRINTF_MODIFIER, D[i][j]); if ((i * ni + j) % 20 == 0) fprintf (stderr, "\n"); } fprintf (stderr, "\n"); } /* Main computational kernel. The whole function will be timed, including the call and return. */ static void kernel_2mm(int ni, int nj, int nk, int nl, DATA_TYPE alpha, DATA_TYPE beta, DATA_TYPE POLYBENCH_2D(tmp,NI,NJ,ni,nj), DATA_TYPE POLYBENCH_2D(A,NI,NK,ni,nk), DATA_TYPE POLYBENCH_2D(B,NK,NJ,nk,nj), DATA_TYPE POLYBENCH_2D(C,NL,NJ,nl,nj), DATA_TYPE POLYBENCH_2D(D,NI,NL,ni,nl)) { int i, j, k; #pragma scop /* D := alpha*A*B*C + beta*D */ for (i = 0; i < _PB_NI; i++) for (j = 0; j < _PB_NJ; j++) { tmp[i][j] = 0; for (k = 0; k < _PB_NK; ++k) tmp[i][j] += alpha * A[i][k] * B[k][j]; } for (i = 0; i < _PB_NI; i++) for (j = 0; j < _PB_NL; j++) { D[i][j] *= beta; for (k = 0; k < _PB_NJ; ++k) D[i][j] += tmp[i][k] * C[k][j]; } #pragma endscop } int main(int argc, char** argv) { /* Retrieve problem size. */ int ni = NI; int nj = NJ; int nk = NK; int nl = NL; /* Variable declaration/allocation. */ DATA_TYPE alpha; DATA_TYPE beta; POLYBENCH_2D_ARRAY_DECL(tmp,DATA_TYPE,NI,NJ,ni,nj); POLYBENCH_2D_ARRAY_DECL(A,DATA_TYPE,NI,NK,ni,nk); POLYBENCH_2D_ARRAY_DECL(B,DATA_TYPE,NK,NJ,nk,nj); POLYBENCH_2D_ARRAY_DECL(C,DATA_TYPE,NL,NJ,nl,nj); POLYBENCH_2D_ARRAY_DECL(D,DATA_TYPE,NI,NL,ni,nl); /* Initialize array(s). */ init_array (ni, nj, nk, nl, &alpha, &beta, POLYBENCH_ARRAY(A), POLYBENCH_ARRAY(B), POLYBENCH_ARRAY(C), POLYBENCH_ARRAY(D)); /* Start timer. */ polybench_start_instruments; /* Run kernel. */ kernel_2mm (ni, nj, nk, nl, alpha, beta, POLYBENCH_ARRAY(tmp), POLYBENCH_ARRAY(A), POLYBENCH_ARRAY(B), POLYBENCH_ARRAY(C), POLYBENCH_ARRAY(D)); /* Stop and print timer. */ polybench_stop_instruments; polybench_print_instruments; /* Prevent dead-code elimination. All live-out data must be printed by the function call in argument. */ polybench_prevent_dce(print_array(ni, nl, POLYBENCH_ARRAY(D))); /* Be clean. */ POLYBENCH_FREE_ARRAY(tmp); POLYBENCH_FREE_ARRAY(A); POLYBENCH_FREE_ARRAY(B); POLYBENCH_FREE_ARRAY(C); POLYBENCH_FREE_ARRAY(D); return 0; } clang -S -emit-llvm -I utilities -I linear-algebra/kernels/2mm utilities/polybench.c linear-algebra/kernels/2mm/2mm.c -march=knl -O3 -mllvm -disable-llvm-optzns On Thu, Mar 15, 2018 at 3:31 AM, Craig Topper <craig.topper at gmail.com> wrote:> It would help if you sent the IR you're giving to opt or at least a > complete C function and your clang command line. > > ~Craig > > On Wed, Mar 14, 2018 at 3:05 PM, hameeza ahmed <hahmed2305 at gmail.com> > wrote: > >> Hello, >> >> I m unable to vectorize following kernel by opt tool; >> >> for (i = 0; i < _PB_NI; i++) >> for (j = 0; j < _PB_NJ; j++) >> { >> tmp[i][j] = 0; >> for (k = 0; k < _PB_NK; ++k) >> tmp[i][j] += alpha * A[i][k] * B[k][j]; >> } >> for (i = 0; i < _PB_NI; i++) >> for (j = 0; j < _PB_NL; j++) >> { >> D[i][j] *= beta; >> for (k = 0; k < _PB_NJ; ++k) >> D[i][j] += tmp[i][k] * C[k][j]; >> } >> >> i m using following command >> $opt -S -O3 -force-vector-width=64 -pass-remarks=loop-vectorize >> -enable-load-pre=0 2mm.ll -o 2mm-64_o3.ll >> >> what is wrong here? what should i do? >> >> Please help.. >> >> >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20180315/17a34455/attachment.html>
Apparently Analagous Threads
- LLVM opt unable to vectorize PolyBench code
- [test-suite] making polybench/symm succeed with "-Ofast" and "-ffp-contract=on"
- [test-suite] making polybench/symm succeed with "-Ofast" and "-ffp-contract=on"
- [test-suite] making polybench/symm succeed with "-Ofast" and "-ffp-contract=on"
- [test-suite] making polybench/symm succeed with "-Ofast" and "-ffp-contract=on"