2016-12-12 1 views
1

OpenCL을 처음 사용합니다. 현재 큰 1 차원 배열을 만들고 있습니다. 배열의 크기는 약 800 만입니다.OpenCL에서 메모리 매핑이 성공적임을 알 수 있습니까?

__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... 
    } 
} 

그러나, 문제는 내가는 경우를 (계산의 진정한 지점에 갈 수 없다 찾을 수 있다는 것입니다 :

//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); 

아래는 내 커널 코드 : 다음은 내 코드의 일부입니다! = 0). 내 Java 코드의 Counts 배열에는 0이 아닌 인덱스 값이 몇 개 있는지 확신 할 수 있습니다. 메모리 매핑을 잘못 사용했기 때문입니까? 도와주세요. 고맙습니다.

답변

0

버퍼를 매핑 한 후에 데이터를 작성한 다음 매핑을 해제해야합니다. 사용법은 호스트 데이터를 복사하여 버퍼를 만드는 것과 비슷합니다.

+0

안녕하세요, 답장을 보내 주셔서 감사합니다. 나는 그 버그를 고쳤다. 그렇습니다. 매핑 한 후에 매핑을 해제하지 않았기 때문에 GPU 메모리 사용량과 호스트 메모리 크기를 잘못 계산했습니다. – Yangg

관련 문제