我目前正在编写一个OpenCL应用程序,进行一些内存密集型计算。为了跟踪所有计算的进度,我创建了一个for循环,它创建了不同的内核组。不幸的是,计算填满了我的整个内存。,我的猜测是,在添加下一个堆之前,内核还没有完成执行。
for (unsigned long i=1; i<maxGlobalThreads; i+=1000000) {
// Calculating Offset
size_t temp = 1000000;
size_t offset = 0;
if (i>1000000) {
offset = i-1000000;
}
cl_event tmp;
clEnqueueNDRangeKernel(command_queue, kernel, 1, &offset, &temp, NULL, NULL, 0, &tmp);
// Wait until Threads finished (-- not working)
clWaitForEvents(1, &tmp);
// Copy results from memory buffer
int *res = (int*)malloc(64*sizeof(int));
int *indexNum = (int*)malloc(14*sizeof(int));
err = clEnqueueReadBuffer(command_queue, foundCombiMem, CL_TRUE, 0, 64*sizeof(int), res, 0, NULL, NULL);
err = clEnqueueReadBuffer(command_queue, indexNumMem, CL_TRUE, 0, 14*sizeof(int), indexNum, 0, NULL, NULL);
// Calculate Time for 1000000 checked combinations
diff = clock() - start;
double msec = diff * 1000 / CLOCKS_PER_SEC;
printf("%f\n", (msec/(i*1000000))*1000000);
[ ... ]
}

发布于 2015-06-19 17:54:20
您正在对在循环的每一次迭代中从未释放过的错误进行处理。这就是为什么你内存不足的原因。
另外,您的循环使用的是一个无符号int变量,这可能是一个问题,取决于maxGloablThreads的值。
发布于 2019-02-03 16:02:49
在这种情况下,您能做的最好是添加
clFinish(CommandQueue);之后
clEnqueueNDRangeKernelhttps://stackoverflow.com/questions/30925417
复制相似问题