Python中的numba调用cuda报错的解决方法

Python中的numba调用cuda报错如下:

    ........

    numba.cuda.cudadrv.error.NvvmSupportError: libNVVM cannot be found. Do `conda install cudatoolkit`:

    /usr/local/cuda10.0/nvvm/lib64/libnvvm.so: cannot open shared object file: No such file or directory

    Exception ignored in: >

    Traceback (most recent call last):

    File "/usr/local/lib/python3.5/dist-packages/numba/cuda/cudadrv/nvvm.py", line 152, in __del__

    driver = NVVM()

    File "/usr/local/lib/python3.5/dist-packages/numba/cuda/cudadrv/nvvm.py", line 116, in __new__

    raise NvvmSupportError(errmsg % e)

    numba.cuda.cudadrv.error.NvvmSupportError: libNVVM cannot be found. Do `conda install cudatoolkit`:

    /usr/local/cuda10.0/nvvm/lib64/libnvvm.so: cannot open shared object file: No such file or directory

        原因就是找不到cuda

 

解决方法:

1、首先查看NVIDIA驱动和cuda是否安装好!

        终端命令如下:

       查看nivida驱动版本

               sudo dpkg --list | grep nvidia-*

       查看cuda版本

              nvcc -V

       安装成功则会显示如下结果:

nvcc: NVIDIA (R) Cuda compiler driver

Copyright (c) 2005-2018 NVIDIA Corporation

Built on Sat_Aug_25_21:08:01_CDT_2018

Cuda compilation tools, release 10.0, V10.0.130

     或者

             cat /usr/local/cuda/version.txt

                       CUDA Version 10.0.130

          (查看cudnn版本: cat /usr/local/cuda/include/cudnn.h | grep CUDNN_MAJOR -A 2)

 

2、设置cuda的环境变量,在/etc/profile文件中最下面添加如下变量:

    export CUDA_HOME=/usr/local/cuda-10.0

    export PATH=/usr/local/cuda-10.0/bin:$PATH

    export LD_LIBRARY_PATH=/usr/local/cuda-10.0/lib64:$LD_LIBRARY_PATH


    export NUMBAPRO_NVVM=/usr/local/cuda-10.0/nvvm/lib64/libnvvm.so

    export NUMBAPRO_LIBDEVICE=/usr/local/cuda-10.0/nvvm/libdevice/

        添加完环境变量后,重启电脑,仍旧会报错,依旧找不到libnvvm.so文件

        用ll命令:ll /usr/local/cuda10.0/nvvm/lib64/libnvvm.so 显示:

    ls: cannot access '/usr/local/cuda10.0/nvvm/lib64/libnvvm.so': No such file or directory

        显然该路径下并没有该文件,

        注意报错的提示:

    /usr/local/cuda10.0/nvvm/lib64/libnvvm.so: cannot open shared object file: No such file or directory

        这里numba寻找的路径是/usr/local/cuda10.0....,而装cuda时nvvm/lib64/libnvvm.so文件是在/usr/local/cuda-10.0....,显然是找不到的,故仍旧会报错,

        ll /usr/local/cuda-10.0/nvvm/lib64就能找到libnvvm.so文件了。由于这里的路径名字cuda10.0和cuda-10.0的不一致,导致错误,解决的办法是在/usr/local/建立一个软链接cuda10.0,让该链接文件指向cuda-10.0文件即可,即:

    sudo ln -r cuda-10.0 cuda10.0

        再运行程序不再报错!

你可能感兴趣的:(python语言)