CUDA支持递归吗?

发布于 2024-09-17 21:50:13 字数 17 浏览 4 评论 0原文

CUDA支持递归吗?

Does CUDA support recursion?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(12

南城旧梦 2024-09-24 21:50:13

它在支持计算能力 2.0 和 CUDA 3.1 的 NVIDIA 硬件上执行:

CUDA C 中添加了新的语言功能
/ C++ 包括

功能支持
指针和递归使事情变得更容易
将许多现有算法移植到
费米 GPU

http://developer.nvidia.com/object/cuda_3_1_downloads.html

函数指针:
http://developer.download.nvidia.com/compute /cuda/sdk/website/CUDA_Advanced_Topics.html#FunctionPointers

递归:
我在 NVIDIA 的网站上找不到代码示例,但在 论坛 上有人找到发布此内容:

__device__ int fact(int f)
{
  if (f == 0)
    return 1;
  else
    return f * fact(f - 1);
}

It does on NVIDIA hardware supporting compute capability 2.0 and CUDA 3.1:

New language features added to CUDA C
/ C++ include:

Support for function
pointers and recursion make it easier
to port many existing algorithms to
Fermi GPUs

http://developer.nvidia.com/object/cuda_3_1_downloads.html

Function pointers:
http://developer.download.nvidia.com/compute/cuda/sdk/website/CUDA_Advanced_Topics.html#FunctionPointers

Recursion:
I can't find a code sample on NVIDIA's website, but on the forum someone post this:

__device__ int fact(int f)
{
  if (f == 0)
    return 1;
  else
    return f * fact(f - 1);
}
浊酒尽余欢 2024-09-24 21:50:13

是的,请参阅NVIDIA CUDA 编程指南

设备函数仅支持为设备编译的设备代码中的递归
计算能力2.0。

您需要一张费米卡才能使用它们。

Yes, see the NVIDIA CUDA Programming Guide:

device functions only support recursion in device code compiled for devices
of compute capability 2.0.

You need a Fermi card to use them.

凉宸 2024-09-24 21:50:13

尽管它仅支持特定芯片的递归,但有时您可以摆脱“模拟”递归:了解我如何对 CUDA 光线追踪器使用编译时递归

Even though it only supports recursion for specific chips, you can sometimes get away with "emulated" recursion: see how I used compile-time recursion for my CUDA raytracer.

陌路黄昏 2024-09-24 21:50:13

在 CUDA 4.1 版本中,CUDA 仅支持 __device__ 函数的递归,但不支持 __global__ 函数。

In CUDA 4.1 release CUDA supports recursion only for __device__ function but not for __global__ function.

江城子 2024-09-24 21:50:13

仅在兼容设备上具有 2.0 计算能力之后

Only after 2.0 compute capability on compatible devices

愿与i 2024-09-24 21:50:13

任何递归算法都可以用堆栈和循环来实现。这更痛苦,但如果你真的需要递归,这可以工作。

Any recursive algorithm can be implemented with a stack and a loop. It's way more of a pain, but if you really need recursion, this can work.

霊感 2024-09-24 21:50:13

当然可以,但它需要开普勒架构才能做到这一点。
查看他们关于经典快速排序的最新示例。

http: //blogs.nvidia.com/2012/09/how-tesla-k20-speeds-up-quicksort-a-familiar-comp-sci-code/

据我所知,只有最新的 Kepler GK110 支持动态并行性,允许这种递归调用并在内核中生成新线程。在开普勒 GK110 之前,这是不可能的。请注意,并非所有 Kepler 架构都支持此功能,只有 GK110 支持。

如果您需要递归,您可能需要 Tesla K20。
我不确定费米是否支持它,从来没有读过它。 :\
但开普勒确实如此。 =)

Sure it does, but it requires the Kepler architecture to do so.
Check out their latest example on the classic quick sort.

http://blogs.nvidia.com/2012/09/how-tesla-k20-speeds-up-quicksort-a-familiar-comp-sci-code/

As far as i know, only latest Kepler GK110 supports dynamic parallelism, which allow this kind of recursive call and spawning of new threads within the kernel. Before Kepler GK110, it was not possible. And note that not all Kepler architecture supports this, only GK110 does.

If you need recursion, you probably need the Tesla K20.
I'm not sure if Fermi does supports it,never read of it. :\
But Kepler sure does. =)

我三岁 2024-09-24 21:50:13

CUDA 3.1支持递归

CUDA 3.1 supports recursion

向地狱狂奔 2024-09-24 21:50:13

如果你的算法涉及大量递归,那么支持与否,它不是为 GPU 设计的,要么重新设计你的算法,要么获得更好的 CPU,无论哪种方式都会更好(我敢打赌,在很多情况下,幅度会更好),然后在GPU。

If your algorithm invovles alot of recursions, then support or not, it is not designed for GPUs, either redesign your algorthims or get a better CPU, either way it will be better (I bet in many cases, maginitudes better) then do recurisons on GPUs.

想念有你 2024-09-24 21:50:13

是的,实际版本是支持的。但是,尽管事实上可以执行递归函数,但您必须记住,执行堆栈中的内存分配是无法预测的(必须执行递归函数才能知道递归的真实深度),因此您的堆栈可能会导致不足以满足您的目的,并且可能需要手动增加默认堆栈大小

Yeah, it is supported on the actual version. But despite the fact it is possible to execute recursive functions, you must have in mind that the memory allocation from the execution stack cannot be predicted (the recursive function must be executed in order to know the true depth of the recursion), so your stack could result being not enough for your purposes and it could need a manual increment of the default stack size

野侃 2024-09-24 21:50:13

是的,它确实支持递归。然而,在 GPU 上进行递归并不是一个好主意。因为每个线程都会这样做。

Yes, it does support recursion. However, it is not a good idea to do recursion on GPU. Because each thread is going to do it.

ι不睡觉的鱼゛ 2024-09-24 21:50:13

刚刚在我的电脑上尝试了具有 1.1 计算能力的 NVIDIA GPU。它说尚不支持递归。所以它与运行时没有任何关系,而是与硬件本身有关

Tried just now on my pc with a NVIDIA GPU with 1.1 Compute capability. It says recursion not yet supported. So its not got anything to do with the runtime but the hardware itself

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文