opencl helloworld的诡异问题,求解答

module_init 2016-08-09 02:39:17
本人最近想在含有GPGPU的嵌入式处理器上学习使用opencl,对着网络上的helloworld进行测试,kernel代码段如下时,在host上可以正确输出赋值后的output的内容,
__kernel void helloworld ( __global uchar *input,
__global uchar *input2,
__global uchar *output,
int width,
int height
)
{
int y = get_global_id (0);
int x = get_global_id (1);
int id = (y * width) + x;

output[id] = input[id]; // 这个如果改成 output[id] = input2[id]; 也可以正确把input2的内容赋值给output
}

获取输出值并打印的host代码:
ret = clEnqueueReadBuffer(cq, buffer_output, CL_TRUE, 0, size_2d, data_out, 0, NULL, NULL);
assert (ret == CL_SUCCESS);

printf ("\nResult:\n");
for (i = 0; i < buffer_width; i++)
{
for (j = 0; j < buffer_height; j++)
{
printf (" %d, ", data_out[i][j]);
}
}

!!!问题来了:
保持所有代码不变,只是把kernel中的output[id]=input[id];改为output[id]=input[id]+input2[id];时,在host上读取出data_out内容,想要打印时(也就是访问 data_out[i][j]),会出现段错误。
进一步地,我把这一句改为output[id]=0x01;时,同样还是出错。

各位opencl前辈,问题可能会是在哪里呢?请赐教,谢谢。
...全文
3213 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
fisherTHW 2017-04-13
  • 打赏
  • 举报
回复
how do you create dataout? clEnqueueReadBuffer accepts a pointer to continuous buffer. the way you access dataout (data_out[i][j]) looks unsafe.
Ven_J 2017-02-24
  • 打赏
  • 举报
回复
cl_int clEnqueueReadBuffer ( cl_command_queue command_queue, cl_mem buffer, cl_bool blocking_read, size_t offset, size_t size, void *ptr, cl_uint num_events_in_wait_list, const cl_event *event_wait_list, cl_event *event) 实际读出来的dataout是一维指针。可能强制转换出问题了。
bluewanderer 2016-08-11
  • 打赏
  • 举报
回复
看看到底在哪儿段错误吧...
module_init 2016-08-11
  • 打赏
  • 举报
回复
在这一句:printf (" %d, ", data_out[i][j]); 出现段错误:segmentation fault,没打印出任何数据。 如果把打印的这一句注释掉就不会报错,应该是访问data_out数组的第1个元素就出错了。
module_init 2016-08-11
  • 打赏
  • 举报
回复
在这一句:printf (" %d, ", data_out[i][j]); 出现段错误:segmentation fault,没打印出任何错误,应该是访问data_out的第1个元素就出错了。
bluewanderer 2016-08-10
  • 打赏
  • 举报
回复
好歹说一下到底出了什么错啊

602

社区成员

发帖
与我相关
我的任务
社区描述
异构开发技术
社区管理员
  • OpenCL和异构编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