# Simple memcpy not working

**URL:** <https://forums.developer.nvidia.com/t/simple-memcpy-not-working/2422>\
**Category:** CUDA Programming and Performance\
**Created:** [January 24, 2008, 8:25pm UTC](https://forums.developer.nvidia.com/t/simple-memcpy-not-working/2422 "2008-01-24T20:25:59Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![philprattszeliga](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@philprattszeliga](https://forums.developer.nvidia.com/u/philprattszeliga)\
**Post date:** [January 24, 2008, 8:25pm UTC](https://forums.developer.nvidia.com/t/simple-memcpy-not-working/2422/1 "2008-01-24T20:25:59Z")

</div>

Hello all,

I am trying to do a simple memcpy with Cuda 1.1 on a Windows XP machine with a GeForce 8600 GTS board. I am compiling under MS Visual Studio 2005 and I have used the template application for a test.

Here is the code for the host:

```auto
/* [2007.12.29 Phil Pratt-Szeliga] : CUDA */

#include <cutil.h>

#include "gpu_kernel.cu"

double tilted_angle[513] = {0.0};

main (int argc, char *argv[])

{

	CUT_DEVICE_INIT();

          

	dim3  grid( 1, 1, 1);

	dim3  threads( 1, 1, 1);

	double *d_tilted_angle;

	CUDA_SAFE_CALL( cudaMalloc( (void**) &d_tilted_angle, sizeof(tilted_angle)));

	CUDA_SAFE_CALL( cudaMemcpy( d_tilted_angle, tilted_angle, sizeof(tilted_angle),cudaMemcpyHostToDevice) );

	slice_kernel<<<grid, threads>>>(d_tilted_angle);

	CUT_CHECK_ERROR("Kernel execution failed");

	CUDA_SAFE_CALL(cudaThreadSynchronize());

	CUT_CHECK_ERROR("Kernel execution failed");

	//copy the memory back

	CUDA_SAFE_CALL( cudaMemcpy( tilted_angle, d_tilted_angle, sizeof(tilted_angle),cudaMemcpyDeviceToHost) );

	//free the allocated memory

	CUDA_SAFE_CALL(cudaFree(d_tilted_angle));

}

```

And here is the code for the device:

```auto
#ifndef _TEMPLATE_KERNEL_H_

#define _TEMPLATE_KERNEL_H_

#include <stdio.h>

__global__ void slice_kernel(double * tilted_angle)

{

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

  tilted_angle[i] = 15.5;

	}

	return;

}

#endif // #ifndef _TEMPLATE_KERNEL_H_

```

Here is my problem: (In Debug mode) Before I call the cudaMemcpy (device to host) tilted\_angle on the host is all zeros. After I call cudaMemcpy tilted\_angle takes on values like: 5.426734841397e-315#DEN

However, in EmuDebug mode tilted\_angle takes on values like 15.5 in main.

Does anyone know what is going on?

Thanks

Phil

---

<div class="post-metadata">

**Author:** ![mfatica](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@mfatica](https://forums.developer.nvidia.com/u/mfatica)\
**Post date:** [January 24, 2008, 8:39pm UTC](https://forums.developer.nvidia.com/t/simple-memcpy-not-working/2422/2 "2008-01-24T20:39:43Z")

</div>

You are using doubles, the current GPU generation is single-precision only.  
The current CUDA compiler will squash doubles to floats. Convert the array before sending to the GPU.

---

<div class="post-metadata">

**Author:** ![philprattszeliga](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@philprattszeliga](https://forums.developer.nvidia.com/u/philprattszeliga)\
**Post date:** [January 24, 2008, 8:44pm UTC](https://forums.developer.nvidia.com/t/simple-memcpy-not-working/2422/3 "2008-01-24T20:44:19Z")

</div>

Okay thanks

---

<div class="post-metadata">

**Author:** ![philprattszeliga](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@philprattszeliga](https://forums.developer.nvidia.com/u/philprattszeliga)\
**Post date:** [January 24, 2008, 11:01pm UTC](https://forums.developer.nvidia.com/t/simple-memcpy-not-working/2422/4 "2008-01-24T23:01:21Z")

</div>

Is double supported on host functions? Where is the documentation related to this?

---

<div class="post-metadata">

**Author:** ![DenisR](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@DenisR](https://forums.developer.nvidia.com/u/DenisR)\
**Post date:** [January 25, 2008, 6:44am UTC](https://forums.developer.nvidia.com/t/simple-memcpy-not-working/2422/5 "2008-01-25T06:44:38Z")

</div>

host code is compiled by your host compiler, so yes. I believe it is in the programming manual, or otherwise the documentation of nvcc
