PandA-2024.02
gemm.c
Go to the documentation of this file.
1 
10 /* gemm.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 "gemm.h"
22 
23 
24 /* Array initialization. */
25 static
26 void init_array(int ni, int nj, int nk,
27  DATA_TYPE *alpha,
28  DATA_TYPE *beta,
29  DATA_TYPE POLYBENCH_2D(C,NI,NJ,ni,nj),
30  DATA_TYPE POLYBENCH_2D(A,NI,NK,ni,nk),
31  DATA_TYPE POLYBENCH_2D(B,NK,NJ,nk,nj))
32 {
33  int i, j;
34 
35  *alpha = 1.5;
36  *beta = 1.2;
37  for (i = 0; i < ni; i++)
38  for (j = 0; j < nj; j++)
39  C[i][j] = (DATA_TYPE) ((i*j+1) % ni) / ni;
40  for (i = 0; i < ni; i++)
41  for (j = 0; j < nk; j++)
42  A[i][j] = (DATA_TYPE) (i*(j+1) % nk) / nk;
43  for (i = 0; i < nk; i++)
44  for (j = 0; j < nj; j++)
45  B[i][j] = (DATA_TYPE) (i*(j+2) % nj) / nj;
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 nj,
53  DATA_TYPE POLYBENCH_2D(C,NI,NJ,ni,nj))
54 {
55  int i, j;
56 
59  for (i = 0; i < ni; i++)
60  for (j = 0; j < nj; j++) {
61  if ((i * ni + j) % 20 == 0) fprintf (POLYBENCH_DUMP_TARGET, "\n");
63  }
64  POLYBENCH_DUMP_END("C");
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_gemm(int ni, int nj, int nk,
73  DATA_TYPE alpha,
74  DATA_TYPE beta,
75  DATA_TYPE POLYBENCH_2D(C,NI,NJ,ni,nj),
76  DATA_TYPE POLYBENCH_2D(A,NI,NK,ni,nk),
77  DATA_TYPE POLYBENCH_2D(B,NK,NJ,nk,nj))
78 {
79  int i, j, k;
80 
81 //BLAS PARAMS
82 //TRANSA = 'N'
83 //TRANSB = 'N'
84 // => Form C := alpha*A*B + beta*C,
85 //A is NIxNK
86 //B is NKxNJ
87 //C is NIxNJ
88 #pragma scop
89  for (i = 0; i < _PB_NI; i++) {
90  for (j = 0; j < _PB_NJ; j++)
91  C[i][j] *= beta;
92  for (k = 0; k < _PB_NK; k++) {
93  for (j = 0; j < _PB_NJ; j++)
94  C[i][j] += alpha * A[i][k] * B[k][j];
95  }
96  }
97 #pragma endscop
98 
99 }
100 
101 
102 int main(int argc, char** argv)
103 {
104  /* Retrieve problem size. */
105  int ni = NI;
106  int nj = NJ;
107  int nk = NK;
108 
109  /* Variable declaration/allocation. */
110  DATA_TYPE alpha;
111  DATA_TYPE beta;
115 
116  /* Initialize array(s). */
117  init_array (ni, nj, nk, &alpha, &beta,
120  POLYBENCH_ARRAY(B));
121 
122  /* Start timer. */
124 
125  /* Run kernel. */
126  kernel_gemm (ni, nj, nk,
127  alpha, beta,
130  POLYBENCH_ARRAY(B));
131 
132  /* Stop and print timer. */
135 
136  /* Prevent dead-code elimination. All live-out data must be printed
137  by the function call in argument. */
139 
140  /* Be clean. */
144 
145  return 0;
146 }
#define POLYBENCH_ARRAY(x)
Definition: polybench.h:84
#define NI
Definition: gemm.h:39
#define POLYBENCH_DUMP_BEGIN(s)
Definition: polybench.h:167
#define C
Definition: generate.c:15
#define POLYBENCH_FREE_ARRAY(x)
Definition: polybench.h:88
static void init_array(int ni, int nj, int nk, DATA_TYPE *alpha, DATA_TYPE *beta, DATA_TYPE POLYBENCH_2D(C, NI, NJ, ni, nj), DATA_TYPE POLYBENCH_2D(A, NI, NK, ni, nk), DATA_TYPE POLYBENCH_2D(B, NK, NJ, nk, nj))
This version is stamped on May 10, 2016.
Definition: gemm.c:26
int main(int argc, char **argv)
Definition: gemm.c:102
#define POLYBENCH_2D(var, dim1, dim2, ddim1, ddim2)
Definition: polybench.h:98
__attribute__((noinline))
Convert the given fixedpt number to a decimal string.
Definition: gemm.c:71
#define A
Definition: generate.c:13
static void print_array(int ni, int nj, DATA_TYPE POLYBENCH_2D(C, NI, NJ, ni, nj))
Definition: gemm.c:52
static const uint32_t k[]
Definition: sha-256.c:22
#define NK
Definition: gemm.h:41
#define _PB_NJ
Definition: gemm.h:54
#define POLYBENCH_DUMP_START
Definition: polybench.h:165
#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
#define NJ
Definition: gemm.h:40
#define POLYBENCH_DUMP_TARGET
Definition: polybench.h:164
#define POLYBENCH_DUMP_END(s)
Definition: polybench.h:168
#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