SHAFFT 1.1.0-alpha
A Scalable High-dimensional Accelerated FFT Library
Loading...
Searching...
No Matches
C++ Free Function API

Free functions for C interoperability and advanced use. More...

Classes

struct  shafft::Version
 Library version information. More...
 

Functions

int shafft::setBuffers (detail::PlanBase *plan, complexf *data, complexf *work) noexcept
 Attach buffers using portable complex types.
 
int shafft::getBuffers (detail::PlanBase *plan, complexf **data, complexf **work) noexcept
 Retrieve current buffer pointers.
 
int shafft::allocBuffer (size_t count, complexf **buf) noexcept
 Allocate buffer for the current backend.
 
int shafft::freeBuffer (complexf *buf) noexcept
 Free buffer allocated with allocBuffer().
 
int shafft::copyToBuffer (complexf *dst, const complexf *src, size_t count) noexcept
 Copy from host to SHAFFT buffer.
 
int shafft::copyFromBuffer (complexf *dst, const complexf *src, size_t count) noexcept
 Copy from SHAFFT buffer to host.
 
int shafft::planNDCreate (detail::FFTNDPlan **out)
 Allocate N-D plan object (C-style API).
 
int shafft::FFT1DCreate (detail::FFT1DPlan **out)
 Allocate 1-D plan object (C-style API).
 
int shafft::configuration1D (size_t globalN, size_t &localN, size_t &localStart, FFTType precision, MPI_Comm comm)
 Compute local layout for 1D distributed FFT.
 
int shafft::planND (detail::FFTNDPlan *plan, const std::vector< int > &commDims, const std::vector< size_t > &dimensions, FFTType precision, MPI_Comm comm)
 Initialize N-D plan (C-style API).
 
int shafft::destroy (detail::PlanBase **plan)
 Release plan resources and null pointer (C-style API).
 
int shafft::getLayout (const detail::PlanBase *plan, std::vector< size_t > &subsize, std::vector< size_t > &offset, TensorLayout layout)
 Query tensor layout (C-style API).
 
int shafft::getAxes (const detail::PlanBase *plan, std::vector< int > &ca, std::vector< int > &da, TensorLayout layout)
 Query axis distribution (C-style API).
 
int shafft::getAllocSize (const detail::PlanBase *plan, size_t &localAllocSize)
 Get required buffer size in complex elements (C-style API).
 
int shafft::execute (detail::PlanBase *plan, FFTDirection direction)
 Execute transform (C-style API).
 
int shafft::normalize (detail::PlanBase *plan)
 Apply normalization (C-style API).
 
const char * shafft::getBackendName () noexcept
 Get the name of the FFT backend used at compile time.
 
Version shafft::getVersion () noexcept
 Get the library version as a struct.
 
int shafft::finalize () noexcept
 Finalize library and release backend resources.
 

Detailed Description

These functions mirror the C API but use C++ types. Use them when:

For most applications, prefer the C++ RAII API instead.

Function Documentation

◆ setBuffers()

int shafft::setBuffers ( detail::PlanBase *  plan,
complexf data,
complexf work 
)
noexcept

GPU backends require device memory; CPU backends require host memory.

Parameters
planPlan handle.
dataData buffer.
workWork buffer.
Returns
0 on success, non-zero on error.

◆ getBuffers()

int shafft::getBuffers ( detail::PlanBase *  plan,
complexf **  data,
complexf **  work 
)
noexcept

Buffers may be swapped after execute().

Parameters
planPlan handle.
[out]dataCurrent data buffer.
[out]workCurrent work buffer.
Returns
0 on success, non-zero on error.

◆ allocBuffer()

int shafft::allocBuffer ( size_t  count,
complexf **  buf 
)
noexcept

Uses hipMalloc on GPU, standard allocation on CPU.

Parameters
countNumber of complex elements.
[out]bufAllocated buffer.
Returns
0 on success, non-zero on error.
Examples
example_FFT1D.cpp, example_portable.cpp, and example_portable_config.cpp.

◆ freeBuffer()

int shafft::freeBuffer ( complexf buf)
noexcept
Parameters
bufBuffer to free (nullptr safe).
Returns
0 on success, non-zero on error.
Examples
example_FFT1D.cpp, example_portable.cpp, and example_portable_config.cpp.

◆ copyToBuffer()

int shafft::copyToBuffer ( complexf dst,
const complexf src,
size_t  count 
)
noexcept

