7 #ifndef HEFFFTE_COMMON_H
8 #define HEFFFTE_COMMON_H
10 #include "heffte_geometry.h"
11 #include "heffte_trace.h"
69 template<
typename source_type,
typename destination_type>
70 static void copy_n(
void*, source_type
const source[],
size_t num_entries, destination_type destination[]){
71 std::copy_n(source, num_entries, destination);
74 template<
typename source_type,
typename destination_type>
75 static void copy_n(source_type
const source[],
size_t num_entries, destination_type destination[]){
76 std::copy_n(source, num_entries, destination);
79 template<
typename source_type,
typename destination_type>
80 static void copy_device_to_host(
void*, source_type
const source[],
size_t num_entries, destination_type destination[]){
81 std::copy_n(source, num_entries, destination);
84 template<
typename source_type,
typename destination_type>
85 static void copy_device_to_device(
void*, source_type
const source[],
size_t num_entries, destination_type destination[]){
86 std::copy_n(source, num_entries, destination);
89 template<
typename source_type,
typename destination_type>
90 static void copy_host_to_device(
void*, source_type
const source[],
size_t num_entries, destination_type destination[]){
91 std::copy_n(source, num_entries, destination);
200 template<
typename tag>
211 template<typename backend_tag, typename std::enable_if<is_enabled<backend_tag>::value,
void*>::type =
nullptr>
223 template<
typename backend_tag,
typename =
void>
230 template<
typename backend_tag>
232 typename std::enable_if<std::is_same<typename buffer_traits<backend_tag>::location, tag::gpu>::value, void>::type>
239 template<
typename backend_tag>
240 inline std::string
name(){
return "unknown"; }
278 template<>
inline std::string
name<mkl>(){
return "mkl"; }
341 template<>
inline std::string name<tag::cpu>(){
return "cpu"; }
346 template<>
inline std::string name<tag::gpu>(){
return "gpu"; }
357 template<
typename backend_tag>
395 template<
typename backend_tag,
typename input,
typename output,
typename =
void>
struct check_types : std::false_type{};
401 template<
typename backend_tag,
typename input,
typename output>
struct check_types<backend_tag, input, output,
402 typename std::enable_if<uses_fft_types<backend_tag>::value and (
403 (std::is_same<input, float>::value and is_ccomplex<output>::value)
404 or (std::is_same<input, double>::value and is_zcomplex<output>::value)
405 or (is_ccomplex<input>::value and is_ccomplex<output>::value)
406 or (is_zcomplex<input>::value and is_zcomplex<output>::value)
407 )>::type> : std::true_type{};
474 template<
typename backend_tag,
typename input,
typename output>
struct check_types<backend_tag, input, output,
475 typename std::enable_if<not uses_fft_types<backend_tag>::value and (
476 (std::is_same<input, float>::value and std::is_same<output, float>::value)
477 or (std::is_same<input, double>::value and std::is_same<output, double>::value)
478 )>::type> : std::true_type{};
493 virtual void forward(
double[],
double*)
const{}
499 virtual void forward(std::complex<float>[], std::complex<float>*)
const{}
501 virtual void forward(std::complex<double>[], std::complex<double>*)
const{}
503 virtual void backward(std::complex<float>[], std::complex<float>*)
const{}
505 virtual void backward(std::complex<double>[], std::complex<double>*)
const{}
507 virtual void forward(
float const[], std::complex<float>[], std::complex<float>*)
const{}
509 virtual void forward(
double const[], std::complex<double>[], std::complex<double>*)
const{}
511 virtual void backward(std::complex<float>[],
float[], std::complex<float>*)
const{}
513 virtual void backward(std::complex<double>[],
double[], std::complex<double>*)
const{}
526 template<
typename scalar_type>
528 return std::vector<scalar_type>(size);
552 template<
typename backend_tag,
typename index>
555 return (box.
empty()) ?
556 std::unique_ptr<typename one_dim_backend<backend_tag>::executor>() :
563 template<
typename backend_tag,
typename index>
565 box3d<index>
const box,
int dir1,
int dir2){
566 return (box.empty()) ?
567 std::unique_ptr<typename one_dim_backend<backend_tag>::executor>() :
568 std::unique_ptr<
typename one_dim_backend<backend_tag>::executor>(
new typename one_dim_backend<backend_tag>::executor(stream, box, dir1, dir2));
574 template<
typename backend_tag,
typename index>
576 box3d<index>
const box){
577 return (box.empty()) ?
578 std::unique_ptr<typename one_dim_backend<backend_tag>::executor>() :
579 std::unique_ptr<
typename one_dim_backend<backend_tag>::executor>(
new typename one_dim_backend<backend_tag>::executor(stream, box));
585 template<
typename backend_tag,
typename index>
587 box3d<index>
const box,
int dimension){
588 return (box.empty()) ?
589 std::unique_ptr<typename one_dim_backend<backend_tag>::executor_r2c>() :
590 std::unique_ptr<
typename one_dim_backend<backend_tag>::executor_r2c>(
new typename one_dim_backend<backend_tag>::executor_r2c(stream, box, dimension));
597 template<
typename backend_tag>
601 return not (std::is_same<backend_tag, backend::stock>::value
602 or std::is_same<backend_tag, backend::stock_cos>::value
603 or std::is_same<backend_tag, backend::fftw_cos>::value
604 or std::is_same<backend_tag, backend::mkl_cos>::value
605 or std::is_same<backend_tag, backend::cufft_cos>::value
606 or std::is_same<backend_tag, backend::rocfft_cos>::value
607 or std::is_same<backend_tag, backend::onemkl_cos>::value
608 or std::is_same<backend_tag, backend::stock_sin>::value
609 or std::is_same<backend_tag, backend::fftw_sin>::value
610 or std::is_same<backend_tag, backend::mkl_sin>::value
611 or std::is_same<backend_tag, backend::cufft_sin>::value
612 or std::is_same<backend_tag, backend::rocfft_sin>::value
613 or std::is_same<backend_tag, backend::onemkl_sin>::value
620 template<
typename backend_tag>
622 return not (std::is_same<backend_tag, backend::stock>::value
623 or std::is_same<backend_tag, backend::stock_cos>::value
624 or std::is_same<backend_tag, backend::fftw_cos>::value
625 or std::is_same<backend_tag, backend::mkl_cos>::value
626 or std::is_same<backend_tag, backend::cufft_cos>::value
627 or std::is_same<backend_tag, backend::rocfft_cos>::value
628 or std::is_same<backend_tag, backend::onemkl_cos>::value
629 or std::is_same<backend_tag, backend::stock_sin>::value
630 or std::is_same<backend_tag, backend::fftw_sin>::value
631 or std::is_same<backend_tag, backend::mkl_sin>::value
632 or std::is_same<backend_tag, backend::cufft_sin>::value
633 or std::is_same<backend_tag, backend::rocfft_sin>::value
634 or std::is_same<backend_tag, backend::onemkl_sin>::value
Base class for all backend executors.
Definition: heffte_common.h:486
virtual void backward(std::complex< double >[], double[], std::complex< double > *) const
Backward FFT real-to-complex, double precision.
Definition: heffte_common.h:513
virtual int complex_size() const
Return the size of the complex-box (r2c executors).
Definition: heffte_common.h:519
virtual void backward(float[], float *) const
Backward r2r, single precision.
Definition: heffte_common.h:495
virtual size_t workspace_size() const
Return the workspace of the size.
Definition: heffte_common.h:517
virtual void forward(std::complex< double >[], std::complex< double > *) const
Forward FFT, double precision.
Definition: heffte_common.h:501
virtual void forward(float const[], std::complex< float >[], std::complex< float > *) const
Forward FFT real-to-complex, single precision.
Definition: heffte_common.h:507
virtual ~executor_base()=default
Virtual destructor.
virtual void forward(float[], float *) const
Forward r2r, single precision.
Definition: heffte_common.h:491
virtual void forward(double[], double *) const
Forward r2r, double precision.
Definition: heffte_common.h:493
virtual void backward(std::complex< double >[], std::complex< double > *) const
Backward FFT, double precision.
Definition: heffte_common.h:505
virtual void forward(std::complex< float >[], std::complex< float > *) const
Forward FFT, single precision.
Definition: heffte_common.h:499
virtual void backward(std::complex< float >[], float[], std::complex< float > *) const
Backward FFT real-to-complex, single precision.
Definition: heffte_common.h:511
virtual void backward(std::complex< float >[], std::complex< float > *) const
Backward FFT, single precision.
Definition: heffte_common.h:503
virtual void backward(double[], double *) const
Backward r2r, double precision.
Definition: heffte_common.h:497
virtual int box_size() const
Return the size of the box.
Definition: heffte_common.h:515
virtual void forward(double const[], std::complex< double >[], std::complex< double > *) const
Forward FFT real-to-complex, double precision.
Definition: heffte_common.h:509
std::vector< scalar_type > make_buffer_container(void *, size_t size)
Factory method to create new buffer container for the CPU backends.
Definition: heffte_common.h:527
std::string name()
Returns the human readable name of the backend.
Definition: heffte_common.h:240
constexpr bool has_executor3d()
Defines whether the executor has a 3D version (single rank).
Definition: heffte_common.h:621
constexpr bool has_executor2d()
Defines whether the executor has a 2D version (slabs).
Definition: heffte_common.h:598
direction
Indicates the direction of the FFT (internal use only).
Definition: heffte_common.h:535
@ backward
Inverse DFT transform.
@ forward
Forward DFT transform.
std::string name< cufft_cos >()
Returns the human readable name of the cuFFT backend.
Definition: heffte_common.h:298
std::string name< cufft_sin >()
Returns the human readable name of the cuFFT backend.
Definition: heffte_common.h:303
std::string name< cufft >()
Returns the human readable name of the cuFFT backend.
Definition: heffte_common.h:293
std::string name< fftw_cos >()
Returns the human readable name of the FFTW backend.
Definition: heffte_common.h:251
std::string name< fftw >()
Returns the human readable name of the FFTW backend.
Definition: heffte_common.h:246
std::string name< fftw_sin >()
Returns the human readable name of the FFTW backend.
Definition: heffte_common.h:256
std::string name< mkl_sin >()
Returns the human readable name of the MKL backend.
Definition: heffte_common.h:288
std::string name< mkl >()
Returns the human readable name of the MKL backend.
Definition: heffte_common.h:278
std::string name< mkl_cos >()
Returns the human readable name of the MKL backend.
Definition: heffte_common.h:283
std::string name< onemkl >()
Returns the human readable name of the oneMKL backend.
Definition: heffte_common.h:325
std::string name< onemkl_sin >()
Returns the human readable name of the oneMKL backend.
Definition: heffte_common.h:335
std::string name< onemkl_cos >()
Returns the human readable name of the oneMKL backend.
Definition: heffte_common.h:330
std::string name< rocfft_cos >()
Returns the human readable name of the rocFFT backend.
Definition: heffte_common.h:314
std::string name< rocfft >()
Returns the human readable name of the rocFFT backend.
Definition: heffte_common.h:309
std::string name< rocfft_sin >()
Returns the human readable name of the rocFFT backend.
Definition: heffte_common.h:319
std::string name< stock_sin >()
Returns the human readable name of the stock backend.
Definition: heffte_common.h:272
std::string name< stock >()
Returns the human readable name of the stock backend.
Definition: heffte_common.h:262
std::string name< stock_cos >()
Returns the human readable name of the stock backend.
Definition: heffte_common.h:267
Namespace containing all HeFFTe methods and classes.
Definition: heffte_backend_cuda.h:38
Defines the container for the temporary buffers.
Definition: heffte_common.h:212
tag::cpu location
Tags the raw-array location tag::cpu or tag::gpu, used by the packers.
Definition: heffte_common.h:214
std::vector< T > container
Defines the container template to use for the temporary buffers in heffte::fft3d.
Definition: heffte_common.h:216
Set to true/false type depending whether the types are compatible with the backend transform.
Definition: heffte_common.h:395
Type-tag for the Cosine Transform using the cuFFT backend.
Definition: heffte_common.h:153
Type-tag for the Sine Transform using the cuFFT backend.
Definition: heffte_common.h:158
Type-tag for the cuFFT backend.
Definition: heffte_common.h:147
static void copy_n(source_type const source[], size_t num_entries, destination_type destination[])
Wrapper around std::copy_n().
Definition: heffte_common.h:75
static void copy_device_to_device(void *, source_type const source[], size_t num_entries, destination_type destination[])
Wrapper around std::copy_n().
Definition: heffte_common.h:85
static void copy_device_to_host(void *, source_type const source[], size_t num_entries, destination_type destination[])
Wrapper around std::copy_n().
Definition: heffte_common.h:80
static void copy_n(void *, source_type const source[], size_t num_entries, destination_type destination[])
Wrapper around std::copy_n().
Definition: heffte_common.h:70
void * stream_type
The stream type for the device.
Definition: heffte_common.h:67
static void copy_host_to_device(void *, source_type const source[], size_t num_entries, destination_type destination[])
Wrapper around std::copy_n().
Definition: heffte_common.h:90
Common data-transfer operations, must be specializes for each location (cpu/gpu).
Definition: heffte_common.h:59
Defines inverse mapping from the location tag to a default backend tag.
Definition: heffte_common.h:380
Holds the auxiliary variables needed by each backend.
Definition: heffte_common.h:358
void synchronize_device() const
Syncs the execution with the queue, no-op in the CPU case.
Definition: heffte_common.h:368
void * stream_type
The type for the internal stream, the cpu uses just a void pointer.
Definition: heffte_common.h:370
void * stream()
Returns the nullptr.
Definition: heffte_common.h:364
device_instance(void *=nullptr)
Empty constructor.
Definition: heffte_common.h:360
virtual ~device_instance()=default
Default destructor.
void * stream() const
Returns the nullptr (const case).
Definition: heffte_common.h:366
Type-tag for the Cosine Transform using the FFTW backend.
Definition: heffte_common.h:104
Type-tag for the Sine Transform using the FFTW backend.
Definition: heffte_common.h:109
Type-tag for the FFTW backend.
Definition: heffte_common.h:99
Allows to define whether a specific backend interface has been enabled.
Definition: heffte_common.h:201
Type-tag for the Cosine Transform using the MKL FFT backend.
Definition: heffte_common.h:136
Type-tag for the Sine Transform using the MKL FFT backend.
Definition: heffte_common.h:141
Type-tag for the MKL backend.
Definition: heffte_common.h:131
Type-tag for the Cosine Transform using the oneMKL backend.
Definition: heffte_common.h:185
Type-tag for the Sine Transform using the oneMKL backend.
Definition: heffte_common.h:190
Type-tag for the oneMKL backend.
Definition: heffte_common.h:180
Type-tag for the Cosine Transform using the rocFFT backend.
Definition: heffte_common.h:169
Type-tag for the Sine Transform using the rocFFT backend.
Definition: heffte_common.h:174
Type-tag for the rocFFT backend.
Definition: heffte_common.h:164
Type-tag for the Cosine Transform using the stock FFT backend.
Definition: heffte_common.h:120
Type-tag for the Sine Transform using the stock FFT backend.
Definition: heffte_common.h:125
Type-tag for the stock FFT backend.
Definition: heffte_common.h:115
Defines whether the backend accepts the standard FFT real-complex or complex-complex transform.
Definition: heffte_common.h:389
Struct that specializes to true type if the location of the backend is on the gpu (false type otherwi...
Definition: heffte_common.h:224
A generic container that describes a 3d box of indexes.
Definition: heffte_geometry.h:67
bool empty() const
Returns true if the box contains no indexes.
Definition: heffte_geometry.h:84
Defines a set of default plan options for a given backend.
Definition: heffte_common.h:642
Indicates the structure that will be used by the fft backend.
Definition: heffte_common.h:546
Indicates the use of cpu backend and that all input/output data and arrays will be bound to the cpu.
Definition: heffte_common.h:38
Indicates the use of gpu backend and that all input/output data and arrays will be bound to the gpu d...
Definition: heffte_common.h:45