forked from xuqiantong/CUDA-Winograd
-
Notifications
You must be signed in to change notification settings - Fork 2
/
util.c
49 lines (40 loc) · 1.08 KB
/
util.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
#include "util.h"
#include "math.h"
#include <time.h>
uint64_t getTimeMicroseconds64()
{
uint64_t nTime;
struct timespec tSpec;
clock_gettime(CLOCK_REALTIME, &tSpec);
nTime = (uint64_t)tSpec.tv_sec * 1000000 + (uint64_t)tSpec.tv_nsec / 1000;
return nTime;
}
float *get_parameter(const char *filename, int size) {
float *parameter = (float*)malloc(size*4);
if (!parameter) {
printf("Bad Malloc\n");
exit(0);
}
FILE *ptr = fopen(filename,"rb");
if (!ptr) {
printf("Bad file path: %p, %s\n", ptr, strerror(errno));
exit(0);
}
fread(parameter,size*4,1,ptr);
fclose(ptr);
return parameter;
}
float output_checker(float *A, float *B, int len, int channel, int shift) {
int error_cnt = 0;
float max_error = 0;
for (int i = 0; i < len; i++) {
for (int j = 0; j < len; j++) {
for (int k = 0; k < channel; k++) {
float diff = fabs(A[((i+shift)*(len+2*shift)+j+shift)*channel + k] - B[(i*len+j)*channel + k]);
if (diff > 1e-5) error_cnt++;
if (diff > max_error) max_error = diff;
}
}
}
printf("[max_error: %f][error_cnt: %d]\n", max_error, error_cnt);
}