mix-object: refactor with lambdas, use two spec instances

This commit is contained in:
2024-06-19 10:38:58 +08:00
parent f1871532cb
commit bc57810801

View File

@@ -7,9 +7,9 @@
*/ */
import { binSearch } from "./algorithm"; import { binSearch } from "./algorithm";
import { pop2, defaultSPEC, SPEC, Bench, mkBench } from "./spec"; import { pop2, SPEC, Bench, mkBench, mkSPEC } from "./spec";
import path from "path"; import path from "path";
import { FLANG, PREFIX, SYSROOT_PREFIX } from "./environment"; import { FLANG, PREFIX, SW_AUTOVEC, SYSROOT_PREFIX } from "./environment";
import { generalCommand, linkerCommand } from "./commands/compiler"; import { generalCommand, linkerCommand } from "./commands/compiler";
import { runcpuOptions } from "./commands/spec"; import { runcpuOptions } from "./commands/spec";
import { renderConfig } from "./spec"; import { renderConfig } from "./spec";
@@ -63,12 +63,6 @@ function mkPop2Bench(spec: SPEC): Bench & Linkable {
async function main() { async function main() {
const spec = defaultSPEC;
// Path to SPEC2017 test suite.
spec.setenv();
// Just use scalar vanilla version of grid, will it work? // Just use scalar vanilla version of grid, will it work?
// //
// No, does not work. // No, does not work.
@@ -77,42 +71,121 @@ async function main() {
const length = pop2.objectNames.length; const length = pop2.objectNames.length;
const beforeHalf = [ const beforeHalfGrid = [
// Empty: /home/lyc/workspace/sw-autovec/spec2017/result/CPU2017.664.fpspeed.refspeed.txt
// 0.336 // 0.336
// Scalar [0, 161): Error,
// /home/lyc/workspace/sw-autovec/spec2017/result/CPU2017.671.fpspeed.refspeed.txt
// : /home/lyc/workspace/sw-autovec/spec2017/result/CPU2017.664.fpspeed.refspeed.txt
// Scalar [161, 322): Correct.
false, false,
// Scalar [161, 241): Error,
// /home/lyc/workspace/sw-autovec/spec2017/result/CPU2017.672.fpspeed.refspeed.txt
// Scalar [241, 322): Error,
// /home/lyc/workspace/sw-autovec/spec2017-2/result/CPU2017.672.fpspeed.refspeed.rsf
// Vector [161, 241): Error,
// Vector [241, 322): Error,
// /home/lyc/workspace/sw-autovec/spec2017-2/result/CPU2017.673.fpspeed.refspeed.txt
false,
// Vector [241, 281): Error,
// /home/lyc/workspace/sw-autovec/spec2017/result/CPU2017.674.fpspeed.refspeed.txt
// Vector [281, 322): Correct.
true,
// Vector [241, 261): Error,
// /home/lyc/workspace/sw-autovec/spec2017/result/CPU2017.675.fpspeed.refspeed.rsf
// Vector [261, 281): Correct.
true,
// Vector [241, 251): Error,
// /home/lyc/workspace/sw-autovec/spec2017/result/CPU2017.676.fpspeed.refspeed.txt
// Vector [251, 261): Stopped.
true,
// Vector [241, 246): Error,
// /home/lyc/workspace/sw-autovec/spec2017/result/CPU2017.677.fpspeed.refspeed.rsf
]; ];
const [vBegin, vHalf, vEnd] = binSearch(0, length, beforeHalf);
const beforeHalfNoGrid: boolean[] = [
false,
// Vector [161, 241): Error
// /home/lyc/workspace/sw-autovec/spec2017/result/CPU2017.679.
// Vector [241, 322): Unknown
true,
// Vector [161, 201): Unknown
// Vector [201, 241): Error
false,
// Vector [201, 221): Error
// /home/lyc/workspace/sw-autovec/spec2017/result/CPU2017.681
// Vector [221, 241): Unknown
true,
// Vector [201, 211): Error
// Vector [211, 221): Unknown
true,
// Vector [201, 206): Unknown
// Vector [206, 211): Error
false,
// Vector [206, 208): Error
// Vector [208, 211): ?
true,
// Vector [206, 207): ?
// !!! Vector [207, 208): Error
];
const [vBegin, vHalf, vEnd] = binSearch(0, length, beforeHalfNoGrid);
// use scalar version if index is in this range. // use scalar version if index is in this range.
const scalarRange = [ const vectorRange: number[][] = [
[0, length / 2], [0, length],
[length / 2, length], // [vBegin, vHalf],
// [vHalf, vEnd],
]; ];
const useVectors = scalarRange.map(([a, b]) => ({ const specs = [
useVector: (_: string, index: number) => { path.join(SW_AUTOVEC, "spec2017"),
// If index is not in range [a, b), use the vector version. path.join(SW_AUTOVEC, "spec2017-2")
return !(a <= index && index < b); ].map(mkSPEC);
const useVectors = vectorRange.map(([a, b], index) => ({
useVector: (name: string, index: number) => {
if (name === "grid.fppized.o")
return false;
if (index == 207) {
console.log(`${name} is a bad object!`);
return false;
}
// If index is in range [a, b), use the vector version.
return a <= index && index < b;
}, },
range: [a, b], range: [a, b],
spec: specs[index],
})); }));
// Linking each "useVector" instances in sequence await Promise.all(useVectors.map(async ({ useVector, range, spec }) => {
for (const { useVector: predicate, range } of useVectors) {
const buildPathObj = (build: string) => (objname: string) => path.join(spec.buildpath(pop2), build, objname); const buildPathObj = (build: string) => (objname: string) => path.join(spec.buildpath(pop2), build, objname);
const vector = buildPathObj("build_vector"); const vector = buildPathObj("build_vector");
const scalar = buildPathObj("build_scalar_vanilla"); const scalar = buildPathObj("build_scalar_vanilla");
const pop2Bench = mkPop2Bench(spec); const pop2Bench = mkPop2Bench(spec);
console.log(`Linking objects. Range in [${range[0]}, ${range[1]}) used scalar version. others are vector version.`); console.log(`Linking objects. Range in [${range[0]}, ${range[1]}) used vector version. others are scalar version.`);
await pop2Bench.link(names => await pop2Bench.link(names =>
names.map((obj, index) => names.map((obj, index) =>
predicate(obj, index) ? vector(obj) : scalar(obj))); useVector(obj, index) ? vector(obj) : scalar(obj)));
const config = "clang-O2.cfg"; const config = "clang-O2.cfg";
@@ -141,10 +214,8 @@ async function main() {
buildType: "nobuild", buildType: "nobuild",
outputFormat: ["text", "config"] outputFormat: ["text", "config"]
}), }),
], { stdio: "inherit" }); ], { stdio: "inherit", env: spec.getEnvironment() });
}));
}
} }
main(); main();