Package Details: adaptivecpp-rocm-git 24.02.0+89.r2736.20240526.31b7c427-1

Git Clone URL: https://aur.archlinux.org/adaptivecpp-git.git (read-only, click to copy)
Package Base: adaptivecpp-git
Description: Independent, community-driven modern platform for C++-based heterogeneous programming models targeting CPUs and GPUs from all major vendors. (formerly known as hipSYCL / Open SYCL). ROCm (AMD Radeon) + OpenCL + CPU backend.
Upstream URL: https://github.com/AdaptiveCpp/AdaptiveCpp
Licenses: BSD-2-Clause
Conflicts: adaptivecpp-backend, adaptivecpp-cpu, adaptivecpp-opencl, adaptivecpp-rocm, syclcc, syclcc-clang
Provides: adaptivecpp-backend, adaptivecpp-cpu, adaptivecpp-opencl, adaptivecpp-rocm, hipsycl, syclcc, syclcc-clang
Submitter: dreieck
Maintainer: None
Last Packager: dreieck
Votes: 0
Popularity: 0.000000
First Submitted: 2024-02-08 13:18 (UTC)
Last Updated: 2024-05-26 13:39 (UTC)

Latest Comments

dreieck commented on 2024-05-28 11:23 (UTC)

I do not use it.

I disown it.

@Eirikr or/ and @illuhad, feel free to adopt!

Regards!

illuhad commented on 2024-03-12 22:21 (UTC)

Hi @Eirikr, @dreieck :) Thanks for your efforts, this is great to see!

We do have some ideas about packaging in the upstream AdaptiveCpp project that I'd like to share with you - perhaps they can be helpful. It is clear that adding packages for each combination of backends is not feasible due to the combinatoric explosion and the flexibility that AdaptiveCpp provides.

We have two ideas how this could be handled. Both rely on the fact that AdaptiveCpp has modular backend plugins that are discovered and loaded at runtime by the core runtime library. So:

  1. There could be a single adaptivecpp-core or similar package which provides the core infrastructure (libacpp-rt, headers, acpp, omp backend, libllvm-to-backend). Then there would be individual adaptivecpp-cuda, adaptivecpp-rocm etc packages that add individual backends (librt-backend-<backend>, libllvm-to-<backend>). Only these packages would then carry dependencies to backend stacks like CUDA or ROCm. Users could then install one or multiple of those backend packages that they actually need. Note that there is currently no way to build "just a backend" without the core infrastructure, so the build process for the backend packages would involve building AdaptiveCpp again with the requested backend, and then only package the backend-specific bits.
  2. Alternatively, we can also exploit that the AdaptiveCpp runtime discards backend plugins that have unresolved symbols in them due to unmet dependencies. So it possible to build a full AdaptiveCpp with all backends enabled, but then only have e.g. CUDA as build dependency. At runtime, the CUDA backend would then only be loaded if users actually install CUDA. This is probably a bit simpler than option 1, as there would only be a single package which includes everything. But the build time would be higher, which might be undesired on a platform like Arch where it is expected that many users will build the package themselves.

Eirikr commented on 2024-03-06 04:36 (UTC) (edited on 2024-03-06 05:15 (UTC) by Eirikr)

Hey there! First of all; I want to say thank you very much for working on this. It is marvelous and works great. Wanted to try to mess around with CUDA... then was having issues with it finding the ROCM library, so I added these to /etc/environment.

HIP_PATH=/opt/rocm
HCC_HOME=/opt/rocm
ROCM_PATH=/opt/rocm
CUDA_PATH=/opt/cuda
PATH=$ROCM_PATH/bin:$CUDA_PATH/bin:$PATH
LD_LIBRARY_PATH=$ROCM_PATH/lib:$CUDA_PATH/lib64:$LD_LIBRARY_PATH
OCL_ICD_VENDORS=/etc/OpenCL/vendors

So then I tried to tinker to address stuff listed in the current PKGBUILD + have a combined package for mixed-use labs and datacenters; mixed arch homelabs and rigs; laptops, edge cases of a mini PC with multiple GPUs, so forth.

So here is the combined CUDA+ROCM+OpenCL+CPU and LevelZero GPU included to satiate my curiosity; tho any CUDA-only errors should be addressed first of course. I was tinkering more than I was paying attention to jotting down what I'm doing so this "noob having fun" list does not cover everything added.

