Simple Cuda malloc and memcpy

I’m having a brain fart and cannot remember how to do this.

I need to allocate memory in CUDA for a few integers and copy over some numbers over. What did write wrong?

[codebox]

unsigned int d_col;

cudaMalloc((void*) &d_col, sizeof(unsigned int));

cudaMemcpy(d_col, col, sizeof(unsigned int), cudaMemcpyHostToDevice);

[/codebox]

Did you forget some thing? ;)
unsigned int d_col = NULL;
cudaMalloc((void
*) &d_col, sizeof(unsigned int));
cudaMemcpy(d_col, col, sizeof(unsigned int), cudaMemcpyHostToDevice);

—sorry I post twice—

I tried what you said and here are the errors that I received from the compiler

error: argument of type “unsigned int” is incompatible with parameter of type “const void *”

error: argument of type “unsigned int *” is incompatible with parameter of type “unsigned int”

What do you think?

I think you variable col in

cudaMemcpy(d_col, col, sizeof(unsigned int), cudaMemcpyHostToDevice);

isn’t a pointer, when it should be. I also think you need consult this (your have your own copy wherever the CUDA toolkit is installed) and maybe brush up on the C chops a little.

[quote name=‘avidday’ post=‘581174’ date=‘Aug 21 2009, 11:05 AM’]

I think you variable col in

[codebox]unsigned int *d_row=NULL;

cudaMalloc((void**) &d_row, sizeof(unsigned int));

cudaMemcpy(&d_row, &row, sizeof(unsigned int), cudaMemcpyHostToDevice);[/codebox]

and the error is now: argument of type “unsigned int **” is incompatible with parameter of type “unsigned int *”

Also if it helps in the kernel when I try to use row I receive this error: expression must have arithmetic or enum type

unsigned int row=(unsigned int)malloc(sizeof(unsigned int));
//initialize data for row variable and then, copy data from host to device memory
//…
unsigned int d_row=NULL;
cudaMalloc((void
*) &d_row, sizeof(unsigned int));
cudaMemcpy(d_row, row, sizeof(unsigned int), cudaMemcpyHostToDevice);
//…