Search in sources :

Example 66 with WhileStatementBlock

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

the class ProgramConverter method createDeepCopyWhileProgramBlock.

public static WhileProgramBlock createDeepCopyWhileProgramBlock(WhileProgramBlock wpb, long pid, int IDPrefix, Program prog, HashSet<String> fnStack, HashSet<String> fnCreated, boolean plain, boolean forceDeepCopy) {
    ArrayList<Instruction> predinst = createDeepCopyInstructionSet(wpb.getPredicate(), pid, IDPrefix, prog, fnStack, fnCreated, plain, true);
    WhileProgramBlock tmpPB = new WhileProgramBlock(prog, predinst);
    tmpPB.setStatementBlock(createWhileStatementBlockCopy((WhileStatementBlock) wpb.getStatementBlock(), pid, plain, forceDeepCopy));
    tmpPB.setThreadID(pid);
    tmpPB.setExitInstructions2(createDeepCopyInstructionSet(wpb.getExitInstructions(), pid, IDPrefix, prog, fnStack, fnCreated, plain, true));
    tmpPB.setChildBlocks(rcreateDeepCopyProgramBlocks(wpb.getChildBlocks(), pid, IDPrefix, fnStack, fnCreated, plain, forceDeepCopy));
    return tmpPB;
}
Also used : WhileProgramBlock(org.apache.sysml.runtime.controlprogram.WhileProgramBlock) GPUInstruction(org.apache.sysml.runtime.instructions.gpu.GPUInstruction) MRJobInstruction(org.apache.sysml.runtime.instructions.MRJobInstruction) CPInstruction(org.apache.sysml.runtime.instructions.cp.CPInstruction) ExternalFunctionInvocationInstruction(org.apache.sysml.udf.ExternalFunctionInvocationInstruction) SpoofCPInstruction(org.apache.sysml.runtime.instructions.cp.SpoofCPInstruction) Instruction(org.apache.sysml.runtime.instructions.Instruction) SPInstruction(org.apache.sysml.runtime.instructions.spark.SPInstruction) VariableCPInstruction(org.apache.sysml.runtime.instructions.cp.VariableCPInstruction) FunctionCallCPInstruction(org.apache.sysml.runtime.instructions.cp.FunctionCallCPInstruction) MRInstruction(org.apache.sysml.runtime.instructions.mr.MRInstruction) WhileStatementBlock(org.apache.sysml.parser.WhileStatementBlock)

Example 67 with WhileStatementBlock

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

the class SpoofCompiler method generateCodeFromStatementBlock.

public static void generateCodeFromStatementBlock(StatementBlock current) {
    if (current instanceof FunctionStatementBlock) {
        FunctionStatementBlock fsb = (FunctionStatementBlock) current;
        FunctionStatement fstmt = (FunctionStatement) fsb.getStatement(0);
        for (StatementBlock sb : fstmt.getBody()) generateCodeFromStatementBlock(sb);
    } else if (current instanceof WhileStatementBlock) {
        WhileStatementBlock wsb = (WhileStatementBlock) current;
        WhileStatement wstmt = (WhileStatement) wsb.getStatement(0);
        wsb.setPredicateHops(optimize(wsb.getPredicateHops(), false));
        for (StatementBlock sb : wstmt.getBody()) generateCodeFromStatementBlock(sb);
    } else if (current instanceof IfStatementBlock) {
        IfStatementBlock isb = (IfStatementBlock) current;
        IfStatement istmt = (IfStatement) isb.getStatement(0);
        isb.setPredicateHops(optimize(isb.getPredicateHops(), false));
        for (StatementBlock sb : istmt.getIfBody()) generateCodeFromStatementBlock(sb);
        for (StatementBlock sb : istmt.getElseBody()) generateCodeFromStatementBlock(sb);
    } else if (// incl parfor
    current instanceof ForStatementBlock) {
        ForStatementBlock fsb = (ForStatementBlock) current;
        ForStatement fstmt = (ForStatement) fsb.getStatement(0);
        fsb.setFromHops(optimize(fsb.getFromHops(), false));
        fsb.setToHops(optimize(fsb.getToHops(), false));
        fsb.setIncrementHops(optimize(fsb.getIncrementHops(), false));
        for (StatementBlock sb : fstmt.getBody()) generateCodeFromStatementBlock(sb);
    } else // generic (last-level)
    {
        current.setHops(generateCodeFromHopDAGs(current.getHops()));
        current.updateRecompilationFlag();
    }
}
Also used : 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) 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 68 with WhileStatementBlock

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

