C++ cudaMalloc Segmentation fault in nested C code cudaMalloc error in C++ kills C program if nested

I jave a C++ function GPU_init() which is ok if called from C main()

but CUDA dies horribly near first cudaMalloc if it is called from nested C function.

The two calls are identical

[codebox]C++ code

//Host-side interface

uch *d_window;

IPos *d_match;

int *d_len;

unsigned int hTimer; //CUDA timer

void GPU_init(const ulg window_size, const int max_chain_length) {

//use device with highest Gflops/s

cutilSafeCall(cudaSetDevice( cutGetMaxGflopsDeviceId() ));

//Allocate memory

cutilSafeCall( cudaMalloc((void **)&d_window, window_size * sizeof(uch)));

cutilSafeCall( cudaMalloc((void **)&d_match,max_chain_length * sizeof(IPos)));

cutilSafeCall( cudaMalloc((void **)&d_len, max_chain_length * sizeof(int)));

cutilCheckError(cutCreateTimer(&hTimer));

}

[/codebox]

Anyone seen anything similar?

Thanks

Bill

ps: does anyone else find these forums hard to navigate?

The only obvious thing is the function interface declaration. If you want to call C++ functions from C, they should be declared as

extern "C" myfunc(.....)

which will tell the compiler to use strictly C semantics. Otherwise, I have never seen anything like that before.

Dear avidday
Yip using extern “C”
Thanks
Bill