当前位置: 首页>>代码示例>>C++>>正文


C++ Stopwatch::runtime方法代码示例

本文整理汇总了C++中Stopwatch::runtime方法的典型用法代码示例。如果您正苦于以下问题:C++ Stopwatch::runtime方法的具体用法?C++ Stopwatch::runtime怎么用?C++ Stopwatch::runtime使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Stopwatch的用法示例。


在下文中一共展示了Stopwatch::runtime方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: unroll

void * avx512_fma(void *args_in)
{
    /* Thread input */
    struct thread_args *args;

    const int n_avx512 = VFMAPS_LATENCY;
    const __m512 add0 = _mm512_set1_ps((float) 1e-6);
    const __m512 mul0 = _mm512_set1_ps((float) (1. + 1e-6));
    __m512 r[n_avx512];

    // Declare as volatile to prevent removal during optimisation
    volatile float result;

    long r_max, i;
    int j;
    double runtime, flops;
    Stopwatch *t;

    /* Read inputs */
    args = (struct thread_args *) args_in;

    t = stopwatch_create(args->timer_type);

    for (j = 0; j < n_avx512; j++) {
        r[j] = _mm512_set1_ps((float) j);
    }

    /* Add over registers r0-r4, multiply over r5-r9, and rely on pipelining,
     * OOO execution, and latency difference (3 vs 5 cycles) for 2x FLOPs
     */

    runtime_flag = 0;
    r_max = 1;
    do {
        pthread_barrier_wait(&timer_barrier);
        t->start(t);
        for (i = 0; i < r_max; i++) {
            #pragma unroll(n_avx512)
            for (j = 0; j < n_avx512; j++)
                r[j] = _mm512_fmadd_ps(r[j], mul0, add0);
        }
        t->stop(t);
        runtime = t->runtime(t);

        /* Set runtime flag if any thread exceeds runtime limit */
        if (runtime > args->min_runtime) {
            pthread_mutex_lock(&runtime_mutex);
            runtime_flag = 1;
            pthread_mutex_unlock(&runtime_mutex);
        }

        pthread_barrier_wait(&timer_barrier);
        if (!runtime_flag) r_max *= 2;

    } while (!runtime_flag);

    /* In order to prevent removal of the prior loop by optimisers,
     * sum the register values and save the result as volatile. */

    for (j = 0; j < n_avx512; j++)
        r[0] = _mm512_add_ps(r[0], r[j]);
    result = reduce_AVX512(r[0]);

    /* (iter) * (16 instr / reg) * (2 flops / instr) * (n_avx512 reg / iter) */
    flops = r_max * 16 * 2 * n_avx512 / runtime;

    /* Cleanup */
    t->destroy(t);

    /* Thread output */
    args->runtime = runtime;
    args->flops = flops;
    args->bw_load = 0.;
    args->bw_store = 0.;

    pthread_exit(NULL);
}
开发者ID:marshallward,项目名称:microbench,代码行数:77,代码来源:avx512.c


注:本文中的Stopwatch::runtime方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。