bin/cpubench: init
This commit is contained in:
@@ -74,7 +74,7 @@ perf_timeout = 60 # Set the collection timeout.
|
|||||||
#=====================================================================
|
#=====================================================================
|
||||||
[default]
|
[default]
|
||||||
clang_dir = @@LLVM_INSTALL@@
|
clang_dir = @@LLVM_INSTALL@@
|
||||||
SYSROOT = /usr/sw/standard-830-6b-test/
|
SYSROOT = @@SYSROOT@@
|
||||||
LD_LIBRARY_PATH = ${clang_dir}/lib
|
LD_LIBRARY_PATH = ${clang_dir}/lib
|
||||||
|
|
||||||
#==========================Compiler for C=============================
|
#==========================Compiler for C=============================
|
||||||
|
|||||||
5
assets/assets.d.ts
vendored
5
assets/assets.d.ts
vendored
@@ -2,3 +2,8 @@ declare module '*.cfg' {
|
|||||||
const content: string;
|
const content: string;
|
||||||
export default content;
|
export default content;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
declare module '*.ini' {
|
||||||
|
const content: string;
|
||||||
|
export default content;
|
||||||
|
}
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ async function buildFile(entryFile) {
|
|||||||
'--format=esm',
|
'--format=esm',
|
||||||
'--minify',
|
'--minify',
|
||||||
'--loader:.cfg=text',
|
'--loader:.cfg=text',
|
||||||
|
'--loader:.ini=text',
|
||||||
'--outfile=' + outputFile,
|
'--outfile=' + outputFile,
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|||||||
86
src/bin/cpubench.ts
Normal file
86
src/bin/cpubench.ts
Normal file
@@ -0,0 +1,86 @@
|
|||||||
|
import { writeFileSync } from 'fs';
|
||||||
|
import { OptimizeOptions, optimizeOptions, sw64TargetOptions } from '../commands/compiler.js';
|
||||||
|
import * as cpubench from '../cpubench/index.js';
|
||||||
|
import path from 'path';
|
||||||
|
import { randomUUID } from 'crypto';
|
||||||
|
import { spawn } from 'child_process';
|
||||||
|
import { promisifySpawn } from '../cli.js';
|
||||||
|
import yargs from 'yargs';
|
||||||
|
import { hideBin } from 'yargs/helpers';
|
||||||
|
|
||||||
|
// 解析命令行参数
|
||||||
|
const argv = await yargs(hideBin(process.argv))
|
||||||
|
.option('llvm', {
|
||||||
|
type: 'string',
|
||||||
|
description: 'Path to the LLVM installation',
|
||||||
|
demandOption: true
|
||||||
|
})
|
||||||
|
.option('cpubench', {
|
||||||
|
type: 'string',
|
||||||
|
description: 'Path to the CPUBench directory',
|
||||||
|
demandOption: true,
|
||||||
|
})
|
||||||
|
.option('simd', {
|
||||||
|
type: 'boolean',
|
||||||
|
description: 'Enable SIMD optimization',
|
||||||
|
demandOption: true
|
||||||
|
})
|
||||||
|
.option('optimize', {
|
||||||
|
type: 'string',
|
||||||
|
description: 'Optimization level',
|
||||||
|
choices: ['0', '1', '2', '3', 's', 'fast', 'g', 'z'], // 限制输入值为合法选项
|
||||||
|
default: '2'
|
||||||
|
})
|
||||||
|
.option('benchmarks', {
|
||||||
|
type: 'array', // 数组类型参数
|
||||||
|
description: 'List of benchmarks to run',
|
||||||
|
demandOption: true,
|
||||||
|
})
|
||||||
|
.option('sysroot', {
|
||||||
|
type: 'string', // 数组类型参数
|
||||||
|
description: '--sysroot setting',
|
||||||
|
demandOption: true,
|
||||||
|
})
|
||||||
|
.parse();
|
||||||
|
|
||||||
|
|
||||||
|
const cpubenchDir = path.resolve(argv.cpubench);
|
||||||
|
const llvmInstall = path.resolve(argv.llvm);
|
||||||
|
|
||||||
|
const cpubenchConfig = cpubench.renderConfig({
|
||||||
|
llvmInstall: llvmInstall,
|
||||||
|
optimize: [
|
||||||
|
...sw64TargetOptions({ simd: argv.simd }),
|
||||||
|
...optimizeOptions({ optimize: argv.optimize as OptimizeOptions["optimize"] })
|
||||||
|
],
|
||||||
|
sysroot: argv.sysroot,
|
||||||
|
});
|
||||||
|
|
||||||
|
const uuid = randomUUID();
|
||||||
|
|
||||||
|
const configFile = path.resolve(cpubenchDir, 'config', `rendered-${uuid}.config`);
|
||||||
|
|
||||||
|
writeFileSync(configFile, cpubenchConfig);
|
||||||
|
|
||||||
|
const systemdArgs = [
|
||||||
|
'--user',
|
||||||
|
`--unit=${uuid}`,
|
||||||
|
`--working-directory=${cpubenchDir}`,
|
||||||
|
path.resolve(cpubenchDir, 'cpubench.sh'),
|
||||||
|
`--config=${configFile}`,
|
||||||
|
"--skip_verify=1",
|
||||||
|
...argv.benchmarks.map(x => `-b=${x}`),
|
||||||
|
"--rebuild=1",
|
||||||
|
"-i=1"
|
||||||
|
];
|
||||||
|
|
||||||
|
const proc = spawn(
|
||||||
|
'systemd-run',
|
||||||
|
systemdArgs,
|
||||||
|
{ cwd: cpubenchDir }
|
||||||
|
);
|
||||||
|
|
||||||
|
proc.stdout.pipe(process.stdout);
|
||||||
|
proc.stderr.pipe(process.stderr);
|
||||||
|
|
||||||
|
await promisifySpawn(proc);
|
||||||
@@ -140,8 +140,8 @@ export function llvmPackages({
|
|||||||
definitions: variable({
|
definitions: variable({
|
||||||
...general,
|
...general,
|
||||||
...{
|
...{
|
||||||
CMAKE_C_FLAGS: "-msimd -mlong-double-64",
|
CMAKE_C_FLAGS: "-mlong-double-64",
|
||||||
CMAKE_CXX_FLAGS: "-msimd -mlong-double-64",
|
CMAKE_CXX_FLAGS: "-mlong-double-64",
|
||||||
CMAKE_C_COMPILER: path.join(installPrefix, "bin", "clang"),
|
CMAKE_C_COMPILER: path.join(installPrefix, "bin", "clang"),
|
||||||
CMAKE_CXX_COMPILER: path.join(installPrefix, "bin", "clang++"),
|
CMAKE_CXX_COMPILER: path.join(installPrefix, "bin", "clang++"),
|
||||||
} as GeneralVariable,
|
} as GeneralVariable,
|
||||||
|
|||||||
@@ -1,16 +1,15 @@
|
|||||||
import fs from 'fs';
|
import cpuBenchTemplate from '../../assets/CPUBenchTemplate.ini';
|
||||||
import path from 'path';
|
|
||||||
import { projectRoot } from '../environment/index.js';
|
|
||||||
|
|
||||||
const cpubenchTemplate = fs.readFileSync(path.resolve(projectRoot, 'assets', 'CPUBenchTemplate.ini')).toString('utf-8');
|
|
||||||
|
|
||||||
export interface CPUBenchConfigOptions {
|
export interface CPUBenchConfigOptions {
|
||||||
llvmInstall: string;
|
llvmInstall: string;
|
||||||
optimize: string[];
|
optimize: string[];
|
||||||
|
sysroot: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function renderConfig({ llvmInstall, optimize }: CPUBenchConfigOptions) {
|
export function renderConfig({ llvmInstall, optimize, sysroot }: CPUBenchConfigOptions) {
|
||||||
return `# Rendered from TypeScript ${new Date().toLocaleString()}, do not edit!\n` + cpubenchTemplate
|
return `# Rendered from TypeScript ${new Date().toLocaleString()}, do not edit!\n` + cpuBenchTemplate
|
||||||
.replace('@@LLVM_INSTALL@@', llvmInstall)
|
.replace('@@LLVM_INSTALL@@', llvmInstall)
|
||||||
.replace('@@OPTIMIZE@@', optimize.join(' '));
|
.replace('@@OPTIMIZE@@', optimize.join(' '))
|
||||||
|
.replace('@@SYSROOT@@', sysroot);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user