removed sse code from normal operator -> class Operator_sse

pull/1/head
Sebastian Held 2010-04-21 15:36:23 +02:00
parent b489d3342d
commit a19ea3350d
7 changed files with 192 additions and 61 deletions

View File

@ -18,13 +18,13 @@
#ifndef ENGINE_SSE_H #ifndef ENGINE_SSE_H
#define ENGINE_SSE_H #define ENGINE_SSE_H
#include "operator.h"
#include "engine.h" #include "engine.h"
#include "operator_sse.h"
class Engine_sse : public Engine class Engine_sse : public Engine
{ {
public: public:
static Engine_sse* New(const Operator* op); static Engine_sse* New(const Operator_sse* op);
virtual ~Engine_sse(); virtual ~Engine_sse();
virtual void Init(); virtual void Init();
@ -39,8 +39,8 @@ public:
inline virtual FDTD_FLOAT GetCurr( unsigned int n, unsigned int x, unsigned int y, unsigned int z ) const { return curr_[n][x][y][z/4].f[z%4]; } inline virtual FDTD_FLOAT GetCurr( unsigned int n, unsigned int x, unsigned int y, unsigned int z ) const { return curr_[n][x][y][z/4].f[z%4]; }
protected: protected:
Engine_sse(const Operator* op); Engine_sse(const Operator_sse* op);
const Operator* Op; const Operator_sse* Op;
virtual void UpdateVoltages(); virtual void UpdateVoltages();
virtual void ApplyVoltageExcite(); virtual void ApplyVoltageExcite();

View File

@ -47,12 +47,8 @@ void Operator::Init()
E_Exc_dir=NULL; E_Exc_dir=NULL;
vv=NULL; vv=NULL;
vi=NULL; vi=NULL;
vv_=NULL;
vi_=NULL;
iv=NULL; iv=NULL;
ii=NULL; ii=NULL;
iv_=NULL;
ii_=NULL;
for (int n=0;n<3;++n) for (int n=0;n<3;++n)
{ {
discLines[n]=NULL; discLines[n]=NULL;
@ -79,12 +75,8 @@ void Operator::Reset()
delete[] E_Exc_amp; delete[] E_Exc_amp;
Delete_N_3DArray(vv,numLines); Delete_N_3DArray(vv,numLines);
Delete_N_3DArray(vi,numLines); Delete_N_3DArray(vi,numLines);
Delete_N_3DArray_v4sf(vv_,numLines);
Delete_N_3DArray_v4sf(vi_,numLines);
Delete_N_3DArray(iv,numLines); Delete_N_3DArray(iv,numLines);
Delete_N_3DArray(ii,numLines); Delete_N_3DArray(ii,numLines);
Delete_N_3DArray_v4sf(iv_,numLines);
Delete_N_3DArray_v4sf(ii_,numLines);
for (int n=0;n<3;++n) for (int n=0;n<3;++n)
{ {
delete[] discLines[n]; delete[] discLines[n];
@ -510,20 +502,12 @@ void Operator::InitOperator()
{ {
Delete_N_3DArray(vv,numLines); Delete_N_3DArray(vv,numLines);
Delete_N_3DArray(vi,numLines); Delete_N_3DArray(vi,numLines);
Delete_N_3DArray_v4sf(vv_,numLines);
Delete_N_3DArray_v4sf(vi_,numLines);
Delete_N_3DArray(iv,numLines); Delete_N_3DArray(iv,numLines);
Delete_N_3DArray(ii,numLines); Delete_N_3DArray(ii,numLines);
Delete_N_3DArray_v4sf(iv_,numLines);
Delete_N_3DArray_v4sf(ii_,numLines);
vv = Create_N_3DArray(numLines); vv = Create_N_3DArray(numLines);
vi = Create_N_3DArray(numLines); vi = Create_N_3DArray(numLines);
vv_ = Create_N_3DArray_v4sf(numLines);
vi_ = Create_N_3DArray_v4sf(numLines);
iv = Create_N_3DArray(numLines); iv = Create_N_3DArray(numLines);
ii = Create_N_3DArray(numLines); ii = Create_N_3DArray(numLines);
iv_ = Create_N_3DArray_v4sf(numLines);
ii_ = Create_N_3DArray_v4sf(numLines);
} }
inline void Operator::Calc_ECOperatorPos(int n, unsigned int* pos) inline void Operator::Calc_ECOperatorPos(int n, unsigned int* pos)
@ -577,27 +561,6 @@ int Operator::CalcECOperator()
if (CalcEFieldExcitation()==false) return -1; if (CalcEFieldExcitation()==false) return -1;
CalcPEC(); CalcPEC();
// copy operator to aligned memory (only for sse engine)
// FIXME this is really inefficient!
for (int n=0;n<3;++n)
{
for (pos[0]=0;pos[0]<numLines[0];++pos[0])
{
for (pos[1]=0;pos[1]<numLines[1];++pos[1])
{
for (pos[2]=0;pos[2]<numLines[2];++pos[2])
{
vv_[n][pos[0]][pos[1]][pos[2]/4].f[pos[2]%4] = vv[n][pos[0]][pos[1]][pos[2]];
vi_[n][pos[0]][pos[1]][pos[2]/4].f[pos[2]%4] = vi[n][pos[0]][pos[1]][pos[2]];
iv_[n][pos[0]][pos[1]][pos[2]/4].f[pos[2]%4] = iv[n][pos[0]][pos[1]][pos[2]];
ii_[n][pos[0]][pos[1]][pos[2]/4].f[pos[2]%4] = ii[n][pos[0]][pos[1]][pos[2]];
}
}
}
}
return 0; return 0;
} }

View File

@ -24,21 +24,6 @@
#define FDTD_FLOAT float #define FDTD_FLOAT float
#if __SIZEOF_FLOAT__ != 4
#error wrong size of float
#endif
typedef float v4sf __attribute__ ((vector_size (16))); // vector of four single floats
union f4vector
{
v4sf v;
float f[4];
};
//! Abstract base-class for the FDTD-operator //! Abstract base-class for the FDTD-operator
class Operator class Operator
{ {
@ -145,10 +130,6 @@ public:
FDTD_FLOAT**** vi; //calc new voltage from old current FDTD_FLOAT**** vi; //calc new voltage from old current
FDTD_FLOAT**** ii; //calc new current from old current FDTD_FLOAT**** ii; //calc new current from old current
FDTD_FLOAT**** iv; //calc new current from old voltage FDTD_FLOAT**** iv; //calc new current from old voltage
f4vector**** vv_; //calc new voltage from old voltage
f4vector**** vi_; //calc new voltage from old current
f4vector**** iv_; //calc new current from old current
f4vector**** ii_; //calc new current from old voltage
//Excitation time-signal //Excitation time-signal
unsigned int ExciteLength; unsigned int ExciteLength;

119
FDTD/operator_sse.cpp Normal file
View File

@ -0,0 +1,119 @@
/*
* Copyright (C) 2010 Sebastian Held (Sebastian.Held@gmx.de)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "operator_sse.h"
#include "tools/array_ops.h"
Operator_sse* Operator_sse::New()
{
Operator_sse* op = new Operator_sse();
op->Init();
return op;
}
Operator_sse::Operator_sse() : Operator()
{
}
Operator_sse::~Operator_sse()
{
Reset();
}
void Operator_sse::Init()
{
Operator::Init();
vv_ = 0;
vi_ = 0;
iv_ = 0;
ii_ = 0;
}
void Operator_sse::Reset()
{
Delete_N_3DArray_v4sf(vv_,numLines);
Delete_N_3DArray_v4sf(vi_,numLines);
Delete_N_3DArray_v4sf(iv_,numLines);
Delete_N_3DArray_v4sf(ii_,numLines);
Operator::Reset();
Init(); // FIXME this calls Operator::Init() twice...
}
void Operator_sse::InitOperator()
{
Operator::InitOperator();
Delete_N_3DArray_v4sf(vv_,numLines);
Delete_N_3DArray_v4sf(vi_,numLines);
Delete_N_3DArray_v4sf(iv_,numLines);
Delete_N_3DArray_v4sf(ii_,numLines);
vv_ = Create_N_3DArray_v4sf(numLines);
vi_ = Create_N_3DArray_v4sf(numLines);
iv_ = Create_N_3DArray_v4sf(numLines);
ii_ = Create_N_3DArray_v4sf(numLines);
}
int Operator_sse::CalcECOperator()
{
Operator::CalcECOperator();
// copy operator to aligned memory
// FIXME this is really inefficient!
unsigned int pos[3];
for (int n=0;n<3;++n)
{
for (pos[0]=0;pos[0]<numLines[0];++pos[0])
{
for (pos[1]=0;pos[1]<numLines[1];++pos[1])
{
for (pos[2]=0;pos[2]<numLines[2];++pos[2])
{
vv_[n][pos[0]][pos[1]][pos[2]/4].f[pos[2]%4] = vv[n][pos[0]][pos[1]][pos[2]];
vi_[n][pos[0]][pos[1]][pos[2]/4].f[pos[2]%4] = vi[n][pos[0]][pos[1]][pos[2]];
iv_[n][pos[0]][pos[1]][pos[2]/4].f[pos[2]%4] = iv[n][pos[0]][pos[1]][pos[2]];
ii_[n][pos[0]][pos[1]][pos[2]/4].f[pos[2]%4] = ii[n][pos[0]][pos[1]][pos[2]];
}
}
}
}
return 0;
}
void Operator_sse::ApplyMagneticBC(bool* dirs)
{
Operator::ApplyMagneticBC(dirs);
// copy operator to aligned memory
// FIXME this is really inefficient!
unsigned int pos[3];
for (int n=0;n<3;++n)
{
for (pos[0]=0;pos[0]<numLines[0];++pos[0])
{
for (pos[1]=0;pos[1]<numLines[1];++pos[1])
{
for (pos[2]=0;pos[2]<numLines[2];++pos[2])
{
vv_[n][pos[0]][pos[1]][pos[2]/4].f[pos[2]%4] = vv[n][pos[0]][pos[1]][pos[2]];
vi_[n][pos[0]][pos[1]][pos[2]/4].f[pos[2]%4] = vi[n][pos[0]][pos[1]][pos[2]];
iv_[n][pos[0]][pos[1]][pos[2]/4].f[pos[2]%4] = iv[n][pos[0]][pos[1]][pos[2]];
ii_[n][pos[0]][pos[1]][pos[2]/4].f[pos[2]%4] = ii[n][pos[0]][pos[1]][pos[2]];
}
}
}
}
}

51
FDTD/operator_sse.h Normal file
View File

@ -0,0 +1,51 @@
/*
* Copyright (C) 2010 Sebastian Held (Sebastian.Held@gmx.de)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef OPERATOR_SSE_H
#define OPERATOR_SSE_H
#include "operator.h"
#include "tools/array_ops.h"
class Operator_sse : public Operator
{
public:
//! Create a new operator
static Operator_sse* New();
virtual ~Operator_sse();
virtual int CalcECOperator();
virtual void ApplyMagneticBC(bool* dirs);
protected:
//! use New() for creating a new Operator
Operator_sse();
virtual void Init();
virtual void Reset();
virtual void InitOperator();
// engine/post-proc needs access
public:
f4vector**** vv_; //calc new voltage from old voltage
f4vector**** vi_; //calc new voltage from old current
f4vector**** iv_; //calc new current from old current
f4vector**** ii_; //calc new current from old voltage
};
#endif // OPERATOR_SSE_H

View File

@ -254,6 +254,10 @@ int openEMS::SetupFDTD(const char* file)
FDTD_Op = Operator_Cylinder::New(); FDTD_Op = Operator_Cylinder::New();
CSX.SetCoordInputType(1); //tell CSX to use cylinder-coords CSX.SetCoordInputType(1); //tell CSX to use cylinder-coords
} }
else if (m_engine == EngineType_SSE)
{
FDTD_Op = Operator_sse::New();
}
else else
{ {
FDTD_Op = Operator::New(); FDTD_Op = Operator::New();
@ -295,7 +299,7 @@ int openEMS::SetupFDTD(const char* file)
FDTD_Eng = Engine_Multithread::New(FDTD_Op,m_engine_numThreads); FDTD_Eng = Engine_Multithread::New(FDTD_Op,m_engine_numThreads);
break; break;
case EngineType_SSE: case EngineType_SSE:
FDTD_Eng = Engine_sse::New(FDTD_Op); FDTD_Eng = Engine_sse::New(dynamic_cast<Operator_sse*>(FDTD_Op));
break; break;
default: default:
FDTD_Eng = Engine::New(FDTD_Op); FDTD_Eng = Engine::New(FDTD_Op);

View File

@ -18,6 +18,19 @@
#ifndef ARRAY_OPS_H #ifndef ARRAY_OPS_H
#define ARRAY_OPS_H #define ARRAY_OPS_H
#if __SIZEOF_FLOAT__ != 4
#error wrong size of float
#endif
typedef float v4sf __attribute__ ((vector_size (16))); // vector of four single floats
union f4vector
{
v4sf v;
float f[4];
};
#include "../FDTD/operator.h" #include "../FDTD/operator.h"
FDTD_FLOAT*** Create3DArray(const unsigned int* numLines); FDTD_FLOAT*** Create3DArray(const unsigned int* numLines);