11// Author: Arjun Ramaswami
22
33#include <stdio.h>
4- #include <stdlib.h>
4+ #include <stdlib.h> // EXIT_FAILURE
55#include <math.h>
6+ #include <stdbool.h>
67
78#include "CL/opencl.h"
89#include "fftfpga/fftfpga.h"
@@ -18,12 +19,12 @@ static const char *const usage[] = {
1819
1920int main (int argc , const char * * argv ) {
2021 int N = 64 , dim = 2 , iter = 1 , inv = 0 , sp = 0 , use_bram = 0 ;
21-
2222 char * path = "fft2d_emulate.aocx" ;
2323 const char * platform = "Intel(R) FPGA" ;
2424 fpga_t timing = {0.0 , 0.0 , 0.0 , 0 };
2525 int use_svm = 0 , use_emulator = 0 ;
2626 double avg_rd = 0.0 , avg_wr = 0.0 , avg_exec = 0.0 ;
27+ bool status = true;
2728
2829 struct argparse_option options [] = {
2930 OPT_HELP (),
@@ -46,69 +47,68 @@ int main(int argc, const char **argv) {
4647 // Print to console the configuration chosen to execute during runtime
4748 print_config (N , dim , iter , inv , sp , use_bram );
4849
49- if (fpga_initialize (platform , path , use_svm , use_emulator )){
50- return 1 ;
50+ int isInit = fpga_initialize (platform , path , use_svm , use_emulator );
51+ if (isInit != 0 ){
52+ return EXIT_FAILURE ;
5153 }
5254
5355 if (sp == 0 ){
54- fprintf ( stderr , "Not implemented. Work in Progress\n" );
55- return 0 ;
56+ printf ( "Not implemented. Work in Progress\n" );
57+ return EXIT_SUCCESS ;
5658 }
5759 else {
5860
59- size_t inp_sz = sizeof (float2 ) * N * N ;
60- float2 * inp = (float2 * )fftfpgaf_complex_malloc (inp_sz , use_svm );
61- float2 * out = (float2 * )fftfpgaf_complex_malloc (inp_sz , use_svm );
62-
63- fftf_create_data (inp , N * N );
64-
6561 for (size_t i = 0 ; i < iter ; i ++ ){
62+ size_t inp_sz = sizeof (float2 ) * N * N ;
63+ float2 * inp = (float2 * )fftfpgaf_complex_malloc (inp_sz , use_svm );
64+ float2 * out = (float2 * )fftfpgaf_complex_malloc (inp_sz , use_svm );
65+
66+ status = fftf_create_data (inp , N * N );
67+ if (!status ){
68+ free (inp );
69+ free (out );
70+ return EXIT_FAILURE ;
71+ }
72+
6673 if (use_bram == 1 ){
74+ // use bram for 2d Transpose
6775 timing = fftfpgaf_c2c_2d_bram (N , inp , out , inv );
6876 }
6977 else {
78+ // use global memory for 2d Transpose
7079 timing = fftfpgaf_c2c_2d_ddr (N , inp , out , inv );
7180 }
7281
7382 #ifdef USE_FFTW
74- if (verify_sp_fft2d_fftw (out , inp , N , inv )){
75- printf ( "2d FFT Verification Passed \n" );
76- }
77- else {
78- printf ( "2d FFT Verification Failed \n" ) ;
83+ if (! verify_sp_fft2d_fftw (out , inp , N , inv )){
84+ fprintf ( stderr , "2d FFT Verification Failed \n" );
85+ free ( inp );
86+ free ( out );
87+ return EXIT_FAILURE ;
7988 }
8089 #endif
81-
82- if ( timing . valid != 0 ){
83- avg_rd += timing . pcie_read_t ;
84- avg_wr += timing . pcie_write_t ;
85- avg_exec += timing . exec_t ;
90+ if ( timing . valid == 0 ){
91+ fprintf ( stderr , "Invalid execution, timing found to be 0" );
92+ free ( inp ) ;
93+ free ( out ) ;
94+ return EXIT_FAILURE ;
8695 }
87- else {
88- break ;
89- }
90- }
91-
92- free (inp );
93- free (out );
94- }
9596
96- // destroy data
97- fpga_final ();
97+ avg_rd += timing .pcie_read_t ;
98+ avg_wr += timing .pcie_write_t ;
99+ avg_exec += timing .exec_t ;
98100
99- if (timing .valid == 1 ){
101+ // destroy FFT input and output
102+ free (inp );
103+ free (out );
104+ } // iter
105+ } // sp condition
100106
101- if (avg_exec == 0.0 ){
102- fprintf (stderr , "Invalid measurement. Execute kernel did not run\n" );
103- return 1 ;
104- }
107+ // destroy fpga state
108+ fpga_final ();
105109
106- display_measures (avg_rd , avg_wr , avg_exec , N , dim , iter , inv , sp );
107- }
108- else {
109- fprintf (stderr , "Invalid timing measurement. Function returned prematurely\n" );
110- return 1 ;
111- }
110+ // display performance measures
111+ display_measures (avg_rd , avg_wr , avg_exec , N , dim , iter , inv , sp );
112112
113- return 0 ;
114- }
113+ return EXIT_SUCCESS ;
114+ }
0 commit comments