Search in sources :

Example 6 with Hop

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

the class HopRewriteUtils method isFullColumnIndexing.

public static boolean isFullColumnIndexing(LeftIndexingOp hop) {
    //single col
    boolean colPred = hop.getColLowerEqualsUpper();
    Hop rl = hop.getInput().get(2);
    Hop ru = hop.getInput().get(3);
    return colPred && rl instanceof LiteralOp && getDoubleValueSafe((LiteralOp) rl) == 1 && ru instanceof LiteralOp && getDoubleValueSafe((LiteralOp) ru) == hop.getDim1();
}
Also used : Hop(org.apache.sysml.hops.Hop) LiteralOp(org.apache.sysml.hops.LiteralOp)

Example 7 with Hop

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

the class HopRewriteUtils method isFullRowIndexing.

public static boolean isFullRowIndexing(LeftIndexingOp hop) {
    //single row
    boolean rowPred = hop.getRowLowerEqualsUpper();
    Hop cl = hop.getInput().get(4);
    Hop cu = hop.getInput().get(5);
    return rowPred && cl instanceof LiteralOp && getDoubleValueSafe((LiteralOp) cl) == 1 && cu instanceof LiteralOp && getDoubleValueSafe((LiteralOp) cu) == hop.getDim2();
}
Also used : Hop(org.apache.sysml.hops.Hop) LiteralOp(org.apache.sysml.hops.LiteralOp)

Example 8 with Hop

use of org.apache.sysml.hops.Hop 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 9 with Hop

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

the class Recompiler method recompileForPredicates.

private static void recompileForPredicates(ForProgramBlock fpb, ForStatementBlock fsb, LocalVariableMap vars, RecompileStatus status, long tid, boolean resetRecompile) throws DMLRuntimeException, HopsException, LopsException, IOException {
    if (fsb != null) {
        Hop fromHops = fsb.getFromHops();
        Hop toHops = fsb.getToHops();
        Hop incrHops = fsb.getIncrementHops();
        //handle recompilation flags
        if (ParForProgramBlock.RESET_RECOMPILATION_FLAGs && resetRecompile) {
            if (fromHops != null) {
                ArrayList<Instruction> tmp = recompileHopsDag(fromHops, vars, status, true, false, tid);
                fpb.setFromInstructions(tmp);
                Hop.resetRecompilationFlag(fromHops, ExecType.CP);
            }
            if (toHops != null) {
                ArrayList<Instruction> tmp = recompileHopsDag(toHops, vars, status, true, false, tid);
                fpb.setToInstructions(tmp);
                Hop.resetRecompilationFlag(toHops, ExecType.CP);
            }
            if (incrHops != null) {
                ArrayList<Instruction> tmp = recompileHopsDag(incrHops, vars, status, true, false, tid);
                fpb.setIncrementInstructions(tmp);
                Hop.resetRecompilationFlag(incrHops, ExecType.CP);
            }
            fsb.updatePredicateRecompilationFlags();
        } else //no reset of recompilation flags
        {
            if (fromHops != null) {
                ArrayList<Instruction> tmp = recompileHopsDag(fromHops, vars, status, true, false, tid);
                fpb.setFromInstructions(tmp);
            }
            if (toHops != null) {
                ArrayList<Instruction> tmp = recompileHopsDag(toHops, vars, status, true, false, tid);
                fpb.setToInstructions(tmp);
            }
            if (incrHops != null) {
                ArrayList<Instruction> tmp = recompileHopsDag(incrHops, vars, status, true, false, tid);
                fpb.setIncrementInstructions(tmp);
            }
        }
        //update predicate vars (potentially after constant folding, e.g., in parfor)
        String[] itervars = fpb.getIterablePredicateVars();
        if (fromHops != null && fromHops instanceof LiteralOp)
            itervars[1] = ((LiteralOp) fromHops).getName();
        if (toHops != null && toHops instanceof LiteralOp)
            itervars[2] = ((LiteralOp) toHops).getName();
        if (incrHops != null && incrHops instanceof LiteralOp)
            itervars[3] = ((LiteralOp) incrHops).getName();
    }
}
Also used : Hop(org.apache.sysml.hops.Hop) MRJobInstruction(org.apache.sysml.runtime.instructions.MRJobInstruction) Instruction(org.apache.sysml.runtime.instructions.Instruction) FunctionCallCPInstruction(org.apache.sysml.runtime.instructions.cp.FunctionCallCPInstruction) SeqInstruction(org.apache.sysml.runtime.instructions.mr.SeqInstruction) RandInstruction(org.apache.sysml.runtime.instructions.mr.RandInstruction) LiteralOp(org.apache.sysml.hops.LiteralOp)

Example 10 with Hop

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

the class OptimizerRuleBased method rIsInLoop.

/* 	
	 * This will check if candidate LeftIndexingOp are in loop (while, for or parfor).
	 * 
	 * @param pn:				OpNode of parfor loop
	 * @param uipCandHopHM:		Hashmap of UIPCandidateHop with name as a key.		
	 * @throws DMLRuntimeException
	 */
