I have the following structure for a 2D map:
typedef struct {
int Nx;
int Nz;
unsigned int data_offset;
} map;
Since I have to share this data, I’m used to packing this kind of structures in a single large array of char with the following code:
map *create_map(int Nx, int Nz){
map *result;
char *buffer;
buffer=malloc(sizeof(map)+Nx*Nz*sizeof(float));
result=(map *)buffer;
result->Nx=Nx;
result->Nz=Nz;
result->data_offset=sizeof(map);
}
void free_map(map *a){
if(a!=NULL) free(a);
}
If I have to set map elements to one I use the following function:
void setOnes(map *a){
int k;
float *data=(float *)(((void *)a)+a->data_offset);
for(k=0;k<a->Nx*a->Nz;k++){
data[k]=1.0;
}
}
This is just an example to explain my problem.
I use very often this way to organize my data because is useful when the pointers cannot be used (with shared memory for example).
Compiling with nvcc this kind of code I have the error:
error: expression must be a pointer to a complete object type
whereas compiling it with gcc there are no problems.
How can I solve this problem?
I hope there is a no safe compiling option or something like that.
Could you be a little more specific? Exactly which code fails and where?
the code fails on instruction:
float *data=(float *)(((void *)a)+a->data_offset);
The compiling error of my true code is:
marco@core-i7:~/NetBeansProjects/migration_cuda$ make -f Makefile_cuda production
make -f Makefile_cuda CFLAGS="-O3 -use_fast_math" CFLAGS2="-O1 -use_fast_math"
make[1]: ingresso nella directory «/home/marco/NetBeansProjects/migration_cuda»
nvcc -O3 -use_fast_math -c gb_parameters.c
nvcc -O1 -use_fast_math -c header_manipulation.c
nvcc -O3 -use_fast_math -c main.cu
main.cu:1:1: warning: "_LARGEFILE_SOURCE" redefined
In file included from /usr/local/cuda/bin/../include/host_config.h:68,
from /usr/local/cuda/bin/../include/cuda_runtime.h:45,
from <command-line>:0:
/usr/include/features.h:249:1: warning: this is the location of the previous definition
main.cu:2:1: warning: "_LARGEFILE64_SOURCE" redefined
/usr/include/features.h:164:1: warning: this is the location of the previous definition
main.cu(225): error: expression must be a pointer to a complete object type
1 error detected in the compilation of "/tmp/tmpxft_00002531_00000000-4_main.cpp1.ii".
make[1]: *** [main.o] Errore 255
make[1]: uscita dalla directory «/home/marco/NetBeansProjects/migration_cuda»
make: *** [production] Errore 2
The line 225 of main.cu is:
input_2d_trace=(float *)(((void *)input_2d)+input_2d->trace_offset);
If you need any other information ask me
Is this in a device function or a host function? Can you post a simple, concise repro case? It is impossible to say anything based on what you have posted so far.
This kind of problem were both in device and host function.
Fortunately I solved it writing:
input_2d_trace=(float *)(((char *)input_2d)+input_2d->trace_offset);
instead of:
input_2d_trace=(float *)(((void *)input_2d)+input_2d->trace_offset);
I think the problem was the void pointer.