run hello world segmentation fault

hi all.
I am following the hello world.
#include <stdio.h>

/*

  • A simple introduction to programming in CUDA. This program prints "Hello
  • World from GPU! from 10 CUDA threads running on the GPU.
    */

global void helloFromGPU()
{
printf(“Hello World from GPU!\n”);
}

int main(int argc, char **argv)
{
printf(“Hello World from CPU!\n”);

helloFromGPU<<<1, 10>>>();
cudaDeviceReset();
return 0;

}

I compile it by $nvcc -arch sm_20 -o hello hello.cu
it’s ok. But when I run it with ./hello
it print segmentation fault

my cuda version is 4.0 and gpu is m2070(fermi)

That last cudaDeviceReset(); is a bad idea.

Change it to cudaDeviceSynchronize();

Then try running it with cuda-memcheck:

cuda-memcheck ./hello

This example isn’t really a good starting point for beginners. It has no cuda error checking, so when it doesn’t work, it gives you no information as to why.

I have replace cudaDeviceReset with cudaDeviceSynchronize and run with cuda-memcheck
the output is:
========= CUDA-MEMCHECK
Hello World from CPU!
========= Error: process didn’t terminate successfully
========= No CUDA-MEMCHECK results found

This is what I get on Fedora 20, CUDA 7, Quadro 5000 GPU:

$ cat t728.cu
#include <stdio.h>

/*
* A simple introduction to programming in CUDA. This program prints "Hello
* World from GPU! from 10 CUDA threads running on the GPU.
*/

__global__ void helloFromGPU()
{
printf("Hello World from GPU!\n");
}

int main(int argc, char **argv)
{
printf("Hello World from CPU!\n");

helloFromGPU<<<1, 10>>>();
cudaDeviceSynchronize();
return 0;
}
$ nvcc -o t728 t728.cu
$ cuda-memcheck ./t728
========= CUDA-MEMCHECK
Hello World from CPU!
Hello World from GPU!
Hello World from GPU!
Hello World from GPU!
Hello World from GPU!
Hello World from GPU!
Hello World from GPU!
Hello World from GPU!
Hello World from GPU!
Hello World from GPU!
Hello World from GPU!
========= ERROR SUMMARY: 0 errors
$

Try running the CUDA vectorAdd sample instead. It has proper CUDA error checking. Or google “proper cuda error checking”, take the first hit, and study that to add proper cuda error checking to this code.

I have tried vectoradd sample from https://github.com/pathscale/nvidia_sdk_samples/blob/master/vectorAdd/0_Simple/vectorAdd/vectorAdd.cu

it still the same error:
cuda-memcheck ./add
========= CUDA-MEMCHECK
[Vector addition of 50000 elements]
========= Error: process didn’t terminate successfully
========= No CUDA-MEMCHECK results found

Something is wrong with your setup. What happens if you run

nvidia-smi

?

NVIDIA: could not open the device file /dev/nvidiactl (No such file or directory).
Nvidia-smi has failed because it couldn’t communicate with NVIDIA driver. Make sure that latest NVIDIA driver is installed and running.

it seems something wrong. I will ask adminisrator for help