Noob needs advice

Hello! I’ve just start to learn Cuda for one verz narrow task. Could You give me a piece of advice whether CUDA will help me in my task. Generally speaking I want to perform the following calculations:

  • double fun2(double a)
    {
    x[10^5];
    x[0]=0;
    for (int i=1;i<10^5; i++)
    {
    x[i]=FN(x[i-1],a);
    }

}

  • double fun1()
    {
    double a[10^5],x[10^5][10^5];
    int n=10^5;

for (iA=0; iA<n; iA++)
{
x[iA]=fun2(a[iA]);
}
return x;
}

What i should read? I see 2 inserted kernels. But in this documentation i read they provide no examples of such kernels. Seconly, i could not understand how many blocks and threads to use. And finally, i read that threadshave very small memory, but my computation is very big is it a problem for CUDA.

Million thanks in advance.

Applying a mathematical function to an array of data is a task commonly performed with CUDA. The size of such an array will be limited by the amount of memory on your graphics card. Your second example would appear to require about 800 MB, so you would need a GPU with at least 1 GB of memory, which is something even low-end GPUs typically provide these days.

Have you had a chance to look at the many example programs that ship with CUDA? They cover a wide range from simple to advanced topics. You may also benefit from reading an introductory book, such as “CUDA by Example”.

I assume when you ask “whether CUDA will help me in my task” you are inquiring whether CUDA will accelerate the task compared to your current CPU version. The answer is, “it depends”. If you plan to simply copy the data from the CPU to the GPU, apply fun2() to it and copy the result back to the CPU, the answer is likely “no”, unless fun2() is very computational intensive. The performance of such code would be limited by the speed of the copies across the PCIe interconnect that connects the CPU and the GPU. If the above code sketch is part of a larger computation that you plan to move to the GPU in its entirety, performing this computation on the GPU should help even if the kernel turns out to be bound by memory bandwidth, since GPUs generally provide higher memory bandwidth than CPUs.