Segmentation Fault on cudaMalloc

Hi, I have a Red Hat Linux machine (64 bit) and I have installed the GeForce 9800 GTX+ card (Cuda capable). I installed the Cuda drivers and SDK. I built some of the examples (not all would build). I also created a simple application based on a webinar:

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <cuda.h>

int main()
int dimx = 16;
int num_bytes = dimx*sizeof(int);
int *d_a=0, *h_a=0; // device and host pointers
h_a = (int *)malloc(num_bytes);
printf (“Before cudaMalloc\n”);
cudaMalloc((void **)&d_a, num_bytes);
if (h_a == 0 || d_a == 0)
printf(“Couldn’t allocate memory\n”);
return 1;
cudaMemset(d_a, 0, num_bytes);
cudaMemcpy(h_a, num_bytes, cudaMemcpyDeviceToHost);
for (int i=0; i<dimx; i++)
printf("%d “, h_a[i]);
return 0;

I did a simple build: nvcc

When I run it it prints: Before cudaMalloc
Then segmentation fault.

When I run the examples that compiled I get segmentation fault error as well. They all seem to fault on the cudaMalloc.

Do I need to set any environment variables?

Thanks for any help.

you’re missing a parameter in cudaMemcpy.

I didn’t copy it correctly it was:

cudaMemcpy(h_a, d_a, num_bytes, cudaMemcpyDeviceToHost);

The compiled source code had the correct number of parameters.

I just noticed that the version I downloaded, 2.3 is for Red Hat 5.3, I am running 5.4. I don’t see a newer version for 5.4.

I updated to the beta version and installed the nVidia beta driver to my card as well. The program now works. Now back to learning.


Hey rvcanning, I’m having a similar problem. I’m running on CentOS 5.3 64-bit with a non-CUDA enabled card, so I’m compiling everything in emulation mode. All the examples in the SDK build just fine, but every time I come across a cuda instruction (cudaMalloc, cudaMemCpy, etc.) I get a segfault.

Could you be a bit more specific with how you resolved your problem?

Exactly the same problem… anybody with solution?