【发布时间】:2016-05-31 20:16:59
【问题描述】:
好的,所以我有两个内核,它们都接受输入和输出图像并执行一些有意义的操作:
#pragma OPENCL EXTENSION cl_khr_3d_image_writes : enable
kernel void Kernel1(read_only image3d_t input, write_only output)
{
//read voxel and some surrounding voxels
//perform some operation
//write voxel
}
#pragma OPENCL EXTENSION cl_khr_3d_image_writes : enable
kernel void Kernel2(read_only image3d_t input, write_only output)
{
//read voxel and some surrounding voxels
//perform some other operation
//write voxel
}
#pragma OPENCL EXTENSION cl_khr_3d_image_writes : enable
kernel void KernelCombined(read_only image3d_t input, write_only output)
{
//read voxel and some surrounding voxels
//...
//perform operation of both kernels (without read, write)
//...
//write voxel
}
现在我想在某些情况下链接内核,所以我可以做的是先调用内核 1,然后调用内核 2。但这意味着,我在两者之间有不必要的写入和读取。我也可以编写第三个内核,两者兼而有之,但维护复制粘贴代码似乎很烦人。据我所知,我无法真正将每个内核的内容放在单独的函数中,因为我无法传递 image3d_t 输入。
问题:有没有什么巧妙的方法可以链接两个内核?也许 OpenCL 已经在做一些我不知道的聪明事情了吗?
编辑:添加了我想要实现的示例。
【问题讨论】:
标签: opencl