(I do not pretend this is a solution: complete or not. This is practicing, experimenting,and brainstorming to comment a rough draft to consider adding Intel + a few different configs. Do I do not expect help nor support for making all these modifications. However if you find any useful, you are free to use them for your effort/efforts.)

  • Added -DCUDAToolkit_ROOT_DIR=/opt/cuda to specify the CUDA toolkit installation path.
  • Added pacman CUDA packages to the depends array.
  • Added _cmake_cuda_options array with CMake options for the CUDA backend.
  • Added _prepare_cuda() function to prepare the build directory for the CUDA backend.
  • Added _build_cuda() function to build the CUDA backend.
  • Added _package_cuda() function to package the CUDA backend.
  • Added Level Zero dependencies to makedepends array (level-zero and level-zero-headers)
  • Added -DWITH_LEVEL_ZERO_BACKEND=ON to the _cmake_general_options array.
  • Added _cmake_level_zero_options array w/CMake options for Level Zero backend.
  • Added _prepare_level_zero() function to prepare the build directory for the Level Zero backend.
  • Added _build_level_zero() function to build the Level Zero backend.
  • Added _package_level_zero() function to package the Level Zero backend.
  • Added "${_pkgbase}-cuda-rocm-opencl-cpu${_vcssuffix}" and "${_pkgbase}-level-zero-opencl-cpu${_vcssuffix}" to the pkgname array.
  • Added _cmake_cuda_rocm_opencl_cpu_options and _cmake_level_zero_opencl_cpu_options arrays w/CMake options for the multi-backends.
  • Added _prepare_cuda_rocm_opencl_cpu() and _prepare_level_zero_opencl_cpu() to prepare build directories for the multi-backends.
  • Added _build_cuda_rocm_opencl_cpu() and _build_level_zero_opencl_cpu() to build the multi-backends.
  • Added _package_cuda_rocm_opencl_cpu() and _package_level_zero_opencl_cpu() to package the multi-backends.
  • Updated the for loop at the end of the PKGBUILD to include new package combinations.
  • Updated the makedepends array to include additional dependencies:
  • Added 'cuda', 'cuda-tools', 'libcublas', 'libcufft', 'libcurand', 'libcusolver', 'libcusparse', 'python', and 'spirv-tools'.
  • Updated the prepare() function to include the preparation steps for the additional backends and multi-backends.
  • Updated the build() function to include the build steps for the additional backends and multi-backends.
  • Updated _package_common() to include the new package combinations in the optdepends array.
_pkgbase='adaptivecpp'
_vcssuffix='-git'
pkgbase="${_pkgbase}${_vcssuffix}"
pkgname=(
  "${_pkgbase}-common${_vcssuffix}"
  "${_pkgbase}-cpu${_vcssuffix}"
  "${_pkgbase}-cuda${_vcssuffix}"
  "${_pkgbase}-opencl${_vcssuffix}"
  "${_pkgbase}-rocm${_vcssuffix}"
  "${_pkgbase}-level-zero${_vcssuffix}"
  "${_pkgbase}-cuda-rocm-opencl-cpu${_vcssuffix}"
  "${_pkgbase}-level-zero-opencl-cpu${_vcssuffix}"
)
pkgver=23.10.0+130.r2453.20240207.f144e21f
pkgrel=1
pkgdesc="Independent, community-driven modern platform for C++-based heterogeneous programming models targeting CPUs and GPUs from all major vendors. (formerly known as hipSYCL / Open SYCL)."
arch=(
  'x86_64'
)
url="https://github.com/AdaptiveCpp/AdaptiveCpp"
license=('BSD-2-Clause')
makedepends=(
  'boost'
  'clang'
  'cmake'
  'cuda'
  'cuda-tools'
  'gcc-libs'
  'git'
  'glibc'
  'hip-runtime-amd'
  'level-zero'
  'level-zero-headers'
  'libcublas'
  'libcufft'
  'libcurand'
  'libcusolver'
  'libcusparse'
  'libffi'
  'libxml2'
  'llvm'
  'llvm-libs'
  'ncurses'
  'opencl-clhpp'
  'opencl-headers'
  'openmp'
  'python'
  'rocm-llvm'
  'spirv-tools'
  'zlib'
  'zstd'
)
source=(
  "${_pkgbase}::git+${url}.git"
)
sha256sums=(
  'SKIP'
)

_cmake_general_options=(
  -S "${_pkgbase}"
  -DCMAKE_BUILD_TYPE=Release
  -DCMAKE_INSTALL_PREFIX=/usr
  -DFETCHCONTENT_FULLY_DISCONNECTED=OFF
  -DFETCHCONTENT_QUIET=OFF
  -DFETCHCONTENT_UPDATES_DISCONNECTED=OFF
  -DFETCHCONTENT_UPDATES_DISCONNECTED_LLVMSPIRVTRANSLATOR="_deps/llvmspirvtranslator-src"
  -DFETCHCONTENT_UPDATES_DISCONNECTED_OCL-CXX-HEADERS="_deps/ocl-cxx-headers-src"
  -DFETCHCONTENT_UPDATES_DISCONNECTED_OCL-HEADERS="_deps/ocl-headers-src"
  -DACPP_CONFIG_FILE_GLOBAL_INSTALLATION=ON
  -DBUILD_DOCS=ON
  -DBUILD_EXAMPLES=ON
  -DHIPSYCL_DEBUG_LEVEL=2
  -DLLVM_DIR=/usr/lib/cmake/llvm
  -DWITH_SSCP_COMPILER=ON
  -DWITH_STDPAR_COMPILER=ON
  -DWITH_LEVEL_ZERO_BACKEND=ON
)

_cmake_cpu_options=(
  -DWITH_ACCELERATED_CPU=ON
  -DWITH_CUDA_BACKEND=OFF
  -DWITH_CUDA_NVCXX_ONLY=OFF
  -DWITH_OPENCL_BACKEND=OFF
  -DWITH_ROCM_BACKEND=OFF
  -DWITH_LEVEL_ZERO_BACKEND=OFF
)

