Date: Wednesday, December 28, 2022 @ 16:03:34
  Author: tpkessler
Revision: 1371820

archrelease: copy trunk to community-testing-x86_64

Added:
  hipsparse/repos/community-testing-x86_64/
  hipsparse/repos/community-testing-x86_64/PKGBUILD
    (from rev 1371819, hipsparse/trunk/PKGBUILD)
  hipsparse/repos/community-testing-x86_64/test.cpp
    (from rev 1371819, hipsparse/trunk/test.cpp)
  hipsparse/repos/community-testing-x86_64/test.sh
    (from rev 1371819, hipsparse/trunk/test.sh)

----------+
 PKGBUILD |   48 +++++++++++++++++++++++++++++
 test.cpp |   99 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 test.sh  |    5 +++
 3 files changed, 152 insertions(+)

Copied: hipsparse/repos/community-testing-x86_64/PKGBUILD (from rev 1371819, 
hipsparse/trunk/PKGBUILD)
===================================================================
--- community-testing-x86_64/PKGBUILD                           (rev 0)
+++ community-testing-x86_64/PKGBUILD   2022-12-28 16:03:34 UTC (rev 1371820)
@@ -0,0 +1,48 @@
+# Maintainer: Torsten Keßler <tpkessler at archlinux dot org>
+# Contributor: Markus Näther <[email protected]>
+# Contributor: acxz <akashpatel2008 at yahoo dot com>
+
+pkgname=hipsparse
+pkgver=5.4.1
+pkgrel=2
+pkgdesc='rocSPARSE marshalling library.'
+arch=('x86_64')
+url='https://hipsparse.readthedocs.io/en/latest/'
+license=('MIT')
+depends=('hip' 'rocsparse')
+makedepends=('rocm-cmake' 'gcc-fortran')
+_git='https://github.com/ROCmSoftwarePlatform/hipSPARSE'
+source=("$pkgname-$pkgver.tar.gz::$_git/archive/rocm-$pkgver.tar.gz"
+        "hipsparse-no-git.patch")
+sha256sums=('fdc9b7f6ce27b544c4be102ca25967ff61272111acdd52d6e21eeeace0213792'
+            '0f4ca37b246e9908ebb3a80818abb28b4c6996036b65f8f89be9affc854efa7f')
+_dirname="$(basename "$_git")-$(basename "${source[0]}" ".tar.gz")"
+
+prepare() {
+    cd "$_dirname"
+    patch -Np1 -i "$srcdir/hipsparse-no-git.patch"
+}
+
+build() {
+  # -fcf-protection is not supported by HIP, see
+  # 
https://docs.amd.com/bundle/ROCm-Compiler-Reference-Guide-v5.4/page/Appendix_A.html
+  CXXFLAGS="${CXXFLAGS} -fcf-protection=none" \
+  HIP_PATH=/opt/rocm \
+  cmake \
+    -Wno-dev \
+    -B build \
+    -S "$_dirname" \
+    -DCMAKE_BUILD_TYPE=None \
+    -DCMAKE_CXX_COMPILER=/opt/rocm/bin/hipcc \
+    -DCMAKE_INSTALL_PREFIX=/opt/rocm
+  cmake --build build
+}
+
+package() {
+  DESTDIR="$pkgdir" cmake --install build
+
+  echo "/opt/rocm/$pkgname/lib" > "$pkgname.conf"
+  install -Dm644 "$pkgname.conf" "$pkgdir/etc/ld.so.conf.d/$pkgname.conf"
+
+  install -Dm644 "$srcdir/$_dirname/LICENSE.md" 
"$pkgdir/usr/share/licenses/$pkgname/LICENSE"
+}

Copied: hipsparse/repos/community-testing-x86_64/test.cpp (from rev 1371819, 
hipsparse/trunk/test.cpp)
===================================================================
--- community-testing-x86_64/test.cpp                           (rev 0)
+++ community-testing-x86_64/test.cpp   2022-12-28 16:03:34 UTC (rev 1371820)
@@ -0,0 +1,99 @@
+#include <hipsparse/hipsparse.h>
+#include <hip/hip_runtime.h>
+#include <iostream>
+#include <vector>
+#include <random>
+#include <algorithm>
+
+int main()
+{
+    int 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);
+
+    hipsparseHandle_t handle;
+    hipsparseCreate(&handle);
+
+    std::vector<int> row_ptr(n + 1);
+    std::vector<int> 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++){
+        int 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;
+    }
+
+    int *rp;
+    int *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;
+
+    hipsparseMatDescr_t descr;
+    hipsparseCreateMatDescr(&descr);
+
+    hipsparseScsrmv(handle, HIPSPARSE_OPERATION_NON_TRANSPOSE,
+        n, n, 3 * n - 2, &alpha, descr, d, rp, c,
+        x, &beta, y);
+
+    std::vector<float> yout(n);
+    hipMemcpy(yout.data(), y, sizeof *y * n, hipMemcpyDeviceToHost);
+
+    float tol = 0.0001f;
+    for(int i = 0; i < n; i++){
+        for(int jj = row_ptr[i]; jj < row_ptr[i + 1]; jj++){
+            int 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;
+
+    hipsparseDestroy(handle);
+    hipsparseDestroyMatDescr(descr);
+    hipFree(rp);
+    hipFree(c);
+    hipFree(d);
+    hipFree(x);
+    hipFree(y);
+}

Copied: hipsparse/repos/community-testing-x86_64/test.sh (from rev 1371819, 
hipsparse/trunk/test.sh)
===================================================================
--- community-testing-x86_64/test.sh                            (rev 0)
+++ community-testing-x86_64/test.sh    2022-12-28 16:03:34 UTC (rev 1371820)
@@ -0,0 +1,5 @@
+#! /usr/bin/env sh
+
+OUT=$(mktemp -d)
+/opt/rocm/bin/hipcc -o "$OUT"/test test.cpp -lhipsparse -lrocsparse
+"$OUT"/test

Reply via email to