# run hello world segmentation fault

**URL:** <https://forums.developer.nvidia.com/t/run-hello-world-segmentation-fault/37611>\
**Category:** CUDA Setup and Installation\
**Created:** [April 14, 2015, 2:10pm UTC](https://forums.developer.nvidia.com/t/run-hello-world-segmentation-fault/37611 "2015-04-14T14:10:30Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![fancyerii](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@fancyerii](https://forums.developer.nvidia.com/u/fancyerii)\
**Post date:** [April 14, 2015, 2:10pm UTC](https://forums.developer.nvidia.com/t/run-hello-world-segmentation-fault/37611/1 "2015-04-14T14:10:30Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![Robert\_Crovella](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/robert_crovella/32/14043_2.png) [@Robert\_Crovella](https://forums.developer.nvidia.com/u/Robert_Crovella)\
**Post date:** [April 14, 2015, 4:00pm UTC](https://forums.developer.nvidia.com/t/run-hello-world-segmentation-fault/37611/2 "2015-04-14T16:00:55Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![fancyerii](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@fancyerii](https://forums.developer.nvidia.com/u/fancyerii)\
**Post date:** [April 15, 2015, 2:09am UTC](https://forums.developer.nvidia.com/t/run-hello-world-segmentation-fault/37611/3 "2015-04-15T02:09:56Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Robert\_Crovella](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/robert_crovella/32/14043_2.png) [@Robert\_Crovella](https://forums.developer.nvidia.com/u/Robert_Crovella)\
**Post date:** [April 15, 2015, 2:24am UTC](https://forums.developer.nvidia.com/t/run-hello-world-segmentation-fault/37611/4 "2015-04-15T02:24:35Z")

</div>

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

```auto
$ 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.

---

<div class="post-metadata">

**Author:** ![fancyerii](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@fancyerii](https://forums.developer.nvidia.com/u/fancyerii)\
**Post date:** [April 15, 2015, 3:26am UTC](https://forums.developer.nvidia.com/t/run-hello-world-segmentation-fault/37611/5 "2015-04-15T03:26:21Z")

</div>

I have tried vectoradd sample from [https://github.com/pathscale/nvidia\_sdk\_samples/blob/master/vectorAdd/0\_Simple/vectorAdd/vectorAdd.cu](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

---

<div class="post-metadata">

**Author:** ![Robert\_Crovella](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/robert_crovella/32/14043_2.png) [@Robert\_Crovella](https://forums.developer.nvidia.com/u/Robert_Crovella)\
**Post date:** [April 15, 2015, 3:48am UTC](https://forums.developer.nvidia.com/t/run-hello-world-segmentation-fault/37611/6 "2015-04-15T03:48:00Z")

</div>

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

nvidia-smi

?

---

<div class="post-metadata">

**Author:** ![fancyerii](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@fancyerii](https://forums.developer.nvidia.com/u/fancyerii)\
**Post date:** [April 15, 2015, 9:54am UTC](https://forums.developer.nvidia.com/t/run-hello-world-segmentation-fault/37611/7 "2015-04-15T09:54:42Z")

</div>

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
