Skip to content

Commit a41027f

Browse files
Frxmsmboehm7
authored andcommitted
[SYSTEMDS-3810] New codegen explain types for debugging
Implements new "-explain" command, "codegen" and "codegen_recompile" to show generated code independent of LOG level Closes #2165.
1 parent ac36426 commit a41027f

File tree

4 files changed

+21
-7
lines changed

4 files changed

+21
-7
lines changed

src/main/java/org/apache/sysds/api/DMLOptions.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,9 @@ else if (lineageType.equalsIgnoreCase("debugger"))
201201
else if (explainType.equalsIgnoreCase("runtime")) dmlOptions.explainType = ExplainType.RUNTIME;
202202
else if (explainType.equalsIgnoreCase("recompile_hops")) dmlOptions.explainType = ExplainType.RECOMPILE_HOPS;
203203
else if (explainType.equalsIgnoreCase("recompile_runtime")) dmlOptions.explainType = ExplainType.RECOMPILE_RUNTIME;
204-
else throw new org.apache.commons.cli.ParseException("Invalid argument specified for -hops option, must be one of [hops, runtime, recompile_hops, recompile_runtime]");
204+
else if (explainType.equalsIgnoreCase("codegen")) dmlOptions.explainType = ExplainType.CODEGEN;
205+
else if (explainType.equalsIgnoreCase("codegen_recompile")) dmlOptions.explainType = ExplainType.CODEGEN_RECOMPILE;
206+
else throw new org.apache.commons.cli.ParseException("Invalid argument specified for -hops option, must be one of [hops, runtime, recompile_hops, recompile_runtime, codegen, codegen_recompile]");
205207
}
206208
}
207209

@@ -376,7 +378,7 @@ private static Options createCLIOptions() {
376378
Option memOpt = OptionBuilder.withDescription("monitors and reports max memory consumption in CP; default off")
377379
.create("mem");
378380
Option explainOpt = OptionBuilder.withArgName("level")
379-
.withDescription("explains plan levels; can be 'hops' / 'runtime'[default] / 'recompile_hops' / 'recompile_runtime'")
381+
.withDescription("explains plan levels; can be 'hops' / 'runtime'[default] / 'recompile_hops' / 'recompile_runtime' / 'codegen' / 'codegen_recompile'")
380382
.hasOptionalArg().create("explain");
381383
Option execOpt = OptionBuilder.withArgName("mode")
382384
.withDescription("sets execution mode; can be 'hadoop' / 'singlenode' / 'hybrid'[default] / 'HYBRID' / 'spark'")

src/main/java/org/apache/sysds/hops/codegen/SpoofCompiler.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,11 @@ public static ArrayList<Hop> optimize(ArrayList<Hop> roots, boolean recompile)
557557
LOG.info(CodegenUtils.printWithLineNumber(src_cuda));
558558
}
559559
}
560+
if(DMLScript.EXPLAIN.isCodegenType()) {
561+
System.out.print("JAVA Codegen EXPLAIN (generated code for HopID: " + cplan.getKey() +
562+
", line m" + tmp.getValue().getBeginLine() + ", hash=" + tmp.getValue().hashCode() + "):");
563+
System.out.println(CodegenUtils.printWithLineNumber(src));
564+
}
560565

561566
//maintain plan cache
562567
if( PLAN_CACHE_POLICY!=PlanCachePolicy.NONE )

src/main/java/org/apache/sysds/utils/Explain.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,18 @@ public enum ExplainType {
8686
HOPS, // explain program and hops
8787
RUNTIME, // explain runtime program (default)
8888
RECOMPILE_HOPS, // explain hops, incl recompile
89-
RECOMPILE_RUNTIME; // explain runtime program, incl recompile
89+
RECOMPILE_RUNTIME, // explain runtime program, incl recompile
90+
CODEGEN, // show generated code, incl runtime explanation
91+
CODEGEN_RECOMPILE; // show generated code, incl runtime explanation and recompilation
9092

9193
public boolean isHopsType(boolean recompile) {
9294
return (this==RECOMPILE_HOPS || (!recompile && this==HOPS));
9395
}
9496
public boolean isRuntimeType(boolean recompile) {
95-
return (this==RECOMPILE_RUNTIME || (!recompile && this==RUNTIME));
97+
return (this==RECOMPILE_RUNTIME || (!recompile && this==RUNTIME) || (this==CODEGEN_RECOMPILE) ||(!recompile && this==CODEGEN));
98+
}
99+
public boolean isCodegenType() {
100+
return (this == CODEGEN || this == CODEGEN_RECOMPILE);
96101
}
97102
}
98103

@@ -185,9 +190,11 @@ public static String explain(DMLProgram prog, Program rtprog, ExplainType type,
185190
case HOPS:
186191
case RECOMPILE_HOPS:
187192
return explain(prog);
188-
//explain runtime program
193+
//explain runtime program
189194
case RUNTIME:
190195
case RECOMPILE_RUNTIME:
196+
case CODEGEN:
197+
case CODEGEN_RECOMPILE:
191198
return explain(rtprog, counts);
192199
case NONE:
193200
//do nothing

src/test/java/org/apache/sysds/test/functions/codegen/SumProductChainTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,8 @@ private void testSumProductChain(String testname, boolean vectors, boolean spars
114114

115115
String HOME = SCRIPT_DIR + TEST_DIR;
116116
fullDMLScriptName = HOME + testname + ".dml";
117-
programArgs = new String[]{"hops", "-stats",
118-
"-args", input("X"), output("R") };
117+
programArgs = new String[]{"-explain", "codegen",
118+
"-stats", "-args", input("X"), output("R") };
119119

120120
fullRScriptName = HOME + testname + ".R";
121121
rCmd = getRCmd(inputDir(), expectedDir());

0 commit comments

Comments
 (0)