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 real output(Backward FFT) using single-precision precision on ILP64 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 FLOAT ILP64 is used here.
22 */
23 aoclfftz_dim_t_64_ dims[] = {{.n = 64, .in_stride = 8, .out_stride = 8}};
24 aoclfftz_dim_t_64_ vecs[] = {{.n = 4, .in_stride = 264, .out_stride = 528}};
25 aoclfftz_prob_desc_f_64_ 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 1, // fft_type : complex(0), real(1)
32 1, // 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
54 UINT8 is_out_of_place = problem.flags.fft_placement;
55 UINT8 is_bwd = problem.flags.fft_direction;
56
57 /* STEP 1.1: Set default vecs and dims strides values.
58 Strides values are already set for the first dimension and
59 `set_default_dims_vecs()` can be used to set the strides
60 to default values for higher dimensions. */
61
62 /* STEP 1.2: Calculate input/output buffer sizes.
63 `calculate_buffer_sizes()` can be used to calculate buffer sizes
64 for higher dimension problem size.
65 in_data_stride/out_data_stride must be 1 for real data
66 2 for complex data to calculate buffer sizes. */
67 UINTP in_buffer_size = ((dims[0].n - 1) * (dims[0].in_stride)) +
68 ((vecs[0].n - 1) * (vecs[0].in_stride)) + 1;
69 UINTP out_buffer_size = ((dims[0].n - 1) * (dims[0].out_stride)) +
70 ((vecs[0].n - 1) * (vecs[0].out_stride)) + 1;
71
72 in_buffer_size *= is_bwd ? 2 : 1; /* in_data_stride */
73 out_buffer_size *= is_bwd ? 1 : 2; /* out_data_stride */
74 in_buffer_size = MAX(in_buffer_size, out_buffer_size);
75
76 /* STEP 1.3: Allocate memory input/output buffers and
77 create new output buffer in case of out-of-place problem. */
78 FLOAT *in = NULL;
79 FLOAT *out = NULL;
80 ALLOC(in, FLOAT, (in_buffer_size));
81 if (is_out_of_place)
82 {
83 ALLOC(out, FLOAT, out_buffer_size);
84 }
85
86 /* STEP 1.4: Prepare input for FFT calculation and
87 Use input buffer as output for in-place buffer. */
88 PREPARE_RANDOM_INPUT(in, in_buffer_size, problem.flags.fft_type, FLOAT);
89 problem.in = in;
90 problem.out = !is_out_of_place ? in : out;
91
92 /* STEP 2: Invoke appropriate setup API to generate solution. */
93 VOID *aoclfftz_handle = aoclfftz_setup_f_64_(&problem);
94
95 /* STEP 3: Invoke execute API. */
96 if (aoclfftz_handle)
97 {
98 printf("\nSetup Successful\n");
99 INT32 res = AOCLFFTZ_SUCCESS;
100 res = aoclfftz_execute(aoclfftz_handle);
101
102 if (res == AOCLFFTZ_EXECUTION_FAILURE)
103 {
104 printf("\nExecution Failure\n");
105 }
106 else
107 {
108 printf("\nExecution successful\n");
109 }
110 }
111 else
112 {
113 printf("\nSetup Failure\n");
114 }
115
116 /* STEP 4: Invoke destroy API to free `aoclfftz_handle` and
117 free the allocated memory. */
118 aoclfftz_destroy(aoclfftz_handle);
119 free(problem.in);
120 if (is_out_of_place)
121 {
122 free(problem.out);
123 }
124}
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_backward.c -laocl_fftz -lm
Clang : clang -I<aoclfftz.h file directory> -L<libaocl_fftz.so file directory> example_one_dim_real_backward.c -laocl_fftz -lm
Before running the example program, ensure it points to the right library dependencies for OpenMP for Multithreading.