PandA-2024.02
polybench.h
Go to the documentation of this file.
1 
10 /*
11  * polybench.h: this file is part of PolyBench/C
12  *
13  * Polybench header for instrumentation.
14  *
15  * Programs must be compiled with `-I utilities utilities/polybench.c'
16  *
17  * Optionally, one can define:
18  *
19  * -DPOLYBENCH_TIME, to report the execution time,
20  * OR (exclusive):
21  * -DPOLYBENCH_PAPI, to use PAPI H/W counters (defined in polybench.c)
22  *
23  *
24  * See README or utilities/polybench.c for additional options.
25  *
26  */
27 #ifndef POLYBENCH_H
28 # define POLYBENCH_H
29 
30 # include <stdlib.h>
31 
32 /* Array padding. By default, none is used. */
33 # ifndef POLYBENCH_PADDING_FACTOR
34 /* default: */
35 # define POLYBENCH_PADDING_FACTOR 0
36 # endif
37 
38 /* Inter-array padding, for use with . By default, none is used. */
39 # ifndef POLYBENCH_INTER_ARRAY_PADDING_FACTOR
40 /* default: */
41 # define POLYBENCH_INTER_ARRAY_PADDING_FACTOR 0
42 # undef POLYBENCH_ENABLE_INTARRAY_PAD
43 # else
44 # define POLYBENCH_ENABLE_INTARRAY_PAD
45 # endif
46 
47 
48 /* C99 arrays in function prototype. By default, do not use. */
49 # ifdef POLYBENCH_USE_C99_PROTO
50 # define POLYBENCH_C99_SELECT(x,y) y
51 # else
52 /* default: */
53 # define POLYBENCH_C99_SELECT(x,y) x
54 # endif
55 
56 
57 /* Scalar loop bounds in SCoPs. By default, use parametric loop bounds. */
58 # ifdef POLYBENCH_USE_SCALAR_LB
59 # define POLYBENCH_LOOP_BOUND(x,y) x
60 # else
61 /* default: */
62 # define POLYBENCH_LOOP_BOUND(x,y) y
63 # endif
64 
65 /* Use the 'restrict' keyword to declare that the different arrays do not
66  * alias. By default, we do not use it as it is only supported in C99 and
67  * even here several compilers do not properly get it.
68  */
69 # ifdef POLYBENCH_USE_RESTRICT
70 # define POLYBENCH_RESTRICT restrict
71 # else
72 /* default: */
73 # define POLYBENCH_RESTRICT
74 # endif
75 
76 /* Macros to reference an array. Generic for heap and stack arrays
77  (C99). Each array dimensionality has his own macro, to be used at
78  declaration or as a function argument.
79  Example:
80  int b[x] => POLYBENCH_1D_ARRAY(b, x)
81  int A[N][N] => POLYBENCH_2D_ARRAY(A, N, N)
82 */
83 # ifndef POLYBENCH_STACK_ARRAYS
84 # define POLYBENCH_ARRAY(x) *x
85 # ifdef POLYBENCH_ENABLE_INTARRAY_PAD
86 # define POLYBENCH_FREE_ARRAY(x) polybench_free_data((void*)x);
87 # else
88 # define POLYBENCH_FREE_ARRAY(x) free((void*)x);
89 # endif
90 # define POLYBENCH_DECL_VAR(x) (*x)
91 # else
92 # define POLYBENCH_ARRAY(x) x
93 # define POLYBENCH_FREE_ARRAY(x)
94 # define POLYBENCH_DECL_VAR(x) x
95 # endif
96 /* Macros for using arrays in the function prototypes. */
97 # define POLYBENCH_1D(var, dim1,ddim1) var[POLYBENCH_RESTRICT POLYBENCH_C99_SELECT(dim1,ddim1) + POLYBENCH_PADDING_FACTOR]
98 # define POLYBENCH_2D(var, dim1, dim2, ddim1, ddim2) var[POLYBENCH_RESTRICT POLYBENCH_C99_SELECT(dim1,ddim1) + POLYBENCH_PADDING_FACTOR][POLYBENCH_C99_SELECT(dim2,ddim2) + POLYBENCH_PADDING_FACTOR]
99 # define POLYBENCH_3D(var, dim1, dim2, dim3, ddim1, ddim2, ddim3) var[POLYBENCH_RESTRICT POLYBENCH_C99_SELECT(dim1,ddim1) + POLYBENCH_PADDING_FACTOR][POLYBENCH_C99_SELECT(dim2,ddim2) + POLYBENCH_PADDING_FACTOR][POLYBENCH_C99_SELECT(dim3,ddim3) + POLYBENCH_PADDING_FACTOR]
100 # define POLYBENCH_4D(var, dim1, dim2, dim3, dim4, ddim1, ddim2, ddim3, ddim4) var[POLYBENCH_RESTRICT POLYBENCH_C99_SELECT(dim1,ddim1) + POLYBENCH_PADDING_FACTOR][POLYBENCH_C99_SELECT(dim2,ddim2) + POLYBENCH_PADDING_FACTOR][POLYBENCH_C99_SELECT(dim3,ddim3) + POLYBENCH_PADDING_FACTOR][POLYBENCH_C99_SELECT(dim4,ddim4) + POLYBENCH_PADDING_FACTOR]
101 # define POLYBENCH_5D(var, dim1, dim2, dim3, dim4, dim5, ddim1, ddim2, ddim3, ddim4, ddim5) var[POLYBENCH_RESTRICT POLYBENCH_C99_SELECT(dim1,ddim1) + POLYBENCH_PADDING_FACTOR][POLYBENCH_C99_SELECT(dim2,ddim2) + POLYBENCH_PADDING_FACTOR][POLYBENCH_C99_SELECT(dim3,ddim3) + POLYBENCH_PADDING_FACTOR][POLYBENCH_C99_SELECT(dim4,ddim4) + POLYBENCH_PADDING_FACTOR][POLYBENCH_C99_SELECT(dim5,ddim5) + POLYBENCH_PADDING_FACTOR]
102 /* Macros for using arrays within the functions. */
103 # define POLYBENCH_1D_F(var, dim1,ddim1) var[POLYBENCH_C99_SELECT(dim1,ddim1) + POLYBENCH_PADDING_FACTOR]
104 # define POLYBENCH_2D_F(var, dim1, dim2, ddim1, ddim2) var[POLYBENCH_C99_SELECT(dim1,ddim1) + POLYBENCH_PADDING_FACTOR][POLYBENCH_C99_SELECT(dim2,ddim2) + POLYBENCH_PADDING_FACTOR]
105 # define POLYBENCH_3D_F(var, dim1, dim2, dim3, ddim1, ddim2, ddim3) var[POLYBENCH_C99_SELECT(dim1,ddim1) + POLYBENCH_PADDING_FACTOR][POLYBENCH_C99_SELECT(dim2,ddim2) + POLYBENCH_PADDING_FACTOR][POLYBENCH_C99_SELECT(dim3,ddim3) + POLYBENCH_PADDING_FACTOR]
106 # define POLYBENCH_4D_F(var, dim1, dim2, dim3, dim4, ddim1, ddim2, ddim3, ddim4) var[POLYBENCH_C99_SELECT(dim1,ddim1) + POLYBENCH_PADDING_FACTOR][POLYBENCH_C99_SELECT(dim2,ddim2) + POLYBENCH_PADDING_FACTOR][POLYBENCH_C99_SELECT(dim3,ddim3) + POLYBENCH_PADDING_FACTOR][POLYBENCH_C99_SELECT(dim4,ddim4) + POLYBENCH_PADDING_FACTOR]
107 # define POLYBENCH_5D_F(var, dim1, dim2, dim3, dim4, dim5, ddim1, ddim2, ddim3, ddim4, ddim5) var[POLYBENCH_C99_SELECT(dim1,ddim1) + POLYBENCH_PADDING_FACTOR][POLYBENCH_C99_SELECT(dim2,ddim2) + POLYBENCH_PADDING_FACTOR][POLYBENCH_C99_SELECT(dim3,ddim3) + POLYBENCH_PADDING_FACTOR][POLYBENCH_C99_SELECT(dim4,ddim4) + POLYBENCH_PADDING_FACTOR][POLYBENCH_C99_SELECT(dim5,ddim5) + POLYBENCH_PADDING_FACTOR]
108 
109 
110 /* Macros to allocate heap arrays.
111  Example:
112  polybench_alloc_2d_array(N, M, double) => allocates N x M x sizeof(double)
113  and returns a pointer to the 2d array
114  */
115 # define POLYBENCH_ALLOC_1D_ARRAY(n1, type) \
116  (type(*)[n1 + POLYBENCH_PADDING_FACTOR])polybench_alloc_data (n1 + POLYBENCH_PADDING_FACTOR, sizeof(type))
117 # define POLYBENCH_ALLOC_2D_ARRAY(n1, n2, type) \
118  (type(*)[n1 + POLYBENCH_PADDING_FACTOR][n2 + POLYBENCH_PADDING_FACTOR])polybench_alloc_data ((n1 + POLYBENCH_PADDING_FACTOR) * (n2 + POLYBENCH_PADDING_FACTOR), sizeof(type))
119 # define POLYBENCH_ALLOC_3D_ARRAY(n1, n2, n3, type) \
120  (type(*)[n1 + POLYBENCH_PADDING_FACTOR][n2 + POLYBENCH_PADDING_FACTOR][n3 + POLYBENCH_PADDING_FACTOR])polybench_alloc_data ((n1 + POLYBENCH_PADDING_FACTOR) * (n2 + POLYBENCH_PADDING_FACTOR) * (n3 + POLYBENCH_PADDING_FACTOR), sizeof(type))
121 # define POLYBENCH_ALLOC_4D_ARRAY(n1, n2, n3, n4, type) \
122  (type(*)[n1 + POLYBENCH_PADDING_FACTOR][n2 + POLYBENCH_PADDING_FACTOR][n3 + POLYBENCH_PADDING_FACTOR][n4 + POLYBENCH_PADDING_FACTOR])polybench_alloc_data ((n1 + POLYBENCH_PADDING_FACTOR) * (n2 + POLYBENCH_PADDING_FACTOR) * (n3 + POLYBENCH_PADDING_FACTOR) * (n4 + POLYBENCH_PADDING_FACTOR), sizeof(type))
123 # define POLYBENCH_ALLOC_5D_ARRAY(n1, n2, n3, n4, n5, type) \
124  (type(*)[n1 + POLYBENCH_PADDING_FACTOR][n2 + POLYBENCH_PADDING_FACTOR][n3 + POLYBENCH_PADDING_FACTOR][n4 + POLYBENCH_PADDING_FACTOR][n5 + POLYBENCH_PADDING_FACTOR])polybench_alloc_data ((n1 + POLYBENCH_PADDING_FACTOR) * (n2 + POLYBENCH_PADDING_FACTOR) * (n3 + POLYBENCH_PADDING_FACTOR) * (n4 + POLYBENCH_PADDING_FACTOR) * (n5 + POLYBENCH_PADDING_FACTOR), sizeof(type))
125 
126 /* Macros for array declaration. */
127 # ifndef POLYBENCH_STACK_ARRAYS
128 # define POLYBENCH_1D_ARRAY_DECL(var, type, dim1, ddim1) \
129  type POLYBENCH_1D_F(POLYBENCH_DECL_VAR(var), dim1, ddim1); \
130  var = POLYBENCH_ALLOC_1D_ARRAY(POLYBENCH_C99_SELECT(dim1, ddim1), type);
131 # define POLYBENCH_2D_ARRAY_DECL(var, type, dim1, dim2, ddim1, ddim2) \
132  type POLYBENCH_2D_F(POLYBENCH_DECL_VAR(var), dim1, dim2, ddim1, ddim2); \
133  var = POLYBENCH_ALLOC_2D_ARRAY(POLYBENCH_C99_SELECT(dim1, ddim1), POLYBENCH_C99_SELECT(dim2, ddim2), type);
134 # define POLYBENCH_3D_ARRAY_DECL(var, type, dim1, dim2, dim3, ddim1, ddim2, ddim3) \
135  type POLYBENCH_3D_F(POLYBENCH_DECL_VAR(var), dim1, dim2, dim3, ddim1, ddim2, ddim3); \
136  var = POLYBENCH_ALLOC_3D_ARRAY(POLYBENCH_C99_SELECT(dim1, ddim1), POLYBENCH_C99_SELECT(dim2, ddim2), POLYBENCH_C99_SELECT(dim3, ddim3), type);
137 # define POLYBENCH_4D_ARRAY_DECL(var, type, dim1, dim2, dim3, dim4, ddim1, ddim2, ddim3, ddim4) \
138  type POLYBENCH_4D_F(POLYBENCH_DECL_VAR(var), dim1, dim2, dim3, dim4, ddim1, ddim2, ddim3, ddim4); \
139  var = POLYBENCH_ALLOC_4D_ARRAY(POLYBENCH_C99_SELECT(dim1, ddim1), POLYBENCH_C99_SELECT(dim2, ddim2), POLYBENCH_C99_SELECT(dim3, ddim3), POLYBENCH_C99_SELECT(dim4, ddim4), type);
140 # define POLYBENCH_5D_ARRAY_DECL(var, type, dim1, dim2, dim3, dim4, dim5, ddim1, ddim2, ddim3, ddim4, ddim5) \
141  type POLYBENCH_5D_F(POLYBENCH_DECL_VAR(var), dim1, dim2, dim3, dim4, dim5, ddim1, ddim2, ddim3, ddim4, ddim5); \
142  var = POLYBENCH_ALLOC_5D_ARRAY(POLYBENCH_C99_SELECT(dim1, ddim1), POLYBENCH_C99_SELECT(dim2, ddim2), POLYBENCH_C99_SELECT(dim3, ddim3), POLYBENCH_C99_SELECT(dim4, ddim4), POLYBENCH_C99_SELECT(dim5, ddim5), type);
143 # else
144 # define POLYBENCH_1D_ARRAY_DECL(var, type, dim1, ddim1) \
145  type POLYBENCH_1D_F(POLYBENCH_DECL_VAR(var), dim1, ddim1);
146 # define POLYBENCH_2D_ARRAY_DECL(var, type, dim1, dim2, ddim1, ddim2) \
147  type POLYBENCH_2D_F(POLYBENCH_DECL_VAR(var), dim1, dim2, ddim1, ddim2);
148 # define POLYBENCH_3D_ARRAY_DECL(var, type, dim1, dim2, dim3, ddim1, ddim2, ddim3) \
149  type POLYBENCH_3D_F(POLYBENCH_DECL_VAR(var), dim1, dim2, dim3, ddim1, ddim2, ddim3);
150 # define POLYBENCH_4D_ARRAY_DECL(var, type, dim1, dim2, dim3, dim4, ddim1, ddim2, ddim3, ddim4) \
151  type POLYBENCH_4D_F(POLYBENCH_DECL_VAR(var), dim1, dim2, dim3, dim4, ddim1, ddim2, ddim3, ddim4);
152 # define POLYBENCH_5D_ARRAY_DECL(var, type, dim1, dim2, dim3, dim4, dim5, ddim1, ddim2, ddim3, ddim4, ddim5) \
153  type POLYBENCH_5D_F(POLYBENCH_DECL_VAR(var), dim1, dim2, dim3, dim4, dim5, ddim1, ddim2, ddim3, ddim4, ddim5);
154 # endif
155 
156 
157 /* Dead-code elimination macros. Use argc/argv for the run-time check. */
158 # ifndef POLYBENCH_DUMP_ARRAYS
159 # define POLYBENCH_DCE_ONLY_CODE if (argc > 42 && ! strcmp(argv[0], ""))
160 # else
161 # define POLYBENCH_DCE_ONLY_CODE
162 # endif
163 
164 #define POLYBENCH_DUMP_TARGET stderr
165 #define POLYBENCH_DUMP_START fprintf(POLYBENCH_DUMP_TARGET, "==BEGIN DUMP_ARRAYS==\n")
166 #define POLYBENCH_DUMP_FINISH fprintf(POLYBENCH_DUMP_TARGET, "==END DUMP_ARRAYS==\n")
167 #define POLYBENCH_DUMP_BEGIN(s) fprintf(POLYBENCH_DUMP_TARGET, "begin dump: %s", s)
168 #define POLYBENCH_DUMP_END(s) fprintf(POLYBENCH_DUMP_TARGET, "\nend dump: %s\n", s)
169 
170 # define polybench_prevent_dce(func) \
171  POLYBENCH_DCE_ONLY_CODE \
172  func
173 
174 
175 /* Performance-related instrumentation. See polybench.c */
176 # define polybench_start_instruments
177 # define polybench_stop_instruments
178 # define polybench_print_instruments
179 
180 
181 /* PAPI support. */
182 # ifdef POLYBENCH_PAPI
183 extern const unsigned int polybench_papi_eventlist[];
184 # undef polybench_start_instruments
185 # undef polybench_stop_instruments
186 # undef polybench_print_instruments
187 # define polybench_set_papi_thread_report(x) \
188  polybench_papi_counters_threadid = x;
189 # define polybench_start_instruments \
190  polybench_prepare_instruments(); \
191  polybench_papi_init(); \
192  int evid; \
193  for (evid = 0; polybench_papi_eventlist[evid] != 0; evid++) \
194  { \
195  if (polybench_papi_start_counter(evid)) \
196  continue; \
197 
198 # define polybench_stop_instruments \
199  polybench_papi_stop_counter(evid); \
200  } \
201  polybench_papi_close(); \
202 
203 # define polybench_print_instruments polybench_papi_print();
204 # endif
205 
206 
207 /* Timing support. */
208 # if defined(POLYBENCH_TIME) || defined(POLYBENCH_GFLOPS)
209 # undef polybench_start_instruments
210 # undef polybench_stop_instruments
211 # undef polybench_print_instruments
212 # define polybench_start_instruments polybench_timer_start();
213 # define polybench_stop_instruments polybench_timer_stop();
214 # define polybench_print_instruments polybench_timer_print();
215 extern double polybench_program_total_flops;
216 extern void polybench_timer_start();
217 extern void polybench_timer_stop();
218 extern void polybench_timer_print();
219 # endif
220 
221 /* PAPI support. */
222 # ifdef POLYBENCH_PAPI
223 extern int polybench_papi_start_counter(int evid);
224 extern void polybench_papi_stop_counter(int evid);
225 extern void polybench_papi_init();
226 extern void polybench_papi_close();
227 extern void polybench_papi_print();
228 # endif
229 
230 /* Function prototypes. */
231 extern void* polybench_alloc_data(unsigned long long int n, int elt_size);
232 extern void polybench_free_data(void* ptr);
233 
234 /* PolyBench internal functions that should not be directly called by */
235 /* the user, unless when designing customized execution profiling */
236 /* approaches. */
237 extern void polybench_flush_cache();
238 extern void polybench_prepare_instruments();
239 
240 
241 #endif /* !POLYBENCH_H */
void polybench_timer_print()
Definition: polybench.c:388
void polybench_prepare_instruments()
Definition: polybench.c:353
void * polybench_alloc_data(unsigned long long int n, int elt_size)
Definition: polybench.c:557
void polybench_free_data(void *ptr)
Definition: polybench.c:547
void polybench_flush_cache()
Definition: polybench.c:112
void polybench_timer_start()
Definition: polybench.c:364
double polybench_program_total_flops
Definition: polybench.c:46
void polybench_timer_stop()
Definition: polybench.c:375

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