Skip to content

Instantly share code, notes, and snippets.

@matthiasdiener
Last active October 6, 2022 00:56
Show Gist options
  • Save matthiasdiener/838ccbdb5d8f4e4917b58fe3da811777 to your computer and use it in GitHub Desktop.
Save matthiasdiener/838ccbdb5d8f4e4917b58fe3da811777 to your computer and use it in GitHub Desktop.
Script to build pocl and pyopencl from source
#!/bin/bash
set -o errexit
pushd .
### Conda
MINIFORGE_INSTALL_PREFIX=$PWD/miniforge3
rm -f Miniforge3-Linux-ppc64le.sh
rm -rf $MINIFORGE_INSTALL_PREFIX
wget https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-Linux-ppc64le.sh
bash Miniforge3-Linux-ppc64le.sh -b -p $MINIFORGE_INSTALL_PREFIX
source $MINIFORGE_INSTALL_PREFIX/bin/activate
conda update --all --yes
conda create --yes --name poclbuild
conda activate poclbuild
conda install --yes clang clangxx clangdev gxx_impl_linux-ppc64le libhwloc=1 cmake ocl-icd pybind11 mako
### Pocl
set -o nounset
echo CUDA_HOME=$CUDA_HOME
rm -rf pocl
git clone github.com:pocl/pocl
cd pocl
export POCL_INSTALL_PREFIX=$PWD/install
export CPATH=$MINIFORGE_INSTALL_PREFIX/envs/poclbuild/include
export LIBRARY_PATH=$MINIFORGE_INSTALL_PREFIX/envs/poclbuild/lib:$CUDA_HOME/lib64/stubs:/usr/lib/x86_64-linux-gnu/
mkdir build
cd build
CC=clang CXX=clang++ cmake .. \
-DENABLE_CUDA=on \
-DENABLE_ICD=on \
-DCMAKE_BUILD_TYPE="RelWithDebugInfo" \
-DCMAKE_INSTALL_PREFIX=$POCL_INSTALL_PREFIX \
-DOPENCL_LIBRARIES=$MINIFORGE_INSTALL_PREFIX/envs/poclbuild/lib/libOpenCL.so \
-DCLANG_MARCH_FLAG="-mcpu="
make -j8
make install
### Pyopencl
popd
rm -rf pyopencl
# N.B. Make sure to load a recent gcc module (>7)
git clone --recursive [email protected]:inducer/pyopencl
cd pyopencl
./configure.py --cl-inc-dir=$MINIFORGE_INSTALL_PREFIX/envs/poclbuild/include --cl-lib-dir=$POCL_INSTALL_PREFIX/lib --cl-libname=OpenCL
python setup.py install
export OCL_ICD_VENDORS=$POCL_INSTALL_PREFIX/etc/OpenCL/vendors/:$OCL_ICD_VENDORS
@ZwFink
Copy link

ZwFink commented Jan 21, 2021

Version for x86_64 Linux:

#!/bin/bash

set -o errexit

pushd .

### Conda

MINIFORGE_INSTALL_PREFIX=$PWD/miniforge3

rm -f Miniforge3-Linux-ppc64le.sh
rm -rf $MINIFORGE_INSTALL_PREFIX

wget https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-Linux-x86_64.sh
bash Miniforge3-Linux-x86_64.sh -b -p $MINIFORGE_INSTALL_PREFIX

source $MINIFORGE_INSTALL_PREFIX/bin/activate

conda update --all --yes

conda create --yes --name poclbuild

conda activate poclbuild

conda install --yes clang clangxx clangdev gxx_impl_linux-ppc64le libhwloc=1 cmake ocl-icd pybind11 mako


### Pocl

if [ -z "$CUDA_HOME" ]; then
  echo "CUDA_HOME not found, please set CUDA_HOME to the directory containing CUDA libraries."
  exit 1
fi

set -o nounset

echo CUDA_HOME=$CUDA_HOME

rm -rf pocl

git clone https://github.com/pocl/pocl.git

cd pocl

POCL_INSTALL_PREFIX=$PWD/install
export CPATH=$MINIFORGE_INSTALL_PREFIX/envs/poclbuild/include
export LIBRARY_PATH=$MINIFORGE_INSTALL_PREFIX/envs/poclbuild/lib:$CUDA_HOME/lib64/stubs

mkdir build
cd build

CMAKE_C_COMPILER=clang CMAKE_CXX_COMPILER=clang++ cmake .. -DENABLE_CUDA=on -DENABLE_ICD=on -DCMAKE_BUILD_TYPE="RelWithDebugInfo" -DCMAKE_INSTALL_PREFIX=$POCL_INSTALL_PREFIX -DOPENCL_LIBRARIES=$MINIFORGE_INSTALL_PREFIX/envs/poclbuild/lib/libOpenCL.so -DCLANG_MARCH_FLAG="-mcpu="

make -j8
make install


### Pyopencl

popd

rm -rf pyopencl

# N.B. Make sure to load a recent gcc module (>7)


git clone --recursive https://github.com/inducer/pyopencl.git

cd pyopencl

./configure.py --cl-inc-dir=$MINIFORGE_INSTALL_PREFIX/envs/poclbuild/include --cl-lib-dir=$POCL_INSTALL_PREFIX/lib --cl-libname=OpenCL

python setup.py install

@matthiasdiener
Copy link
Author

Thank you @ZwFink!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment