Skip to content

Instantly share code, notes, and snippets.

@fwyzard
Last active February 25, 2020 16:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fwyzard/83bb2b7fa7a78f1112b29004cbf2a5cc to your computer and use it in GitHub Desktop.
Save fwyzard/83bb2b7fa7a78f1112b29004cbf2a5cc to your computer and use it in GitHub Desktop.
Build the Intel or Codeplay LLVM branches
#! /bin/bash -e
CUDA_BASE=/usr/local/cuda
SYCL_BASE=$PWD
INSTALL_PATH=/opt/llvm
mkdir -p $SYCL_BASE/llvm
cd $SYCL_BASE/llvm
if ! [ -d .git ]; then
# create a local git repository with remotes for the LLVM, Intel and Codeplay repositories
git init
git remote add -f llvm git@github.com:llvm/llvm-project.git
git branch -t master llvm/master
git remote add -f intel git@github.com:intel/llvm.git
git branch -t sycl intel/sycl
git remote add -f codeplay git@github.com:codeplaysoftware/sycl-for-cuda.git
git branch -t cuda codeplay/cuda
git branch -t cuda-dev codeplay/cuda-dev
else
# update all remotes
git fetch --all
fi
# check out a specific branch, or use the current one
if [ "$1" ]; then
BRANCH=$1
echo "Building branch $BRANCH"
git checkout $BRANCH
else
BRANCH=$(git rev-parse --abbrev-ref HEAD)
echo "Building current branch $BRANCH"
fi
# check out a specific commit, or use the HEAD of the branch
if [ "$2" ]; then
HASH=$2
git reset -hard $HASH
else
git pull
#HASH=$(git log -n1 --pretty='format:%h')
HASH=$(git rev-parse --short HEAD)
fi
BUILD=build-$BRANCH-$HASH
BUILD_DIR=$SYCL_BASE/$BUILD
BUILD_LOG=$SYCL_BASE/$BUILD.log
rm -rf $BUILD_DIR
mkdir $BUILD_DIR
cd $BUILD_DIR
echo "Starting build, see $BUILD_LOG for details"
echo "Running cmake ..."
# broken/incompatible with SYCL_BUILD_PI_CUDA
# -DBUILD_SHARED_LIBS=ON \
cmake $SYCL_BASE/llvm/llvm \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=$INSTALL_PATH/$BRANCH/$HASH \
-DLLVM_TARGETS_TO_BUILD="X86;PowerPC;AArch64;NVPTX" \
-DLLVM_EXTERNAL_PROJECTS="llvm-spirv;sycl;opencl-aot" \
-DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra;compiler-rt;lld;openmp;llvm-spirv;sycl;opencl-aot;libclc" \
-DLLVM_EXTERNAL_SYCL_SOURCE_DIR=$SYCL_BASE/llvm/sycl \
-DLLVM_EXTERNAL_LLVM_SPIRV_SOURCE_DIR=$SYCL_BASE/llvm/llvm-spirv \
-DLLVM_ENABLE_EH=ON \
-DLLVM_ENABLE_PIC=ON \
-DLLVM_ENABLE_RTTI=ON \
-DLLVM_LIBDIR_SUFFIX=64 \
-DBUILD_SHARED_LIBS=OFF \
-DSYCL_BUILD_PI_CUDA=ON \
-DLIBCLC_TARGETS_TO_BUILD="nvptx64--;nvptx64--nvidiacl" \
-DCUDA_TOOLKIT_ROOT_DIR=$CUDA_BASE \
&> $BUILD_LOG
echo "Running make sycl-toolchain ..."
# revisit deploy-sycl-toolchain once official instructions are available
if make -j`nproc` sycl-toolchain opencl-aot &>> $BUILD_LOG; then
echo "Build at $BUILD_DIR successful."
else
echo "Build at $BUILD_DIR failed:"
tail $BUILD_LOG
exit 1
fi
cd $SYCL_BASE
# create symlinks
rm -f build-$BRANCH build
ln -s $BUILD build-$BRANCH
ln -s $BUILD build
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment