From 89f10d493a0393e6b6ac531e24f9bbbb508a74d3 Mon Sep 17 00:00:00 2001 From: Yingchi Long Date: Fri, 25 Apr 2025 11:30:16 +0800 Subject: [PATCH] spec: add function `spawnSPECWithID` --- src/bin/runcpu.ts | 64 ++++++++++++++++++----------------------------- src/spec/index.ts | 41 ++++++++++++++++++++++++------ 2 files changed, 58 insertions(+), 47 deletions(-) diff --git a/src/bin/runcpu.ts b/src/bin/runcpu.ts index bbd5005..cd43078 100644 --- a/src/bin/runcpu.ts +++ b/src/bin/runcpu.ts @@ -1,13 +1,13 @@ -import yargs from 'yargs'; -import { spawn } from 'child_process'; -import { RunCPUOptions, runcpuOptions } from '../commands/spec.js'; -import path from 'path'; -import { ConfigOptions, mkSPEC, renderConfig, getBaseRatios } from '../spec/index.js'; -import { sw64TargetOptions } from '../commands/compiler.js'; -import crypto from 'crypto'; -import { hideBin } from 'yargs/helpers'; -import * as sunway from '../sunway.js'; import chalk from 'chalk'; +import crypto from 'crypto'; +import path from 'path'; +import yargs from 'yargs'; +import { hideBin } from 'yargs/helpers'; +import { sw64TargetOptions } from '../commands/compiler.js'; +import { RunCPUOptions } from '../commands/spec.js'; +import { getBaseRatios, mkSPEC, spawnSPECWithID } from '../spec/index.js'; +import * as sunway from '../sunway.js'; +import { cflangLibs, toolchain, ToolchainSuite } from '../toolchain/index.js'; // Define the yargs options const argv = await yargs(hideBin(process.argv)) @@ -83,27 +83,6 @@ console.log(`using sysroot: ${chalk.red(sysroot)}`); const specPath = path.resolve(argv.spec); - -function runspec(specConfig: string, id: string) { - const config = `${id}.cfg`; - - const spec = mkSPEC(specPath); - - spec.newConfig(config, specConfig); - - return spawn('runcpu', [ - ...runcpuOptions({ - 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() }); -} - // Function to convert hash to prefix // Generate a random UUID for this run @@ -124,12 +103,11 @@ const unalignedFlags = [ ]; -console.log(`Running SPEC compiled from ${prefix} as ${uuid}`); -console.log(`View: ${path.resolve(argv.output, uuid)}`) +const spec = mkSPEC(argv.spec); -const specProc = runspec( - renderConfig({ - prefix, +const specProc = await spawnSPECWithID( + spec, + { optimize: [ "-O2", ...sw64TargetOptions({ simd: argv.simd }), @@ -139,11 +117,19 @@ const specProc = runspec( '-static', `-L${path.resolve(prefix, 'lib')}`, ], - sysroot, - compiler: argv.compilerSuite as ConfigOptions["compiler"], - }), + compilerPaths: toolchain(argv.compilerPrefix, argv.compilerSuite as ToolchainSuite), + libs: argv.compilerSuite === "llvm" ? cflangLibs(prefix) : [], + }, + { + 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"], + }, + argv.output, uuid ); const baseRatios = await getBaseRatios(specProc); -console.log(baseRatios); \ No newline at end of file +console.log(baseRatios); diff --git a/src/spec/index.ts b/src/spec/index.ts index 38cf09c..a5b8480 100644 --- a/src/spec/index.ts +++ b/src/spec/index.ts @@ -1,12 +1,13 @@ -import * as path from 'path'; -import * as fs from "fs"; -import { promisify } from "util"; -import { ChildProcessByStdio } from 'child_process'; -import { Readable, Writable } from 'stream'; -import { createInterface } from 'readline'; -import { SPECBenchData, benchpath, exepath, buildpath } from './benchData.js'; -import specTemplate from '../../assets/specTemplate.cfg'; import assert from 'assert'; +import { ChildProcessByStdio, spawn } from 'child_process'; +import * as fs from "fs"; +import * as path from 'path'; +import { createInterface } from 'readline'; +import { Readable, Writable } from 'stream'; +import { promisify } from "util"; +import specTemplate from '../../assets/specTemplate.cfg'; +import { RunCPUOptions, runcpuOptions } from '../commands/spec.js'; +import { SPECBenchData, benchpath, buildpath, exepath } from './benchData.js'; @@ -211,3 +212,27 @@ export function parseSPECCSVResultsTable(data: string): ParsedResult { } return results; } + + +export async function spawnSPECWithID( + spec: SPEC, + specConfig: ConfigOptions, + runcpuConfig: RunCPUOptions, + outputPath: string, + id: string, +) { + const outputRoot = path.resolve(outputPath, id); + + console.log(`runspec: launch SPEC benchmark at ${id}, config: ${JSON.stringify(specConfig)}`); + console.log(`runspec: view output dir: ${outputRoot}`); + + const config = `${id}.cfg`; + + await spec.newConfig(config, renderConfig(specConfig)); + + return spawn('runcpu', runcpuOptions({ + outputRoot, + config, + ...runcpuConfig, + }), { env: spec.getEnvironment() }); +} -- 2.51.0