Commit b9c62ee4 authored by Philipp Fensch's avatar Philipp Fensch
Browse files

Added basic structure for MNASolver on GPU

parent 56157f4e
......@@ -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;
......
#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
......@@ -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.");
......
#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
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment