From aa986aacbb80e9f92f77d65de74ba5051054eac7 Mon Sep 17 00:00:00 2001 From: Yann Herklotz Date: Sun, 11 Jul 2021 01:19:52 +0200 Subject: Add divider benchmarks --- benchmarks/polybench-syn-div/stencils/heat-3d.c | 112 ++++++++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 benchmarks/polybench-syn-div/stencils/heat-3d.c (limited to 'benchmarks/polybench-syn-div/stencils/heat-3d.c') diff --git a/benchmarks/polybench-syn-div/stencils/heat-3d.c b/benchmarks/polybench-syn-div/stencils/heat-3d.c new file mode 100644 index 0000000..f93082e --- /dev/null +++ b/benchmarks/polybench-syn-div/stencils/heat-3d.c @@ -0,0 +1,112 @@ +/** + * This version is stamped on May 10, 2016 + * + * Contact: + * Louis-Noel Pouchet + * Tomofumi Yuki + * + * Web address: http://polybench.sourceforge.net + */ +/* heat-3d.c: this file is part of PolyBench/C */ + +#include "../include/misc.h" + +#ifndef SYNTHESIS +#include +#endif + +#define plus(i) i = i + ONE +static +void init_array (int n, + int A[ 10 + 0][10 + 0][10 + 0], + int B[ 10 + 0][10 + 0][10 + 0]) +{ + int i, j, k; + int ONE = 1; + + for (i = 0; i < n; plus(i)) + for (j = 0; j < n; plus(j)) + for (k = 0; k < n; plus(k)) + A[i][j][k] = B[i][j][k] = (int) (i + j + (n-k))* (10 / n); +} + + + + +static +int print_array(int n, + int A[ 10 + 0][10 + 0][10 + 0]) + +{ + int i, j, k; + int ONE = 1; + int res = 0; + + for (i = 0; i < n; plus(i)) + for (j = 0; j < n; plus(j)) + for (k = 0; k < n; plus(k)) { + res ^= A[i][j][k]; + } +#ifndef SYNTHESIS + printf("finished %u\n", res); +#endif + return res; +} + + + + +static +void kernel_heat_3d(int tsteps, + int n, + int A[ 10 + 0][10 + 0][10 + 0], + int B[ 10 + 0][10 + 0][10 + 0]) +{ + int t, i, j, k; + int ONE = 1; + int TWO = 2; + + for (t = 1; t <= 5; plus(t)) { + for (i = 1; i < n-ONE; plus(i)) { + for (j = 1; j < n-ONE; plus(j)) { + for (k = 1; k < n-ONE; plus(k)) { + B[i][j][k] = ((A[i+ONE][j][k] - TWO * A[i][j][k] + A[i-ONE][j][k]) >> 4) + + ((A[i][j+ONE][k] - TWO * A[i][j][k] + A[i][j-ONE][k]) >> 4) + + ((A[i][j][k+ONE] - TWO * A[i][j][k] + A[i][j][k-ONE]) >> 4) + + A[i][j][k] + ; + } + } + } + for (i = 1; i < n-ONE; plus(i)) { + for (j = 1; j < n-ONE; plus(j)) { + for (k = 1; k < n-ONE; plus(k)) { + A[i][j][k] = ((B[i+ONE][j][k] - TWO * B[i][j][k] + B[i-ONE][j][k]) >> 4 ) + + ((B[i][j+ONE][k] - TWO * B[i][j][k] + B[i][j-ONE][k]) >> 4 ) + + ((B[i][j][k+ONE] - TWO * B[i][j][k] + B[i][j][k-ONE]) >> 4 ) + + B[i][j][k]; + //; + } + } + } + } +} + + +int main() +{ + + int n = 10; + int tsteps = 20; + + + int A[10 + 0][10 + 0][10 + 0]; + int B[10 + 0][10 + 0][10 + 0]; + + init_array (n, A, B); + + kernel_heat_3d (tsteps, n, A, B); + + return print_array(n, A); + +} -- cgit