_cmake_cuda_options=(
  -DCUDAToolkit_ROOT_DIR=/opt/cuda
  -DCUDAToolkit_NVCC_EXECUTABLE=/opt/cuda/bin/nvcc
  -DWITH_ACCELERATED_CPU=ON
  -DWITH_CUDA_BACKEND=ON
  -DWITH_CUDA_NVCXX_ONLY=OFF
  -DWITH_OPENCL_BACKEND=OFF
  -DWITH_ROCM_BACKEND=OFF
  -DWITH_LEVEL_ZERO_BACKEND=OFF
)

_cmake_opencl_options=(
  -DWITH_ACCELERATED_CPU=ON
  -DWITH_CUDA_BACKEND=OFF
  -DWITH_CUDA_NVCXX_ONLY=OFF
  -DWITH_OPENCL_BACKEND=ON
  -DWITH_ROCM_BACKEND=OFF
  -DWITH_LEVEL_ZERO_BACKEND=OFF
)

_cmake_rocm_options=(
  -DHIPCC_COMPILER=/opt/rocm/bin/hipcc
  -DHIP_DIR=/opt/rocm/lib/cmake/hip
  -DROCM_PATH=/opt/rocm
  -DWITH_ACCELERATED_CPU=ON
  -DWITH_CUDA_BACKEND=OFF
  -DWITH_CUDA_NVCXX_ONLY=OFF
  -DWITH_OPENCL_BACKEND=ON
  -DWITH_ROCM_BACKEND=ON
  -DWITH_LEVEL_ZERO_BACKEND=OFF
)

_cmake_level_zero_options=(
  -DWITH_ACCELERATED_CPU=ON
  -DWITH_CUDA_BACKEND=OFF
  -DWITH_CUDA_NVCXX_ONLY=OFF
  -DWITH_OPENCL_BACKEND=OFF
  -DWITH_ROCM_BACKEND=OFF
  -DWITH_LEVEL_ZERO_BACKEND=ON
)

_cmake_cuda_rocm_opencl_cpu_options=(
  -DHIPCC_COMPILER=/opt/rocm/bin/hipcc
  -DHIP_DIR=/opt/rocm/lib/cmake/hip
  -DROCM_PATH=/opt/rocm
  -DCUDAToolkit_ROOT_DIR=/opt/cuda
  -DCUDAToolkit_NVCC_EXECUTABLE=/opt/cuda/bin/nvcc
  -DWITH_ACCELERATED_CPU=ON
  -DWITH_CUDA_BACKEND=ON
  -DWITH_CUDA_NVCXX_ONLY=OFF
  -DWITH_OPENCL_BACKEND=ON
  -DWITH_ROCM_BACKEND=ON
  -DWITH_LEVEL_ZERO_BACKEND=OFF
)

_cmake_level_zero_opencl_cpu_options=(
  -DWITH_ACCELERATED_CPU=ON
  -DWITH_CUDA_BACKEND=OFF
  -DWITH_CUDA_NVCXX_ONLY=OFF
  -DWITH_OPENCL_BACKEND=ON
  -DWITH_ROCM_BACKEND=OFF
  -DWITH_LEVEL_ZERO_BACKEND=ON
)

_prepare_cpu() {
  cd "${srcdir}"

  if [ -e build-cpu ]; then
    rm -rf build-cpu
  fi
  mkdir -p build-cpu

  cmake -B build-cpu "${_cmake_general_options[@]}" "${_cmake_cpu_options[@]}"
}

_prepare_cuda() {
  cd "${srcdir}"

  if [ -e build-cuda ]; then
    rm -rf build-cuda
  fi
  mkdir -p build-cuda

  cmake -B build-cuda "${_cmake_general_options[@]}" "${_cmake_cuda_options[@]}"
}

_prepare_opencl() {
  cd "${srcdir}"

  if [ -e build-opencl ]; then
    rm -rf build-opencl
  fi
  mkdir -p build-opencl

  cmake -B build-opencl "${_cmake_general_options[@]}" "${_cmake_opencl_options[@]}"
}

_prepare_rocm() {
  cd "${srcdir}"

  if [ -e build-rocm ]; then
    rm -rf build-rocm
  fi
  mkdir -p build-rocm

  cmake -B build-rocm "${_cmake_general_options[@]}" "${_cmake_rocm_options[@]}"
}

_prepare_level_zero() {
  cd "${srcdir}"

  if [ -e build-level-zero ]; then
    rm -rf build-level-zero
  fi
  mkdir -p build-level-zero

  cmake -B build-level-zero "${_cmake_general_options[@]}" "${_cmake_level_zero_options[@]}"
}

_prepare_cuda_rocm_opencl_cpu() {
  cd "${srcdir}"

  if [ -e build-cuda-rocm-opencl-cpu ]; then
    rm -rf build-cuda-rocm-opencl-cpu
  fi
  mkdir -p build-cuda-rocm-opencl-cpu

  cmake -B build-cuda-rocm-opencl-cpu "${_cmake_general_options[@]}" "${_cmake_cuda_rocm_opencl_cpu_options[@]}"
}

