void timer_handler(int signo, siginfo_t *info, void *context){ int i, ret; //Read the values with PAPI if(signo == SIGRTMIN){ scheduler_value = 0; if((ret = PAPI_accum(scheduler_eventset, &scheduler_value)) != PAPI_OK){ fprintf(stderr, "PAPI error: Couldn't read the values %s\n", PAPI_strerror(ret)); exit(20); } //Test the quota and send the sigstop //fprintf(stderr, "%lld\n", scheduler_value); rt_quota_l3 -= scheduler_value; if((rt_quota_l3 <= 0) && (send == 0)){ fprintf(stderr, "Scheduler (%d) > Quota exceeded will stop attackers\n", getpid()); for(i=0; i<nb_attackers; i++) kill(pid_attacker[i],SIGSTOP); send = 1; } new_window --; //If new window send SIGCONT to attackers if(!new_window){ fprintf(stderr, "Scheduler (%d) > New window\n", getpid()); for(i=0; i<nb_attackers; i++) kill(pid_attacker[i], SIGCONT); new_window = 200; rt_quota_l3 = MEMORY_QUOTA; send = 0; } } }
/** * \brief A bit-twiddling load which will run within the given bytes of memory. * \param [in] plan The struct that holds the plan's data values. * \return int Error flag value * \sa parseCBAPlan * \sa makeCBAPlan * \sa initCBAPlan * \sa perfCBAPlan * \sa killCBAPlan */ int execCBAPlan(void *plan){ #ifdef HAVE_PAPI int k; long long start, end; #endif //HAVE_PAPI int i, j; int niters; ORB_t t1, t2; Plan *p; CBA_data *ci; p = (Plan *)plan; ci = (CBA_data *)p->vptr; /* update execution count */ p->exec_count++; for(i = 0; i < ci->niter; i += NITERS){ niters = ci->niter - i; if(niters > NITERS){ niters = NITERS; } for(j = 0; j < niters; j++){ /* pick NITERS random rows in the range 1..(nrow-1) */ ci->out[j] = 1 + (brand(&(ci->br)) % (ci->nrows - 1)); ci->out[j] <<= 48; /* store index in high 16 bits */ } if(DO_PERF){ #ifdef HAVE_PAPI /* Start PAPI counters and time */ TEST_PAPI(PAPI_reset(p->PAPI_EventSet), PAPI_OK, MyRank, 9999, PRINT_SOME); start = PAPI_get_real_usec(); #endif //HAVE_PAPI ORB_read(t1); } //DO_PERF cnt_bit_arr (ci->work, ci->nrows, ci->ncols, ci->out, niters); if(DO_PERF){ ORB_read(t2); #ifdef HAVE_PAPI end = PAPI_get_real_usec(); //PAPI time /* Collect PAPI counters and store time elapsed */ TEST_PAPI(PAPI_accum(p->PAPI_EventSet, p->PAPI_Results), PAPI_OK, MyRank, 9999, PRINT_SOME); for(k = 0; k < p->PAPI_Num_Events && k < TOTAL_PAPI_EVENTS; k++){ p->PAPI_Times[k] += (end - start); } #endif //HAVE_PAPI perftimer_accumulate(&p->timers, TIMER0, ORB_cycles_a(t2, t1)); } //DO_PERF } return ERR_CLEAN; } /* execCBAPlan */
/** * \brief <DESCRIPTION of your plan goes here..> * \param plan The Plan struct that holds the plan's data values. * \return int Error flag value */ int execDOPENACCGEMMPlan(void *plan){ // <- Replace YOUR_NAME with the name of your module. #ifdef HAVE_PAPI int k; long long start, end; #endif //HAVE_PAPI ORB_t t1, t2; // Storage for timestamps, used to accurately find the runtime of the plan execution. Plan *p; p = (Plan *)plan; p->exec_count++; // Update the execution counter stored in the plan. DOPENACCGEMM_DATA *local_data = (DOPENACCGEMM_DATA *)p->vptr; int error; #ifdef HAVE_PAPI /* Start PAPI counters and time */ TEST_PAPI(PAPI_reset(p->PAPI_EventSet), PAPI_OK, MyRank, 9999, PRINT_SOME); start = PAPI_get_real_usec(); #endif //HAVE_PAPI ORB_read(t1); // Store the timestamp for the beginning of the execution. int jdx; for(jdx=0;jdx < local_data->loop_count; jdx++) { systemburn_openaccblas_dgemm(local_data); } // -------------------------------------------- // Plan is executed here... // -------------------------------------------- ORB_read(t2); // Store timestamp for the end of execution. #ifdef HAVE_PAPI end = PAPI_get_real_usec(); //PAPI time /* Collect PAPI counters and store time elapsed */ TEST_PAPI(PAPI_accum(p->PAPI_EventSet, p->PAPI_Results), PAPI_OK, MyRank, 9999, PRINT_SOME); for(k = 0; k < p->PAPI_Num_Events && k < TOTAL_PAPI_EVENTS; k++){ p->PAPI_Times[k] += (end - start); } #endif //HAVE_PAPI perftimer_accumulate(&p->timers, TIMER0, ORB_cycles_a(t2, t1)); // Store the difference between the timestamps in the plan's timers. if(CHECK_CALC){ // Evaluates to true if the '-t' option is passed on the commandline. ORB_read(t1); // ---------------------------------------------------------------- // Optional: Check calculations performed in execution above. // ---------------------------------------------------------------- ORB_read(t2); perftimer_accumulate(&p->timers, TIMER1, ORB_cycles_a(t2, t1)); } return ERR_CLEAN; // <- This inicates a clean run with no errors. Does not need to be changed. } /* execDOPENACCGEMMPlan */
int HWCBE_PAPI_Accum (unsigned int tid, long long *store_buffer) { if (PAPI_accum(HWCEVTSET(tid), store_buffer) != PAPI_OK) { fprintf (stderr, PACKAGE_NAME": PAPI_accum failed for thread %d evtset %d (%s:%d)\n", \ tid, HWCEVTSET(tid), __FILE__, __LINE__); return 0; } return 1; }
int _internal_hl_read_cnts(long long * values, int array_len, int flag) { int retval; HighLevelInfo *state = NULL; if ((retval = _internal_check_state(&state)) != PAPI_OK) return (retval); if (state->running != HL_START_COUNTERS || array_len < state->num_evts) return (PAPI_EINVAL); if (flag == PAPI_HL_ACCUM) return (PAPI_accum(state->EventSet, values)); else if (flag == PAPI_HL_READ) { if ((retval = PAPI_read(state->EventSet, values)) != PAPI_OK) return (retval); return (PAPI_reset(state->EventSet)); } /* Invalid flag passed in */ return (PAPI_EINVAL); }
int main(int argc, char **argv) { int i, retval, EventSet = PAPI_NULL; int bins = 100; int show_dist = 0, show_std_dev = 0; long long totcyc, values[2]; long long *array; tests_quiet(argc, argv); /* Set TESTS_QUIET variable */ for (i = 0; i < argc; i++) { if (argv[i]) { if (strstr(argv[i], "-b")) { bins = atoi(argv[i+1]); if (bins) i++; else { printf ("-b requires a bin count!\n"); exit(1); } } if (strstr(argv[i], "-d")) show_dist = 1; if (strstr(argv[i], "-h")) { print_help(); exit(1); } if (strstr(argv[i], "-s")) show_std_dev = 1; if (strstr(argv[i], "-t")) { num_iters = atol(argv[i+1]); if (num_iters) i++; else { printf ("-t requires a threshold value!\n"); exit(1); } } } } printf("Cost of execution for PAPI start/stop, read and accum.\n"); printf("This test takes a while. Please be patient...\n"); if ((retval = PAPI_library_init(PAPI_VER_CURRENT)) != PAPI_VER_CURRENT) test_fail(__FILE__, __LINE__, "PAPI_library_init", retval); if ((retval = PAPI_set_debug(PAPI_VERB_ECONT)) != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_set_debug", retval); if ((retval = PAPI_query_event(PAPI_TOT_CYC)) != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_query_event", retval); if ((retval = PAPI_query_event(PAPI_TOT_INS)) != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_query_event", retval); if ((retval = PAPI_create_eventset(&EventSet)) != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_create_eventset", retval); if ((retval = PAPI_add_event(EventSet, PAPI_TOT_CYC)) != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_add_event", retval); if ((retval = PAPI_add_event(EventSet, PAPI_TOT_INS)) != PAPI_OK) if ((retval = PAPI_add_event(EventSet, PAPI_TOT_IIS)) != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_add_event", retval); /* Make sure no errors and warm up */ totcyc = PAPI_get_real_cyc(); if ((retval = PAPI_start(EventSet)) != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_start", retval); if ((retval = PAPI_stop(EventSet, NULL)) != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_stop", retval); array = (long long *)malloc(num_iters*sizeof(long long)); if (array == NULL ) test_fail(__FILE__, __LINE__, "PAPI_stop", retval); /* Determine clock latency */ printf("\nPerforming loop latency test...\n"); for (i = 0; i < num_iters; i++) { totcyc = PAPI_get_real_cyc(); totcyc = PAPI_get_real_cyc() - totcyc; array[i] = totcyc; } do_output(0, array, bins, show_std_dev, show_dist); /* Start the start/stop eval */ printf("\nPerforming start/stop test...\n"); for (i = 0; i < num_iters; i++) { totcyc = PAPI_get_real_cyc(); PAPI_start(EventSet); PAPI_stop(EventSet, values); totcyc = PAPI_get_real_cyc() - totcyc; array[i] = totcyc; } do_output(1, array, bins, show_std_dev, show_dist); /* Start the read eval */ printf("\nPerforming read test...\n"); if ((retval = PAPI_start(EventSet)) != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_start", retval); PAPI_read(EventSet, values); for (i = 0; i < num_iters; i++) { totcyc = PAPI_get_real_cyc(); PAPI_read(EventSet, values); totcyc = PAPI_get_real_cyc() - totcyc; array[i] = totcyc; } if ((retval = PAPI_stop(EventSet, values)) != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_stop", retval); do_output(2, array, bins, show_std_dev, show_dist); /* Start the read with timestamp eval */ printf("\nPerforming read with timestamp test...\n"); if ((retval = PAPI_start(EventSet)) != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_start", retval); PAPI_read_ts(EventSet, values, &totcyc); for (i = 0; i < num_iters; i++) { PAPI_read_ts(EventSet, values, &array[i]); } if ((retval = PAPI_stop(EventSet, values)) != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_stop", retval); /* post-process the timing array */ for (i = num_iters - 1; i > 0 ; i--) { array[i] -= array[i-1]; } array[0] -= totcyc; do_output(3, array, bins, show_std_dev, show_dist); /* Start the accum eval */ printf("\nPerforming accum test...\n"); if ((retval = PAPI_start(EventSet)) != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_start", retval); PAPI_accum(EventSet, values); for (i = 0; i < num_iters; i++) { totcyc = PAPI_get_real_cyc(); PAPI_accum(EventSet, values); totcyc = PAPI_get_real_cyc() - totcyc; array[i] = totcyc; } if ((retval = PAPI_stop(EventSet, values)) != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_stop", retval); do_output(4, array, bins, show_std_dev, show_dist); /* Start the reset eval */ printf("\nPerforming reset test...\n"); if ((retval = PAPI_start(EventSet)) != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_start", retval); for (i = 0; i < num_iters; i++) { totcyc = PAPI_get_real_cyc(); PAPI_reset(EventSet); totcyc = PAPI_get_real_cyc() - totcyc; array[i] = totcyc; } if ((retval = PAPI_stop(EventSet, values)) != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_stop", retval); do_output(5, array, bins, show_std_dev, show_dist); free(array); test_pass(__FILE__, NULL, 0); exit(1); }
#endif /** @class PAPIF_accum * @ingroup PAPIF * @brief accumulate and reset counters in an event set * * @par Fortran Interface: * \#include "fpapi.h" @n * PAPIF_accum( C_INT EventSet, C_LONG_LONG(*) values, C_INT check ) * * @see PAPI_accum */ PAPI_FCALL( papif_accum, PAPIF_ACCUM, ( int *EventSet, long long *values, int *check ) ) { *check = PAPI_accum( *EventSet, values ); } /** @class PAPIF_add_event * @ingroup PAPIF * @brief add PAPI preset or native hardware event to an event set * * @par Fortran Interface: * \#include "fpapi.h" @n * PAPIF_add_event( C_INT EventSet, C_INT EventCode, C_INT check ) * * @see PAPI_add_event */ PAPI_FCALL( papif_add_event, PAPIF_ADD_EVENT, ( int *EventSet, int *Event, int *check ) ) {
/** * \brief <DESCRIPTION of your plan goes here..> * \param plan The Plan struct that holds the plan's data values. * \return int Error flag value */ int execOPENCL_MEMPlan(void *plan){ // <- Replace YOUR_NAME with the name of your module. #ifdef HAVE_PAPI int k; long long start, end; #endif //HAVE_PAPI ORB_t t1, t2; // Storage for timestamps, used to accurately find the runtime of the plan execution. Plan *p; p = (Plan *)plan; p->exec_count++; // Update the execution counter stored in the plan. OPENCL_MEM_DATA *local_data = (OPENCL_MEM_DATA *)p->vptr; cl_int error; #ifdef HAVE_PAPI /* Start PAPI counters and time */ TEST_PAPI(PAPI_reset(p->PAPI_EventSet), PAPI_OK, MyRank, 9999, PRINT_SOME); start = PAPI_get_real_usec(); #endif //HAVE_PAPI ORB_read(t1); // Store the timestamp for the beginning of the execution. size_t work_size[1]; int idx,jdx; cl_mem buffer; for(jdx = 0; jdx < local_data->loop_count; jdx++){ for(idx = 0; idx < NUM_PATTERNS; idx++){ error = clSetKernelArg(local_data->kernel,0,sizeof(cl_mem),&(local_data->buffer)); assert(error == CL_SUCCESS); error = clSetKernelArg(local_data->kernel,1,sizeof(cl_ulong),(void *)&patterns[idx]); assert(error == CL_SUCCESS); work_size[0] = local_data->device_memory / sizeof(unsigned int); error = clEnqueueNDRangeKernel(local_data->opencl_queue, local_data->kernel, 1, NULL, work_size, NULL, 0, NULL, NULL); assert(error == CL_SUCCESS); clEnqueueReadBuffer(local_data->opencl_queue, local_data->buffer, CL_TRUE, 0, local_data->device_memory, local_data->return_buffer, 0, NULL, NULL); } } // -------------------------------------------- // Plan is executed here... // -------------------------------------------- ORB_read(t2); // Store timestamp for the end of execution. #ifdef HAVE_PAPI end = PAPI_get_real_usec(); //PAPI time /* Collect PAPI counters and store time elapsed */ TEST_PAPI(PAPI_accum(p->PAPI_EventSet, p->PAPI_Results), PAPI_OK, MyRank, 9999, PRINT_SOME); for(k = 0; k < p->PAPI_Num_Events && k < TOTAL_PAPI_EVENTS; k++){ p->PAPI_Times[k] += (end - start); } #endif //HAVE_PAPI perftimer_accumulate(&p->timers, TIMER0, ORB_cycles_a(t2, t1)); // Store the difference between the timestamps in the plan's timers. if(CHECK_CALC){ // Evaluates to true if the '-t' option is passed on the commandline. ORB_read(t1); // ---------------------------------------------------------------- // Optional: Check calculations performed in execution above. // ---------------------------------------------------------------- ORB_read(t2); perftimer_accumulate(&p->timers, TIMER1, ORB_cycles_a(t2, t1)); } return ERR_CLEAN; // <- This inicates a clean run with no errors. Does not need to be changed. } /* execOPENCL_MEMPlan */
/** * \brief A 2 dimensional complex fast Fourier transform in a memory footprint of "size" bytes. * \param [in] plan Holds the data and memory for the plan. * \return int Error flag value * \sa parseFFT2Plan * \sa makeFFT2Plan * \sa initFFT2Plan * \sa perfFFT2Plan * \sa killFFT2Plan */ int execFFT2Plan(void *plan){ #ifdef HAVE_PAPI int k; long long start, end; #endif //HAVE_PAPI int i; ORB_t t1, t2; Plan *p; FFTdata *d; p = (Plan *)plan; d = (FFTdata *)p->vptr; assert(d); assert(d->forward); assert(d->backward); /* update execution count */ p->exec_count++; // for(i=0;i<d->M;i++) { if(d->forward){ if(DO_PERF){ #ifdef HAVE_PAPI /* Start PAPI counters and time */ TEST_PAPI(PAPI_reset(p->PAPI_EventSet), PAPI_OK, MyRank, 9999, PRINT_SOME); start = PAPI_get_real_usec(); #endif //HAVE_PAPI ORB_read(t1); } //DO_PERF fftw_execute(d->forward); if(DO_PERF){ ORB_read(t2); #ifdef HAVE_PAPI end = PAPI_get_real_usec(); //PAPI time /* Collect PAPI counters and store time elapsed */ TEST_PAPI(PAPI_accum(p->PAPI_EventSet, p->PAPI_Results), PAPI_OK, MyRank, 9999, PRINT_SOME); for(k = 0; k < p->PAPI_Num_Events && k < TOTAL_PAPI_EVENTS; k++){ p->PAPI_Times[k] += (end - start); } #endif //HAVE_PAPI perftimer_accumulate(&p->timers, TIMER0, ORB_cycles_a(t2, t1)); } //DO_PERF } if(d->backward){ if(DO_PERF){ #ifdef HAVE_PAPI /* Start PAPI counters and time */ TEST_PAPI(PAPI_reset(p->PAPI_EventSet), PAPI_OK, MyRank, 9999, PRINT_SOME); start = PAPI_get_real_usec(); #endif //HAVE_PAPI ORB_read(t1); } //DO_PERF fftw_execute(d->backward); if(DO_PERF){ ORB_read(t2); #ifdef HAVE_PAPI end = PAPI_get_real_usec(); //PAPI time /* Collect PAPI counters and store time elapsed */ TEST_PAPI(PAPI_accum(p->PAPI_EventSet, p->PAPI_Results), PAPI_OK, MyRank, 9999, PRINT_SOME); for(k = 0; k < p->PAPI_Num_Events && k < TOTAL_PAPI_EVENTS; k++){ p->PAPI_Times[k] += (end - start); } #endif //HAVE_PAPI perftimer_accumulate(&p->timers, TIMER1, ORB_cycles_a(t2, t1)); } //DO_PERF } // } return ERR_CLEAN; } /* execFFT2Plan */