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