_prepare_level_zero_opencl_cpu() {
  cd "${srcdir}"

  if [ -e build-level-zero-opencl-cpu ]; then
    rm -rf build-level-zero-opencl-cpu
  fi
  mkdir -p build-level-zero-opencl-cpu

  cmake -B build-level-zero-opencl-cpu "${_cmake_general_options[@]}" "${_cmake_level_zero_opencl_cpu_options[@]}"
}

prepare() {
  cd "${srcdir}/${_pkgbase}"

  msg2 "Running preparation for CPU backend ..."
  _prepare_cpu

  msg2 "Running preparation for CUDA backend ..."
  _prepare_cuda

  msg2 "Running preparation for OpenCL backend ..."
  _prepare_opencl

  msg2 "Running preparation for ROCm backend ..."
  _prepare_rocm

  msg2 "Running preparation for Level Zero backend ..."
  _prepare_level_zero

  msg2 "Running preparation for CUDA + ROCm + OpenCL + CPU backends ..."
  _prepare_cuda_rocm_opencl_cpu

  msg2 "Running preparation for Level Zero + OpenCL + CPU backends ..."
  _prepare_level_zero_opencl_cpu

  git log > git.log
}

pkgver() {
  cd "${srcdir}/${_pkgbase}"

  _ver="$(git describe  --tags | sed 's|^[vV]||' | sed 's|-g[0-9a-fA-F]*$||' | tr '-' '+')"
  _rev="$(git rev-list --count HEAD)"
  _date="$(git log -1 --date=format:"%Y%m%d" --format="%ad")"
  _hash="$(git rev-parse --short HEAD)"

  if [ -z "${_ver}" ]; then
    error "Version could not be determined."
    return 1
  else
    printf '%s' "${_ver}.r${_rev}.${_date}.${_hash}"
  fi
}

_build_cpu() {
  cd "${srcdir}"

  make -C build-cpu -j`nproc`
}

_build_cuda() {
  cd "${srcdir}"

  make -C build-cuda -j`nproc`
}

_build_opencl() {
  cd "${srcdir}"

  make -C build-opencl -j`nproc`
}

_build_rocm() {
  cd "${srcdir}"

  make -C build-rocm -j`nproc`
}

_build_level_zero() {
  cd "${srcdir}"

  make -C build-level-zero -j`nproc`
}

_build_cuda_rocm_opencl_cpu() {
  cd "${srcdir}"

  make -C build-cuda-rocm-opencl-cpu -j`nproc`
}

_build_level_zero_opencl_cpu() {
  cd "${srcdir}"

  make -C build-level-zero-opencl-cpu -j`nproc`
}

build() {
  msg2 "Building for CPU backend ..."
  _build_cpu

  msg2 "Building for CUDA backend ..."
  _build_cuda

  msg2 "Building for OpenCL backend ..."
  _build_opencl

  msg2 "Building for ROCm backend ..."
  _build_rocm

  msg2 "Building for Level Zero backend ..."
  _build_level_zero

  msg2 "Building for CUDA + ROCm + OpenCL + CPU backends ..."
  _build_cuda_rocm_opencl_cpu

  msg2 "Building for Level Zero + OpenCL + CPU backends ..."
  _build_level_zero_opencl_cpu
}

_package_common() {
  pkgdesc="Independent, community-driven modern platform for C++-based heterogeneous programming models targeting CPUs and GPUs from all major vendors. (formerly known as hipSYCL / Open SYCL). Common files."
  depends=()
  provides=(
    "${_pkgbase}-common=${pkgver}"
  )
  conflicts=(
    "${_pkgbase}-common"
  )
  optdepends=(
    "${_pkgbase}-cpu${_vcssuffix}=${pkgver}:    For CPU only backend."
    "${_pkgbase}-cuda${_vcssuffix}=${pkgver}:   For CUDA backend."
    "${_pkgbase}-opencl${_vcssuffix}=${pkgver}: For OpenCL backend."
    "${_pkgbase}-rocm${_vcssuffix}=${pkgver}:   For ROCm backend."
    "${_pkgbase}-level-zero${_vcssuffix}=${pkgver}: For Level Zero backend."
    "${_pkgbase}-cuda-rocm-opencl-cpu${_vcssuffix}=${pkgver}: For CUDA + ROCm + OpenCL + CPU backends."
    "${_pkgbase}-level-zero-opencl-cpu${_vcssuffix}=${pkgver}: For Level Zero + OpenCL + CPU backends."
  )

  cd "${srcdir}/${_pkgbase}"
  install -Dvm644 -t "${pkgdir}/usr/share/doc/${_pkgbase}"      git.log CONTRIBUTING.md README.md
  install -Dvm644 -t "${pkgdir}/usr/share/licenses/${pkgbase}"  LICENSE
  ln -svr "${pkgdir}/usr/share/licenses/${pkgbase}/LICENSE"     "${pkgdir}/usr/share/doc/${_pkgbase}/LICENSE"

  install -dvm755 "${pkgdir}/usr/share/licenses/${pkgname}"
  ln -svr "${pkgdir}/usr/share/licenses/${pkgbase}/LICENSE"     "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
}

