【问题标题】:How do I know the memory mapping is successful in OpenCL我如何知道 OpenCL 中的内存映射是否成功
【发布时间】: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


    【解决方案1】:

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

    【讨论】:

    • 您好,感谢您的回复。我已经修复了这个错误。是的,原因是我映射后没有取消映射,计算GPU内存和主机内存的使用大小错误。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-13
    • 1970-01-01
    • 2014-07-07
    • 2011-08-10
    • 2010-11-02
    相关资源
    最近更新 更多