Search in sources :

Example 16 with ForStatementBlock

use of org.apache.sysml.parser.ForStatementBlock in project incubator-systemml by apache.

the class InterProceduralAnalysis method rRemoveConstantBinaryOp.

private void rRemoveConstantBinaryOp(StatementBlock sb, HashMap<String, Hop> mOnes) throws HopsException {
    if (sb instanceof IfStatementBlock) {
        IfStatementBlock isb = (IfStatementBlock) sb;
        IfStatement istmt = (IfStatement) isb.getStatement(0);
        for (StatementBlock c : istmt.getIfBody()) rRemoveConstantBinaryOp(c, mOnes);
        if (istmt.getElseBody() != null)
            for (StatementBlock c : istmt.getElseBody()) rRemoveConstantBinaryOp(c, mOnes);
    } else if (sb instanceof WhileStatementBlock) {
        WhileStatementBlock wsb = (WhileStatementBlock) sb;
        WhileStatement wstmt = (WhileStatement) wsb.getStatement(0);
        for (StatementBlock c : wstmt.getBody()) rRemoveConstantBinaryOp(c, mOnes);
    } else if (sb instanceof ForStatementBlock) {
        ForStatementBlock fsb = (ForStatementBlock) sb;
        ForStatement fstmt = (ForStatement) fsb.getStatement(0);
        for (StatementBlock c : fstmt.getBody()) rRemoveConstantBinaryOp(c, mOnes);
    } else {
        if (sb.get_hops() != null) {
            Hop.resetVisitStatus(sb.get_hops());
            for (Hop hop : sb.get_hops()) rRemoveConstantBinaryOp(hop, mOnes);
        }
    }
}
Also used : ForStatementBlock(org.apache.sysml.parser.ForStatementBlock) IfStatement(org.apache.sysml.parser.IfStatement) Hop(org.apache.sysml.hops.Hop) 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 17 with ForStatementBlock

use of org.apache.sysml.parser.ForStatementBlock in project incubator-systemml by apache.

the class ProgramConverter method createForStatementBlockCopy.

public static ForStatementBlock createForStatementBlockCopy(ForStatementBlock sb, long pid, boolean plain, boolean forceDeepCopy) throws DMLRuntimeException {
    ForStatementBlock ret = null;
    try {
        if (ConfigurationManager.getCompilerConfigFlag(ConfigType.ALLOW_PARALLEL_DYN_RECOMPILATION) && sb != null && (Recompiler.requiresRecompilation(sb.getFromHops()) || Recompiler.requiresRecompilation(sb.getToHops()) || Recompiler.requiresRecompilation(sb.getIncrementHops()) || forceDeepCopy)) {
            ret = (sb instanceof ParForStatementBlock) ? new ParForStatementBlock() : new ForStatementBlock();
            //create new statement (shallow copy livein/liveout for recompile, line numbers for explain)
            ret.setDMLProg(sb.getDMLProg());
            ret.setAllPositions(sb.getFilename(), sb.getBeginLine(), sb.getBeginColumn(), sb.getEndLine(), sb.getEndColumn());
            ret.setLiveIn(sb.liveIn());
            ret.setLiveOut(sb.liveOut());
            ret.setUpdatedVariables(sb.variablesUpdated());
            ret.setReadVariables(sb.variablesRead());
            ret.setUpdateInPlaceVars(sb.getUpdateInPlaceVars());
            //shallow copy child statements
            ret.setStatements(sb.getStatements());
            //deep copy predicate hops dag for concurrent recompile
            if (sb.requiresFromRecompilation()) {
                Hop hops = Recompiler.deepCopyHopsDag(sb.getFromHops());
                ret.setFromHops(hops);
            }
            if (sb.requiresToRecompilation()) {
                Hop hops = Recompiler.deepCopyHopsDag(sb.getToHops());
                ret.setToHops(hops);
            }
            if (sb.requiresIncrementRecompilation()) {
                Hop hops = Recompiler.deepCopyHopsDag(sb.getIncrementHops());
                ret.setIncrementHops(hops);
            }
            ret.updatePredicateRecompilationFlags();
        } else {
            ret = sb;
        }
    } catch (Exception ex) {
        throw new DMLRuntimeException(ex);
    }
    return ret;
}
Also used : ParForStatementBlock(org.apache.sysml.parser.ParForStatementBlock) ForStatementBlock(org.apache.sysml.parser.ForStatementBlock) Hop(org.apache.sysml.hops.Hop) ParForStatementBlock(org.apache.sysml.parser.ParForStatementBlock) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException)

Example 18 with ForStatementBlock

use of org.apache.sysml.parser.ForStatementBlock in project incubator-systemml by apache.

the class ProgramConverter method createDeepCopyForProgramBlock.

