Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does CUDA support recursion?

Tags:

recursion

cuda

Does CUDA support recursion?

like image 970
JuanPablo Avatar asked Sep 05 '10 02:09

JuanPablo


People also ask

Which algorithm is used for recursion?

Contents. A recursive algorithm is an algorithm which calls itself with "smaller (or simpler)" input values, and which obtains the result for the current input by applying simple operations to the returned value for the smaller (or simpler) input.

Which programming languages support recursion?

To my knowledge, all modern imperative programming languages support recursion in the sense that a procedure can call itself.

Is recursion really used in industry?

Yes, recursion can be used in production code with some defensive coding practices.

Does Arduino support recursion?

TLDR; My Arduino Nano (ATmega328 mcu) can do 211 recursive function calls (for the code given below) before it has a stack overflow and crashes.


2 Answers

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); } 
like image 182
Stringer Avatar answered Sep 24 '22 17:09

Stringer


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.

like image 22
Dr. Snoopy Avatar answered Sep 24 '22 17:09

Dr. Snoopy