-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupscale.cpp
More file actions
131 lines (115 loc) · 3.64 KB
/
Copy pathupscale.cpp
File metadata and controls
131 lines (115 loc) · 3.64 KB
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
#include "lodepng.h"
#include "cycleTimer.h"
#include "instrument.h"
#include <stdio.h>
#include <stdlib.h>
#include <getopt.h>
#include "anime4k.h"
#include "anime4k_seq.h"
#include "anime4k_cuda.h"
#include "anime4k_cpu.h"
#include "anime4k_omp.h"
#include "anime4k_ispc.h"
static void usage(char *name) {
const char *use_string = "-i IFILE [-o OFILE] [-b IMP] [-n TIMES] [-W WIDTH] [-H HEIGHT] [-I]";
printf("Usage: %s %s\n", name, use_string);
printf(" -h Print this message\n");
printf(" -i IFILE Input image file\n");
printf(" -o OFILE Output image file\n");
printf(" -b IMP Backend implementation\n");
printf(" -n TIMES Number of benchmark rounds\n");
printf(" -W WIDTH Width of the output\n");
printf(" -H HEIGHT Height of the output\n");
printf(" -I Instrument\n");
exit(0);
}
int main(int argc, char *argv[]) {
char *ifile = NULL;
char *ofile = NULL;
const char *backend = "cuda";
int times = 100;
unsigned int width = 3840;
unsigned int height = 2160;
unsigned int error;
unsigned char* image = 0;
unsigned int old_width, old_height;
bool instrument = false;
const char *optstring = "hi:o:b:n:W:H:I";
int c;
while ((c = getopt(argc, argv, optstring)) != -1) {
switch(c) {
case 'h':
usage(argv[0]);
break;
case 'i':
ifile = optarg;
break;
case 'o':
ofile = optarg;
break;
case 'b':
backend = optarg;
break;
case 'n':
times = atoi(optarg);
break;
case 'W':
width = atoi(optarg);
break;
case 'H':
height = atoi(optarg);
break;
case 'I':
instrument = true;
break;
default:
printf("Unknown option '%c'\n", c);
usage(argv[0]);
exit(1);
}
}
if (ifile == NULL) {
printf("Need input file\n");
usage(argv[0]);
exit(1);
}
error = lodepng_decode32_file(&image, &old_width, &old_height, ifile);
if (error) {
printf("error %u: %s\n", error, lodepng_error_text(error));
exit(1);
}
Anime4k* upscaler;
if (strcasecmp(backend, "seq")==0) {
upscaler = new Anime4kSeq(old_width, old_height, image, width, height);
} else if (strcasecmp(backend, "cuda")==0) {
upscaler = new Anime4kCuda(old_width, old_height, image, width, height);
} else if (strcasecmp(backend, "cpu")==0) {
upscaler = new Anime4kCpu(old_width, old_height, image, width, height);
} else if (strcasecmp(backend, "omp")==0) {
upscaler = new Anime4kOmp(old_width, old_height, image, width, height);
} else if (strcasecmp(backend, "ispc")==0) {
upscaler = new Anime4kIspc(old_width, old_height, image, width, height);
} else {
printf("%s backend is not implemented\n", backend);
exit(1);
}
track_activity(instrument);
double startTime = CycleTimer::currentSeconds();
for (int i = 0; i < times; i++) {
upscaler->run();
}
double endTime = CycleTimer::currentSeconds();
double totalTime = endTime - startTime;
SHOW_ACTIVITY(stderr, instrument);
fprintf(stderr, "Upscaled %d frames in %.4f s (%.4f fps)\n",
times, totalTime, times / totalTime);
if (ofile) {
error = lodepng_encode32_file(ofile, upscaler->get_image(), width, height);
if (error) {
printf("error %u: %s\n", error, lodepng_error_text(error));
}
}
delete upscaler;
free(image);
return 0;
}