DPsim
Loading...
Searching...
No Matches
GpuDenseAdapter.h
1/* Copyright 2017-2021 Institute for Automation of Complex Power Systems,
2 * EONERC, RWTH Aachen University
3 *
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at https://mozilla.org/MPL/2.0/.
7 *********************************************************************************/
8
9#pragma once
10
11#include <bitset>
12#include <iostream>
13#include <list>
14#include <memory>
15#include <unordered_map>
16#include <vector>
17
18#include <dpsim/Config.h>
19#include <dpsim/Definitions.h>
20#include <dpsim/DirectLinearSolver.h>
21
22#include <cuda_runtime.h>
23#include <cusolverDn.h>
24
25#define CUDA_ERROR_HANDLER(func) \
26 { \
27 cudaError_t error; \
28 if ((error = func) != cudaSuccess) \
29 std::cerr << cudaGetErrorString(error) << std::endl; \
30 }
31
32namespace DPsim {
34protected:
35 // #### Attributes required for GPU ####
37 cusolverDnHandle_t mCusolverHandle = nullptr;
39 cudaStream_t mStream = nullptr;
40
42 struct GpuData {
44 double *matrix;
46 UInt size;
48 double *vector;
49
51 double *workSpace;
53 int *pivSeq;
55 int *errInfo;
56 } mDeviceCopy;
57
58 void allocateDeviceMemory();
59
60 void copySystemMatrixToDevice(Matrix systemMatrix);
61
62 void LUfactorization();
63
64public:
67
69 virtual ~GpuDenseAdapter();
70
73
75 virtual void preprocessing(SparseMatrix &systemMatrix,
76 std::vector<std::pair<UInt, UInt>>
77 &listVariableSystemMatrixEntries) override;
78
80 virtual void factorize(SparseMatrix &systemMatrix) override;
81
83 virtual void refactorize(SparseMatrix &systemMatrix) override;
84
86 virtual void partialRefactorize(SparseMatrix &systemMatrix,
87 std::vector<std::pair<UInt, UInt>> &
88 listVariableSystemMatrixEntries) override;
89
91 virtual Matrix solve(Matrix &rightSideVector) override;
92};
93} // namespace DPsim
DirectLinearSolver()=default
Constructor.
DirectLinearSolver()=default
Constructor with logging.
cusolverDnHandle_t mCusolverHandle
Solver-Handle.
virtual Matrix solve(Matrix &rightSideVector) override
solution function for a right hand side
cudaStream_t mStream
Stream.
virtual void factorize(SparseMatrix &systemMatrix) override
factorization function with partial pivoting
virtual ~GpuDenseAdapter()
Destructor.
virtual void partialRefactorize(SparseMatrix &systemMatrix, std::vector< std::pair< UInt, UInt > > &listVariableSystemMatrixEntries) override
partial refactorization withouth partial pivoting
virtual void preprocessing(SparseMatrix &systemMatrix, std::vector< std::pair< UInt, UInt > > &listVariableSystemMatrixEntries) override
preprocessing function pre-ordering and scaling the matrix
virtual void refactorize(SparseMatrix &systemMatrix) override
refactorization without partial pivoting
Variables for solving one Equation-system (All pointer are device-pointer)
double * matrix
Device copy of System-Matrix.
double * vector
Device copy of Vector.
int * pivSeq
Pivoting-Sequence.
UInt size
Size of one dimension.
double * workSpace
Device-Workspace for getrf.