the class IPAPassFlagFunctionsRecompileOnce method rFlagFunctionForRecompileOnce.

/**
 * Returns true if this statementblock requires recompilation inside a
 * loop statement block.
 *
 * @param sb statement block
 * @param inLoop true if in loop
 * @return true if statement block requires recompilation inside a loop statement block
 */
public boolean rFlagFunctionForRecompileOnce(StatementBlock sb, boolean inLoop) {
    boolean ret = false;
    if (sb instanceof FunctionStatementBlock) {
        FunctionStatementBlock fsb = (FunctionStatementBlock) sb;
        FunctionStatement fstmt = (FunctionStatement) fsb.getStatement(0);
        for (StatementBlock c : fstmt.getBody()) ret |= rFlagFunctionForRecompileOnce(c, inLoop);
    } else if (sb instanceof WhileStatementBlock) {
        // recompilation information not available at this point
        // hence, mark any loop statement block
        ret = true;
    } else if (sb instanceof IfStatementBlock) {
        IfStatementBlock isb = (IfStatementBlock) sb;
        IfStatement istmt = (IfStatement) isb.getStatement(0);
        ret |= (inLoop && isb.requiresPredicateRecompilation());
        for (StatementBlock c : istmt.getIfBody()) ret |= rFlagFunctionForRecompileOnce(c, inLoop);
        for (StatementBlock c : istmt.getElseBody()) ret |= rFlagFunctionForRecompileOnce(c, inLoop);
    } else if (sb instanceof ForStatementBlock) {
        // recompilation information not available at this point
        // hence, mark any loop statement block
        ret = true;
    } else {
        ret |= (inLoop && sb.requiresRecompilation());
    }
    return ret;
}
Also used : ForStatementBlock(org.apache.sysml.parser.ForStatementBlock) FunctionStatement(org.apache.sysml.parser.FunctionStatement) IfStatement(org.apache.sysml.parser.IfStatement) FunctionStatementBlock(org.apache.sysml.parser.FunctionStatementBlock) StatementBlock(org.apache.sysml.parser.StatementBlock) FunctionStatementBlock(org.apache.sysml.parser.FunctionStatementBlock) IfStatementBlock(org.apache.sysml.parser.IfStatementBlock) WhileStatementBlock(org.apache.sysml.parser.WhileStatementBlock) ForStatementBlock(org.apache.sysml.parser.ForStatementBlock) WhileStatementBlock(org.apache.sysml.parser.WhileStatementBlock) IfStatementBlock(org.apache.sysml.parser.IfStatementBlock)

Example 69 with WhileStatementBlock

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

the class IPAPassRemoveUnnecessaryCheckpoints method moveCheckpointAfterUpdate.

private static void moveCheckpointAfterUpdate(DMLProgram dmlp) {
    // approach: scan over top-level program (guaranteed to be unconditional),
    // collect checkpoints; determine if used before update; move first checkpoint
    // after update if not used before update (best effort move which often avoids
    // the second checkpoint on loops even though used in between)
    HashMap<String, Hop> chkpointCand = new HashMap<>();
    for (StatementBlock sb : dmlp.getStatementBlocks()) {
        // prune candidates (used before updated)
        Set<String> cands = new HashSet<>(chkpointCand.keySet());
        for (String cand : cands) if (sb.variablesRead().containsVariable(cand) && !sb.variablesUpdated().containsVariable(cand)) {
            // note: variableRead might include false positives due to meta
            // data operations like nrow(X) or operations removed by rewrites
            // double check hops on basic blocks; otherwise worst-case
            boolean skipRemove = false;
            if (sb.getHops() != null) {
                Hop.resetVisitStatus(sb.getHops());
                skipRemove = true;
                for (Hop root : sb.getHops()) skipRemove &= !HopRewriteUtils.rContainsRead(root, cand, false);
            }
            if (!skipRemove)
                chkpointCand.remove(cand);
        }
        // prune candidates (updated in conditional control flow)
        Set<String> cands2 = new HashSet<>(chkpointCand.keySet());
        if (sb instanceof IfStatementBlock || sb instanceof WhileStatementBlock || sb instanceof ForStatementBlock) {
            for (String cand : cands2) if (sb.variablesUpdated().containsVariable(cand)) {
                chkpointCand.remove(cand);
            }
        } else // move checkpoint after update with simple read chain
        // (note: right now this only applies if the checkpoints comes from a previous
        // statement block, within-dag checkpoints should be handled during injection)
        {
            for (String cand : cands2) if (sb.variablesUpdated().containsVariable(cand) && sb.getHops() != null) {
                Hop.resetVisitStatus(sb.getHops());
                for (Hop root : sb.getHops()) if (root.getName().equals(cand)) {
                    if (HopRewriteUtils.rHasSimpleReadChain(root, cand)) {
                        chkpointCand.get(cand).setRequiresCheckpoint(false);
                        root.getInput().get(0).setRequiresCheckpoint(true);
                        chkpointCand.put(cand, root.getInput().get(0));
                    } else
                        chkpointCand.remove(cand);
                }
            }
        }
        // collect checkpoints
        if (HopRewriteUtils.isLastLevelStatementBlock(sb)) {
            ArrayList<Hop> tmp = collectCheckpoints(sb.getHops());
            for (Hop chkpoint : tmp) chkpointCand.put(chkpoint.getName(), chkpoint);
        }
    }
}
Also used : ForStatementBlock(org.apache.sysml.parser.ForStatementBlock) HashMap(java.util.HashMap) Hop(org.apache.sysml.hops.Hop) 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) HashSet(java.util.HashSet) IfStatementBlock(org.apache.sysml.parser.IfStatementBlock)

