【发布时间】:2016-12-12 01:57:59
【问题描述】:
我是 OpenCL 的新手。 目前我正在研究一个大型的一维数组。数组的大小约为 800 万。以下是我的代码的一部分:
//allocate opencl hosted memory for input
int[] Counts = new int[8000000];
//get device and create context....
CLBuffer<Integer> memIn1 = context.createIntBuffer(Usage.Input, 8000000);
Pointer<Integer> a = memIn1.map(queue, MapFlags.Write);
a.setInts(Counts);
//memory allocation for the second parameter memIn2
CLKernel kernel = program.createKernel("gpuScoring", memIn1, memIn2, 8000000, memOut);
kernel.enqueueNDRange(queue, new int[] {8000000}, null);
下面是我的内核代码:
__kernel void gpuScoring(__global int *Counts, __global int *value, int width, int height, __global int *output){
int gid = get_global_id(0);
int x = gid % width;
int y = gid / width;
int count = Counts[y * width + x];
if(count != 0){
//need to do something here...
}
}
但是,问题是我发现我永远无法进入 if(count != 0) 的真正分支。我很确定我的 Java 代码中的 Counts 数组有一些不是 0 的索引值。是因为我错误地使用了内存映射吗?请帮忙。谢谢。
【问题讨论】:
标签: java parallel-processing opencl gpgpu