Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
ACS
Public
Power System Simulation and Optimization
DPsim
DPsim
Commits
b9c62ee4
Commit
b9c62ee4
authored
Mar 25, 2020
by
Philipp Fensch
Browse files
Added basic structure for MNASolver on GPU
parent
56157f4e
Changes
4
Hide whitespace changes
Inline
Side-by-side
Include/dpsim/MNASolver.h
View file @
b9c62ee4
...
...
@@ -93,7 +93,6 @@ namespace DPsim {
std
::
unordered_map
<
std
::
bitset
<
SWITCH_NUM
>
,
CPS
::
LUFactorized
>
mLuFactorizations
;
std
::
unordered_map
<
std
::
bitset
<
SWITCH_NUM
>
,
std
::
vector
<
CPS
::
LUFactorized
>
>
mLuFactorizationsHarm
;
// #### Attributes related to switching ####
/// Index of the next switching event
UInt
mSwitchTimeIndex
=
0
;
...
...
Include/dpsim/MNASolverGpu.h
0 → 100644
View file @
b9c62ee4
#pragma once
#include
<dpsim/MNASolver.h>
#include
<cuda_runtime.h>
#include
<cusolverDn.h>
/**
*
* TODO:
* -initialize();
* -void setSystem(CPS::SystemTopology system);
* -CPS::Task::List getTasks();
* -class SolveTask : public CPS::Task
* -class LogTask : public CPS::Task
*
*/
namespace
DPsim
{
template
<
typename
VarType
>
class
MnaSolverGpu
:
public
MnaSolver
<
VarType
>
{
protected:
// #### Attributes required for GPU ####
///Sovler-Handle
cusolverDnHandle_t
mCusolverHandle
;
///Stream
cudaStream_t
mStream
;
/// Device copy of System-Matrix
double
*
mGpuSystemMatrix
;
/// Device copy of Right Vector
double
*
mGpuRightVector
;
/// Device copy if Left Vector
double
*
mGpuLeftVector
;
/// Initialize cuSolver-library
void
initialize
();
/// Allocate Space for Vectors & Matrices on GPU
void
createEmptyVectors
();
void
createEmptySystemMatrix
();
public:
MnaSolverGpu
();
virtual
~
MnaSolverGpu
();
};
}
\ No newline at end of file
Source/MNASolver.cpp
View file @
b9c62ee4
...
...
@@ -18,6 +18,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************************/
#include
<dpsim/MNASolver.h>
#include
<dpsim/SequentialScheduler.h>
...
...
@@ -63,6 +64,7 @@ void MnaSolver<VarType>::initialize() {
// The system topology is prepared and we create the MNA matrices.
createEmptyVectors
();
createEmptySystemMatrix
();
// Register attribute for solution vector
if
(
mFrequencyParallel
)
{
mSLog
->
info
(
"Computing network harmonics in parallel."
);
...
...
Source/MNASolverGpu.cpp
0 → 100644
View file @
b9c62ee4
#include
<dpsim/MNASolverGpu.h>
#include
<dpsim/Definitions.h>
using
namespace
DPsim
;
namespace
DPsim
{
template
<
typename
VarType
>
MnaSolverGpu
<
VarType
>::
MnaSolverGpu
()
:
mCusolverHandle
(
nullptr
),
mStream
(
nullptr
),
mGpuSystemMatrix
(
nullptr
),
mGpuLeftVector
(
nullptr
),
mGpuRightVector
(
nullptr
)
{
cusolverStatus_t
status
=
CUSOLVER_STATUS_SUCCESS
;
cudaError_t
cudaErrorCode
;
//TODO Error Checking
status
=
cusolverDnCreate
(
&
mCusolverHandle
);
cudaErrorCode
=
cudaStreamCreateWithFlags
(
&
mStream
,
cudaStreamNonBlocking
);
status
=
cusolverDnSetStream
(
cusolverH
,
stream
);
}
template
<
typename
VarType
>
MnaSolverGpu
<
VarType
>::~
MnaSolverGpu
()
{
//Handle & Stream
if
(
mCusolverHandle
)
cusolverDnDestroy
(
mCusolverHandle
);
if
(
mStream
)
cudaStreamDestroy
(
stream
);
//Matrix & Vectors
if
(
mGpuSystemMatrix
)
cudaFree
(
mGpuSystemMatrix
);
if
(
mGpuLeftVector
)
cudaFree
(
mGpuLeftVector
);
if
(
mGpuRightVector
)
cudaFree
(
mGpuRightVector
);
cudaDeviceReset
();
}
template
<
typename
VarType
>
void
MnaSolverGpu
<
VarType
>::
initialize
()
{
MnaSolver
::
initialize
();
createEmptyVectors
();
createEmptySystemMatrix
();
//Copy Systemmatrix to device
}
/// Allocate Space for Vectors & Matrices
template
<
typename
VarType
>
void
MnaSolverGpu
<
VarType
>::
createEmptyVectors
()
{
//TODO Error Checking
auto
size
=
sizeof
(
Real
)
*
mNumSimNodes
;
cudaError_t
stat
;
stat
=
cudaMalloc
(
static_cast
<
void
**>
(
&
mGpuLeftVector
),
size
);
stat
=
cudaMalloc
(
static_cast
<
void
**>
(
&
mGpuRightVector
),
size
);
}
template
<
typename
VarType
>
void
MnaSolverGpu
<
VarType
>::
createEmptySystemMatrix
()
{
//TODO Error Checking
auto
size
=
sizeof
(
Real
)
*
mNumSimNodes
*
mNumSimNodes
;
cudaError_t
stat
=
cudaMalloc
(
static_cast
<
void
**>
(
&
mGpuLeftVector
),
size
);
}
}
template
class
DPsim
::
MnaSolverGpu
<
Real
>;
template
class
DPsim
::
MnaSolverGpu
<
Complex
>;
\ No newline at end of file
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment