* add rocsolver

This commit is contained in:
Alexander Baldeck 2024-03-21 19:40:42 +01:00
parent 9c058e7cfd
commit 83c796d5bb
5 changed files with 143 additions and 0 deletions

22
rocsolver/.SRCINFO Normal file
View File

@ -0,0 +1,22 @@
pkgbase = rocsolver
pkgdesc = Subset of LAPACK functionality on the ROCm platform
pkgver = 6.0.2
pkgrel = 1
url = https://rocm.docs.amd.com/projects/rocSOLVER/en/latest/index.html
arch = x86_64
license = BSD-2-Clause
makedepends = rocm-cmake
makedepends = python-pyaml
makedepends = fmt
depends = rocm-core
depends = glibc
depends = gcc-libs
depends = hip
depends = rocblas
depends = rocsparse
options = !lto
options = !buildflags
source = rocsolver-6.0.2.tar.gz::https://github.com/ROCmSoftwarePlatform/rocSOLVER/archive/rocm-6.0.2.tar.gz
sha256sums = 781d5df2886ab0d5087a215a33ac390dd27653b2a9b4a620c7d51b0ae56f63d2
pkgname = rocsolver

View File

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

43
rocsolver/PKGBUILD Normal file
View File

@ -0,0 +1,43 @@
# POWER Maintainer: Alexander Baldeck <alex.bldck@gmail.com>
# Maintainer: Torsten Keßler <tpkessler at archlinux dot org>
pkgname=rocsolver
pkgver=6.0.2
pkgrel=1
pkgdesc='Subset of LAPACK functionality on the ROCm platform'
arch=(x86_64 powerpc64le powerpc64 riscv64)
url='https://rocm.docs.amd.com/projects/rocSOLVER/en/latest/index.html'
license=('BSD-2-Clause')
depends=('rocm-core' 'glibc' 'gcc-libs' 'hip' 'rocblas' 'rocsparse')
makedepends=('rocm-cmake' 'python-pyaml' 'fmt')
_git='https://github.com/ROCmSoftwarePlatform/rocSOLVER'
source=("$pkgname-$pkgver.tar.gz::$_git/archive/rocm-$pkgver.tar.gz")
sha256sums=('781d5df2886ab0d5087a215a33ac390dd27653b2a9b4a620c7d51b0ae56f63d2')
options=(!debug !lto !buildflags)
_dirname="$(basename "$_git")-$(basename "${source[0]}" .tar.gz)"
build() {
# Compile source code for supported GPU archs in parallel
#export HIPCC_COMPILE_FLAGS_APPEND="-parallel-jobs=$(nproc)"
#export HIPCC_LINK_FLAGS_APPEND="-parallel-jobs=$(nproc)"
# -fcf-protection is not supported by HIP, see
# https://rocm.docs.amd.com/en/latest/reference/rocmcc.html#support-status-of-other-clang-options
local cmake_args=(
-Wno-dev
-S "$_dirname"
-B build
-D CMAKE_BUILD_TYPE=Release
-D CMAKE_CXX_COMPILER=/opt/rocm/bin/hipcc
-D CMAKE_CXX_FLAGS="${CXXFLAGS} -fcf-protection=none"
-D CMAKE_INSTALL_PREFIX=/opt/rocm
-D ROCSOLVER_EMBED_FMT=ON
)
cmake "${cmake_args[@]}"
cmake --build build
}
package() {
DESTDIR="$pkgdir" cmake --install build
install -Dm644 "$_dirname/LICENSE.md" "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
}

68
rocsolver/test.cpp Normal file
View File

@ -0,0 +1,68 @@
#include <rocsolver/rocsolver.h>
#include <hip/hip_runtime.h>
#include <vector>
#include <random>
#include <algorithm>
#include <cmath>
#include <iostream>
int main()
{
size_t n = 128;
size_t size = n * n;
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;
float *x;
hipMalloc((void**)&a, sizeof *a * size);
hipMalloc((void**)&x, sizeof *x * n);
std::vector<float> ain(size);
std::vector<float> xin(n);
std::generate(ain.begin(), ain.end(), myrand);
std::generate(xin.begin(), xin.end(), myrand);
hipMemcpy(a, ain.data(), sizeof *a * size, hipMemcpyHostToDevice);
hipMemcpy(x, xin.data(), sizeof *x * n, hipMemcpyHostToDevice);
rocblas_handle handle;
rocblas_create_handle(&handle);
rocblas_int *info;
hipMalloc((void**)&info, sizeof *info);
rocsolver_sgels(handle, rocblas_operation_none,
n, n, 1, a, n, x, n, info);
std::vector<float> xout(n);
hipMemcpy(xout.data(), x, sizeof *x * n, hipMemcpyDeviceToHost);
rocblas_int hinfo;
hipMemcpy(&hinfo, info, sizeof *info, hipMemcpyDeviceToHost);
if(hinfo != 0){
std::cout << "Matrix is rank deficient!\n";
return 1;
}
float tol = 0.001f;
for(size_t i = 0; i < n; i++){
for(size_t j = 0; j < n; j++){
xin[i] -= ain[i + j * n] * xout[j];
}
if(std::abs(xin[i]) > tol){
std::cout << "Missmatch at index " << i << "\n"
<< "Desired: 0" << "\n"
<< "Actual : " << xin[i] << std::endl;
return 1;
}
}
std::cout << "TESTS PASSED!" << std::endl;
hipFree(a);
hipFree(x);
rocblas_destroy_handle(handle);
}

5
rocsolver/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 -lrocsolver -lrocblas
"$OUT"/test