Hi,
I’m trying to pass a struct containing a pointer to CUDA device memory to a global function, but I can’t get it to work.
The goal of my function is to execute a postfix-expression (stored in a struct) containing zero or more (usually between 2 and 6) arrays. The expressions and the input data will come from other software, so I want to dynamically allocate and copy the data to the GPU. This allocation will be done while analyzing the expression and translating it from infix to postfix.
My struct and the array containing these structs looks like this:
struct cuExprInput {
char *name;
float *ptr;
int begin;
int end;
int length;
};
struct cuExprInput cu_input[50];
For each variable encountered when breaking down the expression:
CUDA_SAFE_CALL( cudaMalloc( (void**)&cu_input[var_cnt].ptr, mem_size );
cudaMemcpy(&cu_input.ptr, data, mem_size, cudaMemcpyHostToDevice);
which stores the pointer in the struct.ptr, I assume.
To transfer the array of structs containing the pointers etc to the GPU and use them, I use:
CUDA_SAFE_CALL( cudaMalloc( (void**)&d_input_structs, var_cnt * sizeof(cuExprInput)) );
cudaMemcpy(d_input_structs, cu_input, (var_cnt * sizeof(cuExprInput)), cudaMemcpyHostToDevice);
__global__ void devRPN(cuExprInput *cu_input, int var_count, float *output) {
/* in emulation, this works: */
int i;
#ifdef EMU
for(i = 0; i < var_count; i++)
printf("%d: name = %s\n", i, cu_input[i].name);
/* Doesn't work: */
for(i = 0; i < var_count; i++)
printf("%d: first val = %f\n", i, cu_input[i].ptr[0];
#endif
/* doesn't work either: */
for(i = 0; i < var_count; i++)
output[threadIdx.x] = cu_input[i].ptr[0];
}
This is just a simplified version, just to test ofcourse.
Also, while compiling, I get the warning:
"/tmp/tmpxft_00004afa_00000000-5.i", line 342: Advisory: Cannot tell what pointer points to, assuming global memory space
My question is then, how can I dynamically store pointers to global device memory and transfer/use this afterwards on the GPU? I’m probably doing something completely wrong here, so any help is very appreciated!
Thanks in advance,
Marcel.