cudaMalloc error

Hello, I’m trying to make a simple Cuda program in Linux, using autotools (as instructions found in the forum), but I’m having a segmentation fault when I try to use cudaMalloc, here’s the snippet of code that’s giving me error:

size_t popMemSize = sizeof(Individual)*POPULATION;

  size_t latMemSize = sizeof(Lattice)*MAX_LATS;

  Lattice *d_lat=NULL;

  Individual *d_pop=NULL;

  cudaError_t d_error = cudaSuccess;

//Allocating device memory

  d_error = cudaMalloc((void**)&d_pop,popMemSize);

  printError(stderr,d_error,"cudaMalloc");

  d_error = cudaMalloc((void**)&d_lat,latMemSize);

  printError(stderr,d_error,"cudaMalloc");

And the structures I’m trying to allocate:

#define LAT_SIZE 149

#define RULE_SIZE 128

#define POPULATION 100

#define MAX_LATS 100

typedef struct Lattice

{

  char cells[LAT_SIZE];

  unsigned int density;

}Lattice;

typedef struct Individual

{

  char rule[RULE_SIZE+1];

  unsigned int fitness;

}Individual;

This is the error:

Allocating population on device...

*** glibc detected *** src/cuCga: free(): invalid next size (fast): 0x0000000000952500 ***

======= Backtrace: =========

/lib64/libc.so.6(+0x76196)[0x7f4c0cd36196]

/lib64/libc.so.6(cfree+0x6c)[0x7f4c0cd3c3dc]

/lib64/ld-linux-x86-64.so.2(+0x638b)[0x7f4c1169e38b]

/lib64/ld-linux-x86-64.so.2(+0x837a)[0x7f4c116a037a]

/lib64/ld-linux-x86-64.so.2(+0x132d9)[0x7f4c116ab2d9]

/lib64/ld-linux-x86-64.so.2(+0xe826)[0x7f4c116a6826]

/lib64/ld-linux-x86-64.so.2(+0x12ce7)[0x7f4c116aace7]

/lib64/libdl.so.2(+0xf36)[0x7f4c0cabcf36]

/lib64/ld-linux-x86-64.so.2(+0xe826)[0x7f4c116a6826]

/lib64/libdl.so.2(+0x127c)[0x7f4c0cabd27c]

/lib64/libdl.so.2(dlopen+0x31)[0x7f4c0cabceb1]

/usr/local/cuda/lib64/libcudart.so.2(+0x8c31)[0x7f4c11460c31]

/usr/local/cuda/lib64/libcudart.so.2(+0x31124)[0x7f4c11489124]

/usr/local/cuda/lib64/libcudart.so.2(+0x315df)[0x7f4c114895df]

/usr/local/cuda/lib64/libcudart.so.2(cudaMalloc+0x2e)[0x7f4c1146e48e]

src/cuCga[0x401320]

src/cuCga[0x400e1f]

/lib64/libc.so.6(__libc_start_main+0xfd)[0x7f4c0ccdeb6d]

src/cuCga[0x400ca9]

======= Memory map: ========

00400000-00404000 r-xp 00000000 08:23 2225626							/home/zarnick/programacao/cuda/cuCga/src/cuCga

00603000-00604000 rw-p 00003000 08:23 2225626							/home/zarnick/programacao/cuda/cuCga/src/cuCga

0094b000-0096c000 rw-p 00000000 00:00 0								  [heap]

7f4c08000000-7f4c08021000 rw-p 00000000 00:00 0

7f4c08021000-7f4c0c000000 ---p 00000000 00:00 0

7f4c0c483000-7f4c0c497000 r-xp 00000000 08:22 195450					 /usr/lib64/libz.so.1.2.3

7f4c0c497000-7f4c0c696000 ---p 00014000 08:22 195450					 /usr/lib64/libz.so.1.2.3

7f4c0c696000-7f4c0c697000 rw-p 00013000 08:22 195450					 /usr/lib64/libz.so.1.2.3

7f4c0c697000-7f4c0c69e000 r-xp 00000000 08:22 26258					  /lib64/librt-2.11.1.so

7f4c0c69e000-7f4c0c89d000 ---p 00007000 08:22 26258					  /lib64/librt-2.11.1.so

7f4c0c89d000-7f4c0c89e000 r--p 00006000 08:22 26258					  /lib64/librt-2.11.1.so

7f4c0c89e000-7f4c0c89f000 rw-p 00007000 08:22 26258					  /lib64/librt-2.11.1.so

7f4c0c89f000-7f4c0c8b6000 r-xp 00000000 08:22 26142					  /lib64/libpthread-2.11.1.so

7f4c0c8b6000-7f4c0cab6000 ---p 00017000 08:22 26142					  /lib64/libpthread-2.11.1.so

7f4c0cab6000-7f4c0cab7000 r--p 00017000 08:22 26142					  /lib64/libpthread-2.11.1.so

7f4c0cab7000-7f4c0cab8000 rw-p 00018000 08:22 26142					  /lib64/libpthread-2.11.1.so

