# Maintainer: Torsten Keßler <tpkessler at archlinux dot org>
pkgname=hipblaslt
pkgver=6.0.2
pkgrel=1
pkgdesc='General matrix-matrix operations beyond a traditional BLAS library'
arch=('x86_64' 'aarch64')
url='https://rocm.docs.amd.com/projects/hipBLASLt/en/latest/index.html'
license=('MIT')
depends=('rocm-core' 'glibc' 'gcc-libs' 'hip' 'hipblas' 'rocblas')
makedepends=('rocm-cmake' 'python' 'cmake' 'git'
             'msgpack-cxx' 'python-msgpack' 'python-joblib' 'python-pyaml')
_git='https://github.com/ROCm/hipBLASLt'
source=("$pkgname-$pkgver.tar.gz::$_git/archive/rocm-$pkgver.tar.gz"
        "$pkgname-find-msgpack5.patch")
sha256sums=('e281a1a7760fab8c3e0baafe17950cf43c422184e3226e3c14eb06e50c69d421'
            '7943de413882065de7d840a4a0f48e8133c4977a04a3e9587ea7936cc8a0939d')
_dirname="$(basename "$_git")-$(basename "${source[0]}" ".tar.gz")"

prepare() {
  cd "$_dirname"
  patch -Np1 -i "$srcdir/$pkgname-find-msgpack5.patch"
}

build() {
  local cmake_args=(
    -Wno-dev
    -B build
    -S "$_dirname"
    -DCMAKE_BUILD_TYPE=None
    -DCMAKE_CXX_COMPILER=/opt/rocm/bin/hipcc
    -DCMAKE_INSTALL_PREFIX=/opt/rocm
    -DTensile_CODE_OBJECT_VERSION=V3  # V2 is not supported by all GPU targets
  )
  # -fcf-protection is not supported by HIP, see
  # https://docs.amd.com/bundle/ROCm-Compiler-Reference-Guide-v5.5/page/Compiler_Options_and_Features.html#d2e2018
  CXXFLAGS="${CXXFLAGS} -fcf-protection=none" cmake "${cmake_args[@]}"
  cmake --build build
}

package() {
  DESTDIR="$pkgdir" cmake --install build

  install -Dm644 "$_dirname/LICENSE.md" "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
}