public static ForProgramBlock createDeepCopyForProgramBlock(ForProgramBlock fpb, long pid, int IDPrefix, Program prog, HashSet<String> fnStack, HashSet<String> fnCreated, boolean plain, boolean forceDeepCopy) throws DMLRuntimeException {
    ForProgramBlock tmpPB = new ForProgramBlock(prog, fpb.getIterablePredicateVars());
    tmpPB.setStatementBlock(createForStatementBlockCopy((ForStatementBlock) fpb.getStatementBlock(), pid, plain, forceDeepCopy));
    tmpPB.setThreadID(pid);
    tmpPB.setFromInstructions(createDeepCopyInstructionSet(fpb.getFromInstructions(), pid, IDPrefix, prog, fnStack, fnCreated, plain, true));
    tmpPB.setToInstructions(createDeepCopyInstructionSet(fpb.getToInstructions(), pid, IDPrefix, prog, fnStack, fnCreated, plain, true));
    tmpPB.setIncrementInstructions(createDeepCopyInstructionSet(fpb.getIncrementInstructions(), pid, IDPrefix, prog, fnStack, fnCreated, plain, true));
    tmpPB.setExitInstructions(createDeepCopyInstructionSet(fpb.getExitInstructions(), pid, IDPrefix, prog, fnStack, fnCreated, plain, true));
    tmpPB.setChildBlocks(rcreateDeepCopyProgramBlocks(fpb.getChildBlocks(), pid, IDPrefix, fnStack, fnCreated, plain, forceDeepCopy));
    return tmpPB;
}
Also used : ParForStatementBlock(org.apache.sysml.parser.ParForStatementBlock) ForStatementBlock(org.apache.sysml.parser.ForStatementBlock) ForProgramBlock(org.apache.sysml.runtime.controlprogram.ForProgramBlock) ParForProgramBlock(org.apache.sysml.runtime.controlprogram.ParForProgramBlock)

Example 19 with ForStatementBlock

use of org.apache.sysml.parser.ForStatementBlock in project incubator-systemml by apache.

the class ProgramRecompiler method replaceConstantScalarVariables.

public static void replaceConstantScalarVariables(StatementBlock sb, LocalVariableMap vars) throws DMLRuntimeException, HopsException {
    if (sb instanceof IfStatementBlock) {
        IfStatementBlock isb = (IfStatementBlock) sb;
        IfStatement is = (IfStatement) sb.getStatement(0);
        replacePredicateLiterals(isb.getPredicateHops(), vars);
        for (StatementBlock lsb : is.getIfBody()) replaceConstantScalarVariables(lsb, vars);
        for (StatementBlock lsb : is.getElseBody()) replaceConstantScalarVariables(lsb, vars);
    } else if (sb instanceof WhileStatementBlock) {
        WhileStatementBlock wsb = (WhileStatementBlock) sb;
        WhileStatement ws = (WhileStatement) sb.getStatement(0);
        replacePredicateLiterals(wsb.getPredicateHops(), vars);
        for (StatementBlock lsb : ws.getBody()) replaceConstantScalarVariables(lsb, vars);
    } else if (//for or parfor
    sb instanceof ForStatementBlock) {
        ForStatementBlock fsb = (ForStatementBlock) sb;
        ForStatement fs = (ForStatement) fsb.getStatement(0);
        replacePredicateLiterals(fsb.getFromHops(), vars);
        replacePredicateLiterals(fsb.getToHops(), vars);
        replacePredicateLiterals(fsb.getIncrementHops(), vars);
        for (StatementBlock lsb : fs.getBody()) replaceConstantScalarVariables(lsb, vars);
    } else //last level block
    {
        ArrayList<Hop> hops = sb.get_hops();
        if (hops != null) {
            //replace constant literals
            Hop.resetVisitStatus(hops);
            for (Hop hopRoot : hops) Recompiler.rReplaceLiterals(hopRoot, vars, true);
        }
    }
}
Also used : ForStatementBlock(org.apache.sysml.parser.ForStatementBlock) IfStatement(org.apache.sysml.parser.IfStatement) Hop(org.apache.sysml.hops.Hop) WhileStatement(org.apache.sysml.parser.WhileStatement) ForStatement(org.apache.sysml.parser.ForStatement) 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 20 with ForStatementBlock

use of org.apache.sysml.parser.ForStatementBlock in project incubator-systemml by apache.

the class ResourceOptimizer method compileProgram.

