-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
137 lines (107 loc) · 4.14 KB
/
index.js
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
const { GPU } = require('gpu.js'),
{ benchmark: bench, multipleBenchmark } = require('./src/index'),
writeFileSyncRecursive = require('./cli/write-file-recursive'),
getOptionsInput = require('./cli/get-options'),
parseArgs = require('./cli/parse-args'),
graphDefaults = require('./cli/graph-defaults.json'),
multipleDefaults = require('./cli/multiple-defaults.json'),
logMinMax = require('./cli/log-min-max'),
{ GREEN_NO_UNDER, NC, RED_FLASH, YELLOW_UNDER, YELLOW_NO_UNDER } = require('./cli/colors'),
{ br } = require('./cli/format'),
{ logRunTimeStats, logBuildTimeStats, logOverallStats } = require('./cli/log-stats');
let options = {
gpu: new GPU(),
cpu: new GPU({ mode: 'gpu' })
},
multiple = false;
const parsedArgs = parseArgs(process.argv);
br();
if (parsedArgs) {
try {
if (parsedArgs.multiple) {
multiple = true;
if (parsedArgs.options) options = JSON.parse(parsedArgs.options);
else {
options = {...multipleDefaults};
}
}
else if (parsedArgs.options) options = JSON.parse(parsedArgs.options);
}
catch (e) {
console.log(`${RED_FLASH}Options argument is not a valid JSON string or contains errors, running benchmarks with default options.${NC}`);
options = {...multipleDefaults};
br();
}
}
if (!multiple) {
options.logs = true;
getOptionsInput(options);
br();
console.log(`MATRIX SIZE: ${YELLOW_UNDER}${options.matrix_size || 512}${YELLOW_NO_UNDER}x${YELLOW_UNDER}${options.matrix_size || 512}${NC}`);
br();
const benchmarks = bench(options).getData();
const cpuBenched = benchmarks.options.cpu_benchmark;
br(2);
console.log(`Matrix Generation Time: ${YELLOW_UNDER}${benchmarks.mat_gen}${NC} ms (Generated 5 Matrices)`);
console.log(`Matrix Padding Time: ${YELLOW_UNDER}${benchmarks.mat_pad}${NC} ms`);
br(2);
console.log(`${GREEN_NO_UNDER}COMPILE TIME:${NC}`);
console.log(`Matrix Multiplication Compile Time: ${YELLOW_UNDER}${benchmarks.build_time.mat_mult.gpu}${NC} ms`);
console.log(`Matrix Multiplication (Pipeline) Compile Time: ${YELLOW_UNDER}${benchmarks.build_time.mat_mult.pipe}${NC} ms`);
console.log(`Matrix Convolution Compile Time: ${YELLOW_UNDER}${benchmarks.build_time.mat_conv.gpu}${NC} ms`);
br(2);
console.log(`${GREEN_NO_UNDER}MATRIX MULTIPLICATION RUN TIME:${NC}`);
logMinMax(benchmarks.run_time.mat_mult);
br(2);
console.log(`${GREEN_NO_UNDER}MATRIX CONVOLUTION RUN TIME:${NC}`);
logMinMax(benchmarks.run_time.mat_conv);
br();
console.log(`${GREEN_NO_UNDER}PIPELINE BENCHMARK:${NC}`);
logMinMax(benchmarks.run_time.pipe);
br();
console.log(`${GREEN_NO_UNDER}STATISTICS:${NC}`);
br();
console.log(`${GREEN_NO_UNDER}Run Time Statistics:${NC}`);
br();
logRunTimeStats(benchmarks.stats, cpuBenched);
console.log(`${GREEN_NO_UNDER}Build Time Statistics:${NC}`);
br();
logBuildTimeStats(benchmarks.stats, cpuBenched);
console.log(`${GREEN_NO_UNDER}Overall Statistics:${NC}`);
br();
logOverallStats(benchmarks.stats, cpuBenched);
console.log(`${GREEN_NO_UNDER}Score:${NC}`);
br();
console.log(`GPU: ${YELLOW_UNDER}${benchmarks.score.gpu}${NC}`);
console.log(`CPU: ${YELLOW_UNDER}${benchmarks.score.cpu < 0 ? 'Not Benchmarked' : benchmarks.score.cpu}${NC}`);
br();
}
else {
const benchmark = multipleBenchmark(options);
if (parsedArgs.returnPlotlyJSON){
br();
console.log('PLOTLY JSON:');
br();
console.log(benchmark.getPlotlyJSON([graphDefaults[0]]))
br();
}
if (parsedArgs.returnChartistJSON){
br();
console.log('CHARTIST JSON:');
br();
console.log(benchmark.getChartistJSON([graphDefaults[0]]))
br();
}
if (parsedArgs.plotlySavePath) {
const path = parsedArgs.plotlySavePath.replace(/^--savePlotlyJSONToFile=/, '').replace(/.json$/, '');
writeFileSyncRecursive(`${path}.json`, JSON.stringify(
benchmark.getPlotlyJSON(graphDefaults)
))
}
if (parsedArgs.chartistSavePath) {
const path = parsedArgs.chartistSavePath.replace(/^--saveChartistJSONToFile=/, '').replace(/.json$/, '');
writeFileSyncRecursive(`${path}.json`, JSON.stringify(
benchmark.getChartistJSON(graphDefaults)
))
}
}