aboutsummaryrefslogtreecommitdiffstats
path: root/benchmarks/polybench-syn/linear-algebra/blas/gemm.c
diff options
context:
space:
mode:
Diffstat (limited to 'benchmarks/polybench-syn/linear-algebra/blas/gemm.c')
-rw-r--r--benchmarks/polybench-syn/linear-algebra/blas/gemm.c111
1 files changed, 111 insertions, 0 deletions
diff --git a/benchmarks/polybench-syn/linear-algebra/blas/gemm.c b/benchmarks/polybench-syn/linear-algebra/blas/gemm.c
new file mode 100644
index 0000000..5a28f08
--- /dev/null
+++ b/benchmarks/polybench-syn/linear-algebra/blas/gemm.c
@@ -0,0 +1,111 @@
+/**
+ * This version is stamped on May 10, 2016
+ *
+ * Contact:
+ * Louis-Noel Pouchet <pouchet.ohio-state.edu>
+ * Tomofumi Yuki <tomofumi.yuki.fr>
+ *
+ * Web address: http://polybench.sourceforge.net
+ */
+/* gemm.c: this file is part of PolyBench/C */
+
+#define plus(i) i = i + ONE
+static
+void init_array(int ni, int nj, int nk,
+ int *alpha,
+ int *beta,
+ int C[ 20 + 0][25 + 0],
+ int A[ 20 + 0][30 + 0],
+ int B[ 30 + 0][25 + 0])
+{
+ int i, j;
+ int ONE = 1;
+
+ *alpha = 2;
+ *beta = 2;
+ for (i = 0; i < ni; plus(i))
+ for (j = 0; j < nj; plus(j))
+ C[i][j] = (int) ((i*j+ONE) % ni) / ni;
+ for (i = 0; i < ni; plus(i))
+ for (j = 0; j < nk; plus(j))
+ A[i][j] = (int) (i*(j+ONE) % nk) / nk;
+ for (i = 0; i < nk; plus(i))
+ for (j = 0; j < nj; plus(j))
+ B[i][j] = (int) (i*(j+ONE+ONE) % nj) / nj;
+}
+
+
+
+
+static
+int print_array(int ni, int nj,
+ int C[ 20 + 0][25 + 0])
+{
+ int i, j;
+ int ONE = 1;
+ int res = 0;
+ for (i = 0; i < ni; plus(i))
+ for (j = 0; j < nj; plus(j)) {
+ res ^= C[i][j];
+ }
+ return res;
+}
+
+static
+void kernel_gemm(int ni, int nj, int nk,
+ int alpha,
+ int beta,
+ int C[ 20 + 0][25 + 0],
+ int A[ 20 + 0][30 + 0],
+ int B[ 30 + 0][25 + 0])
+{
+ int i, j, k;
+ int ONE = 1;
+
+#pragma scop
+ for (i = 0; i < ni; plus(i)) {
+ for (j = 0; j < nj; plus(j))
+ C[i][j] *= beta;
+ for (k = 0; k < nk; plus(k)) {
+ for (j = 0; j < nj; plus(j))
+ C[i][j] += alpha * A[i][k] * B[k][j];
+ }
+ }
+#pragma endscop
+
+}
+
+
+int main()
+{
+
+ int ni = 20;
+ int nj = 25;
+ int nk = 30;
+
+
+ int alpha;
+ int beta;
+ int C[20 + 0][25 + 0];
+ int A[20 + 0][30 + 0];
+ int B[30 + 0][25 + 0];
+
+
+ init_array (ni, nj, nk, &alpha, &beta,
+ C,
+ A,
+ B);
+
+
+ kernel_gemm (ni, nj, nk,
+ alpha, beta,
+ C,
+ A,
+ B);
+
+
+ return
+ print_array(ni, nj, C);
+
+
+}