Java 如何知道内存映射在OpenCL中是否成功

Java 如何知道内存映射在OpenCL中是否成功,java,parallel-processing,opencl,gpgpu,Java,Parallel Processing,Opencl,Gpgpu,我是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);

我是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);

然而,问题是我发现我永远无法进入if(count!=0)的真正分支。我非常确定Java代码中的Counts数组有一些不是0的索引值。是因为我错误地使用了内存映射吗?请帮忙。谢谢。

映射缓冲区后,必须将数据写入缓冲区,然后取消映射。您的使用更像是创建缓冲区,并将主机数据复制到其中。

映射缓冲区后,必须将数据写入其中,然后取消映射。您的使用更像是创建缓冲区,将主机数据复制到缓冲区。

您好,谢谢您的回复。我已经修复了这个错误。是的,原因是我在映射后没有取消映射,并且我计算了GPU内存和主机内存的使用量。您好,谢谢回复。我已经修复了这个错误。是的,原因是我在映射后没有取消映射,并且我计算了GPU内存和主机内存的使用大小,但计算错误。
__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...
    }   
}