Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F87735944
fft_plan_manager.hh
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Mon, Oct 14, 15:39
Size
4 KB
Mime Type
text/x-c++
Expires
Wed, Oct 16, 15:39 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
21494217
Attached To
rTAMAAS tamaas
fft_plan_manager.hh
View Options
/**
*
* @author Guillaume Anciaux <guillaume.anciaux@epfl.ch>
* @author Lucas Frérot <lucas.frerot@epfl.ch>
*
* @section LICENSE
*
* Copyright (©) 2016 EPFL (Ecole Polytechnique Fédérale de
* Lausanne) Laboratory (LSMS - Laboratoire de Simulation en Mécanique des
* Solides)
*
* Tamaas is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option) any
* later version.
*
* Tamaas 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 Lesser General Public License for more
* details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Tamaas. If not, see <http://www.gnu.org/licenses/>.
*
*/
/* -------------------------------------------------------------------------- */
#ifndef FFT_PLAN_MANAGER_H
#define FFT_PLAN_MANAGER_H
/* -------------------------------------------------------------------------- */
#include <map>
#include "fftransform.hh"
#include "fftransform_fftw.hh"
#if (USE_CUFFT)
#include "fftransform_cufft.hh"
#endif
/* -------------------------------------------------------------------------- */
__BEGIN_TAMAAS__
/* -------------------------------------------------------------------------- */
class
FFTPlanManager
{
/* ------------------------------------------------------------------------ */
/* Constructors/Destructors */
/* ------------------------------------------------------------------------ */
protected
:
FFTPlanManager
();
public
:
virtual
~
FFTPlanManager
();
public
:
/* ------------------------------------------------------------------------ */
/* Methods */
/* ------------------------------------------------------------------------ */
/// Get singleton instance
static
FFTPlanManager
&
get
();
/// Create/retrieve a plan from two surfaces
template
<
UInt
dim
>
FFTransform
<
Real
,
dim
>
&
createPlan
(
Grid
<
Real
,
dim
>
&
input
,
GridHermitian
<
Real
,
dim
>
&
output
);
/// Remove all plans
void
clean
();
/// Destroy a plan from two surfaces
template
<
UInt
dim
>
void
destroyPlan
(
Grid
<
Real
,
dim
>
&
input
,
GridHermitian
<
Real
,
dim
>
&
output
);
/// Destroy any plan containing a given data pointer
template
<
typename
T
>
void
destroyPlan
(
const
T
*
some
);
/* ------------------------------------------------------------------------ */
/* Class Members */
/* ------------------------------------------------------------------------ */
private
:
typedef
std
::
map
<
std
::
pair
<
Real
*
,
Complex
*>
,
std
::
tuple
<
FFTransform
<
Real
,
1
>
*
,
FFTransform
<
Real
,
2
>
*
,
FFTransform
<
Real
,
3
>
*>
>
FFTMap
;
FFTMap
plans
;
static
FFTPlanManager
*
singleton
;
};
/* -------------------------------------------------------------------------- */
template
<
UInt
dim
>
FFTransform
<
Real
,
dim
>
&
FFTPlanManager
::
createPlan
(
Grid
<
Real
,
dim
>
&
input
,
GridHermitian
<
Real
,
dim
>
&
output
){
TAMAAS_ASSERT
(
dim
<=
3
,
"Cannot do FFT of dimension higher than 3"
);
auto
index
=
std
::
make_pair
(
const_cast
<
Real
*>
(
input
.
getInternalData
()),
const_cast
<
Complex
*>
(
output
.
getInternalData
()));
auto
it
=
plans
.
find
(
index
);
auto
end
=
plans
.
end
();
if
(
it
==
end
)
{
#if defined(USE_CUFFT)
std
::
get
<
dim
-
1
>
(
plans
[
index
])
=
new
FFTransformCUFFT
<
Real
,
dim
>
(
input
.
size
(),
input
,
output
);
#else
std
::
get
<
dim
-
1
>
(
plans
[
index
])
=
new
FFTransformFFTW
<
Real
,
dim
>
(
input
,
output
);
#endif
}
return
*
std
::
get
<
dim
-
1
>
(
plans
[
index
]);
}
/* -------------------------------------------------------------------------- */
template
<
UInt
dim
>
void
FFTPlanManager
::
destroyPlan
(
Grid
<
Real
,
dim
>
&
input
,
GridHermitian
<
Real
,
dim
>
&
output
){
auto
index
=
std
::
make_pair
(
const_cast
<
Real
*>
(
input
.
getInternalData
()),
const_cast
<
Complex
*>
(
output
.
getInternalData
()));
auto
it
=
plans
.
find
(
index
);
auto
end
=
plans
.
end
();
if
(
it
!=
end
){
delete
std
::
get
<
dim
>
(
plans
[
index
]);
plans
.
erase
(
index
);
}
}
/* -------------------------------------------------------------------------- */
__END_TAMAAS__
/* -------------------------------------------------------------------------- */
#endif
/* FFT_PLAN_MANAGER_H */
Event Timeline
Log In to Comment