ERROR CudafyHostException Data ist not on the device

Feb 8, 2013 at 11:40 AM
Hallo, at the moment i try to get a feeling for using cudafy.
I simply want to copy a float array to the device (Geforce GT 630), do a simple calculation and copy it back to the host, I read the examples and coded it the same way.
public void Ball_new_Position(float Boden, float Decke, float RechteWand, float LinkeWand, float Reibung, float Gravitation)

            int N = 5;
            float Time_gpu = 0.6f;

            CudafyModule km = CudafyTranslator.Cudafy();
            GPGPU gpu = CudafyHost.GetDevice(CudafyModes.Target);

            float[] gpu_dat = new float[N];

            //Speicher auf GPU Allokieren
            float[] GPUdat = gpu.Allocate<float>(N);

            //GPU Array mit den Koordinaten fülle
            gpu_dat[0] = x;
            gpu_dat[1] = y;
            gpu_dat[2] = vx;
            gpu_dat[3] = vy;
            gpu_dat[4] = Time_gpu;

            gpu.CopyToDevice(GPUdat, gpu_dat);

            //Thread ausführen
            gpu.Launch(N, 1).GPU_NEWPosition(gpu_dat);

            // ARRAY zurückkopieren
            gpu.CopyFromDevice(GPUdat, gpu_dat);

            //GPU Speicher freigeben

            x = gpu_dat[0];
            y = gpu_dat[1];
            vx = gpu_dat[2];
            vy = gpu_dat[3];

            Ball_Grenze(Boden, Decke, RechteWand, LinkeWand, Reibung, Time_gpu);

        public static void GPU_NEWPosition(GThread thread, float[] gpu_dat)

            gpu_dat[1] += (gpu_dat[3] * gpu_dat[5]);
            gpu_dat[0] += (gpu_dat[2] * gpu_dat[5]);
while running the code i get the error CudafyHostException Data is not on the device (gpu.CopyFromDevice(GPUdat, gpu_dat);).
And i realy dont understand why. The examples run perfect on my system and i think i did the same.

Maybe somebody got an idea, what the problem is.

Sorry for my bad english, i hope my problem is clear.
Thank you.
Feb 8, 2013 at 2:30 PM

this is wrong, you should switch the order of the arguments:

gpu.CopyToDevice(GPUdat, gpu_dat);

TO prevent that sort of problems, I usually prefix my var names with either h_ if it resides on the host, or d_ if it points to a block of device (gpu) memory.
For example:
        float[] h_dat = new float[N];
        float[] d_dat = gpu.Allocate(h_dat);

        //GPU Array mit den Koordinaten fülle
        h_dat[0] = x;
        // ...

        gpu.CopyToDevice(h_dat, d_dat);

        //Thread ausführen
        gpu.Launch(N, 1).GPU_NEWPosition(d_dat);

        // ARRAY zurückkopieren
        gpu.CopyFromDevice(d_dat, h_dat);

Feb 9, 2013 at 8:46 AM
Fully agree. Keeping track of where memory is - on device or on host - is one of they key issues of working with GPUs. Consistent naming such as h_ and d_ prefix really helps.
Feb 9, 2013 at 9:53 AM
Thank you very much,

i try to keep these things in mind.