繁体   English   中英

如何评估 Integer 每秒操作

[英]How to evaluate Integer Operation Per Second

我开发了一个用于计数排序的 cuda 算法:

/**
 * @brief               This function implement the counting sort algorithm of the array 'array'.
 * @param array         Pointer to the array used in counting sort.
 * @param dim_array     Size of the array 'array'.
 * @param counts        The array containing the 
 */

__global__ void kernelCountingSort(int *array, int dim_array, int *counts) {
    // define index
    int i = blockIdx.x * blockDim.x + threadIdx.x;
    // check that the thread is not out of the vector boundary
    if (i >= dim_array) return;
    
    int count = 0;
    
    int el = array[i];

    for (int j = 0; j < dim_array; ++j) {
        int le = array[j];
        if (le < el)
            count++;
        else if (le == el && j < i)
            count++;
    }
    counts[count] = el;
}

我正在尝试计算该算法每秒的 integer 操作数。 因此,要获得 integer 操作的总数,我假设我只需要计算count变量上的加法操作。 所以我建立了这个方法:

int countIO(int dim_array){
    int s=0;
    for(int i=dim_array;i>0;--i)
        s+=i;
    s+=dim_array;
    return s;
}

此方法计算算法中发生了多少count变量增量,但我有一个问题:我是否需要在循环中包含j变量的增量数,就像我在这里所做的那样: s+=dim_array; ?

一般来说,我计算 integer 操作总数的方式是否正确?

PS。 最后,为了获得每秒 integer 操作的数量,我打算将总的 integer 操作除以算法的经过时间,以秒为单位。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM