why cudamemcpy not working properly?


This is the code fragment:

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

#include <cuda.h>

#include <time.h>

int main()


				int* bugs_bunny;

				int* bugs_bunny_dev;

				bugs_bunny = (int*)malloc(3*sizeof(int));

				memset(bugs_bunny, 0, 3*sizeof(int));

				cudaMalloc((void**)&bugs_bunny_dev, 3*sizeof(int));

				cudaMemset((void**)&bugs_bunny_dev, 0, 3*sizeof(int));

				int status = cudaMemcpy(bugs_bunny, bugs_bunny_dev, 3*sizeof(int), cudaMemcpyDeviceToHost);

				printf("memcpy debug\n");

				printf("0: %d\n",bugs_bunny[0]);


						case cudaSuccess:printf("mem status: success(%d)\n",status);break;

						case cudaErrorInvalidValue:printf("mem status: invalid value(%d)\n",status);break;

						case cudaErrorInvalidDevicePointer:printf("mem status: invalid dev ptr(%d)\n",status);break;

						case cudaErrorInvalidMemcpyDirection:printf("mem status: invalid direction(%d)\n");break;

						default:printf("mem status: %d\n",status);




		return (1);


The output comes out as:

memcpy debug

0: 16779264

Why is garbage value printed instead of 0? I would appreciate some helpful answer.


Your first argument to cudaMemset() is wrong.