Skip to content

Commit 1f5e057

Browse files
author
Arjun Ramaswami
committed
Data created and destroyed every iteration
1 parent c260dca commit 1f5e057

File tree

3 files changed

+60
-54
lines changed

3 files changed

+60
-54
lines changed

examples/common/helper.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,47 +2,48 @@
22

33
#include <stdio.h>
44
#include <stdlib.h>
5+
#include <stdbool.h>
56
#include <math.h>
67
#include "helper.h"
78

89
/**
910
* \brief create random single precision complex floating point values
1011
* \param inp : pointer to float2 data of size N
1112
* \param N : number of points in the array
12-
* \return 0 if successful 1 if not
13+
* \return true if successful
1314
*/
14-
int fftf_create_data(float2 *inp, int N){
15+
bool fftf_create_data(float2 *inp, int N){
1516

1617
if(inp == NULL || N <= 0){
17-
return 1;
18+
return false;
1819
}
1920

2021
for(int i = 0; i < N; i++){
2122
inp[i].x = (float)((float)rand() / (float)RAND_MAX);
2223
inp[i].y = (float)((float)rand() / (float)RAND_MAX);
2324
}
2425

25-
return 0;
26+
return true;
2627
}
2728

2829
/**
2930
* \brief create random double precision complex floating point values
3031
* \param inp : pointer to double2 data of size N
3132
* \param N : number of points in the array
32-
* \return 0 if successful 1 if not
33+
* \return true if successful
3334
*/
34-
int fft_create_data(double2 *inp, int N){
35+
bool fft_create_data(double2 *inp, int N){
3536

3637
if(inp == NULL || N <= 0 || N > 1024){
37-
return 1;
38+
return false;
3839
}
3940

4041
for(int i = 0; i < N; i++){
4142
inp[i].x = (double)((double)rand() / (double)RAND_MAX);
4243
inp[i].y = (double)((double)rand() / (double)RAND_MAX);
4344
}
4445

45-
return 0;
46+
return true;
4647
}
4748

4849
/**

examples/common/helper.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
#ifndef HELPER_H
44
#define HELPER_H
55

6+
#include <stdbool.h>
67
#include "fftfpga/fftfpga.h"
78

8-
int fftf_create_data(float2 *inp, int N);
9+
bool fftf_create_data(float2 *inp, int N);
910

10-
int fft_create_data(double2 *inp, int N);
11+
bool fft_create_data(double2 *inp, int N);
1112

1213
void print_config(int N, int dim, int iter, int inv, int sp, int use_bram);
1314

examples/fft3d.c

Lines changed: 48 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
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

Comments
 (0)