test/amr_stencil.cpp
// Measure the overhead of using RTune
Measure the overhead of using RTune
Measure the overhead of using RTune
void amr_stencil_rtune_overhead(const REAL* src, REAL* dst, int* width, int* height, const float* filter, int flt_width, int flt_height) {
    int cpu_exec, iter_count = 0;
    manual_rtune_objective_set_sample_attr(1, 40);
    double elapsed = read_timer_ms();
    double cpu_time = 0.0;
    double gpu_time = 0.0;
    double sampling_overhead = 0.0;
    double fitting_overhead = 0.0;
    double prediction_overhead = 0.0;
    double total_time = read_timer_ms();
    while (iter_count < MAX_ITER) {
        elapsed = read_timer_ms();
        manual_rtune_begin(&cpu_exec, width[iter_count]);
        if (iter_count == profile_num - 1 || iter_count == profile_num*2 - 1) {
            fitting_overhead += read_timer_ms() - elapsed;
        } else {
            prediction_overhead += read_timer_ms() - elapsed;
        }
        if (cpu_exec) stencil_omp_cpu(src, dst, width[iter_count], height[iter_count], filter, FILTER_WIDTH, FILTER_HEIGHT);
        else stencil_omp_gpu(src, dst, width[iter_count], height[iter_count], filter, FILTER_WIDTH, FILTER_HEIGHT);
        elapsed = read_timer_ms();
        manual_rtune_end();
        if (iter_count == profile_num - 1 || iter_count == profile_num*2 - 1) {
            fitting_overhead += read_timer_ms() - elapsed;
        } else if (iter_count < profile_num*2) {
            sampling_overhead += read_timer_ms() - elapsed;
        } else {
            prediction_overhead += read_timer_ms() - elapsed;
        }
        iter_count++;
    }
    total_time = read_timer_ms() - total_time;
    fprintf(stderr, "Total sampling overhead (ms): %g; Average sampling overhead per iteration: %g\n", sampling_overhead, sampling_overhead/(profile_num*2-2));
    fprintf(stderr, "Total fitting overhead (ms): %g; Average fitting overhead per iteration: %g\n", fitting_overhead, fitting_overhead/2);
    fprintf(stderr, "Total prediction overhead (ms): %g; Average prediction overhead per iteration: %g\n", prediction_overhead, prediction_overhead/(MAX_ITER - profile_num*2));
    fprintf(stderr, "Total execution time (ms): %g\n", total_time);
}
void amr_stencil_rtune_overhead ( const REAL * src , REAL * dst , int * width , int * height , const float * filter , int flt_width , int flt_height ) { int cpu_exec , iter_count = 0 ; manual_rtune_objective_set_sample_attr ( 1 , 40 ) ; double elapsed = read_timer_ms ( ) ; double cpu_time = 0.0 ; double gpu_time = 0.0 ; double sampling_overhead = 0.0 ; double fitting_overhead = 0.0 ; double prediction_overhead = 0.0 ; double total_time = read_timer_ms ( ) ; while ( iter_count < MAX_ITER ) { elapsed = read_timer_ms ( ) ; manual_rtune_begin ( & cpu_exec , width [ iter_count ] ) ; if ( iter_count == profile_num - 1 || iter_count == profile_num * 2 - 1 ) { fitting_overhead += read_timer_ms ( ) - elapsed ; } else { prediction_overhead += read_timer_ms ( ) - elapsed ; } if ( cpu_exec ) stencil_omp_cpu ( src , dst , width [ iter_count ] , height [ iter_count ] , filter , FILTER_WIDTH , FILTER_HEIGHT ) ; else stencil_omp_gpu ( src , dst , width [ iter_count ] , height [ iter_count ] , filter , FILTER_WIDTH , FILTER_HEIGHT ) ; elapsed = read_timer_ms ( ) ; manual_rtune_end ( ) ; if ( iter_count == profile_num - 1 || iter_count == profile_num * 2 - 1 ) { fitting_overhead += read_timer_ms ( ) - elapsed ; } else if ( iter_count < profile_num * 2 ) { sampling_overhead += read_timer_ms ( ) - elapsed ; } else { prediction_overhead += read_timer_ms ( ) - elapsed ; } iter_count ++ ; } total_time = read_timer_ms ( ) - total_time ; fprintf ( stderr , " \n " , sampling_overhead , sampling_overhead / ( profile_num * 2 - 2 ) ) ; fprintf ( stderr , " \n " , fitting_overhead , fitting_overhead / 2 ) ; fprintf ( stderr , " \n " , prediction_overhead , prediction_overhead / ( MAX_ITER - profile_num * 2 ) ) ; fprintf ( stderr , " \n " , total_time ) ; }
Measure the overhead of using RTune
Measure the overhead of using RTune
/* width == height == problem size */ /* API for tuning */ //rtune_objective_set_sample_attr(threshold_obj, 1/* sample_rate */, 40/* num_samples*/, __RTUNE_SAMPLE_DIST_BLOCK); /* sample_rate */ /* num_samples*/ // sampling is started in the begin region of RTune // the prediction is completed by calling the model in the begin region // computing // the fitting happens in the end region of RTune. For this particular iteration, we count one time of sampling overhead into fitting overhead because they happen together in the same iteration. // sampling is completed in the end region of RTune // the prediction has nothing to do with the end region, but it still triggers a function call that can be considered as overhead // All the overheads are collected from multiple iterations and print the average // given 40 samples: // 38 iterations of sampling are measured. // 2 iterations of fitting are measured. // 5000 - 40 = 4960 iterations of prediction are measured.