PandA-2024.02
doitgen.c
Go to the documentation of this file.
1 
10 /* doitgen.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 "doitgen.h"
22 
23 
24 /* Array initialization. */
25 static
26 void init_array(int nr, int nq, int np,
27  DATA_TYPE POLYBENCH_3D(A,NR,NQ,NP,nr,nq,np),
28  DATA_TYPE POLYBENCH_2D(C4,NP,NP,np,np))
29 {
30  int i, j, k;
31 
32  for (i = 0; i < nr; i++)
33  for (j = 0; j < nq; j++)
34  for (k = 0; k < np; k++)
35  A[i][j][k] = (DATA_TYPE) ((i*j + k)%np) / np;
36  for (i = 0; i < np; i++)
37  for (j = 0; j < np; j++)
38  C4[i][j] = (DATA_TYPE) (i*j % np) / np;
39 }
40 
41 
42 /* DCE code. Must scan the entire live-out data.
43  Can be used also to check the correctness of the output. */
44 static
45 void print_array(int nr, int nq, int np,
46  DATA_TYPE POLYBENCH_3D(A,NR,NQ,NP,nr,nq,np))
47 {
48  int i, j, k;
49 
52  for (i = 0; i < nr; i++)
53  for (j = 0; j < nq; j++)
54  for (k = 0; k < np; k++) {
55  if ((i*nq*np+j*np+k) % 20 == 0) fprintf (POLYBENCH_DUMP_TARGET, "\n");
56  fprintf (POLYBENCH_DUMP_TARGET, DATA_PRINTF_MODIFIER, A[i][j][k]);
57  }
58  POLYBENCH_DUMP_END("A");
60 }
61 
62 
63 /* Main computational kernel. The whole function will be timed,
64  including the call and return. */
65 __attribute__((noinline))
66 void kernel_doitgen(int nr, int nq, int np,
67  DATA_TYPE POLYBENCH_3D(A,NR,NQ,NP,nr,nq,np),
68  DATA_TYPE POLYBENCH_2D(C4,NP,NP,np,np),
70 {
71  int r, q, p, s;
72 
73 #pragma scop
74  for (r = 0; r < _PB_NR; r++)
75  for (q = 0; q < _PB_NQ; q++) {
76  for (p = 0; p < _PB_NP; p++) {
77  sum[p] = SCALAR_VAL(0.0);
78  for (s = 0; s < _PB_NP; s++)
79  sum[p] += A[r][q][s] * C4[s][p];
80  }
81  for (p = 0; p < _PB_NP; p++)
82  A[r][q][p] = sum[p];
83  }
84 #pragma endscop
85 
86 }
87 
88 
89 int main(int argc, char** argv)
90 {
91  /* Retrieve problem size. */
92  int nr = NR;
93  int nq = NQ;
94  int np = NP;
95 
96  /* Variable declaration/allocation. */
100 
101  /* Initialize array(s). */
102  init_array (nr, nq, np,
104  POLYBENCH_ARRAY(C4));
105 
106  /* Start timer. */
108 
109  /* Run kernel. */
110  kernel_doitgen (nr, nq, np,
112  POLYBENCH_ARRAY(C4),
114 
115  /* Stop and print timer. */
118 
119  /* Prevent dead-code elimination. All live-out data must be printed
120  by the function call in argument. */
122 
123  /* Be clean. */
127 
128  return 0;
129 }
#define POLYBENCH_ARRAY(x)
Definition: polybench.h:84
#define POLYBENCH_3D(var, dim1, dim2, dim3, ddim1, ddim2, ddim3)
Definition: polybench.h:99
#define POLYBENCH_DUMP_BEGIN(s)
Definition: polybench.h:167
#define POLYBENCH_FREE_ARRAY(x)
Definition: polybench.h:88
#define NP
Definition: doitgen.h:41
#define POLYBENCH_2D(var, dim1, dim2, ddim1, ddim2)
Definition: polybench.h:98
#define POLYBENCH_3D_ARRAY_DECL(var, type, dim1, dim2, dim3, ddim1, ddim2, ddim3)
Definition: polybench.h:134
#define _PB_NQ
Definition: doitgen.h:53
#define A
Definition: generate.c:13
#define _PB_NP
Definition: doitgen.h:55
int sum
Definition: dotproduct.h:3
static void print_array(int nr, int nq, int np, DATA_TYPE POLYBENCH_3D(A, NR, NQ, NP, nr, nq, np))
Definition: doitgen.c:45
static const uint32_t k[]
Definition: sha-256.c:22
#define POLYBENCH_DUMP_START
Definition: polybench.h:165
#define POLYBENCH_2D_ARRAY_DECL(var, type, dim1, dim2, ddim1, ddim2)
Definition: polybench.h:131
#define _PB_NR
Definition: doitgen.h:54
#define DATA_PRINTF_MODIFIER
Definition: correlation.h:73
#define polybench_prevent_dce(func)
Definition: polybench.h:170
#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
#define NR
Definition: doitgen.h:40
#define POLYBENCH_1D(var, dim1, ddim1)
Definition: polybench.h:97
#define NQ
Definition: doitgen.h:39
static void init_array(int nr, int nq, int np, DATA_TYPE POLYBENCH_3D(A, NR, NQ, NP, nr, nq, np), DATA_TYPE POLYBENCH_2D(C4, NP, NP, np, np))
This version is stamped on May 10, 2016.
Definition: doitgen.c:26
__attribute__((noinline))
Convert the given fixedpt number to a decimal string.
Definition: doitgen.c:65
int main(int argc, char **argv)
Definition: doitgen.c:89
#define POLYBENCH_DUMP_FINISH
Definition: polybench.h:166
#define POLYBENCH_1D_ARRAY_DECL(var, type, dim1, ddim1)
Definition: polybench.h:128
#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 DATA_TYPE
Definition: correlation.h:72

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