bin/runcpu: utility to run spec tests under systemd user service
This commit is contained in:
138
src/bin/runcpu.ts
Normal file
138
src/bin/runcpu.ts
Normal file
@@ -0,0 +1,138 @@
|
||||
import yargs from 'yargs';
|
||||
import { spawn } from 'child_process';
|
||||
import { promisifySpawn } from '../cli.js';
|
||||
import { RunCPUOptions, runcpuOptions } from '../commands/spec.js';
|
||||
import { systemdRunOptions } from '../commands/systemd.js';
|
||||
import path from 'path';
|
||||
import { mkSPEC, renderConfig } from '../spec/index.js';
|
||||
import { optimizeOptions, sw64TargetOptions } from '../commands/compiler.js';
|
||||
import crypto from 'crypto';
|
||||
import { hideBin } from 'yargs/helpers';
|
||||
import * as sunway from '../sunway.js';
|
||||
import chalk from 'chalk';
|
||||
|
||||
// Define the yargs options
|
||||
const argv = await yargs(hideBin(process.argv))
|
||||
.option('llvm', {
|
||||
type: 'string',
|
||||
description: 'The llvm path for this test',
|
||||
demandOption: true,
|
||||
})
|
||||
.option('workload', {
|
||||
alias: 'w',
|
||||
type: 'string',
|
||||
description: 'The workload for the SPEC run',
|
||||
choices: ['test', 'train', 'ref'],
|
||||
default: 'ref',
|
||||
})
|
||||
.option('spec', {
|
||||
alias: 's',
|
||||
type: 'string',
|
||||
description: 'SPEC 2017 directory',
|
||||
demandOption: true,
|
||||
})
|
||||
.option('output', {
|
||||
alias: 'o',
|
||||
type: 'string',
|
||||
description: 'SPEC 2017 output directory',
|
||||
demandOption: true,
|
||||
})
|
||||
.option('platform', {
|
||||
alias: 'p',
|
||||
type: 'string',
|
||||
description: 'Sunway host platform for running SPEC',
|
||||
choices: ['8a', '6b', 'host'],
|
||||
default: 'host',
|
||||
})
|
||||
.option('benchmarks', {
|
||||
alias: 'b',
|
||||
type: 'array',
|
||||
description: 'Selected benchmarks',
|
||||
default: ['intspeed', 'fpspeed'],
|
||||
})
|
||||
.option('action', {
|
||||
type: 'string',
|
||||
description: 'The action to perform with runcpu',
|
||||
choices: ['build', 'buildstep', 'validate', 'runsetup'],
|
||||
default: 'validate',
|
||||
})
|
||||
.option('buildType', {
|
||||
type: 'string',
|
||||
description: 'The build type for runcpu',
|
||||
choices: ['nobuild', 'rebuild'],
|
||||
default: 'rebuild',
|
||||
})
|
||||
.help()
|
||||
.parse();
|
||||
|
||||
const sunwayGeneration = argv.platform === "host" ? sunway.getHostGeneration() : argv.platform as sunway.SunwayGeneration;
|
||||
const sysroot = sunwayGeneration == "6b" ? "/usr/sw/standard-830-6b-test/" : "/usr/sw/swgcc1030_native_tools-8a";
|
||||
|
||||
console.log("sunway generation: " + chalk.red(sunwayGeneration));
|
||||
console.log(`using sysroot: ${chalk.red(sysroot)}`);
|
||||
|
||||
const specPath = path.resolve(argv.spec);
|
||||
|
||||
interface systemdRunSPECOptions {
|
||||
specConfig: string;
|
||||
id: string;
|
||||
runcpuOverride?: (old: RunCPUOptions) => RunCPUOptions;
|
||||
}
|
||||
|
||||
function systemdRunSPEC({
|
||||
specConfig,
|
||||
id,
|
||||
runcpuOverride,
|
||||
}: systemdRunSPECOptions) {
|
||||
const config = `${id}.cfg`;
|
||||
|
||||
const spec = mkSPEC(specPath);
|
||||
|
||||
spec.newConfig(config, specConfig);
|
||||
|
||||
return spawn('systemd-run', [
|
||||
...systemdRunOptions({
|
||||
scope: false,
|
||||
unit: id,
|
||||
user: true,
|
||||
}),
|
||||
'runcpu',
|
||||
...runcpuOptions((runcpuOverride || (x => x))({
|
||||
outputRoot: path.resolve(path.resolve(argv.output), id),
|
||||
config,
|
||||
setprocgroup: true,
|
||||
workload: argv.workload as RunCPUOptions["workload"],
|
||||
buildType: argv.buildType as RunCPUOptions["buildType"],
|
||||
benchmarks: argv.benchmarks as RunCPUOptions["benchmarks"],
|
||||
action: argv.action as RunCPUOptions["action"],
|
||||
})),
|
||||
], { env: spec.getEnvironment(), stdio: "inherit" });
|
||||
}
|
||||
|
||||
// Function to convert hash to prefix
|
||||
|
||||
// Generate a random UUID for this run
|
||||
const uuid = crypto.randomUUID();
|
||||
|
||||
const llvmPrefix = path.resolve(argv.llvm);
|
||||
|
||||
// SPEC configuration
|
||||
const specConfig = renderConfig({
|
||||
gccdir: llvmPrefix,
|
||||
optimize: [
|
||||
...optimizeOptions({ optimize: '2' }),
|
||||
...sw64TargetOptions({ simd: true }),
|
||||
sunway.mcpu(sunwayGeneration),
|
||||
],
|
||||
ldflags: [
|
||||
'-static',
|
||||
`-L${path.resolve(llvmPrefix, 'lib')}`,
|
||||
],
|
||||
sysroot
|
||||
});
|
||||
|
||||
console.log(`Running SPEC compiled from ${llvmPrefix} as ${uuid}`);
|
||||
await promisifySpawn(systemdRunSPEC({
|
||||
specConfig,
|
||||
id: uuid,
|
||||
}));
|
||||
Reference in New Issue
Block a user