Skip to content

Instantly share code, notes, and snippets.

@ulyssesrr ulyssesrr/PKGBUILD
Created Aug 31, 2019

Embed
What would you like to do?
PKGBUILD for rocm-opencl-runtime 2.7.0-1
# Maintainer: Ulysses R Ribeiro <ulyssesrr@gmail.com>
_opencl_icd_loader_commit="7433f2acbf5bbc400f26494ff1dc895da6265bef"
pkgname=rocm-opencl-runtime
pkgver=2.7.0
pkgrel=1
pkgdesc="ROCm OpenCL™ Compatible Runtime"
arch=('x86_64')
url="https://github.com/RadeonOpenCompute/ROCm-OpenCL-Runtime"
license=('MIT')
groups=()
depends=("rocr-runtime>=${pkgver}" "opencl-icd-loader" "libz3")
makedepends=(mesa cmake ninja gcc ocaml-findlib python2-z3 gtest git)
provides=("${pkgname}" "opencl-driver")
conflicts=("rocm-opencl-git")
replaces=()
backup=()
options=()
source=(
"rocm-opencl-runtime-${pkgver}.tar.gz::https://github.com/RadeonOpenCompute/ROCm-OpenCL-Runtime/archive/roc-${pkgver}.tar.gz"
"rocm-opencl-driver-${pkgver}.tar.gz::https://github.com/RadeonOpenCompute/ROCm-OpenCL-Driver/archive/roc-${pkgver}.tar.gz"
"llvm-roc-ocl-${pkgver}.tar.gz::https://github.com/RadeonOpenCompute/llvm/archive/roc-ocl-${pkgver}.tar.gz"
"clang-roc-${pkgver}.tar.gz::https://github.com/RadeonOpenCompute/clang/archive/roc-${pkgver}.tar.gz"
"lld-roc-ocl-${pkgver}.tar.gz::https://github.com/RadeonOpenCompute/lld/archive/roc-ocl-${pkgver}.tar.gz"
"rocm-device-libs-${pkgver}.tar.gz::https://github.com/RadeonOpenCompute/ROCm-Device-Libs/archive/roc-ocl-${pkgver}.tar.gz"
"OpenCL-ICD-Loader-${_opencl_icd_loader_commit}.zip::https://github.com/KhronosGroup/OpenCL-ICD-Loader/archive/${_opencl_icd_loader_commit}.zip"
"fix_rocm_opencl_build_order.patch"
)
#pkgver=2.7.0; sha256sum rocm-opencl-runtime-${pkgver}.tar.gz rocm-opencl-driver-${pkgver}.tar.gz llvm-roc-ocl-${pkgver}.tar.gz clang-roc-${pkgver}.tar.gz lld-roc-ocl-${pkgver}.tar.gz rocm-device-libs-${pkgver}.tar.gz OpenCL-ICD-Loader-*.zip fix_rocm_opencl_build_order.patch | cut -d ' ' -f 1
sha256sums=(
"791f361dc174d82452af2a697508620ac51d66afc18d5d1d54a22c7d2a6544d0"
"bf59dac034e4a24567b933e1d94a65335823f547ef5b60da64c40ad2ba9d3042"
"1ed635c23a5e7e64f9b2a299caee658991dde5f2fbc4291e3a53336f340aff68"
"1951e5177d97f77fa4d6b24d5387f20f0ca008fd9d8514d45a1b83c725a3c1c4"
"e1a686e50833b42ab65016a2015d93a3ffb279991aa7c935f79f05884edbdd94"
"fd55cd5f9f5caa358dbfb660a2d68b4b5964f35be0b36914ab2895a6b2c9b533"
"b21a114e624231d1dfd95038def122b35d0ecbf9bc1c704b8c5aec88c5bf4842"
"0f735299810e9e22cd57f5b96a7628a0f399d445a1f3bacefd8b890e84ca372f"
)
prepare() {
# emulate repo opencl.xml layout
cd $srcdir
# <project path="opencl" name="ROCm-OpenCL-Runtime"/>
ln -s $srcdir/ROCm-OpenCL-Runtime-roc-${pkgver} opencl
#<project path="opencl/compiler/driver" name="ROCm-OpenCL-Driver"/>
mkdir -p $srcdir/opencl/compiler/
ln -s $srcdir/ROCm-OpenCL-Driver-roc-${pkgver} opencl/compiler/driver
#<project path="opencl/compiler/llvm" name="llvm"/>
mkdir -p $srcdir/opencl/compiler/
ln -s $srcdir/llvm-roc-ocl-${pkgver} opencl/compiler/llvm
#<project path="opencl/compiler/llvm/tools/clang" name="clang"/>
mkdir -p $srcdir/opencl/compiler/llvm/tools/
ln -s $srcdir/clang-roc-${pkgver} opencl/compiler/llvm/tools/clang
#<project path="opencl/compiler/llvm/tools/lld" name="lld"/>
mkdir -p $srcdir/opencl/compiler/llvm/tools/
ln -s $srcdir/lld-roc-ocl-${pkgver} opencl/compiler/llvm/tools/lld
#<project path="opencl/library/amdgcn" name="ROCm-Device-Libs"/>
mkdir -p $srcdir/opencl/library/
ln -s $srcdir/ROCm-Device-Libs-roc-ocl-${pkgver} opencl/library/amdgcn
#<project path="opencl/api/opencl/khronos/icd" name="OpenCL-ICD-Loader"
mkdir -p $srcdir/opencl/api/opencl/khronos/
ln -s $srcdir/OpenCL-ICD-Loader-${_opencl_icd_loader_commit} opencl/api/opencl/khronos/icd
# Fix build missing dependency
# https://github.com/RadeonOpenCompute/ROCm-OpenCL-Runtime/issues/64#issuecomment-473502685
cd $srcdir/opencl
patch --forward --strip=1 --input="${srcdir}/fix_rocm_opencl_build_order.patch"
}
build() {
MEM_AVAIL=`cat /proc/meminfo | grep MemTotal | awk {'print $2'}`
AVAIL_THREADS=`nproc`
# require ~1536MB per thread
MAX_THREADS=`echo $(( ${MEM_AVAIL} / $(( 1024 * 1536 ))))`
if [ ${MAX_THREADS} -lt ${AVAIL_THREADS} ]; then
NUM_BUILD_THREADS=${MAX_THREADS}
else
NUM_BUILD_THREADS=${AVAIL_THREADS}
fi
if [ ${NUM_BUILD_THREADS} -lt 1 ]; then
NUM_BUILD_THREADS=1
fi
mkdir -p $srcdir/build
cd $srcdir/build
## mimic AMD official binaries LDFLAGS
#export LDFLAGS="-Wl,--no-as-needed"
cmake -DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=/opt/rocm/opencl \
-DCLANG_ENABLE_STATIC_ANALYZER=ON \
-G Ninja \
$srcdir/opencl
# -jNUM_BUILD_THREADS to avoid Out of Memory
ninja -j$NUM_BUILD_THREADS
# FIXME Check why lld has to built manually since 2.3.0
ninja lld
}
package() {
DESTDIR="$pkgdir/" ninja -C $srcdir/build install
# OpenCL vendor file
mkdir -p "$pkgdir/etc/OpenCL/vendors"
echo "/opt/rocm/opencl/lib/x86_64/libamdocl64.so" > "$pkgdir/etc/OpenCL/vendors/rocm-opencl64.icd"
mkdir -p "$pkgdir/etc/ld.so.conf.d/"
echo "/opt/rocm/opencl/lib" > "$pkgdir/etc/ld.so.conf.d/rocm-opencl.conf"
# Discard AMD's OpenCL ICD Loader
# https://wiki.archlinux.org/index.php/GPGPU#OpenCL_ICD_loader_(libOpenCL.so)
rm -f $pkgdir/opt/rocm/opencl/lib/x86_64/libOpenCL.so*
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.