_package_cpu() {
  pkgdesc="Independent, community-driven modern platform for C++-based heterogeneous programming models targeting CPUs and GPUs from all major vendors. (formerly known as hipSYCL / Open SYCL). Accelerated CPU-only backend."
  depends=(
    "${_pkgbase}-common${_vcssuffix}=${pkgver}"
    "gcc-libs"
    "glibc"
    "llvm-libs"
    "python"
  )
  provides=(
    "${_pkgbase}-cpu=${pkgver}"
    "${_pkgbase}-backend"
    "hipsycl"
    "syclcc"
    "syclcc-clang"
  )
  conflicts=("${_pkgbase}-cpu"
    "${_pkgbase}-backend"
    "syclcc"
    "syclcc-clang"
  )
  optdepends=()

  cd "${srcdir}"

  make DESTDIR="${pkgdir}" -C build-cpu install

  install -dvm755 "${pkgdir}/usr/share/licenses/${pkgname}"
  ln -svr "${pkgdir}/usr/share/licenses/${pkgbase}/LICENSE"  "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
}

_package_cuda() {
  pkgdesc="Independent, community-driven modern platform for C++-based heterogeneous programming models targeting CPUs and GPUs from all major vendors. (formerly known as hipSYCL / Open SYCL). CUDA backend."
  depends=(
    "${_pkgbase}-common${_vcssuffix}=${pkgver}"
    "gcc-libs"
    "glibc"
    "llvm-libs"
    "python"
    "cuda"
    "cuda-tools"
    "libcublas"
    "libcufft"
    "libcurand"
    "libcusolver"
    "libcusparse"
  )
  provides=(
    "${_pkgbase}-cuda=${pkgver}"
    "${_pkgbase}-backend"
    "hipsycl"
    "syclcc"
    "syclcc-clang"
  )
  conflicts=(
    "${_pkgbase}-cuda"
    "${_pkgbase}-backend"
    "syclcc"
    "syclcc-clang"
  )
  optdepends=()

  cd "${srcdir}"

  make DESTDIR="${pkgdir}" -C build-cuda install

  install -dvm755 "${pkgdir}/usr/share/licenses/${pkgname}"
  ln -svr "${pkgdir}/usr/share/licenses/${pkgbase}/LICENSE"  "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
}

_package_opencl() {
  pkgdesc="Independent, community-driven modern platform for C++-based heterogeneous programming models targeting CPUs and GPUs from all major vendors. (formerly known as hipSYCL / Open SYCL). OpenCL backend."
  depends=(
    "${_pkgbase}-common${_vcssuffix}=${pkgver}"
    "gcc-libs"
    "glibc"
    "llvm-libs"
    "python"
    "spirv-tools"
    "opencl-clhpp"
    "opencl-headers"
  )
  provides=(
    "${_pkgbase}-opencl${pkgver}"
    "${_pkgbase}-backend"
    "hipsycl"
    "syclcc"
    "syclcc-clang"
  )
  conflicts=(
    "${_pkgbase}-opencl"
    "${_pkgbase}-backend"
    "syclcc"
    "syclcc-clang"
  )
  optdepends=()

  cd "${srcdir}"

  make DESTDIR="${pkgdir}" -C build-opencl install

  install -dvm755 "${pkgdir}/usr/share/licenses/${pkgname}"
  ln -svr "${pkgdir}/usr/share/licenses/${pkgbase}/LICENSE"  "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
}

_package_rocm() {
  pkgdesc="Independent, community-driven modern platform for C++-based heterogeneous programming models targeting CPUs and GPUs from all major vendors. (formerly known as hipSYCL / Open SYCL). ROCm backend."
  depends=(
    "${_pkgbase}-common${_vcssuffix}=${pkgver}"
    "gcc-libs"
    "glibc"
    "llvm-libs"
    "python"
    "spirv-tools"
    "hip-runtime-amd"
    "rocm-llvm"
  )
  provides=(
    "${_pkgbase}-rocm=${pkgver}"
    "${_pkgbase}-backend"
    "hipsycl"
    "syclcc"
    "syclcc-clang"
  )
  conflicts=(
    "${_pkgbase}-rocm"
    "${_pkgbase}-backend"
    "syclcc"
    "syclcc-clang"
  )
  optdepends=()

  cd "${srcdir}"

  make DESTDIR="${pkgdir}" -C build-rocm install

  install -dvm755 "${pkgdir}/usr/share/licenses/${pkgname}"
  ln -svr "${pkgdir}/usr/share/licenses/${pkgbase}/LICENSE"  "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
}

_package_level_zero() {
  pkgdesc="Independent, community-driven modern platform for C++-based heterogeneous programming models targeting CPUs and GPUs from all major vendors. (formerly known as hipSYCL / Open SYCL). Level Zero backend."
  depends=(
    "${_pkgbase}-common${_vcssuffix}=${pkgver}"
    "gcc-libs"
    "glibc"
    "llvm-libs"
    "python"
    "spirv-tools"
    "level-zero"
    "level-zero-headers"
  )
  provides=(
    "${_pkgbase}-level-zero=${pkgver}"
    "${_pkgbase}-backend"
    "hipsycl"
    "syclcc"
    "syclcc-clang"
  )
  conflicts=(
    "${_pkgbase}-level-zero"
    "${_pkgbase}-backend"
    "syclcc"
    "syclcc-clang"
  )
  optdepends=()

  cd "${srcdir}"

  make DESTDIR="${pkgdir}" -C build-level-zero install

  install -dvm755 "${pkgdir}/usr/share/licenses/${pkgname}"
  ln -svr "${pkgdir}/usr/share/licenses/${pkgbase}/LICENSE"  "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
}

