UNPKG

@specs-feup/clava

Version:

A C/C++ source-to-source compiler written in Typescript

30 lines 1.46 kB
import Io from "@specs-feup/lara/api/lara/Io.js"; import Strings from "@specs-feup/lara/api/lara/Strings.js"; import Query from "@specs-feup/lara/api/weaver/Query.js"; import { Pragma } from "../../Joinpoints.js"; import KernelReplacer from "./KernelReplacer.js"; // This aspect can be included in a library, imported and // called by a user, since it needs no configuration/parameterization export default function KernelReplacerAuto() { // look for pragma for (const $pragma of Query.search(Pragma, "clava")) { const $file = $pragma.target.getAncestor("file"); if (!$pragma.content.startsWith("opencl_call")) { continue; } const configFilename = Strings.extractValue("opencl_call", $pragma.content)?.trim(); const configFile = Io.getAbsolutePath($file.path, configFilename); if (!Io.isFile(configFile)) { console.log(`Expected to find the config file '${configFilename}' in the folder '${$file.path}'`); continue; } const config = Io.readJson(configFile); const $call = $pragma.target.getDescendants("call")[0]; const kernel = new KernelReplacer($call, config.kernelName, config.kernelFile, config.bufferSizes, config.localSize, config.iterNumbers); for (const outBuf of config.outputBuffers) { kernel.setOutput(outBuf); } kernel.replaceCall(); } } //# sourceMappingURL=KernelReplacerAuto.js.map