The following test program shows the sample usage and calling sequence of AOCL-FFTZ APIs for single-threaded one dimensional FFT computation for real input to complex output (Forward FFT) using single-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 1, // 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
29 UINT8 is_out_of_place = problem.flags.fft_placement;
30 UINT8 is_bwd = problem.flags.fft_direction;
31
32 /* STEP 1.1: Set default vecs and dims strides values.
33 Strides values are already set for the first dimension and
34 `set_default_dims_vecs()` can be used to set the strides
35 to default values for higher dimensions. */
36
37 /* STEP 1.2: Calculate input/output buffer sizes.
38 `calculate_buffer_sizes()` can be used to calculate buffer sizes
39 for higher dimension problem size.
40 in_data_stride/out_data_stride must be 1 for real data
41 2 for complex data to calculate buffer sizes. */
42 UINTP in_buffer_size = ((dims[0].n - 1) * (dims[0].in_stride)) +
43 ((vecs[0].n - 1) * (vecs[0].in_stride)) + 1;
44 UINTP out_buffer_size = ((dims[0].n - 1) * (dims[0].out_stride)) +
45 ((vecs[0].n - 1) * (vecs[0].out_stride)) + 1;
46
47 in_buffer_size *= is_bwd ? 2 : 1; /* in_data_stride */
48 out_buffer_size *= is_bwd ? 1 : 2; /* out_data_stride */
49 in_buffer_size = MAX(in_buffer_size, out_buffer_size);
50
51 /* STEP 1.3: Allocate memory input/output buffers and
52 create new output buffer in case of out-of-place problem */
53 FLOAT *in = NULL;
54 FLOAT *out = NULL;
55 ALLOC(in, FLOAT, (in_buffer_size));
56 if (is_out_of_place)
57 {
58 ALLOC(out, FLOAT, out_buffer_size);
59 }
60
61 /* STEP 1.4: Prepare input for FFT calculation and
62 Use input buffer as output for in-place buffer. */
63 PREPARE_RANDOM_INPUT(in, in_buffer_size, problem.flags.fft_type, FLOAT);
64 problem.in = in;
65 problem.out = !is_out_of_place ? in : out;
66
67 /* STEP 2: Invoke appropriate setup API to generate solution. */
68 VOID *aoclfftz_handle = aoclfftz_setup_f(&problem);
69
70 /* STEP 3: Invoke execute API. */
71 if (aoclfftz_handle)
72 {
73 printf("\nSetup Successful\n");
74 INT32 res = AOCLFFTZ_SUCCESS;
75 res = aoclfftz_execute(aoclfftz_handle);
76
77 if (res == AOCLFFTZ_EXECUTION_FAILURE)
78 {
79 printf("\nExecution Failure\n");
80 }
81 else
82 {
83 printf("\nExecution successful\n");
84 }
85 }
86 else
87 {
88 printf("\nSetup Failure\n");
89 }
90
91 /* STEP 4: Invoke destroy API to free `aoclfftz_handle` and
92 free the allocated memory. */
93 aoclfftz_destroy(aoclfftz_handle);
94 free(problem.in);
95 if (is_out_of_place)
96 {
97 free(problem.out);
98 }
99}
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_real_forward.c -laocl_fftz -lm
Clang : clang -I<aoclfftz.h file directory> -L<libaocl_fftz.so file directory> example_one_dim_real_forward.c -laocl_fftz -lm
Before running the example program, ensure it points to the right library dependencies for OpenMP for Multithreading.