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();
}
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();
}
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);
}
}
}
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();
}
}
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);
}
}
}
}
}
Aggregations