Last active
November 25, 2022 05:38
-
-
Save dizys/8dedbe94439b91d759b6c1e6e316d542 to your computer and use it in GitHub Desktop.
Build GCC 11 from source with offloading support.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# | |
# Build GCC with support for offloading to NVIDIA GPUs. | |
# | |
netid=$(whoami) | |
work_dir=/tmp/$netid/gcc-build | |
install_dir=/tmp/$netid/gcc | |
# Location of the installed CUDA toolkit | |
cuda=$CUDA_PATH | |
# Build assembler and linking tools | |
mkdir -p $work_dir | |
cd $work_dir | |
git clone https://github.com/MentorEmbedded/nvptx-tools | |
cd nvptx-tools | |
./configure \ | |
--with-cuda-driver-include=$cuda/include \ | |
--with-cuda-driver-lib=$cuda/lib64 \ | |
--prefix=$install_dir | |
make || exit 1 | |
make install || exit 1 | |
cd .. | |
# Set up the GCC source tree | |
git clone git://sourceware.org/git/newlib-cygwin.git nvptx-newlib | |
git clone --branch releases/gcc-11 git://gcc.gnu.org/git/gcc.git gcc | |
cd gcc | |
contrib/download_prerequisites | |
ln -s ../nvptx-newlib/newlib newlib | |
cd .. | |
target=$(gcc/config.guess) | |
# Build nvptx GCC | |
mkdir build-nvptx-gcc | |
cd build-nvptx-gcc | |
../gcc/configure \ | |
--target=nvptx-none --with-build-time-tools=$install_dir/nvptx-none/bin \ | |
--enable-as-accelerator-for=$target \ | |
--disable-sjlj-exceptions \ | |
--enable-newlib-io-long-long \ | |
--enable-languages="c,c++,fortran,lto" \ | |
--prefix=$install_dir | |
make -j`nproc` || exit 1 | |
make install || exit 1 | |
cd .. | |
# Build host GCC | |
mkdir -p build-host-gcc | |
cd build-host-gcc | |
../gcc/configure \ | |
--enable-offload-targets=nvptx-none \ | |
--with-cuda-driver-include=$cuda/include \ | |
--with-cuda-driver-lib=$cuda/lib64 \ | |
--disable-bootstrap \ | |
--disable-multilib \ | |
--enable-languages="c,c++,fortran,lto" \ | |
--prefix=$install_dir | |
make -j`nproc` || exit 1 | |
make install || exit 1 | |
rm -rf $work_dir | |
cd .. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment