Ubuntu 14.04 LTS,32-bit安装Torch7

环境:

主机系统:windows 10,64-bit
虚拟机:VMware Worksation 12.5.0
虚拟系统:ubuntu 14.04 LTS,32-bit

官网

先给出官网的安装步骤:

# in a terminal, run the commands WITHOUT sudo
git clone https://github.com/torch/distro.git ~/torch --recursive
cd ~/torch
bash install-deps
./install.sh
source ~/.bashrc

然后下面是自己的安装过程,包括在安装过程中遇到的问题以及解决办法,希望对读者有所帮助。

Step1:

由于是刚安装的虚拟机,我们需要先安装git:sudo apt-get install git
然后运行:git clone https://github.com/torch/distro.git ~/torch --recursive
这一步若有问题的话,多半是网络问题,多试几次。

Step2:(OpenBLAS could not be compiled)

然后进入torch目录:cd ~/torch
安装基础包:bash install-deps
这个时候出现了下面的问题:

ar: strmm_kernel_LN.o: No such file or directory
make[1]: *** [libs] Error 1
make[1]: Leaving directory `/tmp/OpenBLAS/kernel'
make: *** [libs] Error 1
Error. OpenBLAS could not be compiled

解决方法

sudo apt-get install vim  #安装过vim的忽略此命令
vim ~/torch/install-deps

这时你会看见(15-19行):

if [ $(getconf _NPROCESSORS_CONF) == 1 ]; then
    make NO_AFFINITY=1 USE_OPENMP=0 USE_THREAD=0
else
    make NO_AFFINITY=1 USE_OPENMP=1
fi

键入i进入插入模式,在make语句后面添加BINARY=32,修改后结果如下:

if [ $(getconf _NPROCESSORS_CONF) == 1 ]; then
    make NO_AFFINITY=1 USE_OPENMP=0 USE_THREAD=0 BINARY=32
else
    make NO_AFFINITY=1 USE_OPENMP=1 BINARY=32
fi

修改完成后,按下ESC,键入:wq保存退出,重新执行bash instal-deps即可完成安装:

···
Generating OpenBLASConfig.cmake in /opt/OpenBLAS/lib/cmake/openblas
Generating OpenBLASConfigVersion.cmake in /opt/OpenBLAS/lib/cmake/openblas
Install OK!
make[1]: Leaving directory `/tmp/OpenBLAS'
==> Torch7's dependencies have been installed

相关链接1

https://github.com/xianyi/OpenBLAS/issues/657
https://github.com/xianyi/OpenBLAS/issues/1106
OpenBLAS编译和安装简介

Step3:(inconsistent operand constraints in an 'asm')

安装LuaJIT、LuaRocks等包:./install.sh
出现错误如下:

···
Scanning dependencies of target TH
[  2%] Building C object lib/TH/CMakeFiles/TH.dir/THGeneral.c.o
[  5%] Building C object lib/TH/CMakeFiles/TH.dir/THHalf.c.o
[  8%] Building C object lib/TH/CMakeFiles/TH.dir/THAllocator.c.o
[ 11%] Building C object lib/TH/CMakeFiles/TH.dir/THStorage.c.o
[ 14%] Building C object lib/TH/CMakeFiles/TH.dir/THTensor.c.o
[ 17%] Building C object lib/TH/CMakeFiles/TH.dir/THBlas.c.o
[ 20%] Building C object lib/TH/CMakeFiles/TH.dir/THLapack.c.o
[ 22%] Building C object lib/TH/CMakeFiles/TH.dir/THLogAdd.c.o
[ 25%] Building C object lib/TH/CMakeFiles/TH.dir/THRandom.c.o
[ 28%] Building C object lib/TH/CMakeFiles/TH.dir/THFile.c.o
[ 31%] Building C object lib/TH/CMakeFiles/TH.dir/THDiskFile.c.o
[ 34%] Building C object lib/TH/CMakeFiles/TH.dir/THMemoryFile.c.o
[ 37%] Building C object lib/TH/CMakeFiles/TH.dir/THAtomic.c.o
[ 40%] Building C object lib/TH/CMakeFiles/TH.dir/THVector.c.o
In file included from /home/yang/torch/pkg/torch/lib/TH/THVector.c:3:0:
/home/yang/torch/pkg/torch/lib/TH/generic/THVectorDispatch.c: In function ‘THFloatVector_vectorDispatchInit’:
/home/yang/torch/pkg/torch/lib/TH/generic/simd/simd.h:108:3: error: inconsistent operand constraints in an ‘asm’
   asm volatile ( "cpuid\n\t"
   ^
/home/yang/torch/pkg/torch/lib/TH/generic/simd/simd.h:108:3: error: inconsistent operand constraints in an ‘asm’
   asm volatile ( "cpuid\n\t"
   ^
make[2]: *** [lib/TH/CMakeFiles/TH.dir/THVector.c.o] Error 1
make[1]: *** [lib/TH/CMakeFiles/TH.dir/all] Error 2
make: *** [all] Error 2

Error: Build error: Failed building.

解决方法
ubuntu 14.04默认gcc版本是gcc-4.8,需要升级至gcc-5:

sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update
sudo apt-get install gcc-5 g++-5
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-5 60 --slave /usr/bin/g++ g++ /usr/bin/g++-5

gcc升级后,重新执行./install.sh即可完成安装:

···
Do you want to automatically prepend the Torch install location
to PATH and LD_LIBRARY_PATH in your /home/yang/.bashrc? (yes/no)
[yes] >>> 

键入yes后,刷新你的环境变量:source ~/.bashrc
再键入th命令,可看见:

yang@ubuntu:~/torch$ th
 
  ______             __   |  Torch7 
 /_  __/__  ________/ /   |  Scientific computing for Lua. 
  / / / _ \/ __/ __/ _ \  |  Type ? for help 
 /_/  \___/_/  \__/_//_/  |  https://github.com/torch 
                          |  http://torch.ch 
	
th> 

恭喜你,安装成功!

相关链接2

inconsistent operand constraints in an 'asm'
Ubuntu升级GCC版本

posted @ 2017-05-09 15:20  冬幕丶  阅读(675)  评论(0编辑  收藏  举报