从另一个OpenCL内核调用OpenCL内核 [英] Calling OpenCL kernel from another OpenCL kernel

查看:67
本文介绍了从另一个OpenCL内核调用OpenCL内核的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里的一篇文章中看到,我们可以从OpenCL内核中调用一个函数.但是在我的情况下,我还需要将该复杂的函数并行化(由所有可用线程运行),那么我是否也必须将该函数设为内核并像从主内核中那样直接调用它?或针对这种情况有什么可能的解决方案?预先感谢

I have seen in one post here that we can call a function from an OpenCL kernel. But in my situation, I need that complex function to be parallelized (run by all available threads) as well, so do I have to make that function a kernel too and call it straight away like function from the main kernel ? or whats possible solution for this situation? Thanks in advance

推荐答案

您可以从内核调用帮助程序函数,它们将以与内核相同的方式并行化,想象一下它们内联在内核代码中.因此,每个工作项都会为其处理的工作集调用辅助函数.

You can call helper functions from your kernel and they will be parallelized in the same manner as the kernel, imagine them as inlined inside your kernel code. So, each work item will invoke the helper function for the working set it handles.

float4 helper_function(float4 input)
{
   return input.x + input.y + input.z + input.w;
}
__kernel kernel_function(const float4* arr, float4* out)
{
  id = get_global_id(0);
  out[id] = helper_function(arr[id]);
}

这篇关于从另一个OpenCL内核调用OpenCL内核的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