Commit 21f8d92a authored by lmeinen's avatar lmeinen
Browse files

remove unnecessary files

parent a9777e07
{
"files.associations": {
"lu.h": "c"
}
}
\ No newline at end of file
/**
* 2mm.c: This file is part of the PolyBench/C 3.2 test suite.
*
*
* Contact: Louis-Noel Pouchet <pouchet@cse.ohio-state.edu>
* Web address: http://polybench.sourceforge.net
*/
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <math.h>
/* Include polybench common header. */
#include <polybench.h>
/* Include benchmark-specific header. */
/* Default data type is double, default size is 4000. */
#include "2mm.h"
/* Array initialization. */
static
void init_array(int ni, int nj, int nk, int nl,
DATA_TYPE *alpha,
DATA_TYPE *beta,
DATA_TYPE POLYBENCH_2D(A,NI,NK,ni,nl),
DATA_TYPE POLYBENCH_2D(B,NK,NJ,nk,nj),
DATA_TYPE POLYBENCH_2D(C,NL,NJ,nl,nj),
DATA_TYPE POLYBENCH_2D(D,NI,NL,ni,nl))
{
int i, j;
*alpha = 32412;
*beta = 2123;
for (i = 0; i < ni; i++)
for (j = 0; j < nk; j++)
A[i][j] = ((DATA_TYPE) i*j) / ni;
for (i = 0; i < nk; i++)
for (j = 0; j < nj; j++)
B[i][j] = ((DATA_TYPE) i*(j+1)) / nj;
for (i = 0; i < nl; i++)
for (j = 0; j < nj; j++)
C[i][j] = ((DATA_TYPE) i*(j+3)) / nl;
for (i = 0; i < ni; i++)
for (j = 0; j < nl; j++)
D[i][j] = ((DATA_TYPE) i*(j+2)) / nk;
}
/* DCE code. Must scan the entire live-out data.
Can be used also to check the correctness of the output. */
static
void print_array(int ni, int nl,
DATA_TYPE POLYBENCH_2D(D,NI,NL,ni,nl))
{
int i, j;
for (i = 0; i < ni; i++)
for (j = 0; j < nl; j++) {
fprintf (stderr, DATA_PRINTF_MODIFIER, D[i][j]);
if ((i * ni + j) % 20 == 0) fprintf (stderr, "\n");
}
fprintf (stderr, "\n");
}
/* Main computational kernel. The whole function will be timed,
including the call and return. */
static
void kernel_2mm(int ni, int nj, int nk, int nl,
DATA_TYPE alpha,
DATA_TYPE beta,
DATA_TYPE POLYBENCH_2D(tmp,NI,NJ,ni,nj),
DATA_TYPE POLYBENCH_2D(A,NI,NK,ni,nk),
DATA_TYPE POLYBENCH_2D(B,NK,NJ,nk,nj),
DATA_TYPE POLYBENCH_2D(C,NL,NJ,nl,nj),
DATA_TYPE POLYBENCH_2D(D,NI,NL,ni,nl))
{
int i, j, k;
#pragma scop
/* D := alpha*A*B*C + beta*D */
for (i = 0; i < _PB_NI; i++)
for (j = 0; j < _PB_NJ; j++)
{
tmp[i][j] = 0;
for (k = 0; k < _PB_NK; ++k)
tmp[i][j] += alpha * A[i][k] * B[k][j];
}
for (i = 0; i < _PB_NI; i++)
for (j = 0; j < _PB_NL; j++)
{
D[i][j] *= beta;
for (k = 0; k < _PB_NJ; ++k)
D[i][j] += tmp[i][k] * C[k][j];
}
#pragma endscop
}
int main(int argc, char** argv)
{
/* Retrieve problem size. */
int ni = NI;
int nj = NJ;
int nk = NK;
int nl = NL;
/* Variable declaration/allocation. */
DATA_TYPE alpha;
DATA_TYPE beta;
POLYBENCH_2D_ARRAY_DECL(tmp,DATA_TYPE,NI,NJ,ni,nj);
POLYBENCH_2D_ARRAY_DECL(A,DATA_TYPE,NI,NK,ni,nk);
POLYBENCH_2D_ARRAY_DECL(B,DATA_TYPE,NK,NJ,nk,nj);
POLYBENCH_2D_ARRAY_DECL(C,DATA_TYPE,NL,NJ,nl,nj);
POLYBENCH_2D_ARRAY_DECL(D,DATA_TYPE,NI,NL,ni,nl);
/* Initialize array(s). */
init_array (ni, nj, nk, nl, &alpha, &beta,
POLYBENCH_ARRAY(A),
POLYBENCH_ARRAY(B),
POLYBENCH_ARRAY(C),
POLYBENCH_ARRAY(D));
/* Start timer. */
polybench_start_instruments;
/* Run kernel. */
kernel_2mm (ni, nj, nk, nl,
alpha, beta,
POLYBENCH_ARRAY(tmp),
POLYBENCH_ARRAY(A),
POLYBENCH_ARRAY(B),
POLYBENCH_ARRAY(C),
POLYBENCH_ARRAY(D));
/* Stop and print timer. */
polybench_stop_instruments;
polybench_print_instruments;
/* Prevent dead-code elimination. All live-out data must be printed
by the function call in argument. */
polybench_prevent_dce(print_array(ni, nl, POLYBENCH_ARRAY(D)));
/* Be clean. */
POLYBENCH_FREE_ARRAY(tmp);
POLYBENCH_FREE_ARRAY(A);
POLYBENCH_FREE_ARRAY(B);
POLYBENCH_FREE_ARRAY(C);
POLYBENCH_FREE_ARRAY(D);
return 0;
}
/**
* 2mm.h: This file is part of the PolyBench/C 3.2 test suite.
*
*
* Contact: Louis-Noel Pouchet <pouchet@cse.ohio-state.edu>
* Web address: http://polybench.sourceforge.net
*/
#ifndef _2MM_H
# define _2MM_H
/* Default to STANDARD_DATASET. */
# if !defined(MINI_DATASET) && !defined(SMALL_DATASET) && !defined(LARGE_DATASET) && !defined(EXTRALARGE_DATASET)
# define STANDARD_DATASET
# endif
/* Do not define anything if the user manually defines the size. */
# if !defined(NI) && !defined(NJ) && !defined(NK)
/* Define the possible dataset sizes. */
# ifdef MINI_DATASET
# define NI 32
# define NJ 32
# define NK 32
# define NL 32
# endif
# ifdef SMALL_DATASET
# define NI 128
# define NJ 128
# define NK 128
# define NL 128
# endif
# ifdef STANDARD_DATASET /* Default if unspecified. */
# define NI 1024
# define NJ 1024
# define NK 1024
# define NL 1024
# endif
# ifdef LARGE_DATASET
# define NI 2000
# define NJ 2000
# define NK 2000
# define NL 2000
# endif
# ifdef EXTRALARGE_DATASET
# define NI 4000
# define NJ 4000
# define NK 4000
# define NL 4000
# endif
# endif /* !N */
# define _PB_NI POLYBENCH_LOOP_BOUND(NI,ni)
# define _PB_NJ POLYBENCH_LOOP_BOUND(NJ,nj)
# define _PB_NK POLYBENCH_LOOP_BOUND(NK,nk)
# define _PB_NL POLYBENCH_LOOP_BOUND(NL,nl)
# ifndef DATA_TYPE
# define DATA_TYPE double
# define DATA_PRINTF_MODIFIER "%0.2lf "
# endif
#endif /* !_2MM */
CC = gcc
CFLAGS = -O3 -I utilities -I linear-algebra/kernels/atax utilities/polybench.c linear-algebra/kernels/atax/atax.c -DPOLYBENCH_TIME
RM = rm -f
default: all
all: 2mm
2mm: 2mm.c
$(CC) $(CFLAGS) -o 2mm 2mm.c
clean veryclean:
$(RM) 2mm
/**
* 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
*/
#ifndef _2MM_H
# define _2MM_H
/* Default to LARGE_DATASET. */
# if !defined(MINI_DATASET) && !defined(SMALL_DATASET) && !defined(MEDIUM_DATASET) && !defined(LARGE_DATASET) && !defined(EXTRALARGE_DATASET)
# define LARGE_DATASET
# endif
# if !defined(NI) && !defined(NJ) && !defined(NK) && !defined(NL)
/* Define sample dataset sizes. */
# ifdef MINI_DATASET
# define NI 16
# define NJ 18
# define NK 22
# define NL 24
# endif
# ifdef SMALL_DATASET
# define NI 40
# define NJ 50
# define NK 70
# define NL 80
# endif
# ifdef MEDIUM_DATASET
# define NI 180
# define NJ 190
# define NK 210
# define NL 220
# endif
# ifdef LARGE_DATASET
# define NI 800
# define NJ 900
# define NK 1100
# define NL 1200
# endif
# ifdef EXTRALARGE_DATASET
# define NI 1600
# define NJ 1800
# define NK 2200
# define NL 2400
# endif
#endif /* !(NI NJ NK NL) */
# define _PB_NI POLYBENCH_LOOP_BOUND(NI,ni)
# define _PB_NJ POLYBENCH_LOOP_BOUND(NJ,nj)
# define _PB_NK POLYBENCH_LOOP_BOUND(NK,nk)
# define _PB_NL POLYBENCH_LOOP_BOUND(NL,nl)
/* Default data type */
# if !defined(DATA_TYPE_IS_INT) && !defined(DATA_TYPE_IS_FLOAT) && !defined(DATA_TYPE_IS_DOUBLE)
# define DATA_TYPE_IS_DOUBLE
# endif
#ifdef DATA_TYPE_IS_INT
# define DATA_TYPE int
# define DATA_PRINTF_MODIFIER "%d "
#endif
#ifdef DATA_TYPE_IS_FLOAT
# define DATA_TYPE float
# define DATA_PRINTF_MODIFIER "%0.2f "
# define SCALAR_VAL(x) x##f
# define SQRT_FUN(x) sqrtf(x)
# define EXP_FUN(x) expf(x)
# define POW_FUN(x,y) powf(x,y)
# endif
#ifdef DATA_TYPE_IS_DOUBLE
# define DATA_TYPE double
# define DATA_PRINTF_MODIFIER "%0.2lf "
# define SCALAR_VAL(x) x
# define SQRT_FUN(x) sqrt(x)
# define EXP_FUN(x) exp(x)
# define POW_FUN(x,y) pow(x,y)
# endif
#endif /* !_2MM_H */
/**
* 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
*/
/* 2mm.c: this file is part of PolyBench/C */
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <math.h>
#include <omp.h>
/* Include polybench common header. */
#include <polybench.h>
/* Include benchmark-specific header. */
#include "2mm.h"
/* Kokkos */
#include <Kokkos_Core.hpp>
typedef Kokkos::View<DATA_TYPE **> ViewMatrixType;
//# 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]
/* Array initialization. */
static void init_array(int ni, int nj, int nk, int nl,
DATA_TYPE *alpha,
DATA_TYPE *beta,
ViewMatrixType A,
ViewMatrixType B,
ViewMatrixType C,
ViewMatrixType D)
{
int i, j;
*alpha = 1.5;
*beta = 1.2;
for (i = 0; i < ni; i++)
for (j = 0; j < nk; j++)
A(i, j) = (DATA_TYPE)((i * j + 1) % ni) / ni;
for (i = 0; i < nk; i++)
for (j = 0; j < nj; j++)
B(i, j) = (DATA_TYPE)(i * (j + 1) % nj) / nj;
for (i = 0; i < nj; i++)
for (j = 0; j < nl; j++)
C(i, j) = (DATA_TYPE)((i * (j + 3) + 1) % nl) / nl;
for (i = 0; i < ni; i++)
for (j = 0; j < nl; j++)
D(i, j) = (DATA_TYPE)(i * (j + 2) % nk) / nk;
}
/* DCE code. Must scan the entire live-out data.
Can be used also to check the correctness of the output. */
static void print_array(int ni, int nl,
ViewMatrixType D)
{
int i, j;
for (i = 0; i < ni; i++)
{
for (j = 0; j < nl; j++)
{
fprintf(POLYBENCH_DUMP_TARGET, DATA_PRINTF_MODIFIER, D(i, j));
}
fprintf(POLYBENCH_DUMP_TARGET, "\n");
}
}
/* Main computational kernel. The whole function will be timed,
including the call and return. */
static void kernel_2mm(int ni, int nj, int nk, int nl,
DATA_TYPE alpha,
DATA_TYPE beta,
ViewMatrixType tmp,
ViewMatrixType A,
ViewMatrixType B,
ViewMatrixType C,
ViewMatrixType D)
{
int i, j, k;
#pragma scop
{
/* D := alpha*A*B*C + beta*D */
//#pragma omp parallel for collapse (2)
for (i = 0; i < _PB_NI; i++)
for (j = 0; j < _PB_NJ; j++)
{
tmp(i, j) = SCALAR_VAL(0.0);
//#pragma omp parallel for
for (k = 0; k < _PB_NK; ++k)
tmp(i, j) += alpha * A(i, k) * B(k, j);
}
//#pragma omp parallel for collapse (2)
parallel_for(
Kokkos::MDRangePolicy<Kokkos::Rank<2>>({0, 0}, {_PB_NI, _PB_NL}),
KOKKOS_LAMBDA(const int i, const int j)
{
double temp = 0.0;
D(i, j) *= beta;
/*
Kokkos::parallel_reduce(_PB_NJ,
KOKKOS_LAMBDA (const int64_t k, double & local){
local += tmp(i,k) * C(k,j);
}, temp);
D(i,j) += temp;
*/
for (int k = 0; k < _PB_NJ; ++k)
D(i, j) += tmp(i, k) * C(k, j);
});
/*
for (i = 0; i < _PB_NI; i++)
for (j = 0; j < _PB_NL; j++)
{
double temp = 0.0;
D(i,j) *= beta;
//#pragma omp parallel for
for (k = 0; k < _PB_NJ; ++k)
D(i,j) += tmp(i,k) * C(k,j);
Kokkos::parallel_reduce(_PB_NJ,
KOKKOS_LAMBDA (const int64_t k, double & local){
local += tmp(i,k) * C(k,j);
}, temp);
D(i,j) += temp;
}
*/
}
#pragma endscop
}
int main(int argc, char **argv)
{
/* Retrieve problem size. */
int ni = NI;
int nj = NJ;
int nk = NK;
int nl = NL;
/* Variable declaration/allocation. */
DATA_TYPE alpha;
DATA_TYPE beta;
Kokkos::initialize(argc, argv);
{
ViewMatrixType tmp("tmp", NI, NJ);
ViewMatrixType A("A", NI, NK);
ViewMatrixType B("B", NK, NJ);
ViewMatrixType C("C", NJ, NL);
ViewMatrixType D("D", NI, NL);
/* Initialize array(s). */
init_array(ni, nj, nk, nl, &alpha, &beta, A, B, C, D);
omp_set_num_threads(1);
/* Start timer. */
polybench_start_instruments;
/* Run kernel. */
kernel_2mm(ni, nj, nk, nl, alpha, beta, tmp, A, B, C, D);
/* Stop and print timer. */
polybench_stop_instruments;
polybench_print_instruments;
/* Prevent dead-code elimination. All live-out data must be printed
by the function call in argument. */
polybench_prevent_dce(print_array(ni, nl, D));
}
Kokkos::finalize();
return 0;
}
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <math.h>
#include "2mm.h"
// Text colouring
#define KNRM "\x1B[0m"
#define KRED "\x1B[31m"
#define KGRN "\x1B[32m"
/* Function declaration */
int compareFile(FILE *fPtr1, FILE *fPtr2, DATA_TYPE *line, DATA_TYPE *col);
/**
* Compares two kernel output files for equality
* The first command-line arg should be the file path to the expected output file,
* the second the path to the actual output
*/
int main(int argc, char **argv)
{
if (argc != 3)
{
printf("Expected exactly 2 arguments, got %d\n", argc);
return -1;
}
printf("Testing for size %dx%d: ", NI, NL);
/* Open all files to compare */
FILE *fExp = fopen(argv[1], "r");
FILE *fAct = fopen(argv[2], "r");
/* fopen() return NULL if unable to open file in given mode. */
if (fExp == NULL || fAct == NULL)
{
/* Unable to open file hence exit */
printf("Unable to open file.\n");
printf("Please check whether file exists and you have read privilege.\n");
return -1;
}
/* Call function to compare file */
DATA_TYPE exp, act;
int diff = compareFile(fExp, fAct, &exp, &act);
if (diff == 0)
{
printf("%spassed%s\n", KGRN, KNRM);
}
else if (diff == -1)
{
printf("%serror - expected %0.2lf, but got %0.2lf%s\n", KRED, exp, act, KNRM);
}
/* Finally close files to release resources */
fclose(fExp);
fclose(fAct);
return 0;
}
/**
* Function to compare two files.
* Returns 0 if both files are equivalent, otherwise returns
* -1 and sets line and col where both files differ.
*/
int compareFile(FILE *fExp, FILE *fAct, DATA_TYPE *exp, DATA_TYPE *act)
{
char ch1, ch2;
*exp = 1;
*act = 0;
/* Retrieve problem size. */
int ni = NI;
int nl = NL;
for (int i = 0; i < ni; i++)
{
for (int j = 0; j < nl; j++)
{
if (fscanf(fExp, "%lf", exp) != 1)
{
printf("%serror - couldn't match from expected file row %d, column %d%s\n", KRED, i, j, KNRM);
return -2;
}
else if (fscanf(fAct, "%lf", act) != 1)
{
printf("%serror - couldn't match from actual file %d, column %d%s\n", KRED, i, j, KNRM);
return -2;
}
else if (fabs(*exp - *act) > 0.01)
{