cpubench: specify O3 LTO flags
This commit is contained in:
@@ -5,8 +5,9 @@ import path from 'path';
|
||||
import yargs from 'yargs';
|
||||
import { hideBin } from 'yargs/helpers';
|
||||
import { promisifySpawn } from '../cli.js';
|
||||
import { OptimizeOptions, optimizeOptions, sw64TargetOptions } from '../commands/compiler.js';
|
||||
import { sw64TargetOptions } from '../commands/compiler.js';
|
||||
import * as cpubench from '../cpubench/index.js';
|
||||
import * as sunway from '../sunway.js';
|
||||
|
||||
// 解析命令行参数
|
||||
const argv = await yargs(hideBin(process.argv))
|
||||
@@ -25,38 +26,91 @@ const argv = await yargs(hideBin(process.argv))
|
||||
description: 'Enable SIMD optimization',
|
||||
demandOption: true
|
||||
})
|
||||
.option('optimize', {
|
||||
alias: 'o',
|
||||
type: 'string',
|
||||
description: 'Optimization level',
|
||||
choices: ['0', '1', '2', '3', 's', 'fast', 'g', 'z'], // 限制输入值为合法选项
|
||||
default: '2'
|
||||
})
|
||||
.option('benchmarks', {
|
||||
type: 'array', // 数组类型参数
|
||||
alias: 'b',
|
||||
description: 'List of benchmarks to run',
|
||||
demandOption: true,
|
||||
})
|
||||
.option('workdir-base', {
|
||||
.option('optimize-profile', {
|
||||
type: 'string',
|
||||
choices: ['O2', 'base'],
|
||||
demandOption: true,
|
||||
})
|
||||
.option('rebuild', {
|
||||
type: 'boolean',
|
||||
description: 'Force rebuild of benchmarks',
|
||||
demandOption: true,
|
||||
})
|
||||
.option('workdir', {
|
||||
type: 'string',
|
||||
description: 'Base directory of workdirs',
|
||||
demandOption: true,
|
||||
})
|
||||
.option('uuid', {
|
||||
type: 'boolean',
|
||||
description: "Append uuid to workdir",
|
||||
demandOption: true,
|
||||
})
|
||||
.option('platform', {
|
||||
alias: 'p',
|
||||
type: 'string',
|
||||
description: 'Sunway host platform for running SPEC',
|
||||
choices: ['8a', '6b', 'host'],
|
||||
default: 'host',
|
||||
})
|
||||
.option('allow-misaligned', {
|
||||
type: 'boolean',
|
||||
demandOption: true,
|
||||
})
|
||||
.option('action', {
|
||||
type: 'string',
|
||||
demandOption: true,
|
||||
})
|
||||
.parse();
|
||||
|
||||
const sw64UnalignedFlag = "-sw64-allows-misaligned-memory-accesses";
|
||||
|
||||
const cpubenchDir = path.resolve(argv.cpubench);
|
||||
const llvmInstall = path.resolve(argv.llvm);
|
||||
|
||||
const ltoFlags = [
|
||||
"-flto=thin",
|
||||
"-fuse-ld=lld",
|
||||
];
|
||||
|
||||
const optimizeProfiles = {
|
||||
base: [
|
||||
"-O3",
|
||||
...ltoFlags,
|
||||
],
|
||||
O2: [
|
||||
"-O2",
|
||||
]
|
||||
};
|
||||
|
||||
const optimizeFlags = optimizeProfiles[argv.optimizeProfile as (keyof (typeof optimizeProfiles))];
|
||||
|
||||
const sunwayGeneration = argv.platform === "host" ? sunway.getHostGeneration() : argv.platform as sunway.SunwayGeneration;
|
||||
|
||||
const cpubenchConfig = cpubench.renderConfig({
|
||||
llvmInstall: llvmInstall,
|
||||
optimize: [
|
||||
...sw64TargetOptions({ simd: argv.simd }),
|
||||
...optimizeOptions({ optimize: argv.optimize as OptimizeOptions["optimize"] }),
|
||||
...optimizeFlags,
|
||||
...argv.allowMisaligned ? ["-mllvm", sw64UnalignedFlag] : [],
|
||||
"-g",
|
||||
sunway.mcpu(sunwayGeneration),
|
||||
],
|
||||
benchmarks: argv.benchmarks as cpubench.CPUBenchConfigOptions["benchmarks"],
|
||||
ldflags: [
|
||||
...optimizeFlags,
|
||||
...argv.optimizeProfile === "base" ? [
|
||||
...argv.simd ? ["-Wl,-plugin-opt,--mattr=simd"] : [],
|
||||
...argv.allowMisaligned ? [`-Wl,-plugin-opt,${sw64UnalignedFlag}`] : [],
|
||||
sunway.mcpu(sunwayGeneration),
|
||||
] : [],
|
||||
],
|
||||
});
|
||||
|
||||
const uuid = randomUUID();
|
||||
@@ -65,7 +119,7 @@ const configFile = path.resolve(cpubenchDir, 'config', `rendered-${uuid}.config`
|
||||
|
||||
await fs.promises.writeFile(configFile, cpubenchConfig);
|
||||
|
||||
const workdir = path.join(argv.workdirBase, uuid);
|
||||
const workdir = argv.uuid ? path.join(argv.workdir, uuid) : argv.workdir;
|
||||
console.log(`Using workdir = ${workdir}`);
|
||||
await fs.promises.mkdir(workdir, { recursive: true });
|
||||
|
||||
@@ -74,10 +128,11 @@ const proc = spawn(
|
||||
[
|
||||
`--config=${configFile}`,
|
||||
"--skip_verify=1",
|
||||
"--rebuild=1",
|
||||
("--rebuild=" + (argv.rebuild ? "1" : "0")),
|
||||
"-i=1",
|
||||
`--work_dir=${workdir}`,
|
||||
`--perf=1`,
|
||||
`-a=${argv.action}`,
|
||||
],
|
||||
{ cwd: cpubenchDir }
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user