-
Notifications
You must be signed in to change notification settings - Fork 2
/
test_pattern.c
174 lines (122 loc) · 3.36 KB
/
test_pattern.c
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#include "pciedma.h"
#include "data_patterns.h"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/time.h>
#define SEND
int main(int argc, char **argv)
{
unsigned int *data_samples;
int i,val,j;
int size, new_size;
pd_device_t dev;
void *memr, *mems, *mem_new;
float throughput;
struct timeval tv1,tv2;
int mintime, curtime, vsize;
printf("====================================\n");
printf("= Pattern Tests =\n");
printf("====================================\n\n");
if(pd_open(0,&dev) != 0){
printf("Failed to open file \n");
return -1;
}
printf("Device file opened successfuly\n");
// Allocate send and receive buffers
size = 4*1024*1024; // 32x32 matrix with 4 byte entries
posix_memalign( (void**)&memr, 16, size);
posix_memalign( (void**)&mems, 16, size);
//for(i=0;i < size/4; i++){
// ((int*)mems)[i] = i;
// printf("%d ",((int*)mems)[i]);
//}
/*
vsize = 1;
for(i=1; i < 16; i++)
{
mintime = 99999;
for(j=0; j < 500; j++)
{
gettimeofday(&tv1,NULL);
compressData(mems, &mem_new, &new_size, 0, 4, 120, vsize);
gettimeofday(&tv2,NULL);
curtime = tv2.tv_usec - tv1.tv_usec;
if (curtime < mintime)
mintime = curtime;
free(mem_new);
}
printf("Total Size: %d, Time elapsed: %d\n", new_size, mintime);
vsize *= 2;
}
return;
*/
// Each 5x5 subblock will hold the same value
val = 0;
for(i=0; i < size/4; i++){
if (i % 16 == 0 && i!=0)
val ++;
val = val % 2;
((int *)mems)[i] = val;
}
// Test matrix
for(i=0; i < size/4; i++){
if (i%32 == 0 && i!=0)
printf("\n");
printf("%d ", ((int*)mems)[i]);
}
//--------------------------
if(initDMA(&dev) < 0)
printf("Init DMA failed\n");
// Send and receive in simultaneous
gettimeofday(&tv1,NULL);
#ifdef SEND
if(setupSend(&dev, (void*)mems, size,1) < 0)
printf("Setup Send failed\n");
if(applyBlocking_send(16, 32, 4) < 0)
printf("Apply Blocking send failed\n");
#endif
if(setupRecv(&dev, (void*)memr, size) < 0)
printf("Setup Recv failed\n");
//int applyLinear_recv(int offset, int hsize, int stride, int total_size);
// if(applyBlocking_recv(16, 32, 4) < 0)
if(applyLinear_recv(0,128,128,4096) < 0)
printf("Apply Blocking recv failed\n");
gettimeofday(&tv2,NULL);
printf("Time taken to setup receive AND send transfer:%d\n", tv2.tv_usec - tv1.tv_usec);
//--------------------------
gettimeofday(&tv1,NULL);
#ifdef SEND
//if(startSend(&dev, 0) < 0)
// printf("DMA Send failed\n");
#endif
// printf("Press any key to continue ;)\n");
// getchar();
if(startRecv(&dev, 0) < 0)
printf("DMA Recv failed\n");
if(startSend(&dev, 0) < 0)
printf("DMA Send failed\n");
if(checkRecv() < 0)
printf("Check DMA recv failed\n");
#ifdef SEND
if(checkSend() < 0)
printf("Check DMA send failed\n");
#endif
gettimeofday(&tv2,NULL);
curtime = tv2.tv_usec - tv1.tv_usec;
printf("Time taken to complete and check send AND receive transfer:%d\n", curtime);
printf("Throughput: %f MB/s\n",(float)2*size/((float)(curtime)));
// Test matrix
for(i=0; i < size/4; i++){
if (i%32 == 0 && i!=0)
printf("\n");
printf("%d ", ((int*)memr)[i]);
}
freeSend(&dev);
freeRecv(&dev);
stopDMA(&dev);
//for(i=0;i<size/4;i++)
// printf("%d ",((unsigned int*)memr)[i]);
free(memr); free(mems);
return 0;
}