Skip to content

Instantly share code, notes, and snippets.

@magnade magnade/PKGBUILD
Created Oct 27, 2019

Embed
What would you like to do?
# Maintainer: Ulysses R Ribeiro <ulyssesrr@gmail.com>
_opencl_icd_loader_commit="7433f2acbf5bbc400f26494ff1dc895da6265bef"
pkgname=rocm-opencl-runtime
pkgver=2.9.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.9.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=(
"47d6f623561b574b1c58740804beb48b5134232cd257468ba582f8d505176ad2"
"90b675800542778464745c1e602e0b009cf4810012e096b2baf9d7a5a0a05d20"
"de83fc89a35e7642598b84495c52b990f1bf67549b0cf1a268437ca7932800d4"
"be1630cb23b77671971233e8dca93b102c32a5c9c44eb8dccc599426df59a3c8"
"ce004aba23ed235534f359c88a94fb9bdd580822910c59529cfa0e9c32acf811"
"05bf8c060db68cf5680a05b06ae7c4adefeb0f8d36f357accfa68e5d5185f72b"
"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
ln -s $srcdir/OpenCL-ICD-Loader-${_opencl_icd_loader_commit} opencl/api/opencl/khronos/icd/loader
# 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.