private void rIsInLoop(OptNode pn, HashMap<String, ArrayList<UIPCandidateHop>> uipCandHopHM, boolean bInLoop) throws DMLRuntimeException {
    if (!pn.isLeaf()) {
        ProgramBlock pb = (ProgramBlock) OptTreeConverter.getAbstractPlanMapping().getMappedProg(pn.getID())[1];
        VariableSet varUpdated = pb.getStatementBlock().variablesUpdated();
        boolean bUIPCandHopUpdated = false;
        for (Entry<String, ArrayList<UIPCandidateHop>> entry : uipCandHopHM.entrySet()) {
            String uipCandHopID = entry.getKey();
            if (varUpdated.containsVariable(uipCandHopID)) {
                bUIPCandHopUpdated = true;
                break;
            }
        }
        // As none of the UIP candidates updated in this DAG, no need for further processing within this DAG
        if (!bUIPCandHopUpdated)
            return;
        boolean bLoop = false;
        if (bInLoop || pb instanceof WhileProgramBlock || (pb instanceof ParForProgramBlock && ((ParForProgramBlock) pb).getDegreeOfParallelism() == 1) || (pb instanceof ForProgramBlock && !(pb instanceof ParForProgramBlock)))
            bLoop = true;
        for (OptNode optNode : pn.getChilds()) {
            rIsInLoop(optNode, uipCandHopHM, bLoop);
        }
    } else {
        Hop hop = (Hop) OptTreeConverter.getAbstractPlanMapping().getMappedHop(pn.getID());
        for (Entry<String, ArrayList<UIPCandidateHop>> entry : uipCandHopHM.entrySet()) {
            ArrayList<UIPCandidateHop> uipCandHopList = entry.getValue();
            if (uipCandHopList != null) {
                for (UIPCandidateHop uipCandHop : uipCandHopList) {
                    //Identify where intermediate object has been defined.
                    if (hop instanceof DataGenOp && hop.getName().equals(uipCandHop.getLixHop().getName())) {
                        uipCandHop.setHop(hop);
                        uipCandHop.setLocation(hop.getBeginLine());
                        uipCandHop.setIntermediate(true);
                    }
                    //Update if candiate hop defined outside this loop, and leftindexing is within this loop.
                    if ((bInLoop) && (uipCandHop.getLocation() <= hop.getBeginLine() && uipCandHop.getLixHop().getBeginLine() <= hop.getEndLine()))
                        uipCandHop.setIsLoopApplicable(true);
                }
            }
        }
    }
}
Also used : ForProgramBlock(org.apache.sysml.runtime.controlprogram.ForProgramBlock) ParForProgramBlock(org.apache.sysml.runtime.controlprogram.ParForProgramBlock) ArrayList(java.util.ArrayList) Hop(org.apache.sysml.hops.Hop) MultiThreadedHop(org.apache.sysml.hops.Hop.MultiThreadedHop) WhileProgramBlock(org.apache.sysml.runtime.controlprogram.WhileProgramBlock) ParForProgramBlock(org.apache.sysml.runtime.controlprogram.ParForProgramBlock) VariableSet(org.apache.sysml.parser.VariableSet) DataGenOp(org.apache.sysml.hops.DataGenOp) FunctionProgramBlock(org.apache.sysml.runtime.controlprogram.FunctionProgramBlock) WhileProgramBlock(org.apache.sysml.runtime.controlprogram.WhileProgramBlock) ForProgramBlock(org.apache.sysml.runtime.controlprogram.ForProgramBlock) IfProgramBlock(org.apache.sysml.runtime.controlprogram.IfProgramBlock) ProgramBlock(org.apache.sysml.runtime.controlprogram.ProgramBlock) ParForProgramBlock(org.apache.sysml.runtime.controlprogram.ParForProgramBlock)

Aggregations

Hop (org.apache.sysml.hops.Hop)307 LiteralOp (org.apache.sysml.hops.LiteralOp)94 AggBinaryOp (org.apache.sysml.hops.AggBinaryOp)65 BinaryOp (org.apache.sysml.hops.BinaryOp)63 ArrayList (java.util.ArrayList)61 AggUnaryOp (org.apache.sysml.hops.AggUnaryOp)61 HashMap (java.util.HashMap)44 DataOp (org.apache.sysml.hops.DataOp)41 UnaryOp (org.apache.sysml.hops.UnaryOp)41 HashSet (java.util.HashSet)39 ReorgOp (org.apache.sysml.hops.ReorgOp)32 MemoTableEntry (org.apache.sysml.hops.codegen.template.CPlanMemoTable.MemoTableEntry)28 StatementBlock (org.apache.sysml.parser.StatementBlock)28 IndexingOp (org.apache.sysml.hops.IndexingOp)24 ForStatementBlock (org.apache.sysml.parser.ForStatementBlock)23 WhileStatementBlock (org.apache.sysml.parser.WhileStatementBlock)23 IfStatementBlock (org.apache.sysml.parser.IfStatementBlock)22 DataGenOp (org.apache.sysml.hops.DataGenOp)21 DMLRuntimeException (org.apache.sysml.runtime.DMLRuntimeException)21 HopsException (org.apache.sysml.hops.HopsException)18