|
Kokkos Core Kernels Package
Version of the Day
|
00001 /* 00002 //@HEADER 00003 // ************************************************************************ 00004 // 00005 // Kokkos: Node API and Parallel Node Kernels 00006 // Copyright (2008) Sandia Corporation 00007 // 00008 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, 00009 // the U.S. Government retains certain rights in this software. 00010 // 00011 // Redistribution and use in source and binary forms, with or without 00012 // modification, are permitted provided that the following conditions are 00013 // met: 00014 // 00015 // 1. Redistributions of source code must retain the above copyright 00016 // notice, this list of conditions and the following disclaimer. 00017 // 00018 // 2. Redistributions in binary form must reproduce the above copyright 00019 // notice, this list of conditions and the following disclaimer in the 00020 // documentation and/or other materials provided with the distribution. 00021 // 00022 // 3. Neither the name of the Corporation nor the names of the 00023 // contributors may be used to endorse or promote products derived from 00024 // this software without specific prior written permission. 00025 // 00026 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY 00027 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00028 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 00029 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE 00030 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00031 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00032 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00033 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00034 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00035 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00036 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00037 // 00038 // Questions? Contact Michael A. Heroux (maherou@sandia.gov) 00039 // 00040 // ************************************************************************ 00041 //@HEADER 00042 */ 00043 #ifndef KOKKOS_CRSMATRIX_CUSPARSE_HPP_ 00044 #define KOKKOS_CRSMATRIX_CUSPARSE_HPP_ 00045 00048 00049 #include <impl/Kokkos_PhysicalLayout.hpp> 00050 00051 namespace Kokkos { 00058 namespace CuSparse { 00059 00069 template<typename T, class RangeVectorType, class CrsMatrixType, class DomainVectorType> 00070 bool 00071 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) { 00072 return false; 00073 } 00074 00075 template<typename T, class RangeVector,class CrsMatrix,class DomainVector> 00076 bool 00077 MV_Multiply_DoCuSparse (typename Kokkos::Impl::enable_if<Kokkos::Impl::is_same<T, double>::value, double>::type s_b, 00078 const RangeVector& y, 00079 double s_a, 00080 const CrsMatrix& A, 00081 const DomainVector& x) 00082 { 00083 00084 if (x.dimension_1 () == 1) { 00085 cusparseDcsrmv (A.cusparse_handle, CUSPARSE_OPERATION_NON_TRANSPOSE, 00086 A.numRows(), A.numCols(), A.nnz(), 00087 &s_a, 00088 A.cusparse_descr, 00089 A.values.ptr_on_device(), 00090 (const int*) A.graph.row_map.ptr_on_device(), 00091 A.graph.entries.ptr_on_device(), 00092 x.ptr_on_device(), 00093 &s_b, 00094 y.ptr_on_device()); 00095 } else { 00096 Impl::PhysicalLayout layout_x (x); 00097 Impl::PhysicalLayout layout_y (y); 00098 if ((layout_x.layout_type != layout_x.Left) || layout_y.layout_type != layout_y.Left) { 00099 return false; 00100 } 00101 cusparseDcsrmm (A.cusparse_handle, CUSPARSE_OPERATION_NON_TRANSPOSE, 00102 A.numRows(), x.dimension_1(), A.numCols(), A.nnz(), 00103 &s_a, 00104 A.cusparse_descr, 00105 A.values.ptr_on_device(), 00106 (const int*) A.graph.row_map.ptr_on_device(), 00107 A.graph.entries.ptr_on_device(), 00108 x.ptr_on_device(), 00109 layout_x.stride[1], 00110 &s_b, 00111 y.ptr_on_device(), 00112 layout_y.stride[1]); 00113 } 00114 return true; 00115 } 00116 00117 template<typename T, class RangeVector,class CrsMatrix,class DomainVector> 00118 bool MV_Multiply_DoCuSparse(typename Kokkos::Impl::enable_if<Kokkos::Impl::is_same<T,float>::value, float >::type s_b 00119 ,const RangeVector & y, float s_a, 00120 const CrsMatrix & A , const DomainVector & x) { 00121 if(x.dimension_1()==1) { 00122 cusparseScsrmv(A.cusparse_handle,CUSPARSE_OPERATION_NON_TRANSPOSE, 00123 A.numRows(), A.numCols(), A.nnz(), 00124 &s_a, 00125 A.cusparse_descr, 00126 A.values.ptr_on_device(), 00127 (const int*) A.graph.row_map.ptr_on_device(), 00128 A.graph.entries.ptr_on_device(), 00129 x.ptr_on_device(), 00130 &s_b, 00131 y.ptr_on_device()); 00132 } else { 00133 Impl::PhysicalLayout layout_x(x); 00134 Impl::PhysicalLayout layout_y(y); 00135 if((layout_x.layout_type!=layout_x.Left) || layout_y.layout_type!=layout_y.Left) return false; 00136 cusparseScsrmm(A.cusparse_handle,CUSPARSE_OPERATION_NON_TRANSPOSE, 00137 A.numRows(), x.dimension_1(), A.numCols(), A.nnz(), 00138 &s_a, 00139 A.cusparse_descr, 00140 A.values.ptr_on_device(), 00141 (const int*) A.graph.row_map.ptr_on_device(), 00142 A.graph.entries.ptr_on_device(), 00143 x.ptr_on_device(), 00144 layout_x.stride[1], 00145 &s_b, 00146 y.ptr_on_device(), 00147 layout_y.stride[1]); 00148 } 00149 return true; 00150 } 00151 00152 //ToDo: strip compatible type attributes (const, volatile); make type of s_b and s_a independent 00153 template<class RangeVector,class CrsMatrix,class DomainVector> 00154 bool 00155 MV_Multiply_Try_CuSparse (typename RangeVector::value_type s_b, 00156 const RangeVector& y, 00157 typename DomainVector::value_type s_a, 00158 const CrsMatrix& A, 00159 const DomainVector& x) 00160 { 00161 if(!Kokkos::Impl::is_same<typename RangeVector::device_type,typename Kokkos::Cuda>::value) return false; 00162 if(Kokkos::Impl::is_same<typename RangeVector::non_const_value_type,float>::value&& 00163 Kokkos::Impl::is_same<typename DomainVector::non_const_value_type,float>::value&& 00164 Kokkos::Impl::is_same<typename CrsMatrix::values_type::non_const_value_type,float>::value) { 00165 return MV_Multiply_DoCuSparse<typename RangeVector::value_type,RangeVector,CrsMatrix,DomainVector>(s_b,y,s_a,A,x); 00166 } else 00167 if(Kokkos::Impl::is_same<typename RangeVector::non_const_value_type,double>::value&& 00168 Kokkos::Impl::is_same<typename DomainVector::non_const_value_type,double>::value&& 00169 Kokkos::Impl::is_same<typename CrsMatrix::values_type::non_const_value_type,double>::value) { 00170 return MV_Multiply_DoCuSparse<typename RangeVector::value_type,RangeVector,CrsMatrix,DomainVector>(s_b,y,s_a,A,x); 00171 } else 00172 return false; 00173 } 00174 00175 } // namespace CuSparse 00176 } // namespace Kokkos 00177 00178 #endif // KOKKOS_CRSMATRIX_CUSPARSE_HPP_
1.7.6.1