PandA-2024.02
stencil.c
Go to the documentation of this file.
1 /*
2 Implementation based on algorithm described in:
3 "Stencil computation optimization and auto-tuning on state-of-the-art multicore architectures"
4 K. Datta, M. Murphy, V. Volkov, S. Williams, J. Carter, L. Oliker, D. Patterson, J. Shalf, K. Yelick
5 SC 2008
6 */
7 
8 #include "stencil.h"
9 
10 void stencil3d(TYPE C[2], TYPE orig[SIZE], TYPE sol[SIZE]) {
11  int i, j, k;
12  TYPE sum0, sum1, mul0, mul1;
13 
14  // Handle boundary conditions by filling with original values
15  height_bound_col : for(j=0; j<col_size; j++) {
16  height_bound_row : for(k=0; k<row_size; k++) {
17  sol[INDX(row_size, col_size, k, j, 0)] = orig[INDX(row_size, col_size, k, j, 0)];
18  sol[INDX(row_size, col_size, k, j, height_size-1)] = orig[INDX(row_size, col_size, k, j, height_size-1)];
19  }
20  }
21  col_bound_height : for(i=1; i<height_size-1; i++) {
22  col_bound_row : for(k=0; k<row_size; k++) {
23  sol[INDX(row_size, col_size, k, 0, i)] = orig[INDX(row_size, col_size, k, 0, i)];
24  sol[INDX(row_size, col_size, k, col_size-1, i)] = orig[INDX(row_size, col_size, k, col_size-1, i)];
25  }
26  }
27  row_bound_height : for(i=1; i<height_size-1; i++) {
28  row_bound_col : for(j=1; j<col_size-1; j++) {
29  sol[INDX(row_size, col_size, 0, j, i)] = orig[INDX(row_size, col_size, 0, j, i)];
30  sol[INDX(row_size, col_size, row_size-1, j, i)] = orig[INDX(row_size, col_size, row_size-1, j, i)];
31  }
32  }
33 
34 
35  // Stencil computation
36  loop_height : for(i = 1; i < height_size - 1; i++){
37  loop_col : for(j = 1; j < col_size - 1; j++){
38  loop_row : for(k = 1; k < row_size - 1; k++){
39  sum0 = orig[INDX(row_size, col_size, k, j, i)];
40  sum1 = orig[INDX(row_size, col_size, k, j, i + 1)] +
41  orig[INDX(row_size, col_size, k, j, i - 1)] +
42  orig[INDX(row_size, col_size, k, j + 1, i)] +
43  orig[INDX(row_size, col_size, k, j - 1, i)] +
44  orig[INDX(row_size, col_size, k + 1, j, i)] +
45  orig[INDX(row_size, col_size, k - 1, j, i)];
46  mul0 = sum0 * C[0];
47  mul1 = sum1 * C[1];
48  sol[INDX(row_size, col_size, k, j, i)] = mul0 + mul1;
49  }
50  }
51  }
52 }
#define C
Definition: generate.c:15
#define col_size
Definition: gemm.h:17
#define TYPE
Definition: backprop.h:21
#define row_size
Definition: gemm.h:16
static const uint32_t k[]
Definition: sha-256.c:22
void stencil3d(TYPE C[2], TYPE orig[SIZE], TYPE sol[SIZE])
Definition: stencil.c:10
#define SIZE
Definition: adpcm.c:775
#define height_size
Definition: stencil.h:13
#define INDX(_row_size, _col_size, _i, _j, _k)
Definition: stencil.h:22

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