PandA-2024.02
3mm.c
Go to the documentation of this file.
1 
10 /* 3mm.c: this file is part of PolyBench/C */
11 
12 #include <stdio.h>
13 #include <unistd.h>
14 #include <string.h>
15 #include <math.h>
16 
17 /* Include polybench common header. */
18 #include <polybench.h>
19 
20 /* Include benchmark-specific header. */
21 #include "3mm.h"
22 
23 
24 /* Array initialization. */
25 static
26 void init_array(int ni, int nj, int nk, int nl, int nm,
27  DATA_TYPE POLYBENCH_2D(A,NI,NK,ni,nk),
28  DATA_TYPE POLYBENCH_2D(B,NK,NJ,nk,nj),
29  DATA_TYPE POLYBENCH_2D(C,NJ,NM,nj,nm),
30  DATA_TYPE POLYBENCH_2D(D,NM,NL,nm,nl))
31 {
32  int i, j;
33 
34  for (i = 0; i < ni; i++)
35  for (j = 0; j < nk; j++)
36  A[i][j] = (DATA_TYPE) ((i*j+1) % ni) / (5*ni);
37  for (i = 0; i < nk; i++)
38  for (j = 0; j < nj; j++)
39  B[i][j] = (DATA_TYPE) ((i*(j+1)+2) % nj) / (5*nj);
40  for (i = 0; i < nj; i++)
41  for (j = 0; j < nm; j++)
42  C[i][j] = (DATA_TYPE) (i*(j+3) % nl) / (5*nl);
43  for (i = 0; i < nm; i++)
44  for (j = 0; j < nl; j++)
45  D[i][j] = (DATA_TYPE) ((i*(j+2)+2) % nk) / (5*nk);
46 }
47 
48 
49 /* DCE code. Must scan the entire live-out data.
50  Can be used also to check the correctness of the output. */
51 static
52 void print_array(int ni, int nl,
53  DATA_TYPE POLYBENCH_2D(G,NI,NL,ni,nl))
54 {
55  int i, j;
56 
59  for (i = 0; i < ni; i++)
60  for (j = 0; j < nl; j++) {
61  if ((i * ni + j) % 20 == 0) fprintf (POLYBENCH_DUMP_TARGET, "\n");
62  fprintf (POLYBENCH_DUMP_TARGET, DATA_PRINTF_MODIFIER, G[i][j]);
63  }
64  POLYBENCH_DUMP_END("G");
66 }
67 
68 
69 /* Main computational kernel. The whole function will be timed,
70  including the call and return. */
71 __attribute__((noinline))
72 void kernel_3mm(int ni, int nj, int nk, int nl, int nm,
73  DATA_TYPE POLYBENCH_2D(E,NI,NJ,ni,nj),
74  DATA_TYPE POLYBENCH_2D(A,NI,NK,ni,nk),
75  DATA_TYPE POLYBENCH_2D(B,NK,NJ,nk,nj),
76  DATA_TYPE POLYBENCH_2D(F,NJ,NL,nj,nl),
77  DATA_TYPE POLYBENCH_2D(C,NJ,NM,nj,nm),
78  DATA_TYPE POLYBENCH_2D(D,NM,NL,nm,nl),
79  DATA_TYPE POLYBENCH_2D(G,NI,NL,ni,nl))
80 {
81  int i, j, k;
82 
83 #pragma scop
84  /* E := A*B */
85  for (i = 0; i < _PB_NI; i++)
86  for (j = 0; j < _PB_NJ; j++)
87  {
88  E[i][j] = SCALAR_VAL(0.0);
89  for (k = 0; k < _PB_NK; ++k)
90  E[i][j] += A[i][k] * B[k][j];
91  }
92  /* F := C*D */
93  for (i = 0; i < _PB_NJ; i++)
94  for (j = 0; j < _PB_NL; j++)
95  {
96  F[i][j] = SCALAR_VAL(0.0);
97  for (k = 0; k < _PB_NM; ++k)
98  F[i][j] += C[i][k] * D[k][j];
99  }
100  /* G := E*F */
101  for (i = 0; i < _PB_NI; i++)
102  for (j = 0; j < _PB_NL; j++)
103  {
104  G[i][j] = SCALAR_VAL(0.0);
105  for (k = 0; k < _PB_NJ; ++k)
106  G[i][j] += E[i][k] * F[k][j];
107  }
108 #pragma endscop
109 
110 }
111 
112 
113 int main(int argc, char** argv)
114 {
115  /* Retrieve problem size. */
116  int ni = NI;
117  int nj = NJ;
118  int nk = NK;
119  int nl = NL;
120  int nm = NM;
121 
122  /* Variable declaration/allocation. */
123  POLYBENCH_2D_ARRAY_DECL(E, DATA_TYPE, NI, NJ, ni, nj);
129  POLYBENCH_2D_ARRAY_DECL(G, DATA_TYPE, NI, NL, ni, nl);
130 
131  /* Initialize array(s). */
132  init_array (ni, nj, nk, nl, nm,
136  POLYBENCH_ARRAY(D));
137 
138  /* Start timer. */
140 
141  /* Run kernel. */
142  kernel_3mm (ni, nj, nk, nl, nm,
143  POLYBENCH_ARRAY(E),
149  POLYBENCH_ARRAY(G));
150 
151  /* Stop and print timer. */
154 
155  /* Prevent dead-code elimination. All live-out data must be printed
156  by the function call in argument. */
158 
159  /* Be clean. */
167 
168  return 0;
169 }
#define POLYBENCH_ARRAY(x)
Definition: polybench.h:84
#define NI
Definition: gemm.h:39
#define _PB_NM
Definition: 3mm.h:67
#define POLYBENCH_DUMP_BEGIN(s)
Definition: polybench.h:167
#define C
Definition: generate.c:15
#define POLYBENCH_FREE_ARRAY(x)
Definition: polybench.h:88
#define NL
Definition: 2mm.h:45
#define POLYBENCH_2D(var, dim1, dim2, ddim1, ddim2)
Definition: polybench.h:98
#define A
Definition: generate.c:13
int main(int argc, char **argv)
Definition: 3mm.c:113
static const uint32_t k[]
Definition: sha-256.c:22
#define NM
Definition: 3mm.h:49
#define NK
Definition: gemm.h:41
__attribute__((noinline))
Convert the given fixedpt number to a decimal string.
Definition: 3mm.c:71
#define _PB_NJ
Definition: gemm.h:54
#define POLYBENCH_DUMP_START
Definition: polybench.h:165
#define D
Definition: generate.c:16
#define POLYBENCH_2D_ARRAY_DECL(var, type, dim1, dim2, ddim1, ddim2)
Definition: polybench.h:131
#define DATA_PRINTF_MODIFIER
Definition: correlation.h:73
#define polybench_prevent_dce(func)
Definition: polybench.h:170
static void init_array(int ni, int nj, int nk, int nl, int nm, DATA_TYPE POLYBENCH_2D(A, NI, NK, ni, nk), DATA_TYPE POLYBENCH_2D(B, NK, NJ, nk, nj), DATA_TYPE POLYBENCH_2D(C, NJ, NM, nj, nm), DATA_TYPE POLYBENCH_2D(D, NM, NL, nm, nl))
This version is stamped on May 10, 2016.
Definition: 3mm.c:26
#define NJ
Definition: gemm.h:40
#define SCALAR_VAL(x)
Definition: correlation.h:74
#define POLYBENCH_DUMP_TARGET
Definition: polybench.h:164
#define POLYBENCH_DUMP_END(s)
Definition: polybench.h:168
static void print_array(int ni, int nl, DATA_TYPE POLYBENCH_2D(G, NI, NL, ni, nl))
Definition: 3mm.c:52
#define F(x)
Definition: aes.c:7
#define _PB_NL
Definition: 2mm.h:61
#define POLYBENCH_DUMP_FINISH
Definition: polybench.h:166
#define B
Definition: generate.c:14
#define polybench_stop_instruments
Definition: polybench.h:177
#define polybench_print_instruments
Definition: polybench.h:178
#define polybench_start_instruments
Definition: polybench.h:176
#define _PB_NK
Definition: gemm.h:55
#define DATA_TYPE
Definition: correlation.h:72
#define _PB_NI
Definition: gemm.h:53

Generated on Mon Feb 12 2024 13:02:50 for PandA-2024.02 by doxygen 1.8.13