* add rocsparse
This commit is contained in:
parent
68a40eb41c
commit
2a5ac45880
21
rocsparse/.SRCINFO
Normal file
21
rocsparse/.SRCINFO
Normal file
@ -0,0 +1,21 @@
|
||||
pkgbase = rocsparse
|
||||
pkgdesc = BLAS for sparse computation on top of ROCm
|
||||
pkgver = 6.0.2
|
||||
pkgrel = 2
|
||||
url = https://rocm.docs.amd.com/projects/rocSPARSE/en/latest/index.html
|
||||
arch = x86_64
|
||||
license = MIT
|
||||
makedepends = cmake
|
||||
makedepends = rocm-cmake
|
||||
makedepends = gcc-fortran
|
||||
depends = rocm-core
|
||||
depends = glibc
|
||||
depends = gcc-libs
|
||||
depends = hip
|
||||
depends = rocprim
|
||||
options = !lto
|
||||
options = !buildflags
|
||||
source = rocsparse-6.0.2.tar.gz::https://github.com/ROCmSoftwarePlatform/rocSPARSE/archive/rocm-6.0.2.tar.gz
|
||||
sha256sums = 00292eb7efe5719a65960bdbe391ba8e0ce610487eea11397aad6a14b11e12cd
|
||||
|
||||
pkgname = rocsparse
|
5
rocsparse/.nvchecker.toml
Normal file
5
rocsparse/.nvchecker.toml
Normal file
@ -0,0 +1,5 @@
|
||||
[rocsparse]
|
||||
source = 'github'
|
||||
github = 'ROCm/rocSPARSE'
|
||||
use_latest_release = true
|
||||
prefix = 'rocm-'
|
41
rocsparse/PKGBUILD
Normal file
41
rocsparse/PKGBUILD
Normal file
@ -0,0 +1,41 @@
|
||||
# POWER Maintainer: Alexander Baldeck <alex.bldck@gmail.com>
|
||||
# Maintainer: Torsten Keßler <tpkessler at archlinux dot org>
|
||||
# Contributor: Markus Näther <naetherm@informatik.uni-freiburg.de>
|
||||
pkgname=rocsparse
|
||||
pkgver=6.0.2
|
||||
pkgrel=2
|
||||
pkgdesc='BLAS for sparse computation on top of ROCm'
|
||||
arch=(x86_64 powerpc64le powerpc64 riscv64)
|
||||
url='https://rocm.docs.amd.com/projects/rocSPARSE/en/latest/index.html'
|
||||
license=('MIT')
|
||||
depends=('rocm-core' 'glibc' 'gcc-libs' 'hip' 'rocprim')
|
||||
makedepends=('cmake' 'rocm-cmake' 'gcc-fortran')
|
||||
_git='https://github.com/ROCmSoftwarePlatform/rocSPARSE'
|
||||
source=("$pkgname-$pkgver.tar.gz::$_git/archive/rocm-$pkgver.tar.gz")
|
||||
sha256sums=('00292eb7efe5719a65960bdbe391ba8e0ce610487eea11397aad6a14b11e12cd')
|
||||
# Disable default build flags and use release mode as otherwise the linker step
|
||||
# fails. The symbol offset size reaches the 32 bit integer limits.
|
||||
options=(!lto !buildflags)
|
||||
_dirname="$(basename "$_git")-$(basename "${source[0]}" ".tar.gz")"
|
||||
|
||||
build() {
|
||||
# -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
|
||||
)
|
||||
cmake "${cmake_args[@]}"
|
||||
cmake --build build
|
||||
}
|
||||
|
||||
package() {
|
||||
DESTDIR="$pkgdir" cmake --install build
|
||||
|
||||
install -Dm644 "$_dirname/LICENSE.md" "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
|
||||
}
|
100
rocsparse/test.cpp
Normal file
100
rocsparse/test.cpp
Normal file
@ -0,0 +1,100 @@
|
||||
#include <rocsparse/rocsparse.h>
|
||||
#include <hip/hip_runtime.h>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <random>
|
||||
#include <algorithm>
|
||||
|
||||
int main()
|
||||
{
|
||||
using rint = rocsparse_int;
|
||||
rint n = 1024;
|
||||
|
||||
std::random_device rd;
|
||||
std::mt19937 gen(rd());
|
||||
std::uniform_real_distribution<float> dist(-1.0, 1.0);
|
||||
|
||||
auto myrand = [&]() -> float {return dist(gen);};
|
||||
|
||||
std::vector<float> xin(n);
|
||||
std::generate(xin.begin(), xin.end(), myrand);
|
||||
|
||||
rocsparse_handle handle;
|
||||
rocsparse_create_handle(&handle);
|
||||
|
||||
std::vector<rint> row_ptr(n + 1);
|
||||
std::vector<rint> col(3 * n);
|
||||
std::vector<float> data(3 * n);
|
||||
|
||||
//Second order finite differences matrix in 1D
|
||||
row_ptr[0] = 0;
|
||||
for(size_t i = 0; i < n; i++){
|
||||
rint off = row_ptr[i];
|
||||
if(i > 0){
|
||||
col[off] = i - 1;
|
||||
data[off++] = -1.0f;
|
||||
}
|
||||
col[off] = i;
|
||||
data[off++] = 2.0f;
|
||||
if(i < n - 1){
|
||||
col[off] = i + 1;
|
||||
data[off++] = -1.0f;
|
||||
}
|
||||
row_ptr[i + 1] = off;
|
||||
}
|
||||
|
||||
rint *rp;
|
||||
rint *c;
|
||||
float *d;
|
||||
|
||||
float *x;
|
||||
float *y;
|
||||
hipMalloc((void **)&rp, sizeof *rp * (n + 1));
|
||||
hipMalloc((void **)&c, sizeof *c * 3 * n);
|
||||
hipMalloc((void **)&d, sizeof *d * 3 * n);
|
||||
|
||||
hipMalloc((void **)&x, sizeof *x * n);
|
||||
hipMalloc((void **)&y, sizeof *y * n);
|
||||
|
||||
hipMemcpy(rp, row_ptr.data(), sizeof *rp * (n + 1), hipMemcpyHostToDevice);
|
||||
hipMemcpy(c, col.data(), sizeof *c * 3 * n, hipMemcpyHostToDevice);
|
||||
hipMemcpy(d, data.data(), sizeof *d * 3 * n, hipMemcpyHostToDevice);
|
||||
|
||||
hipMemcpy(x, xin.data(), sizeof *x * n, hipMemcpyHostToDevice);
|
||||
|
||||
float alpha = 14.124f;
|
||||
float beta = 0.0f;
|
||||
|
||||
rocsparse_mat_descr descr;
|
||||
rocsparse_create_mat_descr(&descr);
|
||||
|
||||
rocsparse_scsrmv(handle, rocsparse_operation_none,
|
||||
n, n, 3 * n - 2, &alpha, descr, d, rp, c, nullptr,
|
||||
x, &beta, y);
|
||||
|
||||
std::vector<float> yout(n);
|
||||
hipMemcpy(yout.data(), y, sizeof *y * n, hipMemcpyDeviceToHost);
|
||||
|
||||
float tol = 0.0001f;
|
||||
for(rint i = 0; i < n; i++){
|
||||
for(rint jj = row_ptr[i]; jj < row_ptr[i + 1]; jj++){
|
||||
rint j = col[jj];
|
||||
yout[i] -= alpha * data[jj] * xin[j];
|
||||
}
|
||||
if(std::abs(yout[i]) > tol){
|
||||
std::cout << "Entry " << i << " is not computed correctly.\n";
|
||||
std::cout << "Expected 0 but got " << yout[i] << std::endl;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << "TESTS PASSED!" << std::endl;
|
||||
|
||||
rocsparse_destroy_handle(handle);
|
||||
rocsparse_destroy_mat_descr(descr);
|
||||
hipFree(rp);
|
||||
hipFree(c);
|
||||
hipFree(d);
|
||||
hipFree(x);
|
||||
hipFree(y);
|
||||
}
|
5
rocsparse/test.sh
Executable file
5
rocsparse/test.sh
Executable file
@ -0,0 +1,5 @@
|
||||
#! /usr/bin/env sh
|
||||
|
||||
OUT=$(mktemp -d)
|
||||
/opt/rocm/bin/hipcc -o "$OUT"/test test.cpp -lrocsparse
|
||||
"$OUT"/test
|
Loading…
x
Reference in New Issue
Block a user