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#include <stdio.h>
2#include <stdlib.h>
3#include <string.h>
4#include "aoclfftz.h"
5#include "helpers.h"
6
7int main()
8{
9 /* STEP 1: Create and initialize prob_desc params. */
10
11 /* Available problem descriptor types-
12 * `aoclfftz_prob_desc_f` for FLOAT LP64
13 * `aoclfftz_prob_desc_d` for DOUBLE LP64
14 * `aoclfftz_prob_desc_f_64_` for FLOAT ILP64
15 * `aoclfftz_prob_desc_d_64_` for DOUBLE ILP64
16 *
17 * Available dims/vecs types-
18 * `aoclfftz_dim_t` for LP64
19 * `aoclfftz_dim_t_64_` for ILP64
20 *
21 * type definition for DOUBLE LP64 is used here.
22 */
23 aoclfftz_dim_t dims[] = {{.n = 40, .in_stride = 2, .out_stride = 2}};
24 aoclfftz_dim_t vecs[] = {{.n = 3, .in_stride = 80, .out_stride = 80}};
25 aoclfftz_prob_desc_d problem = {
26 .dim_rank = 1, // the number of batch/vector dimensions, must be >= 1.
27 .vec_rank = 1, // the number of signal/frequency dimensions, must be >= 1.
28 .dims = dims,
29 .vecs = vecs,
30 .flags = {
31 0, // fft_type : complex(0), real(1)
32 0, // fft_direction : forward(0), backward(1)
33 0, // storage_order : inorder(0), out-of-order(1)
34 0, // fft_placement : inplace(0), out-of-place(1)
35 0 // transpose_mode : FFT(0), standalone transpose(1)
36 },
37 .pthr_fft = {
38 /*
39 * num_threads = 1 for Single Threaded Execution
40 * num_threads > 1 for Multithreaded Execution (Make sure that Library
41 * is build with ENABLE_MULTI_THREADING=ON for multithreading execution)
42 */
43 .num_threads = 1,
44 .dynamic_load_model = 0},
45 .cntrl_params =
46 {
47 .opt_level = -1,
48 .opt_off = 1,
49 .logger_mode = 0,
50 .measure_stats = 0,
51 },
52 };
53 UINT8 is_out_of_place = problem.flags.fft_placement;
54
55 /* STEP 1.1: Set default vecs and dims strides values.
56 Strides values are already set for the first dimension and
57 `set_default_dims_vecs()` can be used to set the strides
58 to default values for higher dimensions. */
59
60 /* STEP 1.2: Calculate input/output buffer sizes.
61 `calculate_buffer_sizes()` can be used to calculate buffer sizes
62 for higher dimension problem size. */
63 UINTP in_buffer_size = ((dims[0].n - 1) * (dims[0].in_stride)) +
64 ((vecs[0].n - 1) * (vecs[0].in_stride)) + 1;
65 UINTP out_buffer_size = ((dims[0].n - 1) * (dims[0].out_stride)) +
66 ((vecs[0].n - 1) * (vecs[0].out_stride)) + 1;
67
68 /* STEP 1.3: Allocate memory input/output buffers and
69 create new output buffer in case of out-of-place problem. */
70 DOUBLE *in = NULL;
71 DOUBLE *out = NULL;
72 ALLOC(in, DOUBLE, (in_buffer_size * DATA_STRIDE(problem.flags.fft_type)));
73 if (is_out_of_place)
74 {
75 ALLOC(out, DOUBLE, (out_buffer_size * DATA_STRIDE(problem.flags.fft_type)));
76 }
77
78 /* STEP 1.4: Prepare input for FFT calculation and
79 Use input buffer as output for in-place buffer. */
80 PREPARE_RANDOM_INPUT(in, in_buffer_size, problem.flags.fft_type, DOUBLE);
81 problem.in = in;
82 problem.out = !is_out_of_place ? in : out;
83
84 /* STEP 2: Invoke appropriate setup API to generate solution. */
85 VOID *aoclfftz_handle = aoclfftz_setup_d(&problem);
86
87 /* STEP 3: Invoke execute API. */
88 if (aoclfftz_handle)
89 {
90 printf("\nSetup Successful\n");
91 INT32 res = AOCLFFTZ_SUCCESS;
92 res = aoclfftz_execute(aoclfftz_handle);
93
94 if (res == AOCLFFTZ_EXECUTION_FAILURE)
95 {
96 printf("\nExecution Failure\n");
97 }
98 else
99 {
100 printf("\nExecution successful\n");
101 }
102 }
103 else
104 {
105 printf("\nSetup Failure\n");
106 }
107
108 /* STEP 4: Invoke destroy API to free `aoclfftz_handle` and
109 free the allocated memory. */
110 aoclfftz_destroy(aoclfftz_handle);
111 free(problem.in);
112 if (is_out_of_place)
113 {
114 free(problem.out);
115 }
116}
To build this example test program on a Linux system using GCC or AOCC, you must specify path to aocl_fftz.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.