关于为Torch配置CuDNN 7(或6以上版本)

其实不能直接配置CuDNN 7给Torch使用,贫僧在上次博客里面跳过了测试阶段,所以错过了这个bug(所以说测试还是必不可少的啊)。

闲话少说,直接使用比较新的版本但是没在~/.bashrc里面配置好路径会出现下面这样的错误:

/home/ubuntu/torch/install/bin/luajit: /home/ubuntu/torch/install/share/lua/5.1/trepl/init.lua:389: /home/ubuntu/torch/install/share/lua/5.1/trepl/init.lua:389: /home/ubuntu/torch/install/share/lua/5.1/cudnn/ffi.lua:1603: 'libcudnn (R5) not found in library path.
Please install CuDNN from https://developer.nvidia.com/cuDNN
Then make sure files named as libcudnn.so.5 or libcudnn.5.dylib are placed in
your library load path (for example /usr/local/lib , or manually add a path to LD_LIBRARY_PATH)

Alternatively, set the path to libcudnn.so.5 or libcudnn.5.dylib
to the environment variable CUDNN_PATH and rerun torch.
For example: export CUDNN_PATH="/usr/local/cuda/lib64/libcudnn.so.5"
#注意上面这一行,这是程序推荐的问题解决方法
stack traceback:
        [C]: in function 'error'
        /home/ubuntu/torch/install/share/lua/5.1/trepl/init.lua:389: in function 'require'
        neural_style.lua:350: in function 'setup_gpu'
        neural_style.lua:53: in function 'main'
        neural_style.lua:601: in main chunk
        [C]: in function 'dofile'
        ...untu/torch/install/lib/luarocks/rocks/trepl/scm-1/bin/th:150: in main chunk
        [C]: at 0x00405d50
ubuntu@ip-Address:~/neural-style$

就算是按照上面那样配置好(其实改了点,例如贫僧使用的是7版,那么就会改成export CUDNN_PATH="/usr/local/cuda/lib64/libcudnn.so.7),也会出现这样的错误:

Found Environment variable CUDNN_PATH = /usr/local/cuda-9.0/lib64/libcudnn.so.7/home/ubuntu/torch/install/bin/luajit: /home/ubuntu/torch/install/share/lua/5.1/trepl/init.lua:389: /home/ubuntu/torch/install/share/lua/5.1/trepl/init.lua:389: /home/ubuntu/torch/install/share/lua/5.1/cudnn/ffi.lua:1618: These bindings are for CUDNN 5.x (5005 <= cudnn.version > 6000) , while the loaded CuDNN is version: 7003
Are you using an older or newer version of CuDNN?
stack traceback:
        [C]: in function 'error'
        /home/ubuntu/torch/install/share/lua/5.1/trepl/init.lua:389: in function 'require'
        neural_style.lua:350: in function 'setup_gpu'
        neural_style.lua:53: in function 'main'
        neural_style.lua:601: in main chunk
        [C]: in function 'dofile'
        ...untu/torch/install/lib/luarocks/rocks/trepl/scm-1/bin/th:150: in main chunk
        [C]: at 0x00405d50

上面的意思是CuDNN版本不对,本来的要求是在5到6之间的版本(但是贫僧用的是7,太新了对于Torch来说)
最后贫僧终于找到了解决方案,就是在终端运行这个指令:

git clone https://github.com/soumith/cudnn.torch.git -b R7 && cd cudnn.torch && luarocks make cudnn-scm-1.rockspec

其实就是用luarockstorch版cudnn(按贫僧的理解)。这个东东的功能貌似就是给Torch提供一个接口(可能是某种映射之类的)来兼容最新版本(7以上版本)的CuDNN的结构。不管怎么样,这样就可以在Torch里面调用CuDNN了。
测试:

user@server# th
> require 'cudnn'

最后贫僧跑了一个用到cudnn的程序来测试,只是个小项目,其实如果读者有别的测试程序的话也可以用,因为跑这个程序还是比较麻烦的(而且耗时也长的说)。

补充

对了,上面这两个错误都不是贫僧真实遇到的(但是其实差不多),而是来自热心网友ProGamerGov 提供的案例,具体的东东可以在这里看到的说。

你可能感兴趣的:(机器学习,环境配置)