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"
@@ -23,6 +24,7 @@ int main(int argc, const char **argv) {
2324 fpga_t timing = {0.0 , 0.0 , 0.0 , 0 };
2425 int use_svm = 0 , use_emulator = 0 ;
2526 double avg_rd = 0.0 , avg_wr = 0.0 , avg_exec = 0.0 ;
27+ bool status = true;
2628
2729 struct argparse_option options [] = {
2830 OPT_HELP (),
@@ -44,68 +46,70 @@ int main(int argc, const char **argv) {
4446
4547 // Print to console the configuration chosen to execute during runtime
4648 print_config (N , dim , iter , inv , sp , use_bram );
47-
48- if (fpga_initialize (platform , path , use_svm , use_emulator )){
49- return 1 ;
49+
50+ int isInit = fpga_initialize (platform , path , use_svm , use_emulator );
51+ if (isInit != 0 ){
52+ return EXIT_FAILURE ;
5053 }
5154
5255 if (sp == 0 ){
53- fprintf ( stderr , "Not implemented. Work in Progress\n" );
54- return 0 ;
56+ printf ( "Not implemented. Work in Progress\n" );
57+ return EXIT_SUCCESS ;
5558 }
5659 else {
57- size_t inp_sz = sizeof (float2 ) * N * N * N ;
58- float2 * inp = (float2 * )fftfpgaf_complex_malloc (inp_sz , use_svm );
59- float2 * out = (float2 * )fftfpgaf_complex_malloc (inp_sz , use_svm );
60+ for (size_t i = 0 ; i < iter ; i ++ ){
6061
61- fftf_create_data (inp , N * N * N );
62+ // create and destroy data every iteration
63+ size_t inp_sz = sizeof (float2 ) * N * N * N ;
64+ float2 * inp = (float2 * )fftfpgaf_complex_malloc (inp_sz , use_svm );
65+ float2 * out = (float2 * )fftfpgaf_complex_malloc (inp_sz , use_svm );
66+
67+ status = fftf_create_data (inp , N * N * N );
68+ if (!status ){
69+ free (inp );
70+ free (out );
71+ return EXIT_FAILURE ;
72+ }
6273
63- for (size_t i = 0 ; i < iter ; i ++ ){
6474 if (use_bram == 1 ){
75+ // use bram for 3d Transpose
6576 timing = fftfpgaf_c2c_3d_bram (N , inp , out , inv );
6677 }
6778 else {
79+ // use ddr for 3d Transpose
6880 timing = fftfpgaf_c2c_3d_ddr (N , inp , out , inv );
6981 }
7082
71- #ifdef USE_FFTW
72- if (verify_sp_fft3d_fftw (out , inp , N , inv )){
73- printf ("3d FFT Verification Passed \n" );
83+ #ifdef USE_FFTW
84+ if (!verify_sp_fft3d_fftw (out , inp , N , inv )){
85+ fprintf (stderr , "3d FFT Verification Failed \n" );
86+ free (inp );
87+ free (out );
88+ return EXIT_FAILURE ;
7489 }
75- else {
76- printf ("3d FFT Verification Failed \n" );
90+ #endif
91+ if (timing .valid == 0 ){
92+ fprintf (stderr , "Invalid execution, timing found to be 0" );
93+ free (inp );
94+ free (out );
95+ return EXIT_FAILURE ;
7796 }
78- #endif
7997
80- if (timing .valid != 0 ){
81- avg_rd += timing .pcie_read_t ;
82- avg_wr += timing .pcie_write_t ;
83- avg_exec += timing .exec_t ;
84- }
85- else {
86- break ;
87- }
88- }
89- free (inp );
90- free (out );
91- }
92-
93- // destroy data
94- fpga_final ();
98+ avg_rd += timing .pcie_read_t ;
99+ avg_wr += timing .pcie_write_t ;
100+ avg_exec += timing .exec_t ;
95101
96- if (timing .valid == 1 ){
102+ // destroy FFT input and output
103+ free (inp );
104+ free (out );
105+ } // iter
106+ } // sp condition
97107
98- if (avg_exec == 0.0 ){
99- fprintf (stderr , "Invalid measurement. Execute kernel did not run\n" );
100- return 1 ;
101- }
108+ // destroy fpga state
109+ fpga_final ();
102110
103- display_measures (avg_rd , avg_wr , avg_exec , N , dim , iter , inv , sp );
104- }
105- else {
106- fprintf (stderr , "Invalid timing measurement. Function returned prematurely\n" );
107- return 1 ;
108- }
111+ // display performance measures
112+ display_measures (avg_rd , avg_wr , avg_exec , N , dim , iter , inv , sp );
109113
110- return 0 ;
114+ return EXIT_SUCCESS ;
111115}
0 commit comments