_package_cuda_rocm_opencl_cpu() {
  pkgdesc="Independent, community-driven modern platform for C++-based heterogeneous programming models targeting CPUs and GPUs from all major vendors. (formerly known as hipSYCL / Open SYCL). CUDA + ROCm + OpenCL + CPU backends."
  depends=(
    "${_pkgbase}-common${_vcssuffix}=${pkgver}"
    "gcc-libs"
    "glibc"
    "llvm-libs"
    "python"
    "spirv-tools"
    "hip-runtime-amd"
    "rocm-llvm"
    "cuda"
    "cuda-tools"
    "libcublas"
    "libcufft"
    "libcurand"
    "libcusolver"
    "libcusparse"
    "opencl-clhpp"
    "opencl-headers"
  )
  provides=(
    "${_pkgbase}-cuda-rocm-opencl-cpu=${pkgver}"
    "${_pkgbase}-backend"
    "hipsycl"
    "syclcc"
    "syclcc-clang"
  )
  conflicts=(
    "${_pkgbase}-cuda-rocm-opencl-cpu"
    "${_pkgbase}-backend"
    "syclcc"
    "syclcc-clang"
  )
  optdepends=()

  cd "${srcdir}"

  make DESTDIR="${pkgdir}" -C build-cuda-rocm-opencl-cpu install

  install -dvm755 "${pkgdir}/usr/share/licenses/${pkgname}"
  ln -svr "${pkgdir}/usr/share/licenses/${pkgbase}/LICENSE"  "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
}

_package_level_zero_opencl_cpu() {
  pkgdesc="Independent, community-driven modern platform for C++-based heterogeneous programming models targeting CPUs and GPUs from all major vendors. (formerly known as hipSYCL / Open SYCL). Level Zero + OpenCL + CPU backends."
  depends=(
    "${_pkgbase}-common${_vcssuffix}=${pkgver}"
    "gcc-libs"
    "glibc"
    "llvm-libs"
    "python"
    "spirv-tools"
    "level-zero"
    "level-zero-headers"
    "opencl-clhpp"
    "opencl-headers"
  )
  provides=(
    "${_pkgbase}-level-zero-opencl-cpu=${pkgver}"
    "${_pkgbase}-backend"
    "hipsycl"
    "syclcc"
    "syclcc-clang"
  )
  conflicts=(
    "${_pkgbase}-level-zero-opencl-cpu"
    "${_pkgbase}-backend"
    "syclcc"
    "syclcc-clang"
  )
  optdepends=()

  cd "${srcdir}"

  make DESTDIR="${pkgdir}" -C build-level-zero-opencl-cpu install

  install -dvm755 "${pkgdir}/usr/share/licenses/${pkgname}"
  ln -svr "${pkgdir}/usr/share/licenses/${pkgbase}/LICENSE"  "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
}

for _p in common cpu cuda opencl rocm level-zero cuda-rocm-opencl-cpu level-zero-opencl-cpu; do
  eval "package_${_pkgbase}-${_p}${_vcssuffix}() {
    $(declare -f "_package_${_p}")
    _package_${_p}
  }"
done

Then we have this version which tries to consolidate things down for my scattered brain to try to better understand what's up. Same thing applies above: just some tinkering and experimenting I wish to share.

  • Used variables for repeated values: _common_depends for common dependencies _opencl_depends, _rocm_depends, _cuda_depends, and _level_zero_depends for backend-specific dependencies
  • Crafted _prepare_backend function (prepares each backend)
  • Crafted _build_backend function (builds each backend)
  • Used loops in prepare and build functions (iterates over backends)
  • Used arrays for related variables (_backend_cmake_options associative array) for backend-specific CMake options
  • Used conditional expressions in _package_backend (includes backend-specific dependencies [only when needed])
  • Combined _package_backend description, dependencies, provides, conflicts, and install steps.
  • Parameterized the function for different backends with $backend.

# Maintainer: NotMe

_pkgbase='adaptivecpp'
_vcssuffix='-git'
pkgbase="${_pkgbase}${_vcssuffix}"
pkgname=(
  "${_pkgbase}-common${_vcssuffix}"
  "${_pkgbase}-cpu${_vcssuffix}"
  "${_pkgbase}-cuda${_vcssuffix}"
  "${_pkgbase}-opencl${_vcssuffix}"
  "${_pkgbase}-rocm${_vcssuffix}"
  "${_pkgbase}-level-zero${_vcssuffix}"
  "${_pkgbase}-cuda-rocm-opencl-cpu${_vcssuffix}"
  "${_pkgbase}-level-zero-opencl-cpu${_vcssuffix}"
)
pkgver=23.10.0+130.r2453.20240207.f144e21f
pkgrel=1
pkgdesc="Independent, community-driven modern platform for C++-based heterogeneous programming models targeting CPUs and GPUs from all major vendors. (formerly known as hipSYCL / Open SYCL)."
arch=('x86_64')
url="https://github.com/AdaptiveCpp/AdaptiveCpp"
license=('BSD-2-Clause')
makedepends=(
  'boost' 'clang' 'cmake' 'cuda' 'cuda-tools' 'gcc-libs' 'git' 'glibc' 'hip-runtime-amd' 'level-zero' 'level-zero-headers'
  'libcublas' 'libcufft' 'libcurand' 'libcusolver' 'libcusparse' 'libffi' 'libxml2' 'llvm' 'llvm-libs' 'ncurses' 'opencl-clhpp'
  'opencl-headers' 'openmp' 'python' 'rocm-llvm' 'spirv-tools' 'zlib' 'zstd'
)
source=("${_pkgbase}::git+${url}.git")
sha256sums=('SKIP')

