无法在 Torch 中导入(要求)'cutorch'

Unable to import (require) 'cutorch' in Torch

我在我的机器上安装了 CUDA 7.5,并按照说明安装了 Torch here。在安装 Torch 之前,我将 CMake 升级到版本 3.2.x.x。然后我使用以下命令安装了 cutorchcunn

luarocks install cutorch
luarocks install cunn

在安装 cutorch 时,我看到一些消息说在我的机器上发现了 CUDA 7.5。但是,我无法使用 require 'cotorch 导入 cutorch,当我尝试使用终端中的 torch (th) 解释器 运行 时出现以下错误:

THCudaCheck FAIL file=/tmp/luarocks_cutorch-scm-1-8316/cutorch/lib/THC/THCGeneral.c line=17 error=30 : unknown error
/home/amir/torch/install/share/lua/5.1/trepl/init.lua:384: cuda runtime error (30) : unknown error at /tmp/luarocks_cutorch-scm-1-8316/cutorch/lib/THC/THCGeneral.c:17
stack traceback:
    [C]: in function 'error'
    /home/amir/torch/install/share/lua/5.1/trepl/init.lua:384: in function 'require'
    [string "_RESULT={require "cutorch"}"]:1: in main chunk
    [C]: in function 'xpcall'
    /home/amir/torch/install/share/lua/5.1/trepl/init.lua:651: in function 'repl'
    ...amir/torch/install/lib/luarocks/rocks/trepl/scm-1/bin/th:199: in main chunk
    [C]: at 0x00406670  

然后我按照说明 here 能够使用 Eclipse 编写 Lua/Torch 代码。在那里,我在尝试执行 require 'cutorch':

时收到以下错误
qlua: /home/amir/torch/install/share/lua/5.1/cutorch/init.lua:2: cannot load '/home/amir/torch/install/lib/lua/5.1/libcutorch.so'
stack traceback:
    [C]: at 0x7f05cf9709e0
    [C]: in function 'require'
    /home/amir/torch/install/share/lua/5.1/cutorch/init.lua:2: in main chunk
    [C]: in function 'require'
    /home/amir/workspace/test/src/main.lua:2: in function 'main'
    /home/amir/workspace/test/src/main.lua:6: in main chunk

然而,文件 libcutorch.so 位于上述目录中。 This 也没有帮我解决问题。有谁知道我应该着手解决这个问题吗?

当我输入 luarocks list 时,我得到以下信息:

Installed rocks:
----------------

argcheck
   scm-1 (installed) - /home/amir/torch/install/lib/luarocks/rocks

cudnn
   scm-1 (installed) - /home/amir/torch/install/lib/luarocks/rocks

cunn
   scm-1 (installed) - /home/amir/torch/install/lib/luarocks/rocks

cunnx
   scm-1 (installed) - /home/amir/torch/install/lib/luarocks/rocks

cutorch
   scm-1 (installed) - /home/amir/torch/install/lib/luarocks/rocks

cwrap
   scm-1 (installed) - /home/amir/.luarocks/lib/luarocks/rocks
   scm-1 (installed) - /home/amir/torch/install/lib/luarocks/rocks

dok
   scm-1 (installed) - /home/amir/torch/install/lib/luarocks/rocks

env
   scm-1 (installed) - /home/amir/torch/install/lib/luarocks/rocks

fftw3
   scm-1 (installed) - /home/amir/torch/install/lib/luarocks/rocks

gnuplot
   scm-1 (installed) - /home/amir/torch/install/lib/luarocks/rocks

graph
   scm-1 (installed) - /home/amir/torch/install/lib/luarocks/rocks

graphicsmagick
   1.scm-0 (installed) - /home/amir/torch/install/lib/luarocks/rocks

image
   1.1.alpha-0 (installed) - /home/amir/torch/install/lib/luarocks/rocks

lbase64
   20120820-1 (installed) - /home/amir/torch/install/lib/luarocks/rocks

lua-cjson
   2.1devel-1 (installed) - /home/amir/torch/install/lib/luarocks/rocks

luaffi
   scm-1 (installed) - /home/amir/torch/install/lib/luarocks/rocks

luafilesystem
   1.6.3-1 (installed) - /home/amir/torch/install/lib/luarocks/rocks

luasocket
   3.0rc1-2 (installed) - /home/amir/torch/install/lib/luarocks/rocks

nn
   scm-1 (installed) - /home/amir/torch/install/lib/luarocks/rocks

nngraph
   scm-1 (installed) - /home/amir/torch/install/lib/luarocks/rocks

nnx
   0.1-1 (installed) - /home/amir/torch/install/lib/luarocks/rocks

optim
   1.0.5-0 (installed) - /home/amir/torch/install/lib/luarocks/rocks

paths
   scm-1 (installed) - /home/amir/.luarocks/lib/luarocks/rocks
   scm-1 (installed) - /home/amir/torch/install/lib/luarocks/rocks

penlight
   scm-1 (installed) - /home/amir/torch/install/lib/luarocks/rocks

qtlua
   scm-1 (installed) - /home/amir/torch/install/lib/luarocks/rocks

qttorch
   scm-1 (installed) - /home/amir/torch/install/lib/luarocks/rocks

signal
   scm-1 (installed) - /home/amir/torch/install/lib/luarocks/rocks

sundown
   scm-1 (installed) - /home/amir/torch/install/lib/luarocks/rocks

sys
   1.1-0 (installed) - /home/amir/torch/install/lib/luarocks/rocks

threads
   scm-1 (installed) - /home/amir/torch/install/lib/luarocks/rocks

torch
   scm-1 (installed) - /home/amir/torch/install/lib/luarocks/rocks

trepl
   scm-1 (installed) - /home/amir/torch/install/lib/luarocks/rocks

xlua
   1.0-0 (installed) - /home/amir/torch/install/lib/luarocks/rocks

好的,这是解决问题的方法(感谢 Torch7 google 组上的 alban desmaison):

  • 确保按照我在问题中提到的所有步骤进行操作,以确保正确安装 CUDA。
  • 如果你安装了Theano,执行sudo python
  • 然后import theano
  • 然后转到 CUDA 示例文件夹和 make 其中一个示例(无论哪个)
  • 然后./[name_of_the_sample]
  • 然后 Torch 将可以轻松使用 CUDA 后端

如果您没有安装 Theano,请尝试使用sudo运行安装 CUDA 示例。 重要的步骤 是能够运行 CUDA 样本之一。

大功告成!

尝试sudo bash /torch/update.sh