Search in sources :

Example 6 with ProgramRewriter

use of org.apache.sysml.hops.rewrite.ProgramRewriter in project incubator-systemml by apache.

the class DMLTranslator method rewriteHopsDAG.

public void rewriteHopsDAG(DMLProgram dmlp) throws ParseException, LanguageException, HopsException {
    //apply hop rewrites (static rewrites)
    ProgramRewriter rewriter = new ProgramRewriter(true, false);
    rewriter.rewriteProgramHopDAGs(dmlp);
    resetHopsDAGVisitStatus(dmlp);
    //propagate size information from main into functions (but conservatively)
    if (OptimizerUtils.ALLOW_INTER_PROCEDURAL_ANALYSIS) {
        InterProceduralAnalysis ipa = new InterProceduralAnalysis();
        ipa.analyzeProgram(dmlp);
        resetHopsDAGVisitStatus(dmlp);
        if (OptimizerUtils.ALLOW_IPA_SECOND_CHANCE) {
            // SECOND CHANCE:
            // Rerun static rewrites + IPA to allow for further improvements, such as making use
            // of constant folding (static rewrite) after scalar -> literal replacement (IPA),
            // and then further scalar -> literal replacement (IPA).
            rewriter.rewriteProgramHopDAGs(dmlp);
            resetHopsDAGVisitStatus(dmlp);
            ipa.analyzeProgram(dmlp);
            resetHopsDAGVisitStatus(dmlp);
        }
    }
    //apply hop rewrites (dynamic rewrites, after IPA)
    ProgramRewriter rewriter2 = new ProgramRewriter(false, true);
    rewriter2.rewriteProgramHopDAGs(dmlp);
    resetHopsDAGVisitStatus(dmlp);
    // Compute memory estimates for all the hops. These estimates are used
    // subsequently in various optimizations, e.g. CP vs. MR scheduling and parfor.
    refreshMemEstimates(dmlp);
    resetHopsDAGVisitStatus(dmlp);
}
Also used : ProgramRewriter(org.apache.sysml.hops.rewrite.ProgramRewriter) InterProceduralAnalysis(org.apache.sysml.hops.ipa.InterProceduralAnalysis)

Aggregations

ProgramRewriter (org.apache.sysml.hops.rewrite.ProgramRewriter)6 DMLRuntimeException (org.apache.sysml.runtime.DMLRuntimeException)3 IOException (java.io.IOException)2 HopsException (org.apache.sysml.hops.HopsException)2 InterProceduralAnalysis (org.apache.sysml.hops.ipa.InterProceduralAnalysis)2 ProgramRewriteStatus (org.apache.sysml.hops.rewrite.ProgramRewriteStatus)2 RewriteRemovePersistentReadWrite (org.apache.sysml.hops.rewrite.RewriteRemovePersistentReadWrite)2 LanguageException (org.apache.sysml.parser.LanguageException)2 LocalVariableMap (org.apache.sysml.runtime.controlprogram.LocalVariableMap)2 ArrayList (java.util.ArrayList)1 DMLException (org.apache.sysml.api.DMLException)1 HopRewriteRule (org.apache.sysml.hops.rewrite.HopRewriteRule)1 RewriteConstantFolding (org.apache.sysml.hops.rewrite.RewriteConstantFolding)1 RewriteInjectSparkLoopCheckpointing (org.apache.sysml.hops.rewrite.RewriteInjectSparkLoopCheckpointing)1 RewriteRemoveUnnecessaryBranches (org.apache.sysml.hops.rewrite.RewriteRemoveUnnecessaryBranches)1 StatementBlockRewriteRule (org.apache.sysml.hops.rewrite.StatementBlockRewriteRule)1 LopsException (org.apache.sysml.lops.LopsException)1 DMLProgram (org.apache.sysml.parser.DMLProgram)1 DMLTranslator (org.apache.sysml.parser.DMLTranslator)1 ForStatement (org.apache.sysml.parser.ForStatement)1