After building the environment of PyCUDA, I will suffer from build errors, so I will leave a memorandum of remedies.
An error occurs when trying to create a matrix on the GPU (internal source build process). This is due to the version of gcc, g ++ (C, C ++ compiler). Version 9 of gcc and g ++ is the default in Ubuntu 20.04, but PyCUDA only supports up to GCC 8. Therefore downgrade is required.
CompileError: nvcc preprocessing of /tmp/tmpu7gbjsl2.cu failed
[command: nvcc --preprocess -arch sm_75 -I/opt/conda/lib/python3.8/site-packages/pycuda/cuda /tmp/tmpu7gbjsl2.cu --compiler-options -P]
[stderr:
b'In file included from /usr/local/cuda-10.1/bin/../targets/x86_64-linux/include/cuda_runtime.h:83,\n from <command-line>:\n/usr/local/cuda-10.1/bin/../targets/x86_64-linux/include/crt/host_config.h:129:2: error: #error -- unsupported GNU version! gcc versions later than 8 are not supported!\n 129 | #error -- unsupported GNU version! gcc versions later than 8 are not supported!\n | ^~~~~\n']
Check the version of gcc and g ++. You can see that version 9
is the default for both gcc and g ++.
$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/9/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none:hsa
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 9.3.0-17ubuntu1~20.04' --with-bugurl=file:///usr/share/doc/gcc-9/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++,gm2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-9 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none=/build/gcc-9-HskZEa/gcc-9-9.3.0/debian/tmp-nvptx/usr,hsa --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 9.3.0 (Ubuntu 9.3.0-17ubuntu1~20.04)
$ ll /usr/bin/gcc
lrwxrwxrwx 1 root root 14 Nov 23 05:53 /usr/bin/gcc -> /usr/bin/gcc-9*
$ g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/9/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none:hsa
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 9.3.0-17ubuntu1~20.04' --with-bugurl=file:///usr/share/doc/gcc-9/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++,gm2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-9 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none=/build/gcc-9-HskZEa/gcc-9-9.3.0/debian/tmp-nvptx/usr,hsa --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 9.3.0 (Ubuntu 9.3.0-17ubuntu1~20.04)
$ ll /usr/bin/g++
lrwxrwxrwx 1 root root 14 Nov 23 05:54 /usr/bin/g++ -> /usr/bin/g++-9*
Install gcc-8
, g ++-8
using the package manager apt
.
sudo apt install -y gcc-8 g++-8
Create a symbolic link so that the default version of gcc
,g ++
is 8.
sudo ln -fs /usr/bin/gcc-8 /usr/bin/gcc
sudo ln -fs /usr/bin/g++-8 /usr/bin/gcc
With the above method, the build error will not occur. In many cases, PyCUDA cannot be used unless it clears difficult conditions for environment construction, such as only supporting CUDA 10.1. I hope it will be improved in the future (contribution is also considered). The memorable 50th article is now an error handling article. In 2020, we set the goal of achieving the 50th post, but it was achieved in a way that was not what we expected. In 2021, I would like to continue aiming for at least one report every month.
Reference
Recommended Posts