/
measure-instructions-UVE.js
executable file
·118 lines (99 loc) · 4.94 KB
/
measure-instructions-UVE.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
#!/usr/bin/env node
const { spawnSync }= require("child_process");
// const kernels = [ "3mm", "floyd-marshall", "gemm", "jacobi-1d", "jacobi-2d", "memcpy", "saxpy", "trisolv" ];
const kernels = [ "saxpy", "memcpy" ];
const compileFlags = [ "-Wall", "-pedantic", "-DTYPE=1", "-DSIZE=128" ];
const linkFlags = [ "-Wall", "-pedantic", "-static" ];
const compilerPath = "/home/miguel/diss/sources/install/uve_tc/bin/riscv64-unknown-elf-gcc";
const pkPath = "/home/miguel/diss/tools/riscv64-unknown-elf/bin/pk";
const spikePath = "/home/miguel/diss/tools/bin/spike";
const bin_blank = "./run_blank";
const bin_simple = "./run_simple";
const bin_clava = "./run_clava";
const bin_uve = "./run_uve";
const instructions = {};
function executableRun(command, args) {
const executable = spawnSync(command, args);
if (executable.error) {
throw new Error(`An error occured while trying to run ${command}: ${executable.error.message}`);
}
if (executable.status != 0) {
throw new Error(`Issue in executable ${command} [${args.join(' ')}]: Execution failed\nStderr: ${executable.stderr}\nStdout: ${executable.stdout}`);
}
return executable;
}
function compileKernel(command, args) {
const executable = spawnSync(command, args);
if (executable.error) {
throw new Error(`An error occured while trying to compile ${command}: ${executable.error.message}`);
}
if (executable.status != 0) {
throw new Error(`Issue in Kernel ${command}: Compilation failed\nStderr: ${executable.stderr}\nStdout: ${executable.stdout}`);
}
}
function processInstructions(insBlank, insSimple, insClava, insUVE) {
const strippedClava = insClava - insBlank;
const strippedSimple = insSimple - insBlank;
const strippedUVE = insUVE - insBlank;
return {
"Blank": insBlank,
"Simple": insSimple,
"Clava": insClava,
"UVE": insUVE,
"Simple (stripped)": strippedSimple,
"Clava (stripped)": strippedClava,
"UVE (stripped)": strippedUVE,
"Speedup (Simple/Clava)": strippedSimple / strippedClava,
};
}
function processBinRun(string) {
const lines = string.split("\n");
for (let line of lines) {
const values = line.split(" ");
if (values[1] === "instructions") {
return values[0];
}
}
console.error("Missing instructions tag in output");
return null;
}
for (let kernel of kernels) {
/* Compile commun source files */
compileKernel(compilerPath, [...compileFlags, "-O3", "benchmarks/Commun.c", "-c"]);
compileKernel(compilerPath, [...compileFlags, "-O3", "-Ibenchmarks/", `benchmarks/${kernel}/main.c`, "-c"]);
/* Compile and link each kernel file */
compileKernel(compilerPath, [...compileFlags, "-DRUN_BLANK", "-Ibenchmarks/", "-O0", `benchmarks/${kernel}/kernel.c`, "-c" ]);
compileKernel(compilerPath, [...linkFlags, "-O0", "Commun.o", `kernel.o`, `main.o`, "-o", bin_blank]);
compileKernel(compilerPath, [...compileFlags, "-DRUN_SIMPLE", "-Ibenchmarks/", "-O0", `benchmarks/${kernel}/kernel.c`, "-c" ]);
compileKernel(compilerPath, [...linkFlags, "-O0", "Commun.o", `kernel.o`, `main.o`, "-o", bin_simple]);
executableRun("clava", ["Transform.lara", "-i", "src-lara", `--argv=kernelName:'${kernel}', compFlags:'${compileFlags.join(' ')}'`]);
compileKernel(compilerPath, [...compileFlags, "-Ibenchmarks/", "-O0", `output/${kernel}/kernel.c`, "-c" ]);
compileKernel(compilerPath, [...linkFlags, "-O0", "Commun.o", `kernel.o`, `main.o`, "-o", bin_clava]);
compileKernel(compilerPath, [...compileFlags, "-DRUN_UVE", "-Ibenchmarks/", "-O0", `benchmarks/${kernel}/kernel.c`, "-c" ]);
compileKernel(compilerPath, [...linkFlags, "-O0", "Commun.o", `kernel.o`, `main.o`, "-o", bin_uve]);
/* Run each kernel file */
const execBlank = executableRun(spikePath, [pkPath, "-s", bin_blank]);
const execSimple = executableRun(spikePath, [pkPath, "-s", bin_simple]);
const execClava = executableRun(spikePath, [pkPath, "-s", bin_clava]);
const execUVE = executableRun(spikePath, [pkPath, "-s", bin_uve]);
/* Extract instructions used during execution of both binaries */
const insBlank = processBinRun(execBlank.stdout.toString());
const insSimple = processBinRun(execSimple.stdout.toString());
const insClava = processBinRun(execClava.stdout.toString());
const insUVE = processBinRun(execUVE.stdout.toString());
/* Extract and store kernel information to output later if all kernels pass */
const blank = parseInt(insBlank);
const simple = parseInt(insSimple);
const clava = parseInt(insClava);
const uve = parseInt(insUVE);
const key = kernel.toUpperCase();
instructions[key] = processInstructions(blank, simple, clava, uve);
/* Delete executables for next kernel */
const del = spawnSync("rm", ["-rf", bin_blank, bin_simple, bin_clava, bin_uve, 'woven_code', `main.o`, `kernel.o`, `Commun.o`]);
if (del.error) {
console.error(`Kernel ${kernel}: An error occured while deleting files for next execution: ${del.error.message}`);
break;
}
console.log(`Finished Running ${kernel}`);
}
console.table(instructions);