轉載請注明出處:
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/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.
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了,不更新了。重新配置起來太麻煩了。。。