C function in CUDA

Hi,

I’m brand new to CUDA C.

I am wondering if it is possible to run separate functions in different gpu threads (for example, first would do Matrix Multiplication, second would transpose matrix, third would add up 2 arrays,etc…)

Just simple if else statements won’t work for me, so this:

[codebox]global void MagicFunct (/some args here/)

{

if (threadIdx.x == 1){ /* do matrix mult*/}

else if (threadIdx.x == 2){ /* do transpose*/ }

else if (threadIdx.x == 3){ /do addition/}

}[/codebox]

is not what I desire. Is there any way different threads could run different kernel functions? I did some googling but didn’t find an answer.

Second question is: can I call functions from a kernel function?

kinda like this way

[codebox]global void AnotherFunct (/args here/)

{

//some data

MagicFunct(/* pass args */);

}

[/codebox]

thank you for your help,

Mikhail.

No and no.

When a kernel launches, all the threads have to run the same kernel. Now, you can have your kernel start with a huge if statement, so that different threads perform different tasks. However, that should be done at the warp level. One of the tricks a GPU uses to cram more execution units onto a chip is to only have one program counter per warp. Individual threads can take different branches, but it gets inefficient very quickly.

As for calling other kernels… can’t be done. However, global functions can call device functions.