/*************************************************************************** * Copyright (C) 2014 by Edson Borin * * edson@ic.unicamp.br * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #include // FLT_MAX #include // printf /* Matrices dimentions. */ #ifndef ARRAY_SZ #define ARRAY_SZ 500000 #endif /* Array data type. */ #ifndef DATATYPE #define DATATYPE float #endif /* Number of times each kernel will be executed. */ #ifndef RPT #define RPT 1000 #endif /* Useful macros! */ #define MIN(x,y) ((x)<(y)?(x):(y)) #define MAX(x,y) ((x)>(y)?(x):(y)) #define XSTR(s) STR(s) #define STR(s) #s /*------------------------------------------------*/ /* Code to remove data from the processor caches. */ #define KB (1024) #define MB (1024 * KB) #define GB (1024 * MB) #define LARGEST_CACHE_SZ (16 * MB) static unsigned char dummy_buffer[LARGEST_CACHE_SZ]; void clean_cache() { unsigned long long i; for (i=0; i double mysecond() { struct timeval tp; struct timezone tzp; gettimeofday(&tp,&tzp); return ( (double) tp.tv_sec + (double) tp.tv_usec * 1.e-6 ); } /*------------------------------------------------*/ /* Numeric kernels and data . */ /* Matrices. */ DATATYPE ma[ARRAY_SZ]; DATATYPE mb[ARRAY_SZ]; DATATYPE result; /* Kernel name. */ const char* kernel_name = "inner_prod"; DATATYPE inner_prod(DATATYPE* a, DATATYPE* b) { int i; DATATYPE total = 0.0; for (i=0; i %6.2f s\n", times[k]); } /* Final report */ for (k=1; k