Help with Device Memory and Host Memory

Hi everybody,

I'm tried to do my first program in CUDA but I have some problems about Device and Host Memory.

My code is the follows:

void FunctionOne (Struct1 *HostContext, unsigned char *HostinBuf, unsigned int inLen)
{
UINT4 *in;
int mdi;
unsigned int i=0;

Struct1 *DeviceContext;
unsigned char *inBuf;

// Store Memory in the Device
CUDA_SAFE_CALL(cudaMalloc((void **)&DeviceContext, sizeof(Struct1) ));
CUDA_SAFE_CALL(cudaMemcpy(DeviceContext,HostContext, sizeof(Struct1 ), cudaMemcpyHostToDevice));

    CUDA_SAFE_CALL( cudaMalloc((void **)&inBuf, sizeof(unsigned char )*inLen ));
CUDA_SAFE_CALL(cudaMemcpy(inBuf,HostinBuf, sizeof(unsigned char )*inLen, cudaMemcpyHostToDevice));

// if I’m right the first step is pass the variable in the HOST Memory to Device memory

//… Working with the Device memory

while (inLen--) {
  /* add new character to buffer, increment mdi */
  DeviceContext->in[mdi++] = inBuf[i];   
 i++;
}

// Store the modification to the Host Memory
CUDA_SAFE_CALL(cudaMemcpy(HostContext, DeviceContext, sizeof(Struct1 ), cudaMemcpyDeviceToHost));

// free Device Memory
CUDA_SAFE_CALL(cudaFree(DeviceContext));
CUDA_SAFE_CALL(cudaFree(inBuf));

}

The problem is the HostContext data structure is not update with the DeviceContext data structure and I don’t know why.

I’m working with CUDA 2.0 and 9600GT graphic card.
I’m compiling as Release.

Best Regards,
GUAN

you try to use the device memory address on you cpu, that’s not gonna work… you have to start a kernel on the gpu to modify memory at the device.
have a look at the developer’s manual.

Thanks Ocire.

One question more.

For calling kernel function I make in my host something like this:

ActualizacionIn<<<1,16,0>>>(DeviceContext,in);

Can I uses this type of calls into kernel function too ?

I do but it is a little bit confuse

if you mean, how to call a device function from within a kernel: no, that is done like a normal function call.