* add hipsolver

This commit is contained in:
Alexander Baldeck 2025-02-22 10:29:01 +01:00
parent c5c8cae703
commit 15b2597e8d
5 changed files with 143 additions and 0 deletions

26
rocm/hipsolver/.SRCINFO Normal file
View File

@ -0,0 +1,26 @@
pkgbase = hipsolver
pkgdesc = rocSOLVER marshalling library.
pkgver = 6.2.4
pkgrel = 1
url = https://rocm.docs.amd.com/projects/hipSOLVER/en/latest/index.html
arch = x86_64
arch = powerpc64le
arch = powerpc64
arch = powerpc
arch = riscv64
license = MIT
makedepends = cmake
makedepends = rocm-cmake
makedepends = gcc-fortran
depends = rocm-core
depends = glibc
depends = gcc-libs
depends = hip-runtime-amd
depends = rocsolver
depends = rocblas
depends = suitesparse
options = !lto
source = hipsolver-6.2.4.tar.gz::https://github.com/ROCm/hipSOLVER/archive/rocm-6.2.4.tar.gz
sha256sums = 4dc564498361cb1bac17dcfeaf0f2b9c85320797c75b05ee33160a133f5f4a15
pkgname = hipsolver

View File

@ -0,0 +1,5 @@
[hipsolver]
source = 'github'
github = 'ROCm/hipSOLVER'
use_latest_release = true
prefix = 'rocm-'

40
rocm/hipsolver/PKGBUILD Normal file
View File

@ -0,0 +1,40 @@
# POWER Maintainer: Alexander Baldeck <alex.bldck@gmail.com>
# Maintainer: Torsten Keßler <tpkessler at archlinux dot org>
pkgname=hipsolver
pkgver=6.2.4
pkgrel=1
pkgdesc='rocSOLVER marshalling library.'
arch=(x86_64 powerpc64le powerpc64 powerpc riscv64)
url='https://rocm.docs.amd.com/projects/hipSOLVER/en/latest/index.html'
license=('MIT')
depends=('rocm-core' 'glibc' 'gcc-libs' 'hip-runtime-amd' 'rocsolver' 'rocblas'
'suitesparse')
makedepends=('cmake' 'rocm-cmake' 'gcc-fortran')
_git='https://github.com/ROCm/hipSOLVER'
source=("$pkgname-$pkgver.tar.gz::$_git/archive/rocm-$pkgver.tar.gz")
sha256sums=('4dc564498361cb1bac17dcfeaf0f2b9c85320797c75b05ee33160a133f5f4a15')
options=(!lto)
_dirname="$(basename "$_git")-$(basename "${source[0]}" ".tar.gz")"
build() {
# -fcf-protection is not supported by HIP, see
# https://rocm.docs.amd.com/projects/llvm-project/en/latest/reference/rocmcc.html#support-status-of-other-clang-options
local cmake_args=(
-Wno-dev
-S "$_dirname"
-B build
-D CMAKE_BUILD_TYPE=None
-D CMAKE_CXX_COMPILER=/opt/rocm/bin/hipcc
-D CMAKE_CXX_FLAGS="${CXXFLAGS} -fcf-protection=none"
-D CMAKE_INSTALL_PREFIX=/opt/rocm
)
cmake "${cmake_args[@]}"
cmake --build build
}
package() {
DESTDIR="$pkgdir" cmake --install build
install -Dm644 "$srcdir/$_dirname/LICENSE.md" "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
}

67
rocm/hipsolver/test.cpp Normal file
View File

@ -0,0 +1,67 @@
#include <hipsolver/hipsolver.h>
#include <hip/hip_runtime.h>
#include <vector>
#include <random>
#include <algorithm>
#include <cmath>
#include <iostream>
int main()
{
size_t n = 64;
size_t m = 41;
size_t size = n * m;
std::random_device rd;
std::mt19937 gen(rd());
std::uniform_real_distribution<float> dist(-1.0, 1.0);
auto myrand = [&](){return dist(gen);};
float *a;
hipMalloc((void**)&a, sizeof *a * size);
std::vector<float> ain(size);
std::generate(ain.begin(), ain.end(), myrand);
hipMemcpy(a, ain.data(), sizeof *a * size, hipMemcpyHostToDevice);
hipsolverHandle_t handle;
hipsolverCreate(&handle);
float *work;
int size_work;
hipsolverSgesvd_bufferSize(handle, 'N', 'N', n, m, &size_work);
hipMalloc((void**)&work, size_work);
size_t dim = std::min(n, m);
float *s;
float *rwork;
hipMalloc((void**)&s, sizeof *s * dim);
hipMalloc((void**)&rwork, sizeof *rwork * dim);
int *devInfo;
hipMalloc((void**)&devInfo, sizeof *devInfo);
hipsolverSgesvd(handle, 'N', 'N', n, m, a, n,
s, NULL, n, NULL, n, work, size_work, rwork, devInfo);
std::vector<float> sout(dim);
hipMemcpy(sout.data(), s, sizeof *s * dim, hipMemcpyDeviceToHost);
float tol = 0.001f;
for(size_t i = 0; i < dim; i++){
if(sout[i] / sout[0] < tol){
std::cout << "Rank of matrix is " << i + 1
<< " but should have rank " << dim << std::endl;
return 1;
}
}
std::cout << "TESTS PASSED!" << std::endl;
hipFree(a);
hipFree(s);
hipFree(rwork);
hipFree(work);
hipFree(devInfo);
hipsolverDestroy(handle);
}

5
rocm/hipsolver/test.sh Executable file
View File

@ -0,0 +1,5 @@
#! /usr/bin/env sh
OUT=$(mktemp -d)
/opt/rocm/bin/hipcc -o "$OUT"/test test.cpp -lhipsolver -lrocsolver -lrocblas
"$OUT"/test