From a1a131ea9e11064af510568370589d5d3c571feb Mon Sep 17 00:00:00 2001 From: tomoki Date: Fri, 13 Dec 2024 08:36:40 +0100 Subject: [PATCH] implement new "-explain" command to print the generated code to the console --- src/main/java/org/apache/sysds/api/DMLOptions.java | 2 ++ .../org/apache/sysds/hops/codegen/SpoofCompiler.java | 6 ++++++ src/main/java/org/apache/sysds/utils/Explain.java | 11 ++++++++--- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/apache/sysds/api/DMLOptions.java b/src/main/java/org/apache/sysds/api/DMLOptions.java index 5bd5e019d00..20fb2888e74 100644 --- a/src/main/java/org/apache/sysds/api/DMLOptions.java +++ b/src/main/java/org/apache/sysds/api/DMLOptions.java @@ -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]"); } } diff --git a/src/main/java/org/apache/sysds/hops/codegen/SpoofCompiler.java b/src/main/java/org/apache/sysds/hops/codegen/SpoofCompiler.java index aca07fb413c..5bf599bd4e3 100644 --- a/src/main/java/org/apache/sysds/hops/codegen/SpoofCompiler.java +++ b/src/main/java/org/apache/sysds/hops/codegen/SpoofCompiler.java @@ -519,6 +519,12 @@ public static ArrayList optimize(ArrayList 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) { diff --git a/src/main/java/org/apache/sysds/utils/Explain.java b/src/main/java/org/apache/sysds/utils/Explain.java index 6cf1599ef0e..f69b82c51c3 100644 --- a/src/main/java/org/apache/sysds/utils/Explain.java +++ b/src/main/java/org/apache/sysds/utils/Explain.java @@ -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); } }