/
validate-spike.js
executable file
·88 lines (73 loc) · 3.36 KB
/
validate-spike.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
#!/usr/bin/env node
const { spawnSync }= require("child_process");
const kernels = [ "saxpy", "memcpy", "gemm", "3mm" ];
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_simple = "./run_simple";
const bin_uve = "./run_uve";
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 Kernel ${command}: 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 aproximateEqual(stdout1, stdout2) {
const str1 = stdout1.split("\n");
const str2 = stdout2.split("\n");
if (str1.length !== str2.length) {
console.log(`Tests did not generate same amount of values`);
return false;
}
for (let i = 0; i < str1.length; i++) {
const value1 = parseFloat(str1[i]);
const value2 = parseFloat(str2[i]);
const diff = Math.abs(value1 - value2);
if (diff > 0.0001) {
console.error(`Values were ${str1[i]} and ${str2[i]} with difference of ${diff} at index ${i}`);
return false;
}
}
return true;
}
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_SIMPLE", "-Ibenchmarks/", "-O0", `benchmarks/${kernel}/kernel.c`, "-c" ]);
compileKernel(compilerPath, [...linkFlags, "-O0", "Commun.o", `kernel.o`, `main.o`, "-o", bin_simple]);
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 execSimple = executableRun(spikePath, [pkPath, bin_simple]);
const execUVE = executableRun(spikePath, [pkPath, bin_uve]);
/* Test if generated values are similar */
if (aproximateEqual(execSimple.stdout.toString(), execUVE.stdout.toString())) {
console.log(`Kernel ${kernel} is similar enough`);
} else {
console.error(`Kernel ${kernel}: Did not generate result similar enough`);
break;
}
/* Delete executables for next kernel */
const del = spawnSync("rm", ["-f", bin_simple, bin_uve, '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;
}
}