43 #ifndef KOKKOS_CRSMATRIX_CUSPARSE_HPP_
44 #define KOKKOS_CRSMATRIX_CUSPARSE_HPP_
49 #include <impl/Kokkos_PhysicalLayout.hpp>
69 template<
typename T,
class RangeVectorType,
class CrsMatrixType,
class DomainVectorType>
71 MV_Multiply_DoCuSparse (
typename Kokkos::Impl::enable_if<! Kokkos::Impl::is_same<T, double>::value && ! Kokkos::Impl::is_same<T, float>::value,
typename RangeVectorType::value_type>::type s_b,
const RangeVectorType& y,
typename DomainVectorType::value_type s_a,
const CrsMatrixType& A ,
const DomainVectorType& x) {
75 template<
typename T,
class RangeVector,
class CrsMatrix,
class DomainVector>
77 MV_Multiply_DoCuSparse (
typename Kokkos::Impl::enable_if<Kokkos::Impl::is_same<T, double>::value,
double>::type s_b,
81 const DomainVector& x)
84 if (x.dimension_1 () == 1) {
85 cusparseDcsrmv (A.cusparse_handle, CUSPARSE_OPERATION_NON_TRANSPOSE,
86 A.numRows(), A.numCols(), A.nnz(),
89 A.values.ptr_on_device(),
90 (
const int*) A.graph.row_map.ptr_on_device(),
91 A.graph.entries.ptr_on_device(),
96 Impl::PhysicalLayout layout_x (x);
97 Impl::PhysicalLayout layout_y (y);
98 if ((layout_x.layout_type != layout_x.Left) || layout_y.layout_type != layout_y.Left) {
101 cusparseDcsrmm (A.cusparse_handle, CUSPARSE_OPERATION_NON_TRANSPOSE,
102 A.numRows(), x.dimension_1(), A.numCols(), A.nnz(),
105 A.values.ptr_on_device(),
106 (
const int*) A.graph.row_map.ptr_on_device(),
107 A.graph.entries.ptr_on_device(),
117 template<
typename T,
class RangeVector,
class CrsMatrix,
class DomainVector>
118 bool MV_Multiply_DoCuSparse(
typename Kokkos::Impl::enable_if<Kokkos::Impl::is_same<T,float>::value,
float >::type s_b
119 ,
const RangeVector & y,
float s_a,
120 const CrsMatrix & A ,
const DomainVector & x) {
121 if(x.dimension_1()==1) {
122 cusparseScsrmv(A.cusparse_handle,CUSPARSE_OPERATION_NON_TRANSPOSE,
123 A.numRows(), A.numCols(), A.nnz(),
126 A.values.ptr_on_device(),
127 (
const int*) A.graph.row_map.ptr_on_device(),
128 A.graph.entries.ptr_on_device(),
133 Impl::PhysicalLayout layout_x(x);
134 Impl::PhysicalLayout layout_y(y);
135 if((layout_x.layout_type!=layout_x.Left) || layout_y.layout_type!=layout_y.Left)
return false;
136 cusparseScsrmm(A.cusparse_handle,CUSPARSE_OPERATION_NON_TRANSPOSE,
137 A.numRows(), x.dimension_1(), A.numCols(), A.nnz(),
140 A.values.ptr_on_device(),
141 (
const int*) A.graph.row_map.ptr_on_device(),
142 A.graph.entries.ptr_on_device(),
153 template<
class RangeVector,
class CrsMatrix,
class DomainVector>
155 MV_Multiply_Try_CuSparse (
typename RangeVector::value_type s_b,
156 const RangeVector& y,
157 typename DomainVector::value_type s_a,
159 const DomainVector& x)
161 if(!Kokkos::Impl::is_same<typename RangeVector::device_type,typename Kokkos::Cuda>::value)
return false;
162 if(Kokkos::Impl::is_same<typename RangeVector::non_const_value_type,float>::value&&
163 Kokkos::Impl::is_same<typename DomainVector::non_const_value_type,float>::value&&
164 Kokkos::Impl::is_same<typename CrsMatrix::values_type::non_const_value_type,float>::value) {
165 return MV_Multiply_DoCuSparse<typename RangeVector::value_type,RangeVector,CrsMatrix,DomainVector>(s_b,y,s_a,A,x);
167 if(Kokkos::Impl::is_same<typename RangeVector::non_const_value_type,double>::value&&
168 Kokkos::Impl::is_same<typename DomainVector::non_const_value_type,double>::value&&
169 Kokkos::Impl::is_same<typename CrsMatrix::values_type::non_const_value_type,double>::value) {
170 return MV_Multiply_DoCuSparse<typename RangeVector::value_type,RangeVector,CrsMatrix,DomainVector>(s_b,y,s_a,A,x);
178 #endif // KOKKOS_CRSMATRIX_CUSPARSE_HPP_