Seg Fault when calling cudaMalloc! Can not set up structs with pointers inside!

Hi all,

I’m not going to claim to be the best programmer (by a long shot), but I can not figure out what I am doing wrong in my code. I am trying to initialize a variable that is of a struct type, and then initialize the pointers I have inside that struct. I whipped up a test code so I could isolate the effect, and I will post it below:


#include <stdlib.h>

#include <stdio.h>

#include <cuda.h>

using namespace std;

struct test


int a;

int *b;


int main()


test* x;




for (int l=0; l<10; l++)


cout <<"\nx->a= "<<x->a;

for (int l=0; l<10; l++)

	cout <<"\nx->b["<<l<<"]= "<<x->b[l];


test* x_d;




//Would add more once I get past this point!


The terminal output is as follows:

[codebox]nvcc -run

x->a= 2

x->b[0]= 0

x->b[1]= 1

x->b[2]= 2

x->b[3]= 3

x->b[4]= 4

x->b[5]= 5

x->b[6]= 6

x->b[7]= 7

x->b[8]= 8

x->b[9]= 9

Segmentation fault


Thanks for any help you can give, I have been stumped by this for a bit too long now.


p.s. I forgot to mention: I have had no problems running any of the SDK samples, and so I believe the driver/toolkit/sdk are all installed just fine on my PC.

My setup is a core2duo e6600, Ubuntu 9.04, 2gb ram, 8800gts 312mb.


You’re dereferencing x_d, and that obviously won’t work since it’s on the device.

Ugh, yeah. I see what you meant.

I got what I need working now. Thanks for the help!