Search in sources :

Example 71 with WhileStatementBlock

use of org.apache.sysml.parser.WhileStatementBlock in project systemml by apache.

the class ProgramRewriter method rRewriteStatementBlockHopDAGs.

public void rRewriteStatementBlockHopDAGs(StatementBlock current, ProgramRewriteStatus state) {
    // ensure robustness for calls from outside
    if (state == null)
        state = new ProgramRewriteStatus();
    if (current instanceof FunctionStatementBlock) {
        FunctionStatementBlock fsb = (FunctionStatementBlock) current;
        FunctionStatement fstmt = (FunctionStatement) fsb.getStatement(0);
        for (StatementBlock sb : fstmt.getBody()) rRewriteStatementBlockHopDAGs(sb, state);
    } else if (current instanceof WhileStatementBlock) {
        WhileStatementBlock wsb = (WhileStatementBlock) current;
        WhileStatement wstmt = (WhileStatement) wsb.getStatement(0);
        wsb.setPredicateHops(rewriteHopDAG(wsb.getPredicateHops(), state));
        for (StatementBlock sb : wstmt.getBody()) rRewriteStatementBlockHopDAGs(sb, state);
    } else if (current instanceof IfStatementBlock) {
        IfStatementBlock isb = (IfStatementBlock) current;
        IfStatement istmt = (IfStatement) isb.getStatement(0);
        isb.setPredicateHops(rewriteHopDAG(isb.getPredicateHops(), state));
        for (StatementBlock sb : istmt.getIfBody()) rRewriteStatementBlockHopDAGs(sb, state);
        for (StatementBlock sb : istmt.getElseBody()) rRewriteStatementBlockHopDAGs(sb, state);
    } else if (// incl parfor
    current instanceof ForStatementBlock) {
        ForStatementBlock fsb = (ForStatementBlock) current;
        ForStatement fstmt = (ForStatement) fsb.getStatement(0);
        fsb.setFromHops(rewriteHopDAG(fsb.getFromHops(), state));
        fsb.setToHops(rewriteHopDAG(fsb.getToHops(), state));
        fsb.setIncrementHops(rewriteHopDAG(fsb.getIncrementHops(), state));
        for (StatementBlock sb : fstmt.getBody()) rRewriteStatementBlockHopDAGs(sb, state);
    } else // generic (last-level)
    {
        current.setHops(rewriteHopDAG(current.getHops(), state));
    }
}
Also used : ParForStatementBlock(org.apache.sysml.parser.ParForStatementBlock) ForStatementBlock(org.apache.sysml.parser.ForStatementBlock) FunctionStatement(org.apache.sysml.parser.FunctionStatement) IfStatement(org.apache.sysml.parser.IfStatement) FunctionStatementBlock(org.apache.sysml.parser.FunctionStatementBlock) WhileStatement(org.apache.sysml.parser.WhileStatement) ForStatement(org.apache.sysml.parser.ForStatement) FunctionStatementBlock(org.apache.sysml.parser.FunctionStatementBlock) ParForStatementBlock(org.apache.sysml.parser.ParForStatementBlock) IfStatementBlock(org.apache.sysml.parser.IfStatementBlock) WhileStatementBlock(org.apache.sysml.parser.WhileStatementBlock) ForStatementBlock(org.apache.sysml.parser.ForStatementBlock) StatementBlock(org.apache.sysml.parser.StatementBlock) WhileStatementBlock(org.apache.sysml.parser.WhileStatementBlock) IfStatementBlock(org.apache.sysml.parser.IfStatementBlock)

Example 72 with WhileStatementBlock

use of org.apache.sysml.parser.WhileStatementBlock in project systemml by apache.

the class RewriteMarkLoopVariablesUpdateInPlace method rewriteStatementBlock.

@Override
public List<StatementBlock> rewriteStatementBlock(StatementBlock sb, ProgramRewriteStatus status) {
    if (DMLScript.rtplatform == RUNTIME_PLATFORM.HADOOP || DMLScript.rtplatform == RUNTIME_PLATFORM.SPARK) {
        // nothing to do here, return original statement block
        return Arrays.asList(sb);
    }
    if (// incl parfor
    sb instanceof WhileStatementBlock || sb instanceof ForStatementBlock) {
        ArrayList<String> candidates = new ArrayList<>();
        VariableSet updated = sb.variablesUpdated();
        VariableSet liveout = sb.liveOut();
        for (String varname : updated.getVariableNames()) {
            if (updated.getVariable(varname).getDataType() == DataType.MATRIX && // exclude local vars
            liveout.containsVariable(varname)) {
                if (sb instanceof WhileStatementBlock) {
                    WhileStatement wstmt = (WhileStatement) sb.getStatement(0);
                    if (rIsApplicableForUpdateInPlace(wstmt.getBody(), varname))
                        candidates.add(varname);
                } else if (sb instanceof ForStatementBlock) {
                    ForStatement wstmt = (ForStatement) sb.getStatement(0);
                    if (rIsApplicableForUpdateInPlace(wstmt.getBody(), varname))
                        candidates.add(varname);
                }
            }
        }
        sb.setUpdateInPlaceVars(candidates);
    }
    // return modified statement block
    return Arrays.asList(sb);
}
Also used : ForStatementBlock(org.apache.sysml.parser.ForStatementBlock) VariableSet(org.apache.sysml.parser.VariableSet) ArrayList(java.util.ArrayList) WhileStatement(org.apache.sysml.parser.WhileStatement) ForStatement(org.apache.sysml.parser.ForStatement) WhileStatementBlock(org.apache.sysml.parser.WhileStatementBlock)

Aggregations

WhileStatementBlock (org.apache.sysml.parser.WhileStatementBlock)72 ForStatementBlock (org.apache.sysml.parser.ForStatementBlock)66 IfStatementBlock (org.apache.sysml.parser.IfStatementBlock)62 StatementBlock (org.apache.sysml.parser.StatementBlock)62 ForStatement (org.apache.sysml.parser.ForStatement)37 IfStatement (org.apache.sysml.parser.IfStatement)36 WhileStatement (org.apache.sysml.parser.WhileStatement)35 FunctionStatementBlock (org.apache.sysml.parser.FunctionStatementBlock)32 Hop (org.apache.sysml.hops.Hop)29 WhileProgramBlock (org.apache.sysml.runtime.controlprogram.WhileProgramBlock)26 ArrayList (java.util.ArrayList)25 ForProgramBlock (org.apache.sysml.runtime.controlprogram.ForProgramBlock)24 IfProgramBlock (org.apache.sysml.runtime.controlprogram.IfProgramBlock)24 FunctionStatement (org.apache.sysml.parser.FunctionStatement)23 FunctionProgramBlock (org.apache.sysml.runtime.controlprogram.FunctionProgramBlock)16 ProgramBlock (org.apache.sysml.runtime.controlprogram.ProgramBlock)14 ParForStatementBlock (org.apache.sysml.parser.ParForStatementBlock)12 LocalVariableMap (org.apache.sysml.runtime.controlprogram.LocalVariableMap)12 Instruction (org.apache.sysml.runtime.instructions.Instruction)10 ExternalFunctionStatement (org.apache.sysml.parser.ExternalFunctionStatement)9