[英]How do I know the memory mapping is successful in OpenCL
我是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的索引值。是不是因為我錯誤地使用了內存映射? 請幫忙。 謝謝。
映射緩沖區后,必須在那里寫入數據,然后取消映射。 您的用法更像是創建緩沖區並將主機數據復制到緩沖區。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.