This project is read-only.

Cudafy Add/divide/etc function arguments types

Jun 4, 2014 at 9: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();

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


                    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;

            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 3:02 AM
when using value types, there's no need to allocate memory / copy to device etc. Just pass the argument directly.