(原)ubuntu16重装显卡驱动后,torch中的问题

转载请注明出处:

http://www.cnblogs.com/darkknightzh/p/6030232.html

参考网址:

https://github.com/torch/cutorch/issues/210

https://github.com/torch/cutorch/issues/425

https://developer.nvidia.com/cuda-downloads

http://tieba.baidu.com/p/4210823766

https://github.com/torch/cutorch

https://github.com/torch/cutorch

https://github.com/torch/cutorch/issues/480

https://github.com/torch/cunn

https://github.com/soumith/cudnn.torch/issues/279

说明:最好直接安装lua5.2,而后torch,cutorch,cunn等都安装新版本的,否则可能有冲突。

 

前几天重新安装了最新的显卡驱动,结果今天使用torch的require ‘cutorch’时,报错(类似下面的信息):

cannot load torch/install/lib/lua/5.1/libcutorch.so

https://github.com/torch/cutorch/issues/210说要重新安装cutorch,使用luarocks install cutorch后,又提示Specify CUDA_TOOLKIT_ROOT_DIR,如下:

网上一搜,https://github.com/torch/cutorch/issues/425说是没有安装cuda。。。

 

1. 由于之前重装显卡驱动时,已经将cuda删除了。因而此时需要重新安装cuda。索性安装cuda8.0。官网https://developer.nvidia.com/cuda-downloads下载ubuntu16.04的版本。之后按照官网说明,在终端中输入:

sudo dpkg -i cuda-repo-ubuntu1604-8-0-local_8.0.44-1_amd64.deb
sudo apt-get update
sudo apt-get install cuda

2. 此时直接在终端中输入nvcc --version时,还是会提示找不到nvcc。http://tieba.baidu.com/p/4210823766中9楼指出,需要添加环境变量。在终端中输入gedit .bashrc,最后添加(最后一个不确定是否需要添加):

export PATH=/usr/local/cuda-8.0/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda-8.0/lib64:$LD_LIBRARY_PATH
export CUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda-8.0:$CUDA_TOOLKIT_ROOT_DIR

重启后,输入nvcc --version,成功

3. 下载cutorch,网址:https://github.com/torch/cutorch

4. 终端定位到该文件夹内,而后输入:

luarocks install rocks/cutorch-1.0-0.rockspec

等待安装完成。

说明:rocks文件夹内有cutorch-1.0-0.rockspec和cutorch-scm-1.rockspec两个文件。如果使用如下命令:

luarocks install rocks/cutorch-scm-1.rockspec

会提示:

1 error detected in the compilation of "/tmp/tmpxft_00000c32_00000000-7_THCTensorMath.cpp1.ii".
CMake Error at THC_generated_THCTensorMath.cu.o.cmake:267 (message):
  Error generating file
  /tmp/luarocks_cutorch-scm-1-1850/cutorch/build/lib/THC/CMakeFiles/THC.dir//./THC_generated_THCTensorMath.cu.o


lib/THC/CMakeFiles/THC.dir/build.make:105: recipe for target 'lib/THC/CMakeFiles/THC.dir/THC_generated_THCTensorMath.cu.o' failed
make[2]: *** [lib/THC/CMakeFiles/THC.dir/THC_generated_THCTensorMath.cu.o] Error 1
make[2]: *** 正在等待未完成的任务....
/tmp/luarocks_cutorch-scm-1-1850/cutorch/lib/THC/THCTensorMathReduce.cuh(471): error: identifier "TH_INDEX_BASE" is undefined

/tmp/luarocks_cutorch-scm-1-1850/cutorch/lib/THC/THCTensorMathReduce.cuh(552): error: identifier "TH_INDEX_BASE" is undefined

2 errors detected in the compilation of "/tmp/tmpxft_00000c45_00000000-5_THCTensorMath2.cpp4.ii".
CMake Error at THC_generated_THCTensorMath2.cu.o.cmake:267 (message):
  Error generating file
  /tmp/luarocks_cutorch-scm-1-1850/cutorch/build/lib/THC/CMakeFiles/THC.dir//./THC_generated_THCTensorMath2.cu.o


lib/THC/CMakeFiles/THC.dir/build.make:112: recipe for target 'lib/THC/CMakeFiles/THC.dir/THC_generated_THCTensorMath2.cu.o' failed
make[2]: *** [lib/THC/CMakeFiles/THC.dir/THC_generated_THCTensorMath2.cu.o] Error 1
/tmp/luarocks_cutorch-scm-1-1850/cutorch/lib/THC/THCTensorMathReduce.cuh(471): error: identifier "TH_INDEX_BASE" is undefined

/tmp/luarocks_cutorch-scm-1-1850/cutorch/lib/THC/THCTensorMathReduce.cuh(552): error: identifier "TH_INDEX_BASE" is undefined

2 errors detected in the compilation of "/tmp/tmpxft_00000cd5_00000000-5_THCTensorMathScan.cpp4.ii".
CMake Error at THC_generated_THCTensorMathScan.cu.o.cmake:267 (message):
  Error generating file
  /tmp/luarocks_cutorch-scm-1-1850/cutorch/build/lib/THC/CMakeFiles/THC.dir//./THC_generated_THCTensorMathScan.cu.o


