Skip to content

Instantly share code, notes, and snippets.

@inducer
Created December 28, 2017 23:51
Show Gist options
  • Save inducer/ff35d807fe2f58227908ee179058a45f to your computer and use it in GitHub Desktop.
Save inducer/ff35d807fe2f58227908ee179058a45f to your computer and use it in GitHub Desktop.
Pocl build script
#! /bin/bash
set -e
set -x
apt-get remove --purge pocl-opencl-icd
apt autoremove
apt install libhwloc-dev libz-dev cmake pkg-config
USE_LLVM_PACKAGES=0
LLVM_VERSION=5.0
if test "$1" = "--use-llvm-packages"; then
USE_LLVM_PACKAGES=1
shift
fi
if test "$1" = ""; then
echo "usage: $0 [--llvm-packages] branch"
exit 1
fi
BRANCH="$1"
BUILD_PATH="/opt/pocl-$BRANCH-build"
INSTALL_PATH="/opt/pocl-$BRANCH"
EXECUTABLE="$(readlink -f "$0")"
SCRIPT_DIR="$(dirname "$EXECUTABLE")"
SCRIPT_DIR="$(readlink -f "$SCRIPT_DIR")"
rm -Rf "$INSTALL_PATH"
rm -Rf "$BUILD_PATH"
if [[ "$USE_LLVM_PACKAGES" = 1 ]]; then
apt install libclang-$LLVM_VERSION-dev clang-$LLVM_VERSION
LLVM_CONFIG="/usr/bin/llvm-config-$LLVM_VERSION"
else
$SCRIPT_DIR/build-llvm-$LLVM_VERSION "$INSTALL_PATH"
LLVM_CONFIG="$INSTALL_PATH/bin/llvm-config"
fi
cd /opt
git clone https://github.com/pocl/pocl.git "$BUILD_PATH"
cd "$BUILD_PATH"
git checkout "$BRANCH"
PATCHFILE=/tmp/pocl-fix-macros.patch
cat > $PATCHFILE <<EOF
diff --git a/lib/kernel/vecmathlib/floattypes.h b/lib/kernel/vecmathlib/floattypes.h
index fa4cc44..cb9071b 100644
--- a/lib/kernel/vecmathlib/floattypes.h
+++ b/lib/kernel/vecmathlib/floattypes.h
@@ -40,6 +40,7 @@ using namespace std;
#endif
// Capture libc macros, then undefine them
+/*
#ifndef isfinite
#error "isfinite is not a macro"
#endif
@@ -55,6 +56,7 @@ using namespace std;
#ifndef signbit
#error "signbit is not a macro"
#endif
+*/
namespace {
template <typename T> inline int libc_isfinite(T x) { return isfinite(x); }
EOF
patch -p1 < $PATCHFILE
rm -f $PATCHFILE
mkdir "$BUILD_PATH/build"
(cd "$BUILD_PATH/build" && \
cmake \
-D CMAKE_INSTALL_PREFIX="$INSTALL_PATH" \
-D POCL_INSTALL_ICD_VENDORDIR="$INSTALL_PATH" \
-D LLVM_CONFIG=$LLVM_CONFIG \
-D CMAKE_BUILD_TYPE=Release \
.. && \
make -j15 install)
echo "$INSTALL_PATH/lib/libpocl.so" > /etc/OpenCL/vendors/pocl-$BRANCH.icd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment