尝试在 CUDA 中运行代码时遇到总线错误

尝试在 CUDA 中运行代码时遇到总线错误

是我遇到此错误时尝试在计算机上运行的代码。

./l
[Vector addition of 10 elements]
Bus error (core dumped)

我试过这个

>>>> nvcc -o l vectorAdd.cu -v 
#$ _SPACE_= 
#$ _CUDART_=cudart
#$ _HERE_=/usr/lib/nvidia-cuda-toolkit/bin
#$ _THERE_=/usr/lib/nvidia-cuda-toolkit/bin
#$ _TARGET_SIZE_=
#$ _TARGET_DIR_=
#$ _TARGET_SIZE_=64
#$ NVVMIR_LIBRARY_DIR=/usr/lib/nvidia-cuda-toolkit/libdevice
#$ PATH=/usr/lib/nvidia-cuda-toolkit/bin:/home/anshuman/Downloads/bin:/home/anshuman/anaconda3/bin:/usr/class/cs143/cool/bin:~/get-shit-done/:/home/anshuman/.local/bin:/home/anshuman/bin:/usr/local/cuda-10.1/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/home/anshuman/Documents/PCAP/.openmpi/bin:/home/anshuman/Documents/PCAP/bin:/usr/local/m4/bin/:/home/anshuman/bin:/usr/local/cuda-10.1/bin:/usr/lib/x86_64-linux-gnu/libcublas.so.10:/usr/local/bin/
#$ LIBRARIES=  -L/usr/lib/x86_64-linux-gnu/stubs
#$ gcc -std=c++14 -D__CUDA_ARCH__=300 -E -x c++  -DCUDA_DOUBLE_MATH_FUNCTIONS -D__CUDACC__ -D__NVCC__  -D"__CUDACC_VER_BUILD__=85" -D"__CUDACC_VER_MINOR__=1" -D"__CUDACC_VER_MAJOR__=9" -include "cuda_runtime.h" -m64 "vectorAdd.cu" > "/tmp/tmpxft_00000213_00000000-8_vectorAdd.cpp1.ii" 
#$ cicc --c++14 --gnu_version=70300 --allow_managed  -arch compute_30 -m64 -ftz=0 -prec_div=1 -prec_sqrt=1 -fmad=1 --include_file_name "tmpxft_00000213_00000000-2_vectorAdd.fatbin.c" -tused -nvvmir-library "/usr/lib/nvidia-cuda-toolkit/libdevice/libdevice.10.bc" --gen_module_id_file --module_id_file_name "/tmp/tmpxft_00000213_00000000-3_vectorAdd.module_id" --orig_src_file_name "vectorAdd.cu" --gen_c_file_name "/tmp/tmpxft_00000213_00000000-5_vectorAdd.cudafe1.c" --stub_file_name "/tmp/tmpxft_00000213_00000000-5_vectorAdd.cudafe1.stub.c" --gen_device_file_name "/tmp/tmpxft_00000213_00000000-5_vectorAdd.cudafe1.gpu"  "/tmp/tmpxft_00000213_00000000-8_vectorAdd.cpp1.ii" -o "/tmp/tmpxft_00000213_00000000-5_vectorAdd.ptx"
#$ ptxas -arch=sm_30 -m64 "/tmp/tmpxft_00000213_00000000-5_vectorAdd.ptx"  -o "/tmp/tmpxft_00000213_00000000-9_vectorAdd.sm_30.cubin" 
#$ fatbinary --create="/tmp/tmpxft_00000213_00000000-2_vectorAdd.fatbin" -64 --cmdline="" "--image=profile=sm_30,file=/tmp/tmpxft_00000213_00000000-9_vectorAdd.sm_30.cubin" "--image=profile=compute_30,file=/tmp/tmpxft_00000213_00000000-5_vectorAdd.ptx" --embedded-fatbin="/tmp/tmpxft_00000213_00000000-2_vectorAdd.fatbin.c" --cuda
#$ rm /tmp/tmpxft_00000213_00000000-2_vectorAdd.fatbin
#$ gcc -std=c++14 -E -x c++ -D__CUDACC__ -D__NVCC__  -D"__CUDACC_VER_BUILD__=85" -D"__CUDACC_VER_MINOR__=1" -D"__CUDACC_VER_MAJOR__=9" -include "cuda_runtime.h" -m64 "vectorAdd.cu" > "/tmp/tmpxft_00000213_00000000-4_vectorAdd.cpp4.ii" 
#$ cudafe++ --c++14 --gnu_version=70300 --allow_managed --m64 --parse_templates --gen_c_file_name "/tmp/tmpxft_00000213_00000000-5_vectorAdd.cudafe1.cpp" --stub_file_name "tmpxft_00000213_00000000-5_vectorAdd.cudafe1.stub.c" --module_id_file_name "/tmp/tmpxft_00000213_00000000-3_vectorAdd.module_id" "/tmp/tmpxft_00000213_00000000-4_vectorAdd.cpp4.ii" 
#$ gcc -std=c++14 -D__CUDA_ARCH__=300 -c -x c++  -DCUDA_DOUBLE_MATH_FUNCTIONS -m64 -o "/tmp/tmpxft_00000213_00000000-10_vectorAdd.o" "/tmp/tmpxft_00000213_00000000-5_vectorAdd.cudafe1.cpp" 
#$ nvlink --arch=sm_30 --register-link-binaries="/tmp/tmpxft_00000213_00000000-6_l_dlink.reg.c"  -m64   -L/usr/lib/x86_64-linux-gnu/stubs -cpu-arch=X86_64 "/tmp/tmpxft_00000213_00000000-10_vectorAdd.o"  -o "/tmp/tmpxft_00000213_00000000-11_l_dlink.sm_30.cubin"
#$ fatbinary --create="/tmp/tmpxft_00000213_00000000-7_l_dlink.fatbin" -64 --cmdline="" -link "--image=profile=sm_30,file=/tmp/tmpxft_00000213_00000000-11_l_dlink.sm_30.cubin" --embedded-fatbin="/tmp/tmpxft_00000213_00000000-7_l_dlink.fatbin.c" 
#$ rm /tmp/tmpxft_00000213_00000000-7_l_dlink.fatbin
#$ gcc -std=c++14 -c -x c++ -DFATBINFILE="\"/tmp/tmpxft_00000213_00000000-7_l_dlink.fatbin.c\"" -DREGISTERLINKBINARYFILE="\"/tmp/tmpxft_00000213_00000000-6_l_dlink.reg.c\"" -I. -D__NV_EXTRA_INITIALIZATION= -D__NV_EXTRA_FINALIZATION=  -D"__CUDACC_VER_BUILD__=85" -

