From 7f914686a57673a78de0db99b45ef421973bcf8d Mon Sep 17 00:00:00 2001 From: Yingchi Long Date: Sat, 12 Jul 2025 18:36:58 +0800 Subject: [PATCH] runcpu: support -fopenmp (dynamic linking) --- assets/specTemplate.cfg | 4 ++-- src/bin/runcpu.ts | 19 +++++++++++++++---- src/spec/index.ts | 4 ++++ 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/assets/specTemplate.cfg b/assets/specTemplate.cfg index ce5669e..52c1148 100644 --- a/assets/specTemplate.cfg +++ b/assets/specTemplate.cfg @@ -25,7 +25,7 @@ verify_binaries = 0 intrate,fprate: copies = 1 # EDIT to change number of copies (see above) intspeed,fpspeed: - threads = 1 # EDIT to change number of OpenMP threads (see above) + threads = @@OpenMPThreads@@ # EDIT to change number of OpenMP threads (see above) #------- Compilers ------------------------------------------------------------ @@ -115,4 +115,4 @@ default=base: intrate,intspeed=base: EXTRA_COPTIMIZE = -fno-strict-aliasing - LDCFLAGS = -z muldefs \ No newline at end of file + LDCFLAGS = -z muldefs diff --git a/src/bin/runcpu.ts b/src/bin/runcpu.ts index 57f1b85..5130be7 100644 --- a/src/bin/runcpu.ts +++ b/src/bin/runcpu.ts @@ -31,7 +31,7 @@ const argv = await yargs(hideBin(process.argv)) }) .option('optimize-profile', { type: 'string', - choices: ['O2', 'base'], + choices: ['O2', 'base', 'openmp'], demandOption: true, }) .option('allow-misaligned', { @@ -99,6 +99,12 @@ const optimizeProfiles = { "-O3", "-flto=thin", ], + openmp: [ + "-O3", + "-flto=thin", + "-DSPEC_OPENMP", + "-fopenmp", + ], O2: [ "-O2", ] @@ -132,20 +138,25 @@ const specProc = await spawnSPECWithID( ...argv.compilerSuite == "llvm" ? [sunway.mcpu(sunwayGeneration)] : [], // Only add -mcpu for llvm ], ldflags: [ - '-static', `-L${path.resolve(prefix, 'lib')}`, ...optimizeFlags, "-fuse-ld=lld", ...["--sysroot", sysroot], - ...argv.optimizeProfile === "base" ? [ + ...["base", "openmp"].includes(argv.optimizeProfile) ? [ ...argv.simd ? ["-Wl,-plugin-opt,-mattr=+simd"] : [], ...argv.allowMisaligned ? [`-Wl,-plugin-opt,${sw64UnalignedFlag}`] : [], ...sunwayGeneration === "8a" ? ["-Wl,-plugin-opt,-mattr=+core4"] : [], ] : [], + ...argv.optimizeProfile === "openmp" ? [ + `-Wl,-rpath=${argv.compilerPrefix}/lib`, + ] : ['-static'], ], compilerPaths: toolchain(argv.compilerPrefix, argv.compilerSuite as ToolchainSuite), - libs: argv.compilerSuite === "llvm" ? cflangLibs(prefix) : [], + libs: (argv.compilerSuite === "llvm" || argv.compilerSuite !== "openmp") ? cflangLibs(prefix) : [], specialFlags: getSpecialFlags(), + openmp: { + threads: (argv.optimizeProfile === "openmp" ? 64 : 1), + } }, { setprocgroup: true, diff --git a/src/spec/index.ts b/src/spec/index.ts index 10d6bc6..cd61d3c 100644 --- a/src/spec/index.ts +++ b/src/spec/index.ts @@ -64,6 +64,9 @@ export interface ConfigOptions { optimize: string[]; ldflags: string[]; libs: string[]; + openmp: { + threads: number; + }; compilerPaths: { CXX: string, CC: string, @@ -83,6 +86,7 @@ export const renderConfig = (options: ConfigOptions): string => { .replace("@@CompilerFC@@", options.compilerPaths.FC) .replace("@@LIBS@@", options.libs.join(" ")) .replace("@@SpecialFlags@@", options.specialFlags) + .replace("@@OpenMPThreads@@", options.openmp.threads.toString()) ; };