so I'm trying to make a complex calculation in CUDAfy so that it can reduce the current time it takes on the CPU I am trying to make use of "CUDAfy-ed" methods which I can pass variables into and it will return values very similar to the idea with the .NET Math.Sin(x) or Math.Cos(x) function for example. I am trying to make this to work however it is just spitting out errors from the CUDAfy translator, so is what I am trying to do possible/within the power of CUDAfy or am I going down the wrong route to make this work?
Example:
public static void Main(){
CudafyModule km = CudafyTranslator.Cudafy();
GPGPU gpu = CudafyHost.GetDevice(CudafyModes.Target, CudafyModes.DeviceId);
gpu.LoadModule(km);
double Value;
double[] dev_Value = gpu.Allocate<double>(10);
gpu.Launch(1,1).SumOfSines(dev_Value);
Console.WriteLine(Value);
gpu.FreeAll();}
public static void SumOfSines(double[] Value)
{
int numThreads = thread.blockDim.x * thread.gridDim.x;
int threadID = thread.threadIdx.x + thread.blockIdx.x * thread.blockDim.x;
for (int i = threadID; i < 1000000; i += numThreads)
{
for (double a = 0; a < 100; a++)
{
double angle = MathHelper.DegreesToRadians((double)a); //can I do this?
Value[i] += Math.Sin(angle);
}
}
}
In the MathHelper.cs file it has the method DegreesToRadians which makes this calculation:
public static double DegreesToRadians(double deg)
{
double rad = deg * (Math.PI / 180.0);
return rad;
}
When I do this it spits out the error at the CUDAfy translator.
First thing is, these aren't marked as methods to 'Cudafy' with the
[Cudafy]attribute. The C# code is translated to CUDA-C code (with the translator). But there are rules about what and how.Secondly, these methods shown contain references to the .NET Framework (Math.PI). The .NET Framework is not available to GPU. Try to look (Internet) for GMath. It's a Cudafy class that contains CUDA implementations of .NET Math methods.
Before you bury yourself too deeply, I suggest you start out going through the CUDAfy documentation located here: http://www.hybriddsp.com/cudafy/CUDAfy_User_Manual_1_22.pdf