lib/THC/CMakeFiles/THC.dir/build.make:147: recipe for target 'lib/THC/CMakeFiles/THC.dir/THC_generated_THCTensorMathScan.cu.o' failed
make[2]: *** [lib/THC/CMakeFiles/THC.dir/THC_generated_THCTensorMathScan.cu.o] Error 1
/tmp/luarocks_cutorch-scm-1-1850/cutorch/lib/THC/THCTensorMathReduce.cuh(471): error: identifier "TH_INDEX_BASE" is undefined

/tmp/luarocks_cutorch-scm-1-1850/cutorch/lib/THC/THCTensorMathReduce.cuh(552): error: identifier "TH_INDEX_BASE" is undefined

2 errors detected in the compilation of "/tmp/tmpxft_00000cc9_00000000-5_THCTensorMathReduce.cpp4.ii".
CMake Error at THC_generated_THCTensorMathReduce.cu.o.cmake:267 (message):
  Error generating file
  /tmp/luarocks_cutorch-scm-1-1850/cutorch/build/lib/THC/CMakeFiles/THC.dir//./THC_generated_THCTensorMathReduce.cu.o


lib/THC/CMakeFiles/THC.dir/build.make:140: recipe for target 'lib/THC/CMakeFiles/THC.dir/THC_generated_THCTensorMathReduce.cu.o' failed
make[2]: *** [lib/THC/CMakeFiles/THC.dir/THC_generated_THCTensorMathReduce.cu.o] Error 1
CMakeFiles/Makefile2:172: recipe for target 'lib/THC/CMakeFiles/THC.dir/all' failed
make[1]: *** [lib/THC/CMakeFiles/THC.dir/all] Error 2
Makefile:127: recipe for target 'all' failed
make: *** [all] Error 2

Error: Build error: Failed building.
View Code

https://github.com/torch/cutorch/issues/480指出,需要更新torch,nn,cunn等。懒得更新了,因而就使用老版本的了。

5. 此时再require ‘cutorch’便不会出错。

6. 此时若要使用cunn,还是会报错:

在官网下载cunn:https://github.com/torch/cunn,并安装cunn-1.0-0.rockspec:

luarocks install cunn-1.0-0.rockspec

此处若安装新的cunn-scm-1.rockspec,也会报错:

安装完之后,require ‘cunn’成功。

7. 之后require ‘cudnn’再次遇到问题。重装之后,require时,会提示:

attempt to call field 'hasFastHalfInstructions' (a nil value)

https://github.com/soumith/cudnn.torch/issues/279指出,需要更新lua到5.2。

暂时不使用cndnn了,不更新了。重新配置起来太麻烦了。。。

Ubuntu上安装显卡驱动、CuDNN、CUDA和PyTorch可以按照以下步骤进行: 1. 安装显卡驱动:可以通过以下几种方式安装显卡驱动: - 通过"Software & Updates"工具在“Additional Drivers”选项卡选择一个适用于您的显卡型号的驱动程序,并点击“Apply Changes”进行安装。 - 通过命令行使用`ubuntu-drivers devices`命令查看可用的驱动,然后使用`sudo ubuntu-drivers autoinstall`命令自动安装推荐的驱动。 2. 安装CuDNN:CuDNN是NVIDIA加速库,可提供用于深度学习的GPU加速功能。可以按照以下步骤安装CuDNN: - 前往NVIDIA官方网站,下载适用于您的CUDA版本的CuDNN压缩文件(通常需要注册NVIDIA开发者账号)。 - 将CuDNN压缩文件解压缩到一个合适的位置,例如`~/cuda`文件夹。 - 打开终端,使用`cd`命令进入CuDNN解压缩文件的路径,并执行以下命令安装CuDNN: ``` sudo cp cuda/include/cudnn*.h /usr/local/cuda/include/ sudo cp cuda/lib64/libcudnn* /usr/local/cuda/lib64/ sudo chmod a+r /usr/local/cuda/include/cudnn*.h /usr/local/cuda/lib64/libcudnn* ``` 3. 安装CUDA:CUDA是用于在NVIDIA GPU上进行并行计算的平行计算平台和API。可以按照以下步骤安装CUDA: - 前往NVIDIA官方网站,选择适用于您的显卡和操作系统的CUDA版本,并下载对应的运行文件(通常需要注册NVIDIA开发者账号)。 - 打开终端,使用`cd`命令进入CUDA运行文件所在的目录,并执行以下命令安装CUDA: ``` sudo sh cuda*.run ``` - 执行安装向导的步骤,根据提示进行安装配置,包括选择安装路径和设置环境变量。 - 安装完成后,可以通过执行`nvcc --version`命令验证CUDA的安装情况。 4. 安装PyTorch:PyTorch是一个用于构建深度学习模型的开源Python库。可以按照以下方式安装PyTorch: - 打开终端,执行以下命令安装PyTorch: ``` pip install torch torchvision ``` - 在安装过程,可能需要下载和编译一些依赖项。请耐心等待安装完成。 安装完成后,您可以在Ubuntu上使用显卡驱动、CuDNN、CUDA和PyTorch进行深度学习任务。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值