It’s hard to say what is going on, but if you are segfaulting, you’ll first want to debug on the CPU:
- Compile your code in debug mode (-g) and run in gdb so you can see which line is segfaulting.
- Run your code with valgrind to catch memory access errors on the CPU. The segfault might be caused by an earlier problem.
If it looks like your segfault is caused by bad results from CUDA, then you should:
- Make sure you check the return codes from all CUDA functions. If they are not cudaSuccess, print out the error and quit immediately. If your segfault is caused by incorrectly using data from a failed kernel, this might catch that.
- Run your program with cuda-memcheck to catch device memory accesses that are out-of-bounds, which can also lead to bad results.