_common_depends=('gcc-libs' 'glibc' 'llvm-libs' 'python')
_opencl_depends=('spirv-tools' 'opencl-clhpp' 'opencl-headers')
_rocm_depends=('hip-runtime-amd' 'rocm-llvm')
_cuda_depends=('cuda' 'cuda-tools' 'libcublas' 'libcufft' 'libcurand' 'libcusolver' 'libcusparse')
_level_zero_depends=('level-zero' 'level-zero-headers')

declare -A _backend_cmake_options=(
  ["cpu"]="-DWITH_ACCELERATED_CPU=ON -DWITH_CUDA_BACKEND=OFF -DWITH_CUDA_NVCXX_ONLY=OFF -DWITH_OPENCL_BACKEND=OFF -DWITH_ROCM_BACKEND=OFF -DWITH_LEVEL_ZERO_BACKEND=OFF"
  ["cuda"]="-DCUDAToolkit_ROOT_DIR=/opt/cuda -DCUDAToolkit_NVCC_EXECUTABLE=/opt/cuda/bin/nvcc -DWITH_ACCELERATED_CPU=ON -DWITH_CUDA_BACKEND=ON -DWITH_CUDA_NVCXX_ONLY=OFF -DWITH_OPENCL_BACKEND=OFF -DWITH_ROCM_BACKEND=OFF -DWITH_LEVEL_ZERO_BACKEND=OFF"
  ["opencl"]="-DWITH_ACCELERATED_CPU=ON -DWITH_CUDA_BACKEND=OFF -DWITH_CUDA_NVCXX_ONLY=OFF -DWITH_OPENCL_BACKEND=ON -DWITH_ROCM_BACKEND=OFF -DWITH_LEVEL_ZERO_BACKEND=OFF"
  ["rocm"]="-DHIPCC_COMPILER=/opt/rocm/bin/hipcc -DHIP_DIR=/opt/rocm/lib/cmake/hip -DROCM_PATH=/opt/rocm -DWITH_ACCELERATED_CPU=ON -DWITH_CUDA_BACKEND=OFF -DWITH_CUDA_NVCXX_ONLY=OFF -DWITH_OPENCL_BACKEND=ON -DWITH_ROCM_BACKEND=ON -DWITH_LEVEL_ZERO_BACKEND=OFF"
  ["level_zero"]="-DWITH_ACCELERATED_CPU=ON -DWITH_CUDA_BACKEND=OFF -DWITH_CUDA_NVCXX_ONLY=OFF -DWITH_OPENCL_BACKEND=OFF -DWITH_ROCM_BACKEND=OFF -DWITH_LEVEL_ZERO_BACKEND=ON"
  ["cuda_rocm_opencl_cpu"]="-DHIPCC_COMPILER=/opt/rocm/bin/hipcc -DHIP_DIR=/opt/rocm/lib/cmake/hip -DROCM_PATH=/opt/rocm -DCUDAToolkit_ROOT_DIR=/opt/cuda -DCUDAToolkit_NVCC_EXECUTABLE=/opt/cuda/bin/nvcc -DWITH_ACCELERATED_CPU=ON -DWITH_CUDA_BACKEND=ON -DWITH_CUDA_NVCXX_ONLY=OFF -DWITH_OPENCL_BACKEND=ON -DWITH_ROCM_BACKEND=ON -DWITH_LEVEL_ZERO_BACKEND=OFF"
  ["level_zero_opencl_cpu"]="-DWITH_ACCELERATED_CPU=ON -DWITH_CUDA_BACKEND=OFF -DWITH_CUDA_NVCXX_ONLY=OFF -DWITH_OPENCL_BACKEND=ON -DWITH_ROCM_BACKEND=OFF -DWITH_LEVEL_ZERO_BACKEND=ON"
)