Example 70 with WhileStatementBlock

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

the class Recompiler method recompileProgramBlockInstructions.

/**
 * This method does NO full program block recompile (no stats update, no rewrites, no recursion) but
 * only regenerates lops and instructions. The primary use case is recompilation after are hop configuration
 * changes which allows to preserve statistics (e.g., propagated worst case stats from other program blocks)
 * and better performance for recompiling individual program blocks.
 *
 * @param pb program block
 * @throws IOException if IOException occurs
 */
public static void recompileProgramBlockInstructions(ProgramBlock pb) throws IOException {
    if (pb instanceof WhileProgramBlock) {
        // recompile while predicate instructions
        WhileProgramBlock wpb = (WhileProgramBlock) pb;
        WhileStatementBlock wsb = (WhileStatementBlock) pb.getStatementBlock();
        if (wsb != null && wsb.getPredicateHops() != null)
            wpb.setPredicate(recompileHopsDagInstructions(wsb.getPredicateHops()));
    } else if (pb instanceof IfProgramBlock) {
        // recompile if predicate instructions
        IfProgramBlock ipb = (IfProgramBlock) pb;
        IfStatementBlock isb = (IfStatementBlock) pb.getStatementBlock();
        if (isb != null && isb.getPredicateHops() != null)
            ipb.setPredicate(recompileHopsDagInstructions(isb.getPredicateHops()));
    } else if (pb instanceof ForProgramBlock) {
        // recompile for/parfor predicate instructions
        ForProgramBlock fpb = (ForProgramBlock) pb;
        ForStatementBlock fsb = (ForStatementBlock) pb.getStatementBlock();
        if (fsb != null && fsb.getFromHops() != null)
            fpb.setFromInstructions(recompileHopsDagInstructions(fsb.getFromHops()));
        if (fsb != null && fsb.getToHops() != null)
            fpb.setToInstructions(recompileHopsDagInstructions(fsb.getToHops()));
        if (fsb != null && fsb.getIncrementHops() != null)
            fpb.setIncrementInstructions(recompileHopsDagInstructions(fsb.getIncrementHops()));
    } else {
        // recompile last-level program block instructions
        StatementBlock sb = pb.getStatementBlock();
        if (sb != null && sb.getHops() != null) {
            pb.setInstructions(recompileHopsDagInstructions(sb, sb.getHops()));
        }
    }
}
Also used : IfProgramBlock(org.apache.sysml.runtime.controlprogram.IfProgramBlock) ForStatementBlock(org.apache.sysml.parser.ForStatementBlock) ForProgramBlock(org.apache.sysml.runtime.controlprogram.ForProgramBlock) ParForProgramBlock(org.apache.sysml.runtime.controlprogram.ParForProgramBlock) WhileProgramBlock(org.apache.sysml.runtime.controlprogram.WhileProgramBlock) WhileStatementBlock(org.apache.sysml.parser.WhileStatementBlock) IfStatementBlock(org.apache.sysml.parser.IfStatementBlock) WhileStatementBlock(org.apache.sysml.parser.WhileStatementBlock) ForStatementBlock(org.apache.sysml.parser.ForStatementBlock) StatementBlock(org.apache.sysml.parser.StatementBlock) IfStatementBlock(org.apache.sysml.parser.IfStatementBlock)

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