Search code examples
luaubuntu-14.04torchluajit

Unable to import (require) 'cutorch' in Torch


I have CUDA 7.5 installed on my machine and installed Torch by following the instructions here. Before installing Torch I upgraded CMake to version 3.2.x.x. Then I installed cutorch and cunn using the following commands:

luarocks install cutorch
luarocks install cunn

While installing cutorch I saw some messages say8ing that CUDA 7.5 was found on my machine. However, I am unable to import cutorch using require 'cotorch and get the following error when I try to run it using the torch (th) interpreter in Terminal:

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  

Then I followed the instructions here to be able to use Eclipse to write Lua/Torch code. There, I get the following error when trying to execute 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

This is however the file libcutorch.so is in the mentioned directory. This also did not help me resolve the issue. Does anyone know should I go about resolving the issue?

When I enter luarocks list I get the followings:

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

Solution

  • Okay, here's how you can resolve the problem (thanks to alban desmaison on Torch7 google group):

    • Make sure you follow all the steps I mentioned in the question in order to make sure CUDA is installed correctly.
    • If you have Theano installed, execute sudo python
    • Then do import theano
    • Then go to CUDA samples folder and make one of the samples (does not matter which one)
    • Then do ./[name_of_the_sample]
    • Then Torch will easily be able use CUDA backend

    If you do not have Theano installed, try running the CUDA samples using sudo. The important step is to be able to run one of the CUDA samples.

    Now you're all set!