Skip to content

Commit

Permalink
Working cuda 11 SpSV solver in CuSparseILU0 class
Browse files Browse the repository at this point in the history
  • Loading branch information
kswirydo committed Nov 29, 2023
1 parent 17b75f9 commit abf20be
Show file tree
Hide file tree
Showing 6 changed files with 230 additions and 181 deletions.
313 changes: 170 additions & 143 deletions resolve/LinSolverDirectCuSparseILU0.cpp

Large diffs are not rendered by default.

72 changes: 39 additions & 33 deletions resolve/LinSolverDirectCuSparseILU0.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,44 +24,50 @@ namespace ReSolve
class LinSolverDirectCuSparseILU0 : public LinSolverDirect
{
using vector_type = vector::Vector;

public:
LinSolverDirectCuSparseILU0(LinAlgWorkspaceCUDA* workspace);
~LinSolverDirectCuSparseILU0();

int setup(matrix::Sparse* A,
matrix::Sparse* L = nullptr,
matrix::Sparse* U = nullptr,
index_type* P = nullptr,
index_type* Q = nullptr,
vector_type* rhs =nullptr);
// if values of A change, but the nnz pattern does not, redo the analysis only (reuse buffers though)
int reset(matrix::Sparse* A);

int solve(vector_type* rhs, vector_type* x);
int solve(vector_type* rhs);// the solutuon is returned IN RHS (rhs is overwritten)

LinSolverDirectCuSparseILU0(LinAlgWorkspaceCUDA* workspace);
~LinSolverDirectCuSparseILU0();
int setup(matrix::Sparse* A,
matrix::Sparse* L = nullptr,
matrix::Sparse* U = nullptr,
index_type* P = nullptr,
index_type* Q = nullptr,
vector_type* rhs = nullptr);
// if values of A change, but the nnz pattern does not, redo the analysis only (reuse buffers though)
int reset(matrix::Sparse* A);
int solve(vector_type* rhs, vector_type* x);
int solve(vector_type* rhs);// the solutuon is returned IN RHS (rhs is overwritten)

private:
cusparseStatus_t status_cusparse_;

MemoryHandler mem_; ///< Device memory manager object
LinAlgWorkspaceCUDA* workspace_;

cusparseMatDescr_t descr_A_{nullptr};

cusparseMatDescr_t descr_L_{nullptr};
cusparseMatDescr_t descr_U_{nullptr};
csrilu02Info_t info_A_{nullptr};
cusparseStatus_t status_cusparse_;

void* buffer_;
void* buffer_LU_;
MemoryHandler mem_; ///< Device memory manager object
LinAlgWorkspaceCUDA* workspace_;

real_type* d_aux1_;
cusparseMatDescr_t descr_A_{nullptr};

cusparseSpMatDescr_t mat_L_;
cusparseSpMatDescr_t mat_U_;

cusparseSpSVDescr_t descr_spsv_L_{nullptr};
cusparseSpSVDescr_t descr_spsv_U_{nullptr};
csrilu02Info_t info_A_{nullptr};

void* buffer_;
void* buffer_L_;
void* buffer_U_;

real_type* d_aux1_;
real_type* d_aux2_;

cusparseDnVecDescr_t vec_X_;
cusparseDnVecDescr_t vec_Y_;

csrsv2Info_t info_L_ = 0;
csrsv2Info_t info_U_ = 0;
// since ILU OVERWRITES THE MATRIX values, we need a buffer to keep the values of ILU decomposition.
real_type* d_ILU_vals_;
// since ILU OVERWRITES THE MATRIX values, we need a buffer to keep the values of ILU decomposition.
real_type* d_ILU_vals_;
};
}// namespace
5 changes: 4 additions & 1 deletion resolve/RandSketchingCountSketch.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
#include "RandSketchingCountSketch.hpp"
#include <resolve/MemoryUtils.hpp>
#include <resolve/vector/Vector.hpp>

#ifdef RESOLVE_USE_HIP
#include <resolve/hip/hipKernels.h>
#endif
#ifdef RESOLVE_USE_CUDA
#include <resolve/cuda/cudaKernels.h>
#endif
#include <resolve/RandSketchingCountSketch.hpp>

namespace ReSolve
{
RandSketchingCountSketch::RandSketchingCountSketch()
Expand Down Expand Up @@ -49,7 +52,7 @@ namespace ReSolve
k_rand_ = k;
n_ = n;
srand(time(NULL));
//srand(1234);
// srand(1234);
//allocate labeling scheme vector and move to GPU

h_labels_ = new int[n_];
Expand Down
11 changes: 9 additions & 2 deletions resolve/RandSketchingCountSketch.hpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
#pragma once
#include <resolve/Common.hpp>
#include <resolve/vector/Vector.hpp>
#include <resolve/RandSketchingManager.hpp>

namespace ReSolve {

// Forward declaration of vector::Vector class
namespace vector
{
class Vector;
}

class RandSketchingCountSketch : public RandSketchingManager
{

using vector_type = vector::Vector;
public:
// constructor

// constructor
RandSketchingCountSketch();

// destructor
Expand Down
2 changes: 1 addition & 1 deletion resolve/RandSketchingFWHT.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "RandSketchingFWHT.hpp"
#include <resolve/MemoryUtils.hpp>
#include <resolve/vector/VectorHandler.hpp>
#include <resolve/vector/Vector.hpp>
#include <math.h>
#ifdef RESOLVE_USE_HIP
#include <resolve/hip/hipKernels.h>
Expand Down
8 changes: 7 additions & 1 deletion resolve/RandSketchingFWHT.hpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
#pragma once
#include <resolve/Common.hpp>
#include <resolve/vector/Vector.hpp>
#include <resolve/RandSketchingManager.hpp>

namespace ReSolve {
// Forward declaration of vector::Vector class
namespace vector
{
class Vector;
}

class RandSketchingFWHT : public RandSketchingManager
{

Expand Down

0 comments on commit abf20be

Please sign in to comment.