|
SHAFFT 1.1.0-alpha
A Scalable High-dimensional Accelerated FFT Library
|
C interface for SHAFFT. More...
Classes | |
| struct | shafft_nd_layout_t |
| N-D layout state (initial or output). More... | |
| struct | shafft_nd_config_t |
| N-D configuration object (C POD struct). More... | |
| struct | shafft_1d_layout_t |
| 1-D layout state (initial or output). More... | |
| struct | shafft_1d_config_t |
| 1-D configuration object (C POD struct). More... | |
Typedefs | |
| typedef struct shafft_nd_layout_t | shafft_nd_layout_t |
| N-D layout state (initial or output). | |
| typedef struct shafft_nd_config_t | shafft_nd_config_t |
| N-D configuration object (C POD struct). | |
| typedef struct shafft_1d_layout_t | shafft_1d_layout_t |
| 1-D layout state (initial or output). | |
| typedef struct shafft_1d_config_t | shafft_1d_config_t |
| 1-D configuration object (C POD struct). | |
Functions | |
| int | shafftLastErrorStatus (void) |
| Get the SHAFFT status code from the last error on this thread. | |
| int | shafftLastErrorSource (void) |
| Get the error source domain from the last error on this thread. | |
| int | shafftLastErrorDomainCode (void) |
| Get the raw domain-specific error code from the last error. | |
| int | shafftLastErrorMessage (char *buf, int buflen) |
| Get a human-readable message for the last error. | |
| void | shafftClearLastError (void) |
| Clear the last error state on this thread. | |
| const char * | shafftErrorSourceName (int source) |
| Get the name of an error source as a string. | |
| int | shafftConfigNDInit (shafft_nd_config_t *cfg, int ndim, const size_t *globalShape, shafft_t precision, const int *commDims, int hintNda, shafft_decomposition_strategy_t strategy, shafft_transform_layout_t outputPolicy, size_t memLimit, MPI_Comm comm) |
| Initialize and resolve an N-D configuration object. | |
| void | shafftConfigNDRelease (shafft_nd_config_t *cfg) |
| Release internal resources of an N-D config object. | |
| int | shafftConfigNDResolve (shafft_nd_config_t *cfg) |
| Re-resolve an N-D configuration. | |
| int | shafftNDInitFromConfig (void *planPtr, shafft_nd_config_t *cfg) |
| Initialize an N-D plan from a resolved config object. | |
| int | shafftConfig1DInit (shafft_1d_config_t *cfg, size_t globalSize, shafft_t precision, MPI_Comm comm) |
| Initialize and resolve a 1-D configuration object. | |
| void | shafftConfig1DRelease (shafft_1d_config_t *cfg) |
| Release internal resources of a 1-D config object. | |
| int | shafftConfig1DResolve (shafft_1d_config_t *cfg) |
| Re-resolve a 1-D configuration. | |
| int | shafft1DInitFromConfig (void *planPtr, shafft_1d_config_t *cfg) |
| Initialize a 1-D plan from a resolved config object. | |
| int | shafftGetCommunicator (void *planPtr, MPI_Comm *outComm) |
| Get a duplicated communicator from a plan. | |
| int | shafftConfigurationND (int ndim, int *size, shafft_t precision, int *commDims, int *nda, size_t *subsize, size_t *offset, int *commSize, shafft_decomposition_strategy_t strategy, size_t memLimit, MPI_Comm cComm) |
| Compute local layout and process grid for N-D distributed FFT. | |
| int | shafftNDCreate (void **outPlan) |
| Allocate uninitialized N-D plan object. | |
| int | shafftNDInit (void *planPtr, int ndim, int commDims[], int dimensions[], shafft_t precision, MPI_Comm cComm, shafft_transform_layout_t output_policy) |
| Initialize N-D plan from process grid. | |
| int | shafftPlan (void *planPtr) |
| Create backend FFT plans. | |
| int | shafftDestroy (void **planPtr) |
| Release plan resources. | |
| int | shafftGetLayout (void *planPtr, size_t *subsize, size_t *offset, shafft_tensor_layout_t layout) |
| Query local tensor layout. | |
| int | shafftGetAxes (void *planPtr, int *ca, int *da, shafft_tensor_layout_t layout) |
| Query contiguous and distributed axis indices. | |
| int | shafftGetAllocSize (void *plan, size_t *localAllocSize) |
| Get required buffer size in complex elements. | |
| int | shafftGetGlobalSize (void *plan, size_t *globalSize) |
| Get global FFT size (product of all dimensions). | |
| int | shafftIsConfigured (void *plan, int *configured) |
| Check if plan is configured (init succeeded). | |
| int | shafftIsActive (void *plan, int *active) |
| Check if this rank participates in the plan. | |
| int | shafftSetBuffers (void *planPtr, void *data, void *work) |
| Attach data and work buffers to a plan. | |
| int | shafftGetBuffers (void *planPtr, void **data, void **work) |
| Retrieve current buffer pointers. | |
| int | shafftExecute (void *planPtr, shafft_direction_t direction) |
| Execute FFT transform. | |
| int | shafftNormalize (void *planPtr) |
| Apply normalization to data buffer. | |
| int | shafftConfiguration1D (size_t N, size_t *localN, size_t *localStart, size_t *localAllocSize, shafft_t precision, MPI_Comm cComm) |
| Compute local layout for 1D distributed FFT. | |
| int | shafft1DCreate (void **outPlan) |
| Allocate uninitialized 1D plan object. | |
| int | shafft1DInit (void *planPtr, size_t N, size_t localN, size_t localStart, shafft_t precision, MPI_Comm cComm) |
| Initialize 1D distributed FFT plan. | |
| int | shafftAllocBufferF (size_t count, void **buf) |
| Allocate single-precision complex buffer. | |
| int | shafftAllocBufferD (size_t count, void **buf) |
| Allocate double-precision complex buffer. | |
| int | shafftFreeBufferF (void *buf) |
| Free single-precision buffer from shafftAllocBufferF(). | |
| int | shafftFreeBufferD (void *buf) |
| Free double-precision buffer from shafftAllocBufferD(). | |
| int | shafftCopyToBufferF (void *dst, const void *src, size_t count) |
| Copy single-precision data from host to SHAFFT buffer. | |
| int | shafftCopyToBufferD (void *dst, const void *src, size_t count) |
| Copy double-precision data from host to SHAFFT buffer. | |
| int | shafftCopyFromBufferF (void *dst, const void *src, size_t count) |
| Copy single-precision data from SHAFFT buffer to host. | |
| int | shafftCopyFromBufferD (void *dst, const void *src, size_t count) |
| Copy double-precision data from SHAFFT buffer to host. | |
| const char * | shafftGetBackendName (void) |
| Get the name of the FFT backend used at compile time. | |
| void | shafftGetVersion (int *major, int *minor, int *patch) |
| Get the library version as major, minor, patch components. | |
| const char * | shafftGetVersionString (void) |
| Get the library version as a string. | |
| int | shafftFinalize (void) |
| Finalize library and release backend resources. | |
Procedural functions for plan creation, execution, and resource management.
| typedef struct shafft_nd_layout_t shafft_nd_layout_t |
Contains per-axis arrays describing the local block for one layout state. All pointer fields are config-owned and populated by resolve.
| typedef struct shafft_nd_config_t shafft_nd_config_t |
The authoritative data store for all language APIs. Caller-owned (stack/heap); internal arrays are config-owned. Do NOT copy by value (owning pointers — double-free hazard). Use shafftConfigNDInit/shafftConfigNDRelease to manage lifecycle.
| typedef struct shafft_1d_layout_t shafft_1d_layout_t |
| typedef struct shafft_1d_config_t shafft_1d_config_t |
Simpler than N-D: no adjustable hints, no strategy/policy. Do NOT copy by value (owning pointers — double-free hazard).
| enum shafft_t |
Conventions:
ndim elements.FFT type.
| Enumerator | |
|---|---|
| SHAFFT_C2C | |
| SHAFFT_Z2Z | |
| enum shafft_direction_t |
Controls the data layout after a forward transform for N-D plans. Used by shafftNDInit(); not applicable to shafft1DInit().
| Enumerator | |
|---|---|
| SHAFFT_LAYOUT_REDISTRIBUTED | Keep post-forward redistributed layout. |
| SHAFFT_LAYOUT_INITIAL | Restore initial layout after forward transform. |
| enum shafft_status_t |
| enum shafft_errsrc_t |
When a SHAFFT function returns an error, call shafftLastErrorSource() to determine which subsystem caused the failure.
| int shafftLastErrorStatus | ( | void | ) |
| int shafftLastErrorSource | ( | void | ) |
| int shafftLastErrorDomainCode | ( | void | ) |
The meaning of this code depends on shafftLastErrorSource():
| int shafftLastErrorMessage | ( | char * | buf, |
| int | buflen | ||
| ) |
| buf | Buffer to receive the null-terminated message. |
| buflen | Size of the buffer in bytes. |
| void shafftClearLastError | ( | void | ) |
| const char * shafftErrorSourceName | ( | int | source | ) |
| source | Error source value from shafftLastErrorSource(). |
| int shafftConfigNDInit | ( | shafft_nd_config_t * | cfg, |
| int | ndim, | ||
| const size_t * | globalShape, | ||
| shafft_t | precision, | ||
| const int * | commDims, | ||
| int | hintNda, | ||
| shafft_decomposition_strategy_t | strategy, | ||
| shafft_transform_layout_t | outputPolicy, | ||
| size_t | memLimit, | ||
| MPI_Comm | comm | ||
| ) |
Allocates internal arrays, copies inputs, resolves decomposition, populates layouts and metadata, stores worldComm (dup of comm), and creates activeComm via MPI_Comm_split. The struct must be zero-initialized before this call. Collective on comm.
| cfg | [in,out] Config struct (caller-owned, zero-initialized). |
| ndim | Number of tensor dimensions (>= 1). |
| globalShape | Global extents per axis (length = ndim). |
| precision | FFT type (SHAFFT_C2C or SHAFFT_Z2Z). |
| commDims | Process grid hint (length = ndim; NULL = auto). |
| hintNda | Number of distributed axes hint (0 = auto). |
| strategy | Decomposition strategy. |
| outputPolicy | Forward output-layout policy (0 = REDISTRIBUTED default). |
| memLimit | Per-rank memory limit in bytes (0 = no limit). |
| comm | MPI communicator. |
| void shafftConfigNDRelease | ( | shafft_nd_config_t * | cfg | ) |
Frees config-owned arrays/strings and owned communicators (worldComm, activeComm), then zero-fills the struct. Must be called before MPI_Finalize. Does not free the struct itself. Idempotent; safe after failed init.
| cfg | Config struct. |
| int shafftConfigNDResolve | ( | shafft_nd_config_t * | cfg | ) |
Uses stored worldComm (no comm parameter). Frees old activeComm and creates a new one. For advanced use after modifying struct fields.
| cfg | [in,out] Initialized config struct. |
| int shafftNDInitFromConfig | ( | void * | planPtr, |
| shafft_nd_config_t * | cfg | ||
| ) |
Auto-resolves if SHAFFT_CONFIG_RESOLVED is not set. Communicator is read from the config struct (worldComm).
| planPtr | Plan from shafftNDCreate(). |
| cfg | [in,out] Config struct (resolved or will be auto-resolved). |
| int shafftConfig1DInit | ( | shafft_1d_config_t * | cfg, |
| size_t | globalSize, | ||
| shafft_t | precision, | ||
| MPI_Comm | comm | ||
| ) |
Allocates internals, copies inputs, resolves layout, stores worldComm (dup of comm), and creates activeComm. Collective on comm.
| cfg | [in,out] Config struct (caller-owned, zero-initialized). |
| globalSize | Global FFT length (> 0). |
| precision | FFT type (SHAFFT_C2C or SHAFFT_Z2Z). |
| comm | MPI communicator. |
| void shafftConfig1DRelease | ( | shafft_1d_config_t * | cfg | ) |
Frees config-owned strings and owned communicators (worldComm, activeComm), then zero-fills the struct. Must be called before MPI_Finalize.
| cfg | Config struct. |
| int shafftConfig1DResolve | ( | shafft_1d_config_t * | cfg | ) |
Uses stored worldComm (no comm parameter). Frees old activeComm and creates a new one.
| cfg | [in,out] Initialized config struct. |
| int shafft1DInitFromConfig | ( | void * | planPtr, |
| shafft_1d_config_t * | cfg | ||
| ) |
Auto-resolves if SHAFFT_CONFIG_RESOLVED is not set. Communicator is read from the config struct (worldComm).
| planPtr | Plan from shafft1DCreate(). |
| cfg | [in,out] Config struct (resolved or will be auto-resolved). |
| int shafftGetCommunicator | ( | void * | planPtr, |
| MPI_Comm * | outComm | ||
| ) |
Returns MPI_COMM_NULL on inactive ranks. The caller is responsible for MPI_Comm_free() on the returned non-null communicator. Valid only after planning stage (shafftPlan).
| planPtr | Plan pointer (N-D or 1D). |
| outComm | [out] Receives duplicated communicator. |
| int shafftConfigurationND | ( | int | ndim, |
| int * | size, | ||
| shafft_t | precision, | ||
| int * | commDims, | ||
| int * | nda, | ||
| size_t * | subsize, | ||
| size_t * | offset, | ||
| int * | commSize, | ||
| shafft_decomposition_strategy_t | strategy, | ||
| size_t | memLimit, | ||
| MPI_Comm | cComm | ||
| ) |
Attempts configuration using the fallback chain: commDims -> nda -> strategy.
| ndim | Number of tensor dimensions. |
| size | Global extents per axis (length = ndim). |
| precision | FFT type (SHAFFT_C2C or SHAFFT_Z2Z). |
| commDims | [in,out] Process grid preference (0 = no preference); updated on output. |
| nda | [in,out] Distributed axes preference (0 = no preference); updated on output. |
| subsize | [out] Local extents per axis (length = ndim). |
| offset | [out] Global starting indices per axis (length = ndim). |
| commSize | [out] Number of active ranks. |
| strategy | Fallback strategy (SHAFFT_MAXIMIZE_NDA or SHAFFT_MINIMIZE_NDA). |
| memLimit | Per-rank memory limit in bytes (0 = no limit). |
| cComm | MPI communicator. |
| int shafftNDCreate | ( | void ** | outPlan | ) |
| outPlan | [out] Receives plan pointer (NULL on failure). |
| int shafftNDInit | ( | void * | planPtr, |
| int | ndim, | ||
| int | commDims[], | ||
| int | dimensions[], | ||
| shafft_t | precision, | ||
| MPI_Comm | cComm, | ||
| shafft_transform_layout_t | output_policy | ||
| ) |
| planPtr | Plan from shafftNDCreate(). |
| ndim | Number of dimensions. |
| commDims | Process grid dimensions (length = ndim). |
| dimensions | Global tensor extents (length = ndim). |
| precision | FFT type (SHAFFT_C2C or SHAFFT_Z2Z). |
| cComm | MPI communicator. |
| output_policy | Forward output-layout policy. |
| int shafftPlan | ( | void * | planPtr | ) |
Must be called after init completes. Works on N-D and 1D plans. Calling plan() more than once is an error.
| planPtr | Plan pointer (N-D or 1D). |
| int shafftDestroy | ( | void ** | planPtr | ) |
Works on N-D and 1D plans. Does not free user-provided buffers.
| planPtr | [in,out] Pointer to plan; set to NULL on return. |
| int shafftGetLayout | ( | void * | planPtr, |
| size_t * | subsize, | ||
| size_t * | offset, | ||
| shafft_tensor_layout_t | layout | ||
| ) |
| planPtr | Plan pointer (N-D or 1D). |
| subsize | [out] Local extents per axis. |
| offset | [out] Global starting indices per axis. |
| layout | Which layout to query. |
| int shafftGetAxes | ( | void * | planPtr, |
| int * | ca, | ||
| int * | da, | ||
| shafft_tensor_layout_t | layout | ||
| ) |
| planPtr | Plan pointer (N-D or 1D). |
| ca | [out] Contiguous axis indices (innermost to outermost stride). |
| da | [out] Distributed axis indices (innermost to outermost stride). |
| layout | Which layout to query. |
| int shafftGetAllocSize | ( | void * | plan, |
| size_t * | localAllocSize | ||
| ) |
| plan | Plan pointer (N-D or 1D). |
| localAllocSize | [out] Required element count. |
| int shafftGetGlobalSize | ( | void * | plan, |
| size_t * | globalSize | ||
| ) |
| plan | Plan pointer (N-D or 1D). |
| globalSize | [out] Total element count. |
| int shafftIsConfigured | ( | void * | plan, |
| int * | configured | ||
| ) |
| plan | Plan pointer (N-D or 1D). |
| configured | [out] 1 if configured, 0 otherwise. |
| int shafftIsActive | ( | void * | plan, |
| int * | active | ||
| ) |
| plan | Plan pointer (N-D or 1D). |
| active | [out] 1 if active, 0 otherwise. |
| int shafftSetBuffers | ( | void * | planPtr, |
| void * | data, | ||
| void * | work | ||
| ) |
Buffers must remain valid until plan destruction or new buffers are set.
| planPtr | Plan pointer (N-D or 1D). |
| data | Main data buffer. |
| work | Work/scratch buffer. |
| int shafftGetBuffers | ( | void * | planPtr, |
| void ** | data, | ||
| void ** | work | ||
| ) |
Buffers may be swapped during execution; call after shafftExecute() to locate the most recent execution result.
| planPtr | Plan pointer (N-D or 1D). |
| data | [out] Current data buffer. |
| work | [out] Current work buffer. |
| int shafftExecute | ( | void * | planPtr, |
| shafft_direction_t | direction | ||
| ) |
| planPtr | Plan pointer (N-D or 1D). |
| direction | SHAFFT_FORWARD or SHAFFT_BACKWARD. |
| int shafftNormalize | ( | void * | planPtr | ) |
| planPtr | Plan pointer (N-D or 1D). |
| int shafftConfiguration1D | ( | size_t | N, |
| size_t * | localN, | ||
| size_t * | localStart, | ||
| size_t * | localAllocSize, | ||
| shafft_t | precision, | ||
| MPI_Comm | cComm | ||
| ) |
| N | Global FFT size. |
| localN | [out] Elements for this rank. |
| localStart | [out] This rank's offset in global array. |
| localAllocSize | [out] Required buffer size. |
| precision | FFT type (SHAFFT_C2C or SHAFFT_Z2Z). |
| cComm | MPI communicator. |
| int shafft1DCreate | ( | void ** | outPlan | ) |
| outPlan | [out] Receives plan pointer. |
| int shafft1DInit | ( | void * | planPtr, |
| size_t | N, | ||
| size_t | localN, | ||
| size_t | localStart, | ||
| shafft_t | precision, | ||
| MPI_Comm | cComm | ||
| ) |
| planPtr | Plan from shafft1DCreate(). |
| N | Global FFT size. |
| localN | Elements for this rank. |
| localStart | This rank's offset. |
| precision | FFT type (SHAFFT_C2C or SHAFFT_Z2Z). |
| cComm | MPI communicator. |
| int shafftAllocBufferF | ( | size_t | count, |
| void ** | buf | ||
| ) |
Uses device memory on GPU, host memory on CPU. Free with shafftFreeBufferF().
| count | Number of complex elements. |
| buf | [out] Allocated buffer. |
| int shafftAllocBufferD | ( | size_t | count, |
| void ** | buf | ||
| ) |
Uses device memory on GPU, host memory on CPU. Free with shafftFreeBufferD().
| count | Number of complex elements. |
| buf | [out] Allocated buffer. |
| int shafftFreeBufferF | ( | void * | buf | ) |
| buf | Buffer to free (NULL safe). |
| int shafftFreeBufferD | ( | void * | buf | ) |
| buf | Buffer to free (NULL safe). |
| int shafftCopyToBufferF | ( | void * | dst, |
| const void * | src, | ||
| size_t | count | ||
| ) |
| dst | Destination buffer. |
| src | Source host memory. |
| count | Number of complex elements. |
| int shafftCopyToBufferD | ( | void * | dst, |
| const void * | src, | ||
| size_t | count | ||
| ) |
| dst | Destination buffer. |
| src | Source host memory. |
| count | Number of complex elements. |
| int shafftCopyFromBufferF | ( | void * | dst, |
| const void * | src, | ||
| size_t | count | ||
| ) |
| dst | Destination host memory. |
| src | Source buffer. |
| count | Number of complex elements. |
| int shafftCopyFromBufferD | ( | void * | dst, |
| const void * | src, | ||
| size_t | count | ||
| ) |
| dst | Destination host memory. |
| src | Source buffer. |
| count | Number of complex elements. |
| const char * shafftGetBackendName | ( | void | ) |
| void shafftGetVersion | ( | int * | major, |
| int * | minor, | ||
| int * | patch | ||
| ) |
| major | [out] Receives major version. |
| minor | [out] Receives minor version. |
| patch | [out] Receives patch version. |
| const char * shafftGetVersionString | ( | void | ) |
| int shafftFinalize | ( | void | ) |
Call after all plans are destroyed. Must be called before MPI_Finalize() for FFTW backend. Safe to call multiple times.