_cmake_general_options=(
  -S "${_pkgbase}"
  -DCMAKE_BUILD_TYPE=Release
  -DCMAKE_INSTALL_PREFIX=/usr
  -DFETCHCONTENT_FULLY_DISCONNECTED=OFF
  -DFETCHCONTENT_QUIET=OFF
  -DFETCHCONTENT_UPDATES_DISCONNECTED=OFF
  -DFETCHCONTENT_UPDATES_DISCONNECTED_LLVMSPIRVTRANSLATOR="_deps/llvmspirvtranslator-src"
  -DFETCHCONTENT_UPDATES_DISCONNECTED_OCL-CXX-HEADERS="_deps/ocl-cxx-headers-src"
  -DFETCHCONTENT_UPDATES_DISCONNECTED_OCL-HEADERS="_deps/ocl-headers-src"
  -DACPP_CONFIG_FILE_GLOBAL_INSTALLATION=ON
  -DBUILD_DOCS=ON
  -DBUILD_EXAMPLES=ON
  -DHIPSYCL_DEBUG_LEVEL=2
  -DLLVM_DIR=/usr/lib/cmake/llvm
  -DWITH_SSCP_COMPILER=ON
  -DWITH_STDPAR_COMPILER=ON
  -DWITH_LEVEL_ZERO_BACKEND=ON
)

_prepare_backend() {
  local backend="$1"
  mkdir -p "build-$backend"
  cmake -B "build-$backend" "${_cmake_general_options[@]}" ${_backend_cmake_options["$backend"]}
}

_build_backend() {
  local backend="$1"
  make -C "build-$backend" -j$(nproc)
}

prepare() {
  cd "${srcdir}/${_pkgbase}"
  for backend in "${!_backend_cmake_options[@]}"; do
    _prepare_backend "$backend"
  done
  git log > git.log
}

pkgver() {
  cd "${srcdir}/${_pkgbase}"
  _ver="$(git describe --tags | sed 's|^[vV]||' | sed 's|-g[0-9a-fA-F]*$||' | tr '-' '+')"
  _rev="$(git rev-list --count HEAD)"
  _date="$(git log -1 --date=format:"%Y%m%d" --format="%ad")"
  _hash="$(git rev-parse --short HEAD)"
  printf '%s' "${_ver}.r${_rev}.${_date}.${_hash}"
}

build() {
  for backend in "${!_backend_cmake_options[@]}"; do
    _build_backend "$backend"
  done
}

_package_common() {
  pkgdesc="Independent, community-driven modern platform for C++-based heterogeneous programming models targeting CPUs and GPUs from all major vendors. (formerly known as hipSYCL / Open SYCL). Common files."
  depends=()
  provides=("${_pkgbase}-common=${pkgver}")
  conflicts=("${_pkgbase}-common")
  optdepends=(
    "${_pkgbase}-cpu${_vcssuffix}=${pkgver}:    For CPU only backend."
    "${_pkgbase}-cuda${_vcssuffix}=${pkgver}:   For CUDA backend."
    "${_pkgbase}-opencl${_vcssuffix}=${pkgver}: For OpenCL backend."
    "${_pkgbase}-rocm${_vcssuffix}=${pkgver}:   For ROCm backend."
    "${_pkgbase}-level-zero${_vcssuffix}=${pkgver}: For Level Zero backend."
    "${_pkgbase}-cuda-rocm-opencl-cpu${_vcssuffix}=${pkgver}: For CUDA + ROCm + OpenCL + CPU backends."
    "${_pkgbase}-level-zero-opencl-cpu${_vcssuffix}=${pkgver}: For Level Zero + OpenCL + CPU backends."
  )
  cd "${srcdir}/${_pkgbase}"
  install -Dvm644 -t "${pkgdir}/usr/share/doc/${_pkgbase}"      git.log CONTRIBUTING.md README.md
  install -Dvm644 -t "${pkgdir}/usr/share/licenses/${pkgbase}"  LICENSE
  ln -svr "${pkgdir}/usr/share/licenses/${pkgbase}/LICENSE"     "${pkgdir}/usr/share/doc/${_pkgbase}/LICENSE"
  install -dvm755 "${pkgdir}/usr/share/licenses/${pkgname}"
  ln -svr "${pkgdir}/usr/share/licenses/${pkgbase}/LICENSE"     "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
}

_package_backend() {
  local backend="$1"
  pkgdesc="Independent, community-driven modern platform for C++-based heterogeneous programming models targeting CPUs and GPUs from all major vendors. (formerly known as hipSYCL / Open SYCL). $backend backend."
  depends=("${_pkgbase}-common${_vcssuffix}=${pkgver}" "${_common_depends[@]}" ${_opencl_depends[@]+"${_opencl_depends[@]}"} ${_rocm_depends[@]+"${_rocm_depends[@]}"} ${_cuda_depends[@]+"${_cuda_depends[@]}"} ${_level_zero_depends[@]+"${_level_zero_depends[@]}"})
  provides=("${_pkgbase}-$backend=${pkgver}" "${_pkgbase}-backend" "hipsycl" "syclcc" "syclcc-clang")
  conflicts=("${_pkgbase}-$backend" "${_pkgbase}-backend" "syclcc" "syclcc-clang")
  optdepends=()
  make DESTDIR="$pkgdir" -C "build-$backend" install
  install -dvm755 "${pkgdir}/usr/share/licenses/${pkgname}"
  ln -svr "${pkgdir}/usr/share/licenses/${pkgbase}/LICENSE"  "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
}

for _p in common cpu cuda opencl rocm level-zero cuda-rocm-opencl-cpu level-zero-opencl-cpu; do
  eval "package_${_pkgbase}-${_p}${_vcssuffix}() {
    $(declare -f "_package_${_p//-/_}")
    _package_${_p//-/_}
  }"
done