cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
hafiz
Visitor
Visitor
311 Views
Registered: ‎09-16-2020

Separating File I/O

Hi, i am trying to synthesize my coding, but failed because it has unsupported function like fopen, fclose, etc. So i am trying to separate the file i/o from source code, and put it into the test bench

 

for(i=1; i<=no_sets; ++i){
    for(j=0; j<no_seqs; ++j){
	   for(k=0; k<length; ++k){
	    x[k]=uni(filename)/UNIMAX;
	   }
      
      udruns(x, length, &ustat, &dstat, ucnt, dcnt);
      
      /*printf("no of sequences,%d : Up Statistic=%f Down Statistic=%f\n", j+1, ustat, dstat);*/

      pu[j]=Chisq(6, ustat);
      pd[j]=Chisq(6, dstat);
   }

      /*for(j=0; j<10; ++j)
      {
        printf("pu[%d]=%f pd[%d]=%f\n",j+1, pu[j], j+1, pd[j]);
      }*/

  pv_up[i-1]=KStest(pu,no_seqs);
    printf("\t\t\t\tSet %d\n", i);
    printf("\t\t runs up; ks test for %d p's: %f\n", no_seqs, pv_up[i-1]);
    
  pv_down[i-1]=KStest(pd,no_seqs);
    printf("\t\t runs down; ks test for %d p's: %f\n", no_seqs, pv_down[i-1]);

    pv_all[i - 1] = pv_up[i - 1];
    pv_all[i - 1 + no_sets] = pv_down[i - 1];
  }

 

here is part of the source code. the file i/o is located inside the uni() function.

#include "header.h"
#include "macro.h"

int main()
{
	const length=10000, no_seqs=10;
	int k;
	real *x, *pu, *pd;
	counter *ucnt, *dcnt;

	x=(real*)malloc(length*sizeof(real));

	pu=(real*)malloc(no_seqs*sizeof(real));
	pd=(real*)malloc(no_seqs*sizeof(real));

	ucnt=(counter*)calloc(6, sizeof(counter) );
	dcnt=(counter*)calloc(6, sizeof(counter) );

	runtest("papi_count_delay10_xor8_himeno_input.txt", x, pu, pd, ucnt, dcnt);

	free(x); free(pu); free(pd);

  return 0;
}

and this is my testbench right now. as you can see, i have malloc, calloc, free in my testbench. previously it was in the source code, but i put it here because it cannot be synthesized. i am hoping to do the same for the uni() function (file i/o)

i do hope this is possible. i attached all the source code needed if anyone want to help. thank you

(i did not attached the text file needed, as it is exceeded the maximum size. if you need it let me know it comment)

0 Kudos
1 Reply
u4223374
Advisor
Advisor
274 Views
Registered: ‎04-26-2015

That should work fine, but you may need to think further about how these interfaces will work in hardware. In particular, if you've got a large text file (too large to attach to the forums? So over 19MB?) how are you going to manage that in the FPGA? Virtually no FPGAs have that much internal memory available.

 

The normal approach here would be to leave the file in off-chip memory (either RAM or flash) and process it as either a stream or as chunks of data. Both imply some restrictions on how the block works. For example:

 

Streaming - ideally uses the hls::stream type, since that provides more sensible behaviour. Every element must be read/written exactly once, and they can only be read/written in order. Each stream can only be either input or output, you can't have bidirectional streams.

Chunks - need to look at what a sensible size is for the storage medium and is sensible for the FPGA. Most off-chip memory will be fastest if you read the whole thing at once, but as above you probably don't have that much space on the chip. Within a chunk of data, you can work freely (eg. random order, not reading every element, etc). You can also read the chunks in a non-linear order. However, you really don't want to be doing random access over the whole file.

0 Kudos