7f4c0cab8000-7f4c0cabc000 rw-p 00000000 00:00 0

7f4c0cabc000-7f4c0cabe000 r-xp 00000000 08:22 26263					  /lib64/libdl-2.11.1.so

7f4c0cabe000-7f4c0ccbe000 ---p 00002000 08:22 26263					  /lib64/libdl-2.11.1.so

7f4c0ccbe000-7f4c0ccbf000 r--p 00002000 08:22 26263					  /lib64/libdl-2.11.1.so

7f4c0ccbf000-7f4c0ccc0000 rw-p 00003000 08:22 26263					  /lib64/libdl-2.11.1.so

7f4c0ccc0000-7f4c0ce28000 r-xp 00000000 08:22 19013					  /lib64/libc-2.11.1.so

7f4c0ce28000-7f4c0d027000 ---p 00168000 08:22 19013					  /lib64/libc-2.11.1.so

7f4c0d027000-7f4c0d02b000 r--p 00167000 08:22 19013					  /lib64/libc-2.11.1.so

7f4c0d02b000-7f4c0d02c000 rw-p 0016b000 08:22 19013					  /lib64/libc-2.11.1.so

7f4c0d02c000-7f4c0d031000 rw-p 00000000 00:00 0

7f4c0d031000-7f4c0d047000 r-xp 00000000 08:22 27934					  /usr/lib64/libgcc_s.so.1

7f4c0d047000-7f4c0d247000 ---p 00016000 08:22 27934					  /usr/lib64/libgcc_s.so.1

7f4c0d247000-7f4c0d248000 rw-p 00016000 08:22 27934					  /usr/lib64/libgcc_s.so.1

7f4c0d248000-7f4c0d335000 r-xp 00000000 08:22 36803					  /usr/lib64/libstdc++.so.6.0.13

7f4c0d335000-7f4c0d535000 ---p 000ed000 08:22 36803					  /usr/lib64/libstdc++.so.6.0.13

7f4c0d535000-7f4c0d53c000 r--p 000ed000 08:22 36803					  /usr/lib64/libstdc++.so.6.0.13

7f4c0d53c000-7f4c0d53e000 rw-p 000f4000 08:22 36803					  /usr/lib64/libstdc++.so.6.0.13

7f4c0d53e000-7f4c0d553000 rw-p 00000000 00:00 0

7f4c0d553000-7f4c0d5d5000 r-xp 00000000 08:22 19018					  /lib64/libm-2.11.1.so

7f4c0d5d5000-7f4c0d7d4000 ---p 00082000 08:22 19018					  /lib64/libm-2.11.1.so

7f4c0d7d4000-7f4c0d7d5000 r--p 00081000 08:22 19018					  /lib64/libm-2.11.1.so

7f4c0d7d5000-7f4c0d7d6000 rw-p 00082000 08:22 19018					  /lib64/libm-2.11.1.so

7f4c0d7d6000-7f4c0de5b000 r-xp 00000000 08:22 19003					  /usr/lib64/libcuda.so.195.30

7f4c0de5b000-7f4c0df5a000 ---p 00685000 08:22 19003					  /usr/lib64/libcuda.so.195.30

7f4c0df5a000-7f4c0dfef000 rw-p 00684000 08:22 19003					  /usr/lib64/libcuda.so.195.30

7f4c0dfef000-7f4c11458000 rw-p 00000000 00:00 0

7f4c11458000-7f4c11496000 r-xp 00000000 08:22 1444127					/usr/local/cuda/lib64/libcudart.so.2.3

7f4c11496000-7f4c11696000 ---p 0003e000 08:22 1444127					/usr/local/cuda/lib64/libcudart.so.2.3

7f4c11696000-7f4c11697000 r--p 0003e000 08:22 1444127					/usr/local/cuda/lib64/libcudart.so.2.3

7f4c11697000-7f4c11698000 rw-p 0003f000 08:22 1444127					/usr/local/cuda/lib64/libcudart.so.2.3

7f4c11698000-7f4c116b8000 r-xp 00000000 08:22 26285					  /lib64/ld-2.11.1.so

7f4c1187b000-7f4c11882000 rw-p 00000000 00:00 0

7f4c118b6000-7f4c118b7000 rw-p 00000000 00:00 0

7f4c118b7000-7f4c118b8000 r--p 0001f000 08:22 26285					  /lib64/ld-2.11.1.so

7f4c118b8000-7f4c118b9000 rw-p 00020000 08:22 26285					  /lib64/ld-2.11.1.so

7f4c118b9000-7f4c118ba000 rw-p 00000000 00:00 0

7fff60f3e000-7fff60f53000 rw-p 00000000 00:00 0						  [stack]

7fff60fff000-7fff61000000 r-xp 00000000 00:00 0						  [vdso]

ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0				  [vsyscall]

Aborted

Thinking it could be the size I was trying to allocate, I reduced the values, but had no luck, any tips?

Thanks.