Skip to content

Commit

Permalink
implement new "-explain" command to print the generated code to the c…
Browse files Browse the repository at this point in the history
…onsole
  • Loading branch information
Frxms committed Dec 13, 2024
1 parent 1e86da3 commit a1a131e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/main/java/org/apache/sysds/api/DMLOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,8 @@ else if (lineageType.equalsIgnoreCase("debugger"))
else if (explainType.equalsIgnoreCase("runtime")) dmlOptions.explainType = ExplainType.RUNTIME;
else if (explainType.equalsIgnoreCase("recompile_hops")) dmlOptions.explainType = ExplainType.RECOMPILE_HOPS;
else if (explainType.equalsIgnoreCase("recompile_runtime")) dmlOptions.explainType = ExplainType.RECOMPILE_RUNTIME;
else if (explainType.equalsIgnoreCase("codegen_hops")) dmlOptions.explainType = ExplainType.CODEGEN_HOPS;
else if (explainType.equalsIgnoreCase("codegen_runtime")) dmlOptions.explainType = ExplainType.CODEGEN_RUNTIME;
else throw new org.apache.commons.cli.ParseException("Invalid argument specified for -hops option, must be one of [hops, runtime, recompile_hops, recompile_runtime]");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,12 @@ public static ArrayList<Hop> optimize(ArrayList<Hop> roots, boolean recompile)
if( cla == null ) {
String src_cuda = "";
String src = tmp.getValue().codegen(false, GeneratorAPI.JAVA);
if(DMLScript.EXPLAIN.isCodegenType()) {
System.out.println("# SHOW GENERATED CODE");
System.out.println("-----------------------------");
System.out.println(src);
System.out.println("-----------------------------");
}
cla = CodegenUtils.compileClass("codegen." + tmp.getValue().getClassname(), src);

if(API == GeneratorAPI.CUDA) {
Expand Down
11 changes: 8 additions & 3 deletions src/main/java/org/apache/sysds/utils/Explain.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,18 @@ public enum ExplainType {
HOPS, // explain program and hops
RUNTIME, // explain runtime program (default)
RECOMPILE_HOPS, // explain hops, incl recompile
RECOMPILE_RUNTIME; // explain runtime program, incl recompile
RECOMPILE_RUNTIME, // explain runtime program, incl recompile
CODEGEN_HOPS, // show generated code, incl hops explanation
CODEGEN_RUNTIME; // show generated code, incl runtime explanation

public boolean isHopsType(boolean recompile) {
return (this==RECOMPILE_HOPS || (!recompile && this==HOPS));
return (this==RECOMPILE_HOPS || (!recompile && this==HOPS) || (this==CODEGEN_HOPS));
}
public boolean isRuntimeType(boolean recompile) {
return (this==RECOMPILE_RUNTIME || (!recompile && this==RUNTIME));
return (this==RECOMPILE_RUNTIME || (!recompile && this==RUNTIME) || (this==CODEGEN_RUNTIME));
}
public boolean isCodegenType() {
return (this == CODEGEN_HOPS || this == CODEGEN_RUNTIME);
}
}

Expand Down

0 comments on commit a1a131e

Please sign in to comment.