(记录于2019.01.17,该解决方案并不一定支持旧版本或更新版本)
条件:Ubuntu 18.04系统、CUDA 10.0已安装。
过程:依照Torch7官方指引(Torch | Getting started with Torch),在目标安装目录下依次运行:
$ git clone https://github.com/torch/distro.git ~/torch --recursive
$ cd ~/torch
$ bash install-deps
$ ./install.sh
1)运行(如果没有安装git先安装)
$ git clone https://github.com/torch/distro.git ~/torch --recursive
$ cd ~/torch
2)依据 ubuntu18.04安装torch 遇到的几个Error处理
- 2.1)修改文件install-deps,将sudo apt-get install -y python-software-properties替换成sudo apt-get install -y software-properties-common
- 2.2)运行
$ git config --global url."https://".insteadOf git://
3)运行
$ bash install-deps
4)依据 Fails to build against CUDA 10 · Issue #834 · torch/cutorch
- 4.1)Remove FindCUDA.cmake
$ cd ~/torch
$ rm -fr cmake/3.6/Modules/FindCUDA*
- 4.2)在extra/cutorch中新建文件atomic.patch并添加内容:
diff --git a/lib/THC/THCAtomics.cuh b/lib/THC/THCAtomics.cuh
index 400875c..ccb7a1c 100644
--- a/lib/THC/THCAtomics.cuh
+++ b/lib/THC/THCAtomics.cuh
@@ -94,6 +94,7 @@ static inline __device__ void atomicAdd(long *address, long val) {
}
#ifdef CUDA_HALF_TENSOR
+#if !(__CUDA_ARCH__ >= 700 || !defined(__CUDA_ARCH__) )
static inline __device__ void atomicAdd(half *address, half val) {
unsigned int * address_as_ui =
(unsigned int *) ((char *)address - ((size_t)address & 2));
@@ -117,6 +118,7 @@ static inline __device__ void atomicAdd(half *address, half val) {
} while (assumed != old);
}
#endif
+#endif
然后运行
$ cd extra/cutorch
$ patch -p1 < atomic.patch
$ export TORCH_NVCC_FLAGS="-D__CUDA_NO_HALF_OPERATORS__"
5)运行
$ ./install.sh
$ cd ~
$ source .bashrc
6)根据需要安装其他包,如:
luarocks install nn