【发布时间】:2012-02-27 04:15:53
【问题描述】:
我在一个文件上有几个数字列表。例如,
.333, .324, .123 , .543, .00054
.2243, .333, .53343 , .4434
现在,我想使用 GPU 获取每个数字出现的次数。我相信这在 GPU 上会比在 CPU 上更快,因为每个线程都可以处理一个列表。我应该在 GPU 上使用什么数据结构来轻松获得上述计数。例如,对于上述情况,答案将如下所示:
.333 = 2 times in entire file
.324 = 1 time
等等。
我正在寻找一个通用的解决方案。不是仅适用于具有特定计算能力的设备
只需编写 Pavan 建议的内核,看看我是否有效地实现了它:
int uniqueEle = newend.valiter – d_A;
int* count;
cudaMalloc((void**)&count, uniqueEle * sizeof(int)); // stores the count of each unique element
int TPB = 256;
int blocks = uniqueEle + TPB -1 / TPB;
//Cast d_I to raw pointer called d_rawI
launch<<<blocks,TPB>>>(d_rawI,count,uniqueEle);
__global__ void launch(int *i, int* count, int n){
int id = blockDim.x * blockIdx.x + threadIdx.x;
__shared__ int indexes[256];
if(id < n ){
indexes[threadIdx.x] = i[id];
//as occurs between two blocks
if(id % 255 == 0){
count[indexes] = i[id+1] - i[id];
}
}
__syncthreads();
if(id < ele - 1){
if(threadIdx.x < 255)
count[id] = indexes[threadIdx.x+1] – indexes[threadIdx.x];
}
}
问题:如何修改此内核以使其处理任意大小的数组。即处理线程总数时的情况
【问题讨论】:
-
您的号码列表大约有多长?它们都是 32 位浮点数吗?
-
@programmer:你认为内核代码到底是做什么的(撇开它不会编译的事实不谈)?
-
@talonmies:它计算两个连续数组索引的值之间的差异
-
@Programmer:那个“代码”中有一些非常荒谬的东西。看看我的回答,可能是你想要做的事情。
-
@Programmer,把我在聊天中提供的编辑后的代码贴出来可能会很好。
标签: cuda parallel-processing gpu gpgpu