PandA-2024.02
syrk.c
Go to the documentation of this file.
1 
10 /* syrk.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 "syrk.h"
22 
23 
24 /* Array initialization. */
25 static
26 void init_array(int n, int m,
27  DATA_TYPE *alpha,
28  DATA_TYPE *beta,
29  DATA_TYPE POLYBENCH_2D(C,N,N,n,n),
30  DATA_TYPE POLYBENCH_2D(A,N,M,n,m))
31 {
32  int i, j;
33 
34  *alpha = 1.5;
35  *beta = 1.2;
36  for (i = 0; i < n; i++)
37  for (j = 0; j < m; j++)
38  A[i][j] = (DATA_TYPE) ((i*j+1)%n) / n;
39  for (i = 0; i < n; i++)
40  for (j = 0; j < n; j++)
41  C[i][j] = (DATA_TYPE) ((i*j+2)%m) / m;
42 }
43 
44 
45 /* DCE code. Must scan the entire live-out data.
46  Can be used also to check the correctness of the output. */
47 static
48 void print_array(int n,
49  DATA_TYPE POLYBENCH_2D(C,N,N,n,n))
50 {
51  int i, j;
52 
55  for (i = 0; i < n; i++)
56  for (j = 0; j < n; j++) {
57  if ((i * n + j) % 20 == 0) fprintf (POLYBENCH_DUMP_TARGET, "\n");
59  }
60  POLYBENCH_DUMP_END("C");
62 }
63 
64 
65 /* Main computational kernel. The whole function will be timed,
66  including the call and return. */
67 __attribute__((noinline))
68 void kernel_syrk(int n, int m,
69  DATA_TYPE alpha,
70  DATA_TYPE beta,
71  DATA_TYPE POLYBENCH_2D(C,N,N,n,n),
72  DATA_TYPE POLYBENCH_2D(A,N,M,n,m))
73 {
74  int i, j, k;
75 
76 //BLAS PARAMS
77 //TRANS = 'N'
78 //UPLO = 'L'
79 // => Form C := alpha*A*A**T + beta*C.
80 //A is NxM
81 //C is NxN
82 #pragma scop
83  for (i = 0; i < _PB_N; i++) {
84  for (j = 0; j <= i; j++)
85  C[i][j] *= beta;
86  for (k = 0; k < _PB_M; k++) {
87  for (j = 0; j <= i; j++)
88  C[i][j] += alpha * A[i][k] * A[j][k];
89  }
90  }
91 #pragma endscop
92 
93 }
94 
95 
96 int main(int argc, char** argv)
97 {
98  /* Retrieve problem size. */
99  int n = N;
100  int m = M;
101 
102  /* Variable declaration/allocation. */
103  DATA_TYPE alpha;
104  DATA_TYPE beta;
107 
108  /* Initialize array(s). */
109  init_array (n, m, &alpha, &beta, POLYBENCH_ARRAY(C), POLYBENCH_ARRAY(A));
110 
111  /* Start timer. */
113 
114  /* Run kernel. */
115  kernel_syrk (n, m, alpha, beta, POLYBENCH_ARRAY(C), POLYBENCH_ARRAY(A));
116 
117  /* Stop and print timer. */
120 
121  /* Prevent dead-code elimination. All live-out data must be printed
122  by the function call in argument. */
124 
125  /* Be clean. */
128 
129  return 0;
130 }
__attribute__((noinline))
Convert the given fixedpt number to a decimal string.
Definition: syrk.c:67
#define POLYBENCH_ARRAY(x)
Definition: polybench.h:84
static void init_array(int n, int m, DATA_TYPE *alpha, DATA_TYPE *beta, DATA_TYPE POLYBENCH_2D(C, N, N, n, n), DATA_TYPE POLYBENCH_2D(A, N, M, n, m))
This version is stamped on May 10, 2016.
Definition: syrk.c:26
#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 POLYBENCH_2D(var, dim1, dim2, ddim1, ddim2)
Definition: polybench.h:98
#define A
Definition: generate.c:13
static const uint32_t k[]
Definition: sha-256.c:22
#define POLYBENCH_DUMP_START
Definition: polybench.h:165
#define _PB_M
Definition: correlation.h:48
#define N
Definition: dfdiv.c:60
#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 POLYBENCH_DUMP_TARGET
Definition: polybench.h:164
#define POLYBENCH_DUMP_END(s)
Definition: polybench.h:168
#define M
Definition: gsm.c:30
#define POLYBENCH_DUMP_FINISH
Definition: polybench.h:166
static void print_array(int n, DATA_TYPE POLYBENCH_2D(C, N, N, n, n))
Definition: syrk.c:48
int main(int argc, char **argv)
Definition: syrk.c:96
#define _PB_N
Definition: correlation.h:49
#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