D"__CUDACC_VER_MINOR__=1" -D"__CUDACC_VER_MAJOR__=9" -m64 -o "/tmp/tmpxft_00000213_00000000-12_l_dlink.o" "/usr/lib/nvidia-cuda-toolkit/bin/crt/link.stub" 
#$ g++ -m64 -o "l" -std=c++14 -Wl,--start-group "/tmp/tmpxft_00000213_00000000-12_l_dlink.o" "/tmp/tmpxft_00000213_00000000-10_vectorAdd.o"   -L/usr/lib/x86_64-linux-gnu/stubs -lcudadevrt  -lcudart_static  -lrt -lpthread  -ldl  -Wl,--end-group 

但是,我不太清楚这里出了什么问题。有人能帮忙吗?

nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2017 NVIDIA Corporation
Built on Fri_Nov__3_21:07:56_CDT_2017
Cuda compilation tools, release 9.1, V9.1.85

 nvidia-smi
Sat Apr  6 15:58:15 2019       
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 390.116                Driver Version: 390.116                   |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|===============================+======================+======================|
|   0  GeForce 940MX       Off  | 00000000:01:00.0 Off |                  N/A |
| N/A   51C    P5    N/A /  N/A |    842MiB /  4046MiB |     12%      Default |
+-------------------------------+----------------------+----------------------+

+-----------------------------------------------------------------------------+
| Processes:                                                       GPU Memory |
|  GPU       PID   Type   Process name                             Usage      |
|=============================================================================|
|    0      1341      G   /usr/lib/xorg/Xorg                           293MiB |
|    0      1708      G   /usr/bin/gnome-shell                         311MiB |
|    0      2282      G   ...uest-channel-token=10764068675564210353   181MiB |
|    0     29177      G   ...uest-channel-token=10528584851110459654    52MiB |

我的 GPU 是 940MX,我确信代码没有错,因为我已经在另一台机器上运行过,它执行得非常好。另外,它来自 CUDA 的官方代码库。在网上找东西真的没用,因为大部分都与 Python 和 Tensorflow 有关,而我在这个例子中没有用到它们。不过,Reddit 上还有另一个建议:

很可能是你的电源不够。我在将一些 Torch 深度学习模型移植到工业计算机上时遇到了这个问题。我们用来构建和测试模型的机器上的电源比部署箱中的电源要强大得多,所以我经常看到这个错误。

现在我不太清楚这意味着什么。我有一台 HP Pavilion 笔记本电脑,我一直使用原装充电器和原装电池(去年 11 月因原装电池有缺陷而更换)。这个问题似乎在我尝试升级到 CUDA 10.0 [未成功] 后才开始出现。此外,如果有人对我可以暂时使用的基于云的 GPU 有建议,因为我需要它来完成一个项目。我考虑过 AWS,但那似乎太贵了。

答案1

正如您所说,该问题仅在 CUDA 10.0 安装失败后才出现,这可能意味着此安装未完全撤消,因此现在两个版本的混合版本无法正常工作。

最好卸载除视频驱动程序之外的所有 NVIDIA 产品,清除所有文件夹,然后重新安装 CUDA 9.1。 文档 列出此命令:

sudo /usr/local/cuda-<version>/bin/cuda-uninstaller

在 Windows 上我建议使用卸载程序,例如 Revo Uninstaller 免费软件 来获取所有剩余的碎片,但是在 Linux 上,您可能需要在磁盘上搜索“cuda”子字符串来获取这些剩余的碎片。

答案2

harrymc 说的是正确的,我按照这个步骤操作关联正是要解决这个问题。我想也许 CUDA 10.0 的旧文件可能已损坏,于是我清除了所有内容,包括 9.0 和 10.0,然后重做了一切。

相关内容