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