Skip to content

Commit

Permalink
Merge pull request #27 from stratika/fixup/internal/taskgraph-parameters
Browse files Browse the repository at this point in the history
[fix] Resolved internal scalar values from the TaskGraph input/output lists
  • Loading branch information
stratika authored Sep 4, 2024
2 parents 79a9f06 + 630a6fa commit 0ef4630
Showing 1 changed file with 17 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.file.Paths;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -75,20 +75,24 @@ private static File createFile(Project project, PsiMethod method, ArrayList<PsiM
import uk.ac.manchester.tornado.api.TornadoExecutionPlan;
import uk.ac.manchester.tornado.api.exceptions.TornadoExecutionPlanException;
""";
StringBuilder methodWithParameters = new StringBuilder();
StringBuilder taskParameters = new StringBuilder();
StringBuilder taskGraphParameters = new StringBuilder();
String methodWithClass = filename + "::" + method.getName();
String variableInit = VariableInit.variableInitHelper(method);

for (PsiParameter p : method.getParameterList().getParameters()) {
methodWithParameters.append(", ").append(p.getName());
taskParameters.append(", ").append(p.getName());
if (isParameterBoxedType(p)) {
taskGraphParameters.append(", ").append(p.getName());
}
}
String mainCode = "\n\tpublic static void main(String[] args) throws TornadoExecutionPlanException {\n" +
"\n" +
variableInit +
"TaskGraph taskGraph = new TaskGraph(\"s0\") \n" +
".transferToDevice(DataTransferMode.EVERY_EXECUTION" + methodWithParameters + ")\n" +
".task(\"t0\", " + methodWithClass + methodWithParameters + ") \n" +
".transferToHost(DataTransferMode.EVERY_EXECUTION" + methodWithParameters + ");\n" +
".transferToDevice(DataTransferMode.EVERY_EXECUTION" + taskGraphParameters + ")\n" +
".task(\"t0\", " + methodWithClass + taskParameters + ") \n" +
".transferToHost(DataTransferMode.EVERY_EXECUTION" + taskGraphParameters + ");\n" +
"ImmutableTaskGraph immutableTaskGraph = taskGraph.snapshot();\n" +
"try (TornadoExecutionPlan executionPlan = new TornadoExecutionPlan(immutableTaskGraph)) {\n" +
"executionPlan.withWarmUp().execute();\n" +
Expand Down Expand Up @@ -123,11 +127,17 @@ private static File createFile(Project project, PsiMethod method, ArrayList<PsiM
return javaFile;
}

private static boolean isParameterBoxedType(PsiParameter p) {
return switch (p.getTypeElement().getText()) {
case "int", "float", "double", "long", "boolean" -> false;
default -> true;
};
}
private static void saveFileToDisk(File sourceFile, String targetDir) {
File target = new File(targetDir);
File targetFile = new File(target, sourceFile.getName());
try (BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(targetFile))) {
bufferedWriter.write(new String(java.nio.file.Files.readAllBytes(sourceFile.toPath())));
bufferedWriter.write(new String(Files.readAllBytes(sourceFile.toPath())));
} catch (IOException e) {
throw new RuntimeException(e);
}
Expand Down

0 comments on commit 0ef4630

Please sign in to comment.