Install from source fails on Ubuntu 18.04

Hi, I saw that the precompiled binaries dropped support for my (older) GPU and read that I need to compile from source. I’m relatively new to installing large projects from source and I’ve hit a roadblock. After installing cuda and cudnn and following the provided instructions found on pytorch.org I’m failing the build process with the following output. Any help would be very much appreciated.

running install
running build_deps
+ WITH_CUDA=0
+ [[ --with-cuda == \-\-\w\i\t\h\-\c\u\d\a ]]
+ WITH_CUDA=1
+ shift
+ WITH_NNPACK=0
+ [[ --with-nnpack == \-\-\w\i\t\h\-\n\n\p\a\c\k ]]
+ WITH_NNPACK=1
+ shift
+ WITH_MKLDNN=0
+ [[ nccl == \-\-\w\i\t\h\-\m\k\l\d\n\n ]]
+ WITH_GLOO_IBVERBS=0
+ [[ nccl == \-\-\w\i\t\h\-\g\l\o\o\-\i\b\v\e\r\b\s ]]
+ WITH_DISTRIBUTED_MW=0
+ [[ nccl == \-\-\w\i\t\h\-\d\i\s\t\r\i\b\u\t\e\d\-\m\w ]]
+ CMAKE_INSTALL='make install'
+ USER_CFLAGS=
+ USER_LDFLAGS=
+ [[ -n '' ]]
+ [[ -n '' ]]
+ [[ -n '' ]]
++ dirname tools/build_pytorch_libs.sh
+ cd tools/..
+++ pwd
++ printf '%q\n' /home/kevin/pytorch
+ PWD=/home/kevin/pytorch
+ BASE_DIR=/home/kevin/pytorch
+ TORCH_LIB_DIR=/home/kevin/pytorch/torch/lib
+ INSTALL_DIR=/home/kevin/pytorch/torch/lib/tmp_install
+ THIRD_PARTY_DIR=/home/kevin/pytorch/third_party
+ CMAKE_VERSION=cmake
+ C_FLAGS=' -DTH_INDEX_BASE=0 -I"/home/kevin/pytorch/torch/lib/tmp_install/include"   -I"/home/kevin/pytorch/torch/lib/tmp_install/include/TH" -I"/home/kevin/pytorch/torch/lib/tmp_install/include/THC"   -I"/home/kevin/pytorch/torch/lib/tmp_install/include/THS" -I"/home/kevin/pytorch/torch/lib/tmp_install/include/THCS"   -I"/home/kevin/pytorch/torch/lib/tmp_install/include/THNN" -I"/home/kevin/pytorch/torch/lib/tmp_install/include/THCUNN"'
+ C_FLAGS=' -DTH_INDEX_BASE=0 -I"/home/kevin/pytorch/torch/lib/tmp_install/include"   -I"/home/kevin/pytorch/torch/lib/tmp_install/include/TH" -I"/home/kevin/pytorch/torch/lib/tmp_install/include/THC"   -I"/home/kevin/pytorch/torch/lib/tmp_install/include/THS" -I"/home/kevin/pytorch/torch/lib/tmp_install/include/THCS"   -I"/home/kevin/pytorch/torch/lib/tmp_install/include/THNN" -I"/home/kevin/pytorch/torch/lib/tmp_install/include/THCUNN" -DOMPI_SKIP_MPICXX=1'
+ LDFLAGS='-L"/home/kevin/pytorch/torch/lib/tmp_install/lib" '
+ LD_POSTFIX=.so.1
+ LD_POSTFIX_UNVERSIONED=.so
++ uname
+ [[ Linux == \D\a\r\w\i\n ]]
+ LDFLAGS='-L"/home/kevin/pytorch/torch/lib/tmp_install/lib"  -Wl,-rpath,$ORIGIN'
+ CPP_FLAGS=' -std=c++11 '
+ GLOO_FLAGS=
+ THD_FLAGS=
+ NCCL_ROOT_DIR=/home/kevin/pytorch/torch/lib/tmp_install
+ [[ 1 -eq 1 ]]
+ GLOO_FLAGS='-DUSE_CUDA=1 -DNCCL_ROOT_DIR=/home/kevin/pytorch/torch/lib/tmp_install'
+ [[ 0 -eq 1 ]]
+ [[ 0 -eq 1 ]]
+ CWRAP_FILES='/home/kevin/pytorch/torch/lib/ATen/Declarations.cwrap;/home/kevin/pytorch/torch/lib/THNN/generic/THNN.h;/home/kevin/pytorch/torch/lib/THCUNN/generic/THCUNN.h;/home/kevin/pytorch/torch/lib/ATen/nn.yaml'
+ CUDA_NVCC_FLAGS=' -DTH_INDEX_BASE=0 -I"/home/kevin/pytorch/torch/lib/tmp_install/include"   -I"/home/kevin/pytorch/torch/lib/tmp_install/include/TH" -I"/home/kevin/pytorch/torch/lib/tmp_install/include/THC"   -I"/home/kevin/pytorch/torch/lib/tmp_install/include/THS" -I"/home/kevin/pytorch/torch/lib/tmp_install/include/THCS"   -I"/home/kevin/pytorch/torch/lib/tmp_install/include/THNN" -I"/home/kevin/pytorch/torch/lib/tmp_install/include/THCUNN" -DOMPI_SKIP_MPICXX=1'
+ [[ '' -eq 1 ]]
+ '[' -z 4 ']'
+ BUILD_TYPE=Release
+ [[ -n '' ]]
+ [[ -n '' ]]
+ echo 'Building in Release mode'
Building in Release mode
+ mkdir -p torch/lib/tmp_install
+ for arg in "$@"
+ [[ nccl == \n\c\c\l ]]
+ pushd /home/kevin/pytorch/third_party
~/pytorch/third_party ~/pytorch
+ build_nccl
+ mkdir -p build/nccl
+ pushd build/nccl
~/pytorch/third_party/build/nccl ~/pytorch/third_party ~/pytorch
+ cmake ../../nccl -DCMAKE_MODULE_PATH=/home/kevin/pytorch/cmake/FindCUDA -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/home/kevin/pytorch/torch/lib/tmp_install '-DCMAKE_C_FLAGS= -DTH_INDEX_BASE=0 -I"/home/kevin/pytorch/torch/lib/tmp_install/include"   -I"/home/kevin/pytorch/torch/lib/tmp_install/include/TH" -I"/home/kevin/pytorch/torch/lib/tmp_install/include/THC"   -I"/home/kevin/pytorch/torch/lib/tmp_install/include/THS" -I"/home/kevin/pytorch/torch/lib/tmp_install/include/THCS"   -I"/home/kevin/pytorch/torch/lib/tmp_install/include/THNN" -I"/home/kevin/pytorch/torch/lib/tmp_install/include/THCUNN" -DOMPI_SKIP_MPICXX=1 ' '-DCMAKE_CXX_FLAGS= -DTH_INDEX_BASE=0 -I"/home/kevin/pytorch/torch/lib/tmp_install/include"   -I"/home/kevin/pytorch/torch/lib/tmp_install/include/TH" -I"/home/kevin/pytorch/torch/lib/tmp_install/include/THC"   -I"/home/kevin/pytorch/torch/lib/tmp_install/include/THS" -I"/home/kevin/pytorch/torch/lib/tmp_install/include/THCS"   -I"/home/kevin/pytorch/torch/lib/tmp_install/include/THNN" -I"/home/kevin/pytorch/torch/lib/tmp_install/include/THCUNN" -DOMPI_SKIP_MPICXX=1  -std=c++11  ' -DCMAKE_SHARED_LINKER_FLAGS=
-- The C compiler identification is GNU 7.3.0
-- The CXX compiler identification is GNU 7.3.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Looking for pthread_create
-- Looking for pthread_create - not found
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE  
-- Found CUDA: /usr (found suitable version "9.1", minimum required is "7.0") 
-- Configuring done
-- Generating done
-- Build files have been written to: /home/kevin/pytorch/third_party/build/nccl
+ make install
Scanning dependencies of target nccl
[100%] Generating lib/libnccl.so
ls: cannot access '/usr/lib64/libcudart.so.*': No such file or directory
ls: cannot access '/usr/lib64/libcudart.so.*': No such file or directory
ls: cannot access '/usr/lib64/libcudart.so.*': No such file or directory
/bin/sh: 1: [: -lt: unexpected operator
ls: cannot access '/usr/lib64/libcudart.so.*': No such file or directory
ls: cannot access '/usr/lib64/libcudart.so.*': No such file or directory
ls: cannot access '/usr/lib64/libcudart.so.*': No such file or directory
ls: cannot access '/usr/lib64/libcudart.so.*': No such file or directory
Grabbing  src/nccl.h                          > /home/kevin/pytorch/third_party/build/nccl/include/nccl.h
ls: cannot access '/usr/lib64/libcudart.so.*': No such file or directory
ls: cannot access '/usr/lib64/libcudart.so.*': No such file or directory
Compiling src/libwrap.cu                      > /home/kevin/pytorch/third_party/build/nccl/obj/libwrap.o
ls: cannot access '/usr/lib64/libcudart.so.*': No such file or directory
ls: cannot access '/usr/lib64/libcudart.so.*': No such file or directory
Compiling src/core.cu                         > /home/kevin/pytorch/third_party/build/nccl/obj/core.o
ls: cannot access '/usr/lib64/libcudart.so.*': No such file or directory
ls: cannot access '/usr/lib64/libcudart.so.*': No such file or directory
ls: cannot access '/usr/lib64/libcudart.so.*': No such file or directory
Compiling src/all_gather.cu                   > /home/kevin/pytorch/third_party/build/nccl/obj/all_gather.o
ls: cannot access '/usr/lib64/libcudart.so.*': No such file or directory
Compiling src/all_reduce.cu                   > /home/kevin/pytorch/third_party/build/nccl/obj/all_reduce.o
src/core.cu(719): error: expected an expression

src/core.cu(719): error: expected an expression

2 errors detected in the compilation of "/tmp/tmpxft_0000262f_00000000-12_core.compute_70.cpp1.ii".
Makefile:136: recipe for target '/home/kevin/pytorch/third_party/build/nccl/obj/core.o' failed
make[3]: *** [/home/kevin/pytorch/third_party/build/nccl/obj/core.o] Error 1
make[3]: *** Waiting for unfinished jobs....
ptxas warning : Too big maxrregcount value specified 96, will be ignored
ptxas warning : Too big maxrregcount value specified 96, will be ignored
ptxas warning : Too big maxrregcount value specified 96, will be ignored
CMakeFiles/nccl.dir/build.make:60: recipe for target 'lib/libnccl.so' failed
make[2]: *** [lib/libnccl.so] Error 2
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/nccl.dir/all' failed
make[1]: *** [CMakeFiles/nccl.dir/all] Error 2
Makefile:129: recipe for target 'all' failed
make: *** [all] Error 2

I’m not sure that we support ubuntu 18.04 yet. 16.04 is a safe bet.

I believe Ubuntu 18.04 should work, since the ELF project uses it.
I guess you’re not setting some build flag correctly, see #675 or #1696, if those do not help you, search around the issues section on github, I bet someone has faced (and solved) a similar problem.

Try changing line 16 in pytorch/third_party/nccl/Makefile to

CUDA_LIB ?= $(CUDA_HOME)/lib/x86_64-linux-gnu