Cudafy Add/divide/etc function arguments types

Jun 4, 2014 at 8:56 PM
HI, im trying to do some things with my gpu processor, so i have this problem:
  • I want to do some operation like add or divide, but i want to do this with doubles and not arrays like double[] ...
my code:
public double[] Executeadd(double[] a, double[] b)
            {
                CudafyModule km = CudafyTranslator.Cudafy();
                //CudafyModule.Deserialize(typeof(CUDAfunc).Name);

                GPGPU gpu = CudafyHost.GetDevice(CudafyModes.Target, CudafyModes.DeviceId);

                gpu.LoadModule(km);

                    double[] c = new double[N];

                    //gpu memory
                    double[] dev_a = gpu.Allocate<double>();
                    double[] dev_b = gpu.Allocate<double>();
                    double[] dev_c = gpu.Allocate<double>(c);

                    gpu.CopyToDevice(a, dev_a);
                    gpu.CopyToDevice(b, dev_b);

                    gpu.Launch().Add(dev_a, dev_b, dev_c);

                    gpu.CopyFromDevice(dev_c, c);

                    return c;
            }

 [Cudafy]
            public static void add(GThread thread, double[] a, double[] b, double[] c)
            {
                int tid = thread.blockIdx.x;
                while (tid < N)
                {
                    c[tid] = a[tid] + b[tid];
                    tid += thread.gridDim.x;
                }
            }

(...)

 double normalizingSum = 0;
                double[] strategyy;

normalizingSum = Executeadd(normalizingSum,strategyy[i]);
When i change the given arguments to double over double[] it give me errors ... like when i allocate memory on gpu. I know we need to allocate as arrays, but there are some way to do double + double = double instead double[] ?
Jun 6, 2014 at 2:02 AM
when using value types, there's no need to allocate memory / copy to device etc. Just pass the argument directly.