-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestbench.cpp
112 lines (92 loc) · 2.67 KB
/
testbench.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#include "./kernel.h"
using namespace std;
int main()
{
FILE *fp;
// ap_uint<8> x[22*NUM_BYTES];
uint8_t x[100000] = {0}; //beware of limited memory
uint16_t golden[1000000] = {0};
ap_uint<9> y[10000] = {0};
int sz = SIZE;
int bpb = BYTES_PER_BEAT;
int i = 0;
fp=fopen("/home/jonathan/Documents/Chalmers/Year5/DAT480/Lab_Project/DAT480/Rules_div_by_length/test_vec_input.txt","r");
if(fp == NULL){
cout << "ERROR OPENING FILE\n";
exit(1);
}
fseek(fp, 0L, SEEK_END);
int sz_f_x = ftell(fp);
fseek(fp, 0L, SEEK_SET);
for (i=0; i<sz_f_x; i++){
uint8_t tmp;
fscanf(fp, "%c", &tmp);
x[i] = tmp;
printf("%c", tmp);
}
fclose(fp);
fp=fopen("/home/jonathan/Documents/Chalmers/Year5/DAT480/Lab_Project/DAT480/Rules_div_by_length/test_vec_gold.txt","r");
if(fp == NULL){
cout << "ERROR OPENING FILE\n";
exit(1);
}
int sz_f_g = 0;
char c;
for (c = getc(fp); c != EOF; c = getc(fp))
if (c == '\n') // Increment count if this character is newline
sz_f_g++;
printf("\n");
printf("%d\n", sz_f_g);
fseek(fp, 0L, SEEK_SET);
for (i=0; i<sz_f_g; i++){
int tmp;
fscanf(fp, "%d", &tmp);
golden[i] = tmp & 0xffff;
// printf(" golden = %d\n",golden[i]);
}
fclose(fp);
hls::stream<pkt> in;//, out;
pkt word_in, word_out;
ap_uint<NUM_BYTES*8> out;
int count = 0;
for(int i = 0; i<(int)ceil((float) sz_f_x/(float)sz); i++){
for (unsigned int l = 0; l < sz/bpb; l++) {
// printf("writing\n");
ap_uint<512> res;
for(int j=0;j<NUM_BYTES;j++)
{
res.range((j*8),(j*8)+7) = x[i*sz+NUM_BYTES*l+j];
// cout << "TB reads " << (char) res.range((j*8),(j*8)+7) << endl;
}
// printf("\n");
word_in.data = res;
word_in.keep = -1;
// set last signals when last piece of data or
// multiple of 1408 bytes, packetize the payload
if ((((sz/bpb) - 1)==l) || ((((l + 1) * bpb) % sz) == 0))
word_in.last = 1;
else
word_in.last = 0;
word_in.dest = 0; //not sure if i need to set this in the tb
in.write(word_in);
krnl_s2mm(in,&out);
// out.read(word_out);
for(int j=0;j<41;j++)
{
ap_uint<12> result = out.range((j*12),(j*12)+11);//word_out.data.range((j*12),(j*12)+11);
if(result != 4095){ //not a match, skip check.
y[count] = result;
cout << "Count = " << count ;
cout << ": y = " << y[count] << " golden = " << golden[count] << endl;
if(y[count] != golden[count]){
cout << "TB failed at count = " << count << endl;
return 1; //return 1 to indicate fail
}
count++;
}
}
}
}
printf("Reached end of tb\n");
return 0;
}