WEIRD cudaMemcpy error

Please help me, I don’t know what I’m doing wrong.

I’m using the MACRO HANDLE_ERROR to check where my program is not working and it seems that some of the cudaMemcpy calls are not working 'cuz I’m getting this error:

“unspecified launch failure in X.cu at line 198”

and that line is :

HANDLE_ERROR( cudaMemcpy( id, dev_id, sizeof(int), cudaMemcpyDeviceToHost ) );

the weird part is that I’ve already reserve memory for both id and dev_id before that cudaMemcpy call here is a part of my code:


int id;
id = (int
)malloc(sizeof(int));

HANDLE_ERROR( cudaMalloc( (void**)&dev_id, sizeof(int) ) );

recognize<<<blocks,threads>>>(dev_red, dev_redVec, dev_cmp, dev_con, dev_ptr, dev_id);

HANDLE_ERROR( cudaMemcpy( id, dev_id, sizeof(int), cudaMemcpyDeviceToHost ) );
HANDLE_ERROR( cudaMemcpy( MRED, dev_red, *tamRed * sizeof(int), cudaMemcpyDeviceToHost ) );
HANDLE_ERROR( cudaMemcpy( MREDvec, dev_redVec, *tamRedV * sizeof(int), cudaMemcpyDeviceToHost ) );

I’m getting the same error in the other two calls of cudaMemcpy.

Please help me, I don’t know what I’m doing wrong.

The error is not in the cudaMemcpy()s, but in the kernel(s) preceding them. Check them for illegal memory accesses etc. (out of bounds array accesses, mistakes in pointer arithmetic).
Also check the launch configuration (threads, blocks) and whether you are compiling for the right architecture.

EDIT: I see njuffa has already answered the same posting in a different thread. Please do not cross-post to multiple subforums.

thanks, and sorry I’m new in the forum, I solve it… in my kernel I was accessing and modifying dev_red more than *tamRed * sizeof(int) …

Thanks again.