cudaMemcpy
The post [url="http://forums.nvidia.com/index.php?showtopic=42001"]here [/url]discussed this issue, but it did not resolve mine.

I get no errors when copying my data to and from the device. I have a function that checks the difference between the data on the host and the device by copying it back to the host and summing the differences (the data are floats). Both before and after my call to the kernel, their is no difference. However, when operating on the data in the kernel, it is clear that it has not been copied.

Any advice?

(can't post code)
The post here discussed this issue, but it did not resolve mine.



I get no errors when copying my data to and from the device. I have a function that checks the difference between the data on the host and the device by copying it back to the host and summing the differences (the data are floats). Both before and after my call to the kernel, their is no difference. However, when operating on the data in the kernel, it is clear that it has not been copied.



Any advice?



(can't post code)

#1
Posted 03/16/2009 11:22 AM   
Same Problem here!

I'm currently using some code someone else wrote two years ago for an old version of Cuda. I worked with it a little and adapted it for Linux but all I got were some black output images. Finally I figured out that it seems to be a problem with cudaMemcpy.
Here's the part of code:
[code]for(int i = 0; i < w*d*h; i++)
std::cout << (in->GetBufferPointer())[i] << " ";

CUDA_SAFE_CALL(cudaMalloc((void**) &d_in, sizeof(InPixType)*w*h*d));
CUDA_SAFE_CALL(cudaMemcpy(d_in, in->GetBufferPointer(), sizeof(InPixType)*w*h*d, cudaMemcpyHostToDevice));

OutPixType *outputBuffer = (OutPixType *) malloc(sizeof(OutPixType)*w*h*d);
cudaMemcpy(outputBuffer, d_in, sizeof(OutPixType)*w*h*d, cudaMemcpyDeviceToHost);
for(int i = 0; i < w*d*h; i++)
std::cout << outputBuffer[i] << " ";[/code]
First I thought it could be a problem with the kernel, but then I tried to copy the InputImage to the device and after this copy it right back. In the first loop the correct pixel values are printed out, but in the second loop there are only zeros....
btw: InPixType and OutPixType are the same in this case.
Currently I'm using Ubuntu 8.10 with a 8400M GS and KUbuntu 8.10 with a 9500GT
Same Problem here!



I'm currently using some code someone else wrote two years ago for an old version of Cuda. I worked with it a little and adapted it for Linux but all I got were some black output images. Finally I figured out that it seems to be a problem with cudaMemcpy.

Here's the part of code:

for(int i = 0; i < w*d*h; i++)

std::cout << (in->GetBufferPointer())[i] << " ";



CUDA_SAFE_CALL(cudaMalloc((void**) &d_in, sizeof(InPixType)*w*h*d));

CUDA_SAFE_CALL(cudaMemcpy(d_in, in->GetBufferPointer(), sizeof(InPixType)*w*h*d, cudaMemcpyHostToDevice));



OutPixType *outputBuffer = (OutPixType *) malloc(sizeof(OutPixType)*w*h*d);

cudaMemcpy(outputBuffer, d_in, sizeof(OutPixType)*w*h*d, cudaMemcpyDeviceToHost);

for(int i = 0; i < w*d*h; i++)

std::cout << outputBuffer[i] << " ";


First I thought it could be a problem with the kernel, but then I tried to copy the InputImage to the device and after this copy it right back. In the first loop the correct pixel values are printed out, but in the second loop there are only zeros....

btw: InPixType and OutPixType are the same in this case.

Currently I'm using Ubuntu 8.10 with a 8400M GS and KUbuntu 8.10 with a 9500GT

#2
Posted 04/08/2009 11:12 AM   
Have you compiled in debug mode so that CUDA_SAFE_CALL actually checks for errors? 95% of the time, failures of simple code like this are the result of 1) insufficient memory or 2) the driver not being fully installed so that CUDA is available. Either of these cases would result in an error being returned by cudaMalloc. Note that it is also a good idea to check for errors on your 2nd cudaMemcpy.
Have you compiled in debug mode so that CUDA_SAFE_CALL actually checks for errors? 95% of the time, failures of simple code like this are the result of 1) insufficient memory or 2) the driver not being fully installed so that CUDA is available. Either of these cases would result in an error being returned by cudaMalloc. Note that it is also a good idea to check for errors on your 2nd cudaMemcpy.

#3
Posted 04/08/2009 02:23 PM   
CUDA_SAFE_CALL should not be used ever by anyone. It's a much better idea to check errors yourself.
CUDA_SAFE_CALL should not be used ever by anyone. It's a much better idea to check errors yourself.

#4
Posted 04/08/2009 04:44 PM   
Scroll To Top