-
Notifications
You must be signed in to change notification settings - Fork 99
SPARSE 2::sptrsv
Nathan Ellingwood edited this page Jun 24, 2020
·
4 revisions
Header File: KokkosSparse_sptrsv.hpp
Usage: KokkosSparse::Experimental::sptrsv_symbolic(handle, rowmap, entries, values);
Usage: KokkosSparse::Experimental::sptrsv_solve(handle, rowmap, entries, values, b, x);
Perform sparse triangular solve of linear system with triangular matrix stored in compressed row sparse ("Crs") format.
- Note: This capability is in the
Experimental
namespace, which indicates the interface is subject to change.
template <typename KernelHandle,
typename lno_row_view_t_,
typename lno_nnz_view_t_,
typename scalar_nnz_view_t_>
void sptrsv_symbolic(KernelHandle *handle,
lno_row_view_t_ rowmap,
lno_nnz_view_t_ entries,
scalar_nnz_view_t_ values);
template <typename KernelHandle,
typename lno_row_view_t_,
typename lno_nnz_view_t_,
typename scalar_nnz_view_t_,
class BType,
class XType>
void sptrsv_solve(KernelHandle *handle,
lno_row_view_t_ rowmap,
lno_nnz_view_t_ entries,
scalar_nnz_view_t_ values,
BType b,
XType x);
sptrsv_symbolic
- KernelHandle
- lno_row_view_t: a rank-1
Kokkos::View
of input matrix row map - lno_nnz_view_t: a rank-1
Kokkos::View
of input matrix entries - scalar_nnz_view_t: a rank-1
Kokkos::View
of input matrix values.
sptrsv_solve
- KernelHandle
- lno_row_view_t: a rank-1
Kokkos::View
of input matrix row map - lno_nnz_view_t: a rank-1
Kokkos::View
of input matrix entries - scalar_nnz_view_t: a rank-1
Kokkos::View
of input matrix values. - BType: a rank-1
Kokkos::View
of vector values. - XType: a rank-1
Kokkos::View
of vector values.
- Creation of a
KernelHandle
- All Views must have rank 1
-
lno_row_view_t::non_const_value_type
must matchKernelHandle::size_type
-
lno_nnz_view_t::non_const_value_type
must matchKernelHandle::nnz_lno_t
-
scalar_nnz_view_t::value_type
must matchKernelHandle::nnz_scalar_t
-
XType::value_type
must be non-const - KernelHandle and Views have same execution spaces, all Views have same device types
#include <Kokkos_Core.hpp>
#include <KokkosSparse_CrsMatrix.hpp>
#include <KokkosSparse_sptrsv.hpp>
#include <KokkosKernels_IOUtils.hpp>
#include <KokkosKernels_SparseUtils.hpp>
int main(int argc, char* argv[]) {
using namespace KokkosSparse;
using namespace KokkosSparse::Experimental;
using namespace KokkosKernels;
using namespace KokkosKernels::Impl;
using namespace KokkosKernels::Experimental;
Kokkos::initialize();
{
using scalar_t = double;
using lno_t = int;
using size_type = int;
using device = typename Kokkos::DefaultExecutionSpace::device_type;
using RowMapType = Kokkos::View< size_type*, device >;
using EntriesType = Kokkos::View< lno_t*, device >;
using ValuesType = Kokkos::View< scalar_t*, device >;
using KernelHandle = KokkosKernels::Experimental::KokkosKernelsHandle <size_type, lno_t, scalar_t,
typename device::execution_space, typename device::memory_space, typename device::memory_space>;
scalar_t ZERO = scalar_t(0);
scalar_t ONE = scalar_t(1);
const size_type nrows = 5;
const size_type nnz = 10;
// Upper triangular solve: x = U \ b
{
RowMapType row_map("row_map", nrows+1);
EntriesType entries("entries", nnz);
ValuesType values("values", nnz);
auto hrow_map = Kokkos::create_mirror_view(row_map);
auto hentries = Kokkos::create_mirror_view(entries);
auto hvalues = Kokkos::create_mirror_view(values);
// Fill rowmap, entries, of Crs graph for simple example matrix, values set to ones
// [ [1 0 1 0 0]
// [0 1 0 0 1]
// [0 0 1 1 1]
// [0 0 0 1 1]
// [0 0 0 0 1] ];
hrow_map(0) = 0;
hrow_map(1) = 2;
hrow_map(2) = 4;
hrow_map(3) = 7;
hrow_map(4) = 9;
hrow_map(5) = 10;
hentries(0) = 0;
hentries(1) = 2;
hentries(2) = 1;
hentries(3) = 4;
hentries(4) = 2;
hentries(5) = 3;
hentries(6) = 4;
hentries(7) = 3;
hentries(8) = 4;
hentries(9) = 4;
Kokkos::deep_copy(row_map, hrow_map);
Kokkos::deep_copy(entries, hentries);
Kokkos::deep_copy(values, ONE);
// Create the x and b vectors
// Solution to find
ValuesType x("x", nrows);
ValuesType b("b", nrows);
Kokkos::deep_copy(b, ONE);
// Create sptrsv kernel handle
KernelHandle kh;
bool is_lower_tri = false;
kh.create_sptrsv_handle(SPTRSVAlgorithm::SEQLVLSCHD_TP1, nrows, is_lower_tri);
sptrsv_symbolic(&kh, row_map, entries, values);
Kokkos::fence();
sptrsv_solve(&kh, row_map, entries, values, b, x);
Kokkos::fence();
kh.destroy_sptrsv_handle();
}
// Lower triangular solve: x = L \ b
{
RowMapType row_map("row_map", nrows+1);
EntriesType entries("entries", nnz);
ValuesType values("values", nnz);
auto hrow_map = Kokkos::create_mirror_view(row_map);
auto hentries = Kokkos::create_mirror_view(entries);
auto hvalues = Kokkos::create_mirror_view(values);
// Fill rowmap, entries, of Crs graph for simple example matrix, values set to ones
// [ [1 0 0 0 0]
// [0 1 0 0 0]
// [1 0 1 0 0]
// [0 0 1 1 0]
// [1 1 1 1 1] ];
hrow_map(0) = 0;
hrow_map(1) = 1;
hrow_map(2) = 2;
hrow_map(3) = 4;
hrow_map(4) = 6;
hrow_map(5) = 10;
hentries(0) = 0;
hentries(1) = 1;
hentries(2) = 0;
hentries(3) = 2;
hentries(4) = 2;
hentries(5) = 3;
hentries(6) = 1;
hentries(7) = 2;
hentries(8) = 3;
hentries(9) = 4;
Kokkos::deep_copy(row_map, hrow_map);
Kokkos::deep_copy(entries, hentries);
Kokkos::deep_copy(values, ONE);
// Create the x and b vectors
// Solution to find
ValuesType x("x", nrows);
ValuesType b("b", nrows);
Kokkos::deep_copy(b, ONE);
// Create sptrsv kernel handle
KernelHandle kh;
bool is_lower_tri = true;
kh.create_sptrsv_handle(SPTRSVAlgorithm::SEQLVLSCHD_TP1, nrows, is_lower_tri);
sptrsv_symbolic(&kh, row_map, entries, values);
Kokkos::fence();
sptrsv_solve(&kh, row_map, entries, values, b, x);
Kokkos::fence();
kh.destroy_sptrsv_handle();
}
}
Kokkos::finalize();
}
When the CuSPARSE TPL is enabled at configuration the algorithm is available as an option for sptrsv.
Set the solver to use CuSPARSE during handle creation with the option SPTRSVAlgorithm::SPTRSV_CUSPARSE