* Copyright (c) 2026 Huawei Technologies Co., Ltd.
* This program is free software, you can redistribute it and/or modify it under the terms and conditions of
* CANN Open Software License Agreement Version 2.0 (the "License").
* Please refer to the License for details. You may not use this file except in compliance with the License.
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
* See LICENSE in the root of the software repository for the full text of the License.
*/
* \file cann_ops_fft.h
* \brief CANN FFT 公共 API 头文件
*/
#ifndef CANN_OPS_FFT_H
#define CANN_OPS_FFT_H
#include <stdint.h>
#include <stddef.h>
#include "acl/acl.h"
#if defined(_WIN32) || defined(__CYGWIN__)
#define ACLFFT_API __declspec(dllexport)
#else
#define ACLFFT_API __attribute__((visibility("default")))
#endif
typedef enum aclfftResult_t
{
ACLFFT_SUCCESS = 0,
ACLFFT_INVALID_PLAN = 1,
ACLFFT_ALLOC_FAILED = 2,
ACLFFT_INVALID_TYPE = 3,
ACLFFT_INVALID_VALUE = 4,
ACLFFT_INTERNAL_ERROR = 5,
ACLFFT_EXEC_FAILED = 6,
ACLFFT_SETUP_FAILED = 7,
ACLFFT_INVALID_SIZE = 8,
ACLFFT_UNALIGNED_DATA = 9,
ACLFFT_INCOMPLETE_PARAMETER_LIST = 10,
ACLFFT_INVALID_DEVICE = 11,
ACLFFT_PARSE_ERROR = 12,
ACLFFT_NO_WORKSPACE = 13,
ACLFFT_NOT_IMPLEMENTED = 14,
ACLFFT_NOT_SUPPORTED = 16
} aclfftResult;
* @details This type is used to declare the Fourier transform type that will be executed.
* */
typedef enum aclfftType_t
{
ACLFFT_R2C = 0x2a,
ACLFFT_C2R = 0x2c,
ACLFFT_C2C = 0x29,
ACLFFT_D2Z = 0x6a,
ACLFFT_Z2D = 0x6c,
ACLFFT_Z2Z = 0x69
} aclfftType;
typedef enum aclfftLibraryPropertyType_t
{
ACLFFT_MAJOR_VERSION,
ACLFFT_MINOR_VERSION,
ACLFFT_PATCH_LEVEL
} aclfftLibraryPropertyType;
* */
#define ACLFFT_FORWARD (-1)
* */
#define ACLFFT_BACKWARD 1
#define ACLFFT_HORIZONTAL 0
#define ACLFFT_VERTICAL 1
typedef struct aclfftHandle_t* aclfftHandle;
* */
typedef struct {
float x;
float y;
} aclfftComplex;
* */
typedef struct {
double x;
double y;
} aclfftDoubleComplex;
* */
typedef float aclfftReal;
* */
typedef double aclfftDoubleReal;
#ifdef __cplusplus
extern "C" {
#endif
*
* @details Allocate and initialize a new one-dimensional FFT plan.
*
* @param[out] plan Pointer to the FFT plan handle.
* @param[in] nx FFT length.
* @param[in] type FFT type.
* @param[in] batch Number of batched transforms to compute.
* @param[in] dimType Dimension direction, must be ACLFFT_HORIZONTAL or ACLFFT_VERTICAL.
*/
ACLFFT_API aclfftResult aclfftPlan1d(aclfftHandle* plan,
int nx,
aclfftType type,
int batch,
int dimType);
*
* @details Allocate and initialize a new two-dimensional FFT plan.
* Two-dimensional data should be stored in C ordering (row-major
* format), so that indexes in y-direction (j index) vary the
* fastest.
*
* @param[out] plan Pointer to the FFT plan handle.
* @param[in] nx Number of elements in the x-direction (slow index).
* @param[in] ny Number of elements in the y-direction (fast index).
* @param[in] type FFT type.
* @param[in] batch Number of batched transforms to compute.
*/
ACLFFT_API aclfftResult aclfftPlan2d(aclfftHandle* plan, int batch, int nx, int ny, aclfftType type);
*
* @details Allocate and initialize a new three-dimensional FFT plan.
* Three-dimensional data should be stored in C ordering (row-major
* format), so that indexes in z-direction (k index) vary the
* fastest.
*
* @param[out] plan Pointer to the FFT plan handle.
* @param[in] nx Number of elements in the x-direction (slowest index).
* @param[in] ny Number of elements in the y-direction.
* @param[in] nz Number of elements in the z-direction (fastest index).
* @param[in] type FFT type.
*/
ACLFFT_API aclfftResult
aclfftPlan3d(aclfftHandle* plan, int nx, int ny, int nz, aclfftType type);
*
* @param[out] plan Pointer to the FFT plan handle to be allocated.
*/
ACLFFT_API aclfftResult aclfftCreate(aclfftHandle* plan);
*
* @details Assumes that the plan has been created already, and
* modifies the plan associated with the plan handle.
*
* @param[in] plan Handle of the FFT plan.
* @param[in] nx FFT length.
* @param[in] type FFT type.
* @param[in] batch Number of batched transforms to compute.
* @param[in] dimType Dimension direction, must be ACLFFT_HORIZONTAL or ACLFFT_VERTICAL.
* @param[out] workSize Pointer to work area size (returned value).
*/
ACLFFT_API aclfftResult aclfftMakePlan1d(aclfftHandle plan,
int nx,
aclfftType type,
int batch,
int dimType,
size_t* workSize);
*
* @details Assumes that the plan has been created already, and
* modifies the plan associated with the plan handle.
* Two-dimensional data should be stored in C ordering (row-major
* format), so that indexes in y-direction (j index) vary the
* fastest.
*
* @param[in] plan Handle of the FFT plan.
* @param[in] nx Number of elements in the x-direction (slow index).
* @param[in] ny Number of elements in the y-direction (fast index).
* @param[in] type FFT type.
* @param[in] batch Number of batched transforms to compute.
* @param[out] workSize Pointer to work area size (returned value).
*/
ACLFFT_API aclfftResult
aclfftMakePlan2d(aclfftHandle plan, int batch, int nx, int ny, aclfftType type, size_t* workSize);
*
* @details Assumes that the plan has been created already, and
* modifies the plan associated with the plan handle.
* Three-dimensional data should be stored in C ordering (row-major
* format), so that indexes in z-direction (k index) vary the
* fastest.
*
* @param[in] plan Handle of the FFT plan.
* @param[in] nx Number of elements in the x-direction (slowest index).
* @param[in] ny Number of elements in the y-direction.
* @param[in] nz Number of elements in the z-direction (fastest index).
* @param[in] type FFT type.
* @param[out] workSize Pointer to work area size (returned value).
*/
ACLFFT_API aclfftResult
aclfftMakePlan3d(aclfftHandle plan, int nx, int ny, int nz, aclfftType type, size_t* workSize);
*
* @param[in] plan Pointer to the FFT plan.
* @param[in] nx Number of elements in the x-direction.
* @param[in] type FFT type.
* @param[in] batch Number of batched transforms to perform.
* @param[out] workSize Pointer to work area size (returned value).
*/
ACLFFT_API aclfftResult aclfftGetSize1d(aclfftHandle plan,
int nx,
aclfftType type,
int batch,
size_t* workSize);
*
* @param[in] plan Pointer to the FFT plan.
* @param[in] nx Number of elements in the x-direction.
* @param[in] ny Number of elements in the y-direction.
* @param[in] type FFT type.
* @param[out] workSize Pointer to work area size (returned value).
*/
ACLFFT_API aclfftResult
aclfftGetSize2d(aclfftHandle plan, int nx, int ny, aclfftType type, size_t* workSize);
*
* @param[in] plan Pointer to the FFT plan.
* @param[in] nx Number of elements in the x-direction.
* @param[in] ny Number of elements in the y-direction.
* @param[in] nz Number of elements in the z-direction.
* @param[in] type FFT type.
* @param[out] workSize Pointer to work area size (returned value).
*/
ACLFFT_API aclfftResult
aclfftGetSize3d(aclfftHandle plan, int nx, int ny, int nz, aclfftType type, size_t* workSize);
*
* @param[in] plan Pointer to the FFT plan.
* @param[out] workSize Pointer to work area size (returned value).
*/
ACLFFT_API aclfftResult aclfftGetSize(aclfftHandle plan, size_t* workSize);
*
* @param[in] plan Pointer to the FFT plan.
* @param[in] autoAllocate 0 to disable auto-allocation, non-zero to enable.
*/
ACLFFT_API aclfftResult aclfftSetAutoAllocation(aclfftHandle plan, int autoAllocate);
*
* @param[in] plan Pointer to the FFT plan.
* @param[in] workArea Pointer to the work area.
*/
ACLFFT_API aclfftResult aclfftSetWorkArea(aclfftHandle plan, void* workArea);
*
* @details If the input and output buffers are equal, an in-place
* transform is performed.
*
* @param[in] plan The FFT plan.
* @param[in] idata Input data.
* @param[out] odata Output data.
* @param[in] direction Either `ACLFFT_FORWARD` or `ACLFFT_BACKWARD`.
*/
ACLFFT_API aclfftResult aclfftExecC2C(aclfftHandle plan,
aclfftComplex* idata,
aclfftComplex* odata,
int direction);
*
* @details If the input and output buffers are equal, an in-place
* transform is performed.
*
* @param[in] plan The FFT plan.
* @param[in] idata Input data.
* @param[out] odata Output data.
*/
ACLFFT_API aclfftResult aclfftExecR2C(aclfftHandle plan,
aclfftReal* idata,
aclfftComplex* odata);
*
* @details If the input and output buffers are equal, an in-place
* transform is performed.
*
* @param[in] plan The FFT plan.
* @param[in] idata Input data.
* @param[out] odata Output data.
*/
ACLFFT_API aclfftResult aclfftExecC2R(aclfftHandle plan,
aclfftComplex* idata,
aclfftReal* odata);
*
* @details If the input and output buffers are equal, an in-place
* transform is performed.
*
* @param[in] plan The FFT plan.
* @param[in] idata Input data.
* @param[out] odata Output data.
* @param[in] direction Either `ACLFFT_FORWARD` or `ACLFFT_BACKWARD`.
*/
ACLFFT_API aclfftResult aclfftExecZ2Z(aclfftHandle plan,
aclfftDoubleComplex* idata,
aclfftDoubleComplex* odata,
int direction);
*
* @details If the input and output buffers are equal, an in-place
* transform is performed.
*
* @param[in] plan The FFT plan.
* @param[in] idata Input data.
* @param[out] odata Output data.
*/
ACLFFT_API aclfftResult aclfftExecD2Z(aclfftHandle plan,
aclfftDoubleReal* idata,
aclfftDoubleComplex* odata);
*
* @details If the input and output buffers are equal, an in-place
* transform is performed.
*
* @param[in] plan The FFT plan.
* @param[in] idata Input data.
* @param[out] odata Output data.
*/
ACLFFT_API aclfftResult aclfftExecZ2D(aclfftHandle plan,
aclfftDoubleComplex* idata,
aclfftDoubleReal* odata);
*
* @details Associates an ACL stream with an CANN FFT plan. All kernels
* launched by this plan are associated with the provided stream.
*
* @param[in] plan The FFT plan.
* @param[in] stream The ACL stream.
*/
ACLFFT_API aclfftResult aclfftSetStream(aclfftHandle plan, aclrtStream stream);
ACLFFT_API aclfftResult aclfftSetStride(aclfftHandle plan, int32_t stride);
*
* @param[in] plan Handle of the FFT plan to be destroyed.
*/
ACLFFT_API aclfftResult aclfftDestroy(aclfftHandle plan);
*
* @param[out] version CANN FFT version (returned value).
*/
ACLFFT_API aclfftResult aclfftGetVersion(int* version);
*
* @param[in] type Property type.
* @param[out] value Returned value.
*/
ACLFFT_API aclfftResult aclfftGetProperty(aclfftLibraryPropertyType type, int* value);
*
* @param[in] result Error code.
* @return Error description string.
*/
ACLFFT_API const char* aclfftGetErrorString(aclfftResult result);
#ifdef __cplusplus
}
#endif
#endif