6.4.1. One Dimensional Complex - 6.4.1. One Dimensional Complex - 5.3 English - 68552

AOCL API Guide (68552)

Document_ID
68552
Release_Date
2026-05-13
Version
5.3 English

The following test program shows the sample usage and calling sequence of AOCL-FFTZ APIs for single-threaded one dimensional FFT computation for complex input to complex output using double-precision on LP64 architecture systems:

 1        .dim_rank = 1, // the number of signal/frequency dimensions, must be >= 1.
 2        .vec_rank = 1, // the number of batch/vector dimensions, must be >= 1.
 3        .dims = dims,
 4        .vecs = vecs,
 5        .flags = {
 6            0, // fft_type       : complex(0), real(1)
 7            0, // fft_direction  : forward(0), backward(1)
 8            0, // storage_order  : inorder(0), out-of-order(1)
 9            0, // fft_placement  : inplace(0), out-of-place(1)
10            0  // transpose_mode : FFT(0), standalone transpose(1)
11        },
12        .pthr_fft = {
13                    /*
14                     * num_threads = 1 for Single Threaded Execution
15                     * num_threads > 1 for Multithreaded Execution (Make sure that Library
16                     * is build with ENABLE_MULTI_THREADING=ON for multithreading execution)
17                     */
18                     .num_threads = 1,
19                     .dynamic_load_model = 0},
20        .cntrl_params =
21            {
22                .opt_level = 0,
23                .opt_off = 1,
24                .logger_mode = 0,
25                .measure_stats = 0,
26            },
27    };
28    UINT8 is_out_of_place = problem.flags.fft_placement;
29
30    /* STEP 1.1: Set default vecs and dims strides values.
31                 Strides values are already set for the first dimension and
32                 `set_default_dims_vecs()` can be used to set the strides
33                 to default values for higher dimensions. */
34
35    /* STEP 1.2: Calculate input/output buffer sizes.
36                 `calculate_buffer_sizes()` can be used to calculate buffer sizes
37                 for higher dimension problem size. */
38    UINTP in_buffer_size =  ((dims[0].n - 1) * (dims[0].in_stride)) +
39                            ((vecs[0].n - 1) * (vecs[0].in_stride)) + 1;
40    UINTP out_buffer_size = ((dims[0].n - 1) * (dims[0].out_stride)) +
41                            ((vecs[0].n - 1) * (vecs[0].out_stride)) + 1;
42
43    /* STEP 1.3: Allocate memory input/output buffers and
44                 create new output buffer in case of out-of-place problem. */
45    DOUBLE *in = NULL;
46    DOUBLE *out = NULL;
47    ALLOC(in, DOUBLE, (in_buffer_size * DATA_STRIDE(problem.flags.fft_type)));
48    if (is_out_of_place)
49    {
50        ALLOC(out, DOUBLE, (out_buffer_size * DATA_STRIDE(problem.flags.fft_type)));
51    }
52
53    /* STEP 1.4: Prepare input for FFT calculation and
54                 Use input buffer as output for in-place buffer. */
55    PREPARE_RANDOM_INPUT(in, in_buffer_size, problem.flags.fft_type, DOUBLE);
56    problem.in = in;
57    problem.out = !is_out_of_place ? in : out;
58
59    /* STEP 2: Invoke appropriate setup API to generate solution. */
60    VOID *aoclfftz_handle = aoclfftz_setup_d(&problem);
61
62    /* STEP 3: Invoke execute API. */
63    if (aoclfftz_handle)
64    {
65        printf("\nSetup Successful\n");
66        INT32 res = AOCLFFTZ_SUCCESS;
67        res = aoclfftz_execute(aoclfftz_handle);
68
69        if (res == AOCLFFTZ_EXECUTION_FAILURE)
70        {
71            printf("\nExecution Failure\n");
72        }
73        else
74        {
75            printf("\nExecution successful\n");
76        }
77    }
78    else
79    {
80        printf("\nSetup Failure\n");
81    }
82
83    /* STEP 4: Invoke destroy API to free `aoclfftz_handle` and
84               free the allocated memory. */
85    aoclfftz_destroy(aoclfftz_handle);
86    free(problem.in);
87    if (is_out_of_place)
88    {
89        free(problem.out);
90    }
91}

To build this example test program on a Linux system using GCC or AOCC, you must specify path to aoclfftz.h header file and link with libaocl_fftz.so file as follows:

GCC : gcc -I<aoclfftz.h file directory> -L<libaocl_fftz.so file directory> example_one_dim_complex.c -laocl_fftz -lm

Clang : clang -I<aoclfftz.h file directory> -L<libaocl_fftz.so file directory> example_one_dim_complex.c -laocl_fftz -lm

Before running the example program, ensure it points to the right library dependencies for OpenMP for Multithreading.