cudaMemcpy what am i doing wrong?

Im trying to do a basic memcpy to the device and back to the host and end up with the same values i started with. Its not working though (it gives me a jumble of integers), can anyone see why?

int main(int argc, char** argv)

{

        int in1[512];

        int *in2;

        int test[512];

       for(int i=0;i<512;i++){

                in1[i]=i;

        }

       cudaMalloc((void**)&in2,512*sizeof(int));

        cudaMemcpy(in2,in1,512*sizeof(int),cudaMemcpyHostToDevice);

        cudaMemcpy(test,in2,512*sizeof(int),cudaMemcpyDeviceToHost);

       for(int i=0;i<512;i++)

                printf("%i ",test[i]);

       cudaFree(in2);

       CUT_EXIT(argc, argv);

}

Works perfectly fine when I run it.

You should check the return values of cudaMemcpy for any errors.

Do SDK samples (like deviceQuery) run on your machine? Errors in simple programs like this usually turn out to be an incorrect driver version or a driver package that fails to install libcuda

i ran deviceQuery and it says that i have -1 bytes of global memory. also all of the SDK examples fail their tests (‘Test failed’).

Does this mean that my device has a problem with its global memory or am i missing a driver or something?

Most likely. What OS, driver version, and CUDA toolkit version are you running?

using fedora 9 (i think thats it) using driver 169.9 and toolkit 1.1

Doesn’t fedora 9 run a beta version of xorg that isn’t compatible with 169.* drivers? Or are you running on the console?

If you are running on the text console, you’ll need to run the script in the CUDA 1.1 release notes (as root) to populate the device nodes. [url=“http://developer.download.nvidia.com/compute/cuda/1_1/CUDA_Toolkit_Release_Notes.txt”]http://developer.download.nvidia.com/compu...lease_Notes.txt[/url]

If you are running X11, then you’ll need to upgrade to the latest drivers. For compatibility with Fedora, I’d recommend installing the fedora nvidia driver package (Fedora 9 and Nvidia xorg 1.5 compatible driver (nvidia 174.14.05 version) ~ Naresh). The default install will not include CUDA though. You’ll need to install an additional package (named something like nvidia-x11-drv-dev, sorry I don’t know the exact name).