19 #include <sys/resource.h> 26 #if defined(POLYBENCH_PAPI) 27 # undef POLYBENCH_PAPI 29 # define POLYBENCH_PAPI 35 #ifndef POLYBENCH_THREAD_MONITOR 36 # define POLYBENCH_THREAD_MONITOR 0 40 #ifndef POLYBENCH_CACHE_SIZE_KB 41 # define POLYBENCH_CACHE_SIZE_KB 32770 50 # define POLYBENCH_MAX_NB_PAPI_COUNTERS 96 51 char* _polybench_papi_eventlist[] = {
52 #include "papi_counters.list" 55 int polybench_papi_eventset;
56 int polybench_papi_eventlist[POLYBENCH_MAX_NB_PAPI_COUNTERS];
57 long_long polybench_papi_values[POLYBENCH_MAX_NB_PAPI_COUNTERS];
66 #define NB_INITIAL_TABLE_ENTRIES 512 85 #if defined(POLYBENCH_TIME) || defined(POLYBENCH_GFLOPS) 88 stat = gettimeofday (&Tp,
NULL);
90 printf (
"Error return from gettimeofday: %d", stat);
91 return (Tp.tv_sec + Tp.tv_usec * 1.0e-6);
98 #ifdef POLYBENCH_CYCLE_ACCURATE_TIMER 100 unsigned long long int rdtsc()
102 unsigned long long int ret = 0;
103 unsigned int cycles_lo;
104 unsigned int cycles_hi;
105 __asm__
volatile (
"RDTSC" :
"=a" (cycles_lo),
"=d" (cycles_hi));
106 ret = (
unsigned long long int)cycles_hi << 32 | cycles_lo;
115 double* flush = (
double*) calloc (cs,
sizeof(
double));
119 #pragma omp parallel for reduction(+:tmp) private(i) 121 for (i = 0; i < cs; i++)
123 assert (tmp <= 10.0);
128 #ifdef POLYBENCH_LINUX_FIFO_SCHEDULER 129 void polybench_linux_fifo_scheduler()
133 struct sched_param schedParam;
134 schedParam.sched_priority = sched_get_priority_max (SCHED_FIFO);
135 sched_setscheduler (0, SCHED_FIFO, &schedParam);
139 void polybench_linux_standard_scheduler()
142 struct sched_param schedParam;
143 schedParam.sched_priority = sched_get_priority_max (SCHED_OTHER);
144 sched_setscheduler (0, SCHED_OTHER, &schedParam);
148 #ifdef POLYBENCH_PAPI 151 void test_fail(
char *
file,
int line,
char *call,
int retval)
155 memset(buf,
'\0',
sizeof(buf));
163 if (retval == PAPI_ESYS)
165 sprintf (buf,
"System error in %s", call);
169 fprintf (
stdout,
"Error: %s\n", call);
170 else if (retval == 0)
171 fprintf (
stdout,
"Error: %s\n", call);
174 char errstring[PAPI_MAX_STR_LEN];
176 #if defined (PAPI_VERSION) && ((PAPI_VERSION_MAJOR(PAPI_VERSION) == 5 && PAPI_VERSION_MINOR(PAPI_VERSION) >= 4) || PAPI_VERSION_MAJOR(PAPI_VERSION) > 5) 177 fprintf (
stdout,
"Error in %s: %s\n", call, PAPI_strerror(retval));
179 PAPI_perror (retval, errstring, PAPI_MAX_STR_LEN);
180 fprintf (
stdout,
"Error in %s: %s\n", call, errstring);
184 if (PAPI_is_initialized ())
190 void polybench_papi_init()
206 polybench_papi_eventset = PAPI_NULL;
207 if ((retval = PAPI_library_init (PAPI_VER_CURRENT)) != PAPI_VER_CURRENT)
208 test_fail (__FILE__, __LINE__,
"PAPI_library_init", retval);
209 if ((retval = PAPI_create_eventset (&polybench_papi_eventset))
211 test_fail (__FILE__, __LINE__,
"PAPI_create_eventset", retval);
213 for (k = 0; _polybench_papi_eventlist[
k]; ++
k)
216 PAPI_event_name_to_code (_polybench_papi_eventlist[k],
217 &(polybench_papi_eventlist[k])))
219 test_fail (__FILE__, __LINE__,
"PAPI_event_name_to_code", retval);
221 polybench_papi_eventlist[
k] = 0;
232 void polybench_papi_close()
241 if ((retval = PAPI_destroy_eventset (&polybench_papi_eventset))
243 test_fail (__FILE__, __LINE__,
"PAPI_destroy_eventset", retval);
244 if (PAPI_is_initialized ())
253 int polybench_papi_start_counter(
int evid)
255 # ifndef POLYBENCH_NO_FLUSH_CACHE 260 # pragma omp parallel 267 char descr[PAPI_MAX_STR_LEN];
268 PAPI_event_info_t evinfo;
269 PAPI_event_code_to_name (polybench_papi_eventlist[evid], descr);
270 if (PAPI_add_event (polybench_papi_eventset,
271 polybench_papi_eventlist[evid]) != PAPI_OK)
272 test_fail (__FILE__, __LINE__,
"PAPI_add_event", 1);
273 if (PAPI_get_event_info (polybench_papi_eventlist[evid], &evinfo)
275 test_fail (__FILE__, __LINE__,
"PAPI_get_event_info", retval);
276 if ((retval = PAPI_start (polybench_papi_eventset)) != PAPI_OK)
277 test_fail (__FILE__, __LINE__,
"PAPI_start", retval);
287 void polybench_papi_stop_counter(
int evid)
290 # pragma omp parallel 298 if ((retval = PAPI_read (polybench_papi_eventset, &values[0]))
300 test_fail (__FILE__, __LINE__,
"PAPI_read", retval);
302 if ((retval = PAPI_stop (polybench_papi_eventset,
NULL)) != PAPI_OK)
303 test_fail (__FILE__, __LINE__,
"PAPI_stop", retval);
305 polybench_papi_values[evid] = values[0];
307 if ((retval = PAPI_remove_event
308 (polybench_papi_eventset,
309 polybench_papi_eventlist[evid])) != PAPI_OK)
310 test_fail (__FILE__, __LINE__,
"PAPI_remove_event", retval);
319 void polybench_papi_print()
323 # pragma omp parallel 327 #ifdef POLYBENCH_PAPI_VERBOSE 334 for (evid = 0; polybench_papi_eventlist[evid] != 0; ++evid)
337 printf (
"%s=", _polybench_papi_eventlist[evid]);
338 printf (
"%llu ", polybench_papi_values[evid]);
355 #ifndef POLYBENCH_NO_FLUSH_CACHE 358 #ifdef POLYBENCH_LINUX_FIFO_SCHEDULER 359 polybench_linux_fifo_scheduler ();
367 #ifndef POLYBENCH_CYCLE_ACCURATE_TIMER 377 #ifndef POLYBENCH_CYCLE_ACCURATE_TIMER 382 #ifdef POLYBENCH_LINUX_FIFO_SCHEDULER 383 polybench_linux_standard_scheduler ();
390 #ifdef POLYBENCH_GFLOPS 393 printf (
"[PolyBench][WARNING] Program flops not defined, use polybench_set_program_flops(value)\n");
401 # ifndef POLYBENCH_CYCLE_ACCURATE_TIMER 418 #ifdef POLYBENCH_ENABLE_INTARRAY_PAD 420 void grow_alloc_table()
422 if (_polybench_alloc_table ==
NULL ||
427 fprintf (
stderr,
"[ERROR] Inter-array padding requires to use polybench_alloc_data and polybench_free_data\n");
430 size_t sz = _polybench_alloc_table->
nb_entries;
433 realloc (_polybench_alloc_table->
user_view, sz *
sizeof(
void*));
436 realloc (_polybench_alloc_table->
real_ptr, sz *
sizeof(
void*));
442 void* register_padded_pointer(
void* ptr,
size_t orig_sz,
size_t padded_sz)
444 if (_polybench_alloc_table ==
NULL)
446 fprintf (
stderr,
"[ERROR] Inter-array padding requires to use polybench_alloc_data and polybench_free_data\n");
451 int id = _polybench_alloc_table->
nb_entries++;
452 _polybench_alloc_table->
real_ptr[id] = ptr;
453 _polybench_alloc_table->
user_view[id] = ptr + (padded_sz - orig_sz);
455 return _polybench_alloc_table->
user_view[id];
461 free_data_from_alloc_table (
void* ptr)
463 if (_polybench_alloc_table !=
NULL && _polybench_alloc_table->
nb_entries > 0)
466 for (i = 0; i < _polybench_alloc_table->
nb_entries; ++i)
467 if (_polybench_alloc_table->
user_view[i] == ptr ||
468 _polybench_alloc_table->
real_ptr[i] == ptr)
472 free (_polybench_alloc_table->
real_ptr[i]);
473 for (; i < _polybench_alloc_table->
nb_entries - 1; ++i)
476 _polybench_alloc_table->
user_view[i + 1];
477 _polybench_alloc_table->
real_ptr[i] =
478 _polybench_alloc_table->
real_ptr[i + 1];
484 free (_polybench_alloc_table->
user_view);
485 free (_polybench_alloc_table->
real_ptr);
486 free (_polybench_alloc_table);
487 _polybench_alloc_table =
NULL;
494 void check_alloc_table_state()
496 if (_polybench_alloc_table ==
NULL)
500 assert(_polybench_alloc_table !=
NULL);
512 #endif // !POLYBENCH_ENABLE_INTARRAY_PAD 523 int err = posix_memalign (&ret, 4096, padded_sz);
526 fprintf (
stderr,
"[PolyBench] posix_memalign: cannot allocate memory");
536 #ifdef POLYBENCH_ENABLE_INTARRAY_PAD 540 ret = register_padded_pointer(ret, alloc_sz, padded_sz);
549 #ifdef POLYBENCH_ENABLE_INTARRAY_PAD 550 free_data_from_alloc_table (ptr);
559 #ifdef POLYBENCH_ENABLE_INTARRAY_PAD 560 check_alloc_table_state ();
void polybench_timer_print()
static void * xmalloc(size_t alloc_sz)
void polybench_free_data(void *ptr)
#define POLYBENCH_THREAD_MONITOR
This version is stamped on May 10, 2016.
#define POLYBENCH_CACHE_SIZE_KB
void * polybench_alloc_data(unsigned long long int n, int elt_size)
void line(int x1, int y1, int x2, int y2, unsigned int color)
static size_t polybench_inter_array_padding_sz
void polybench_flush_cache()
static struct polybench_data_ptrs * _polybench_alloc_table
static const uint32_t k[]
void polybench_timer_start()
int polybench_papi_counters_threadid
unsigned long long int polybench_c_end
double polybench_program_total_flops
#define POLYBENCH_INTER_ARRAY_PADDING_FACTOR
#define NB_INITIAL_TABLE_ENTRIES
void polybench_timer_stop()
unsigned long long int polybench_c_start
void polybench_prepare_instruments()