Performs copy to a backend buffer.

Parameters
dstDestination buffer.
srcSource host memory.
countNumber of complex elements.
Returns
0 on success, non-zero on error.
Examples
example_FFT1D.cpp, example_portable.cpp, and example_portable_config.cpp.

◆ copyFromBuffer()

int shafft::copyFromBuffer ( complexf dst,
const complexf src,
size_t  count 
)
noexcept

Performs copy from a backend buffer to host memory.

Parameters
dstDestination host memory.
srcSource buffer.
countNumber of complex elements.
Returns
0 on success, non-zero on error.
Examples
example_FFT1D.cpp, example_portable.cpp, and example_portable_config.cpp.

◆ planNDCreate()

int shafft::planNDCreate ( detail::FFTNDPlan **  out)

Prefer the RAII FFTND class. Release with destroy().

Parameters
[out]outPlan pointer.
Returns
0 on success, non-zero on error.

◆ FFT1DCreate()

int shafft::FFT1DCreate ( detail::FFT1DPlan **  out)

Prefer the RAII FFT1D class. Release with destroy().

Parameters
[out]outPlan pointer.
Returns
0 on success, non-zero on error.

◆ configuration1D()

int shafft::configuration1D ( size_t  globalN,
size_t &  localN,
size_t &  localStart,
FFTType  precision,
MPI_Comm  comm 
)

Call before FFT1D::init() to obtain layout parameters.

Parameters
globalNGlobal FFT size.
[out]localNLocal element count.
[out]localStartLocal offset in global array.
precisionFFT precision (C2C or Z2Z).
commMPI communicator.
Returns
0 on success, non-zero on error.
Examples
example_FFT1D.cpp.

◆ planND()

int shafft::planND ( detail::FFTNDPlan *  plan,
const std::vector< int > &  commDims,
const std::vector< size_t > &  dimensions,
FFTType  precision,
MPI_Comm  comm 
)

Prefer FFTND::init() for RAII interface.

Parameters
planPlan from planNDCreate().
commDimsProcess grid dimensions.
dimensionsGlobal tensor dimensions.
precisionFFT precision (C2C or Z2Z).
commMPI communicator.
Returns
0 on success, non-zero on error.

◆ destroy()

int shafft::destroy ( detail::PlanBase **  plan)

Does not free user buffers. RAII classes handle this automatically.

Parameters
[in,out]planPlan pointer; set to nullptr on success.
Returns
0 on success, non-zero on error.

◆ getLayout()

int shafft::getLayout ( const detail::PlanBase *  plan,
std::vector< size_t > &  subsize,
std::vector< size_t > &  offset,
TensorLayout  layout 
)
Parameters
planPlan handle.
[out]subsizeLocal extent per axis.
[out]offsetGlobal offset per axis.
layoutLayout to query (CURRENT, INITIAL, or REDISTRIBUTED).
Returns
0 on success, non-zero on error.

◆ getAxes()

int shafft::getAxes ( const detail::PlanBase *  plan,
std::vector< int > &  ca,
std::vector< int > &  da,
TensorLayout  layout 
)
Parameters
planPlan handle.
[out]caContiguous (non-distributed) axes.
[out]daDistributed axes.
layoutLayout to query (CURRENT, INITIAL, or REDISTRIBUTED).
Returns
0 on success, non-zero on error.

◆ getAllocSize()

int shafft::getAllocSize ( const detail::PlanBase *  plan,
size_t &  localAllocSize 
)
Parameters
planPlan handle.
[out]localAllocSizeRequired buffer size in complex elements.
Returns
0 on success, non-zero on error.

◆ execute()

int shafft::execute ( detail::PlanBase *  plan,
FFTDirection  direction 
)
Parameters
planPlan handle.
directionFORWARD or BACKWARD.
Returns
0 on success, non-zero on error.

◆ normalize()

int shafft::normalize ( detail::PlanBase *  plan)
Parameters
planPlan handle.
Returns
0 on success, non-zero on error.

◆ getBackendName()

const char * shafft::getBackendName ( )
inlinenoexcept
Returns
"FFTW" or "hipFFT".

◆ getVersion()

Version shafft::getVersion ( )
inlinenoexcept
Returns
Version with major, minor, and patch fields populated.

◆ finalize()

int shafft::finalize ( )
noexcept

Call after all plans are destroyed, before MPI_Finalize() for FFTW backend. Safe to call multiple times.

Returns
0 on success, non-zero on error.