private static ArrayList<ProgramBlock> compileProgram(ProgramBlock pb, ArrayList<ProgramBlock> B, double cp, double mr) throws DMLRuntimeException, HopsException, LopsException, IOException {
    if (pb instanceof FunctionProgramBlock) {
        FunctionProgramBlock fpb = (FunctionProgramBlock) pb;
        compileProgram(fpb.getChildBlocks(), B, cp, mr);
    } else if (pb instanceof WhileProgramBlock) {
        WhileProgramBlock wpb = (WhileProgramBlock) pb;
        WhileStatementBlock sb = (WhileStatementBlock) pb.getStatementBlock();
        if (INCLUDE_PREDICATES && sb != null && sb.getPredicateHops() != null) {
            ArrayList<Instruction> inst = Recompiler.recompileHopsDag(sb.getPredicateHops(), new LocalVariableMap(), null, false, false, 0);
            wpb.setPredicate(inst);
            B.add(wpb);
            _cntCompilePB++;
        }
        compileProgram(wpb.getChildBlocks(), B, cp, mr);
    } else if (pb instanceof IfProgramBlock) {
        IfProgramBlock ipb = (IfProgramBlock) pb;
        IfStatementBlock sb = (IfStatementBlock) ipb.getStatementBlock();
        if (INCLUDE_PREDICATES && sb != null && sb.getPredicateHops() != null) {
            ArrayList<Instruction> inst = Recompiler.recompileHopsDag(sb.getPredicateHops(), new LocalVariableMap(), null, false, false, 0);
            ipb.setPredicate(inst);
            B.add(ipb);
            _cntCompilePB++;
        }
        compileProgram(ipb.getChildBlocksIfBody(), B, cp, mr);
        compileProgram(ipb.getChildBlocksElseBody(), B, cp, mr);
    } else if (//incl parfor
    pb instanceof ForProgramBlock) {
        ForProgramBlock fpb = (ForProgramBlock) pb;
        ForStatementBlock sb = (ForStatementBlock) fpb.getStatementBlock();
        if (INCLUDE_PREDICATES && sb != null) {
            if (sb.getFromHops() != null) {
                ArrayList<Instruction> inst = Recompiler.recompileHopsDag(sb.getFromHops(), new LocalVariableMap(), null, false, false, 0);
                fpb.setFromInstructions(inst);
            }
            if (sb.getToHops() != null) {
                ArrayList<Instruction> inst = Recompiler.recompileHopsDag(sb.getToHops(), new LocalVariableMap(), null, false, false, 0);
                fpb.setToInstructions(inst);
            }
            if (sb.getIncrementHops() != null) {
                ArrayList<Instruction> inst = Recompiler.recompileHopsDag(sb.getIncrementHops(), new LocalVariableMap(), null, false, false, 0);
                fpb.setIncrementInstructions(inst);
            }
            B.add(fpb);
            _cntCompilePB++;
        }
        compileProgram(fpb.getChildBlocks(), B, cp, mr);
    } else {
        StatementBlock sb = pb.getStatementBlock();
        ArrayList<Instruction> inst = Recompiler.recompileHopsDag(sb, sb.get_hops(), new LocalVariableMap(), null, false, false, 0);
        pb.setInstructions(inst);
        B.add(pb);
        _cntCompilePB++;
    }
    return B;
}
Also used : FunctionProgramBlock(org.apache.sysml.runtime.controlprogram.FunctionProgramBlock) IfProgramBlock(org.apache.sysml.runtime.controlprogram.IfProgramBlock) ForStatementBlock(org.apache.sysml.parser.ForStatementBlock) LocalVariableMap(org.apache.sysml.runtime.controlprogram.LocalVariableMap) ForProgramBlock(org.apache.sysml.runtime.controlprogram.ForProgramBlock) ArrayList(java.util.ArrayList) WhileProgramBlock(org.apache.sysml.runtime.controlprogram.WhileProgramBlock) MRJobInstruction(org.apache.sysml.runtime.instructions.MRJobInstruction) Instruction(org.apache.sysml.runtime.instructions.Instruction) 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

ForStatementBlock (org.apache.sysml.parser.ForStatementBlock)31 WhileStatementBlock (org.apache.sysml.parser.WhileStatementBlock)27 IfStatementBlock (org.apache.sysml.parser.IfStatementBlock)26 StatementBlock (org.apache.sysml.parser.StatementBlock)26 ForStatement (org.apache.sysml.parser.ForStatement)14 FunctionStatementBlock (org.apache.sysml.parser.FunctionStatementBlock)13 IfStatement (org.apache.sysml.parser.IfStatement)13 WhileStatement (org.apache.sysml.parser.WhileStatement)13 ForProgramBlock (org.apache.sysml.runtime.controlprogram.ForProgramBlock)13 ArrayList (java.util.ArrayList)12 Hop (org.apache.sysml.hops.Hop)12 IfProgramBlock (org.apache.sysml.runtime.controlprogram.IfProgramBlock)12 WhileProgramBlock (org.apache.sysml.runtime.controlprogram.WhileProgramBlock)12 FunctionStatement (org.apache.sysml.parser.FunctionStatement)8 FunctionProgramBlock (org.apache.sysml.runtime.controlprogram.FunctionProgramBlock)8 ParForStatementBlock (org.apache.sysml.parser.ParForStatementBlock)7 ProgramBlock (org.apache.sysml.runtime.controlprogram.ProgramBlock)7 ParForProgramBlock (org.apache.sysml.runtime.controlprogram.ParForProgramBlock)6 LocalVariableMap (org.apache.sysml.runtime.controlprogram.LocalVariableMap)5 ExternalFunctionStatement (org.apache.sysml.parser.ExternalFunctionStatement)4