<div dir="ltr">C- Code;<br><br>/**<br> * 2mm.c: This file is part of the PolyBench/C 3.2 test suite.<br> *<br> *<br> * Contact: Louis-Noel Pouchet <<a href="mailto:pouchet@cse.ohio-state.edu">pouchet@cse.ohio-state.edu</a>><br> * Web address: <a href="http://polybench.sourceforge.net">http://polybench.sourceforge.net</a><br> */<br>#include <stdio.h><br>#include <unistd.h><br>#include <string.h><br>#include <math.h><br><br>/* Include polybench common header. */<br>#include <polybench.h><br><br>/* Include benchmark-specific header. */<br>/* Default data type is double, default size is 4000. */<br>#include "2mm.h"<br><br><br>/* Array initialization. */<br>static<br>void init_array(int ni, int nj, int nk, int nl,<br> DATA_TYPE *alpha,<br> DATA_TYPE *beta,<br> DATA_TYPE POLYBENCH_2D(A,NI,NK,ni,nl),<br> DATA_TYPE POLYBENCH_2D(B,NK,NJ,nk,nj),<br> DATA_TYPE POLYBENCH_2D(C,NL,NJ,nl,nj),<br> DATA_TYPE POLYBENCH_2D(D,NI,NL,ni,nl))<br>{<br> int i, j;<br><br> *alpha = 32412;<br> *beta = 2123;<br> for (i = 0; i < ni; i++)<br> for (j = 0; j < nk; j++)<br> A[i][j] = ((DATA_TYPE) i*j) / ni;<br> for (i = 0; i < nk; i++)<br> for (j = 0; j < nj; j++)<br> B[i][j] = ((DATA_TYPE) i*(j+1)) / nj;<br> for (i = 0; i < nl; i++)<br> for (j = 0; j < nj; j++)<br> C[i][j] = ((DATA_TYPE) i*(j+3)) / nl;<br> for (i = 0; i < ni; i++)<br> for (j = 0; j < nl; j++)<br> D[i][j] = ((DATA_TYPE) i*(j+2)) / nk;<br>}<br><br><br>/* DCE code. Must scan the entire live-out data.<br> Can be used also to check the correctness of the output. */<br>static<br>void print_array(int ni, int nl,<br> DATA_TYPE POLYBENCH_2D(D,NI,NL,ni,nl))<br>{<br> int i, j;<br><br> for (i = 0; i < ni; i++)<br> for (j = 0; j < nl; j++) {<br> fprintf (stderr, DATA_PRINTF_MODIFIER, D[i][j]);<br> if ((i * ni + j) % 20 == 0) fprintf (stderr, "\n");<br> }<br> fprintf (stderr, "\n");<br>}<br><br><br>/* Main computational kernel. The whole function will be timed,<br> including the call and return. */<br>static<br>void kernel_2mm(int ni, int nj, int nk, int nl,<br> DATA_TYPE alpha,<br> DATA_TYPE beta,<br> DATA_TYPE POLYBENCH_2D(tmp,NI,NJ,ni,nj),<br> DATA_TYPE POLYBENCH_2D(A,NI,NK,ni,nk),<br> DATA_TYPE POLYBENCH_2D(B,NK,NJ,nk,nj),<br> DATA_TYPE POLYBENCH_2D(C,NL,NJ,nl,nj),<br> DATA_TYPE POLYBENCH_2D(D,NI,NL,ni,nl))<br>{<br> int i, j, k;<br><br>#pragma scop<br> /* D := alpha*A*B*C + beta*D */<br> for (i = 0; i < _PB_NI; i++)<br> for (j = 0; j < _PB_NJ; j++)<br> {<br> tmp[i][j] = 0;<br> for (k = 0; k < _PB_NK; ++k)<br> tmp[i][j] += alpha * A[i][k] * B[k][j];<br> }<br> for (i = 0; i < _PB_NI; i++)<br> for (j = 0; j < _PB_NL; j++)<br> {<br> D[i][j] *= beta;<br> for (k = 0; k < _PB_NJ; ++k)<br> D[i][j] += tmp[i][k] * C[k][j];<br> }<br>#pragma endscop<br><br>}<br><br><br>int main(int argc, char** argv)<br>{<br> /* Retrieve problem size. */<br> int ni = NI;<br> int nj = NJ;<br> int nk = NK;<br> int nl = NL;<br><br> /* Variable declaration/allocation. */<br> DATA_TYPE alpha;<br> DATA_TYPE beta;<br> POLYBENCH_2D_ARRAY_DECL(tmp,DATA_TYPE,NI,NJ,ni,nj);<br> POLYBENCH_2D_ARRAY_DECL(A,DATA_TYPE,NI,NK,ni,nk);<br> POLYBENCH_2D_ARRAY_DECL(B,DATA_TYPE,NK,NJ,nk,nj);<br> POLYBENCH_2D_ARRAY_DECL(C,DATA_TYPE,NL,NJ,nl,nj);<br> POLYBENCH_2D_ARRAY_DECL(D,DATA_TYPE,NI,NL,ni,nl);<br><br> /* Initialize array(s). */<br> init_array (ni, nj, nk, nl, &alpha, &beta,<br> POLYBENCH_ARRAY(A),<br> POLYBENCH_ARRAY(B),<br> POLYBENCH_ARRAY(C),<br> POLYBENCH_ARRAY(D));<br><br> /* Start timer. */<br> polybench_start_instruments;<br><br> /* Run kernel. */<br> kernel_2mm (ni, nj, nk, nl,<br> alpha, beta,<br> POLYBENCH_ARRAY(tmp),<br> POLYBENCH_ARRAY(A),<br> POLYBENCH_ARRAY(B),<br> POLYBENCH_ARRAY(C),<br> POLYBENCH_ARRAY(D));<br><br> /* Stop and print timer. */<br> polybench_stop_instruments;<br> polybench_print_instruments;<br><br> /* Prevent dead-code elimination. All live-out data must be printed<br> by the function call in argument. */<br> polybench_prevent_dce(print_array(ni, nl, POLYBENCH_ARRAY(D)));<br><br> /* Be clean. */<br> POLYBENCH_FREE_ARRAY(tmp);<br> POLYBENCH_FREE_ARRAY(A);<br> POLYBENCH_FREE_ARRAY(B);<br> POLYBENCH_FREE_ARRAY(C);<br> POLYBENCH_FREE_ARRAY(D);<br><br> return 0;<br>}<br><br> 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<br><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Mar 15, 2018 at 3:31 AM, Craig Topper <span dir="ltr"><<a href="mailto:craig.topper@gmail.com" target="_blank">craig.topper@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">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.</div><div class="gmail_extra"><span class="HOEnZb"><font color="#888888"><br clear="all"><div><div class="m_8990161338757842953gmail_signature" data-smartmail="gmail_signature">~Craig</div></div></font></span><div><div class="h5">
<br><div class="gmail_quote">On Wed, Mar 14, 2018 at 3:05 PM, hameeza ahmed <span dir="ltr"><<a href="mailto:hahmed2305@gmail.com" target="_blank">hahmed2305@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div><div><div>Hello,<br><br></div>I m unable to vectorize following kernel by opt tool;<br><br>for (i = 0; i < _PB_NI; i++)<br> for (j = 0; j < _PB_NJ; j++)<br> {<br> tmp[i][j] = 0;<br> for (k = 0; k < _PB_NK; ++k)<br> tmp[i][j] += alpha * A[i][k] * B[k][j];<br> }<br> for (i = 0; i < _PB_NI; i++)<br> for (j = 0; j < _PB_NL; j++)<br> {<br> D[i][j] *= beta;<br> for (k = 0; k < _PB_NJ; ++k)<br> D[i][j] += tmp[i][k] * C[k][j];<br> }<br><br></div>i m using following command<br>$opt -S -O3 -force-vector-width=64 -pass-remarks=loop-vectorize -enable-load-pre=0 2mm.ll -o 2mm-64_o3.ll<br><br></div>what is wrong here? what should i do?<br><br></div>Please help..<br><div><div><br></div></div></div>
</blockquote></div><br></div></div></div>
</blockquote></div><br></div>