我在内核中使用大量无符号字符工作,我用clCreateBuffer创建了内存对象。比我通过clEnqueueWriteBuffer复制一块无符号字符到这个内存对象。而且,我在循环中调用从这个内存对象读取的内核,执行一些逻辑并将新数据写入同一位置(在本周期中,我没有调用clEnqueueWriteBuffer或clEnqueueReadBuffer)。下面是内核代码:OpenCL内核的优化
__kernel void test(__global unsigned char *in, unsigned int offset) {
int grId = get_group_id(0);
unsigned char msg[1024];
offset *= grId;
// Copy from global to private memory
size_t i;
for (i = 0; i < 1024; i++)
msg[i] = in[ offset + i ];
// Make some computation here, not complicated logic
// Copy from private to global memory
for (i = 0; i < 1024; i++)
in[ offset + i ] = msg[i];
}
当周期完成后(循环运行CCA 1000倍),那么我读通过clEnqueueReadBuffer内存对象的结果。
可以优化这段代码吗?
你可以使用clCreateBuffer从数组中创建一个缓冲区,然后使用clEnqueueMapBuffer将它映射到你的orivate内存中吗? – 2011-05-03 21:33:53