SparseLibrary  Version 1.6.0
CuHyb.hpp
1 /*
2  * Copyright (c) 2007-2014, A. N. Yzelman, Utrecht University 2007-2011;
3  * KU Leuven 2011-2014.
4  * R. H. Bisseling, Utrecht University 2007-2014.
5  *
6  * This file is part of the Sparse Library.
7  *
8  * This library was developed under supervision of Prof. dr. Rob H. Bisseling at
9  * Utrecht University, from 2007 until 2011. From 2011-2014, development continued
10  * at KU Leuven, where Prof. dr. Dirk Roose contributed significantly to the ideas
11  * behind the newer parts of the library code.
12  *
13  * The Sparse Library is free software: you can redistribute it and/or modify
14  * it under the terms of the GNU General Public License as published by the
15  * Free Software Foundation, either version 3 of the License, or (at your
16  * option) any later version.
17  *
18  * The Sparse Library is distributed in the hope that it will be useful, but
19  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
20  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  * for more details.
22  *
23  * You should have received a copy of the GNU General Public License along
24  * with the Sparse Library. If not, see <http://www.gnu.org/licenses/>.
25  */
26 
27 /*
28  * File created by:
29  * A. N. Yzelman, Dept. of Computer Science, KU Leuven, 2014.
30  */
31 
32 
33 #include <assert.h>
34 
35 #include <cuda_runtime.h>
36 #include <cusparse_v2.h>
37 
38 #include "SparseMatrix.hpp"
39 
40 #ifndef _H_CUHYB
41 #define _H_CUHYB
42 
44 class CuHyb : public SparseMatrix< double, size_t > {
45 
46  private:
47 
48  protected:
49 
51  cusparseHandle_t handle;
52 
54  cusparseMatDescr_t descrA;
55 
57  cusparseHybMat_t hybA;
58 
60  double * GPUx;
61 
63  double * GPUz;
64 
66  static int compareTriplets( const void * left, const void * right );
67 
69  size_t i;
70 
72  size_t j;
73 
74 
75  public:
76 
78  CuHyb();
79 
84  CuHyb( std::string file, double zero = 0 );
85 
95  CuHyb( const ULI number_of_nonzeros, const ULI number_of_rows, const ULI number_of_cols, double zero );
96 
107  CuHyb( std::vector< Triplet< double > > input, ULI m, ULI n, double zero );
108 
110  virtual ~CuHyb();
111 
113  virtual void load( std::vector< Triplet< double > >& input, ULI m, ULI n, double zero );
114 
118  virtual void zxa( const double *__restrict__ x, double *__restrict__ z );
119 
126  virtual void zax( const double *__restrict__ x, double *__restrict__ z );
127 
137  virtual void zax( const double *__restrict__ x, double *__restrict__ z, const unsigned long int repeat, const clockid_t clock_id = 0, double *elapsed_time = NULL );
138 
140  virtual size_t bytesUsed();
141 
143  virtual void getFirstIndexPair( size_t &i, size_t &j );
144 
145 };
146 
147 #endif
148 
virtual void zax(const double *__restrict__ x, double *__restrict__ z)
In-place z=Ax function.
Definition: CuHyb.cpp:217
virtual ~CuHyb()
Base deconstructor.
Definition: CuHyb.cpp:62
virtual void getFirstIndexPair(size_t &i, size_t &j)
Definition: CuHyb.cpp:281
CuHyb()
Base constructor.
Definition: CuHyb.cpp:45
virtual unsigned long int m()
Queries the number of rows this matrix contains.
Definition: SparseMatrix.hpp:107
double * GPUz
GPU-local buffer to the output vector.
Definition: CuHyb.hpp:63
size_t j
Top-right column coordinate.
Definition: CuHyb.hpp:72
Wrapper class for the CuSparse HYB data structure for CUDA C.
Definition: CuHyb.hpp:44
Interface common to all sparse matrix storage schemes.
Definition: SparseMatrix.hpp:46
cusparseMatDescr_t descrA
CuSparse matrix descriptor.
Definition: CuHyb.hpp:54
double * GPUx
GPU-local buffer to the input vector.
Definition: CuHyb.hpp:60
static int compareTriplets(const void *left, const void *right)
Sorts 1D columnwise.
Definition: CuHyb.cpp:35
cusparseHybMat_t hybA
GPU-local matrix.
Definition: CuHyb.hpp:57
virtual unsigned long int n()
Queries the number of columns this matrix contains.
Definition: SparseMatrix.hpp:115
A single triplet value.
Definition: Triplet.hpp:52
cusparseHandle_t handle
Handle to CuSparse.
Definition: CuHyb.hpp:51
virtual size_t bytesUsed()
Definition: CuHyb.cpp:272
virtual void zxa(const double *__restrict__ x, double *__restrict__ z)
In-place z=xA function.
Definition: CuHyb.cpp:212
virtual void load(std::vector< Triplet< double > > &input, ULI m, ULI n, double zero)
Definition: CuHyb.cpp:79
size_t i
Top-left row coordinate.
Definition: CuHyb.hpp:69