use of org.apache.sysml.runtime.controlprogram.ProgramBlock in project incubator-systemml by apache.
the class ResourceOptimizer method initGlobalMemoTable.
private static double[][] initGlobalMemoTable(ArrayList<ProgramBlock> B, ArrayList<ProgramBlock> Bp, double[][] lmemo, double min) {
// allocate memo structure
int len = B.size();
// lenp<=len
int lenp = Bp.size();
double[][] memo = new double[len][2];
// init with min resources
for (int i = 0; i < len; i++) {
memo[i][0] = min;
memo[i][1] = -1;
}
// overwrite existing values
int j = 0;
for (int i = 0; i < len && j < lenp; i++) {
ProgramBlock pb = B.get(i);
if (pb != Bp.get(j))
continue;
// map local memo entry
memo[i][0] = lmemo[j][0];
memo[i][1] = -1;
j++;
}
return memo;
}
use of org.apache.sysml.runtime.controlprogram.ProgramBlock in project incubator-systemml by apache.
the class OptimizerRuleBased method rewriteNestedParallelism.
///////
//REWRITE enable nested parallelism
///
@SuppressWarnings("all")
protected boolean rewriteNestedParallelism(OptNode n, double M, boolean flagLIX) throws DMLRuntimeException {
boolean nested = false;
if (APPLY_REWRITE_NESTED_PARALLELISM && // if not applied left indexing rewrite
!flagLIX && // at least exploit all nodes
_N >= _rnk && // only for 1D problems, otherwise potentially bad load balance
!n.hasNestedParallelism(false) && // only if we can exploit full local parallelism in the map task JVM memory
M * _lkmaxCP <= _rm) {
//modify tree
ArrayList<OptNode> tmpOld = n.getChilds();
OptNode nest = new OptNode(NodeType.PARFOR, ExecType.CP);
ArrayList<OptNode> tmpNew = new ArrayList<OptNode>();
tmpNew.add(nest);
n.setChilds(tmpNew);
nest.setChilds(tmpOld);
//modify rtprog
long id = n.getID();
ParForProgramBlock pfpb = (ParForProgramBlock) OptTreeConverter.getAbstractPlanMapping().getMappedProg(id)[1];
ArrayList<ProgramBlock> tmpPBOld = pfpb.getChildBlocks();
//create new program block structure and modify parameters (from, to, incr, types,)
//from, to stay original
String[] iterVars = pfpb.getIterablePredicateVars();
//itervar, incr stay original
String[] iterVars2 = iterVars.clone();
int outIncr = (int) Math.ceil(((double) _N) / _rnk);
// already checked for uniqueness in ParForStatementBlock
iterVars[0] = ParForStatementBlock.INTERAL_FN_INDEX_ROW;
iterVars[3] = String.valueOf(outIncr);
//sub start
iterVars2[1] = ParForStatementBlock.INTERAL_FN_INDEX_ROW;
iterVars2[2] = null;
HashMap<String, String> params = pfpb.getParForParams();
HashMap<String, String> params2 = (HashMap<String, String>) params.clone();
ParForProgramBlock pfpb2 = new ParForProgramBlock(pfpb.getProgram(), iterVars2, params2);
OptTreeConverter.getAbstractPlanMapping().putProgMapping(null, pfpb2, nest);
ArrayList<ProgramBlock> tmpPBNew = new ArrayList<ProgramBlock>();
tmpPBNew.add(pfpb2);
pfpb.setChildBlocks(tmpPBNew);
pfpb.setIterablePredicateVars(iterVars);
pfpb.setIncrementInstructions(new ArrayList<Instruction>());
pfpb.setExecMode(PExecMode.REMOTE_MR);
pfpb2.setChildBlocks(tmpPBOld);
pfpb2.setResultVariables(pfpb.getResultVariables());
pfpb2.setFromInstructions(new ArrayList<Instruction>());
pfpb2.setToInstructions(ProgramRecompiler.createNestedParallelismToInstructionSet(ParForStatementBlock.INTERAL_FN_INDEX_ROW, String.valueOf(outIncr - 1)));
pfpb2.setIncrementInstructions(new ArrayList<Instruction>());
pfpb2.setExecMode(PExecMode.LOCAL);
nested = true;
}
_numEvaluatedPlans++;
LOG.debug(getOptMode() + " OPT: rewrite 'enable nested parallelism' - result=" + nested);
return nested;
}
use of org.apache.sysml.runtime.controlprogram.ProgramBlock in project incubator-systemml by apache.
the class OptimizerRuleBased method rValidateUIPConsumerList.
/*
* This will validate candidate's consumer list.
*
* @param pn: OpNode of parfor loop
* @param uipCandHopHM: Hashmap of UIPCandidateHop with name as a key.
* @throws DMLRuntimeException
*/
private void rValidateUIPConsumerList(OptNode pn, HashMap<String, ArrayList<UIPCandidateHop>> uipCandHopHM) throws DMLRuntimeException {
if (!pn.isLeaf()) {
if (pn.getNodeType() == OptNode.NodeType.FUNCCALL) {
Hop hop = (Hop) OptTreeConverter.getAbstractPlanMapping().getMappedHop(pn.getID());
rValidateUIPConsumerList(hop.getInput(), uipCandHopHM);
return;
}
ProgramBlock pb = (ProgramBlock) OptTreeConverter.getAbstractPlanMapping().getMappedProg(pn.getID())[1];
VariableSet varRead = pb.getStatementBlock().variablesRead();
boolean bUIPCandHopRead = false;
for (Entry<String, ArrayList<UIPCandidateHop>> entry : uipCandHopHM.entrySet()) {
ArrayList<UIPCandidateHop> uipCandHopList = entry.getValue();
if (uipCandHopList != null) {
for (UIPCandidateHop uipCandHop : uipCandHopList) {
ArrayList<Hop> consumerHops = uipCandHop.getConsumerHops();
if (consumerHops != null) {
// remove candidate from the list.
for (Hop consumerHop : consumerHops) {
if (varRead.containsVariable(consumerHop.getName())) {
bUIPCandHopRead = true;
break;
}
}
}
}
}
}
// As none of the UIP candidates updated in this DAG, no need for further processing within this DAG
if (!bUIPCandHopRead)
return;
for (OptNode optNode : pn.getChilds()) rValidateUIPConsumerList(optNode, uipCandHopHM);
} else {
OptTreePlanMappingAbstract map = OptTreeConverter.getAbstractPlanMapping();
long ppid = map.getMappedParentID(map.getMappedParentID(pn.getID()));
Object[] o = map.getMappedProg(ppid);
ProgramBlock pb = (ProgramBlock) o[1];
if (pb instanceof IfProgramBlock || pb instanceof WhileProgramBlock || //TODO
(pb instanceof ForProgramBlock && !(pb instanceof ParForProgramBlock)))
rValidateUIPConsumerList(pb, uipCandHopHM);
long pid = map.getMappedParentID(pn.getID());
o = map.getMappedProg(pid);
pb = (ProgramBlock) o[1];
Hop hop = map.getMappedHop(pn.getID());
rValidateUIPConsumerList(hop, uipCandHopHM, pb.getStatementBlock().variablesRead());
}
}
use of org.apache.sysml.runtime.controlprogram.ProgramBlock in project incubator-systemml by apache.
the class OptimizerRuleBased method rGetUIPConsumerList.
/*
* This will get consumer list for candidate LeftIndexingOp.
*
* @param pn: OpNode of parfor loop
* @param uipCandHopHM: Hashmap of UIPCandidateHop with name as a key.
* @throws DMLRuntimeException
*/
private void rGetUIPConsumerList(OptNode pn, HashMap<String, ArrayList<UIPCandidateHop>> uipCandHopHM) throws DMLRuntimeException {
if (!pn.isLeaf()) {
if (pn.getNodeType() == OptNode.NodeType.FUNCCALL)
return;
ProgramBlock pb = (ProgramBlock) OptTreeConverter.getAbstractPlanMapping().getMappedProg(pn.getID())[1];
VariableSet varRead = pb.getStatementBlock().variablesRead();
boolean bUIPCandHopRead = false;
for (Entry<String, ArrayList<UIPCandidateHop>> entry : uipCandHopHM.entrySet()) {
String uipCandHopID = entry.getKey();
if (varRead.containsVariable(uipCandHopID)) {
bUIPCandHopRead = true;
break;
}
}
// As none of the UIP candidates updated in this DAG, no need for further processing within this DAG
if (!bUIPCandHopRead)
return;
for (OptNode optNode : pn.getChilds()) rGetUIPConsumerList(optNode, uipCandHopHM);
} else {
OptTreePlanMappingAbstract map = OptTreeConverter.getAbstractPlanMapping();
long ppid = map.getMappedParentID(map.getMappedParentID(pn.getID()));
Object[] o = map.getMappedProg(ppid);
ProgramBlock pb = (ProgramBlock) o[1];
Hop hop = (Hop) OptTreeConverter.getAbstractPlanMapping().getMappedHop(pn.getID());
rGetUIPConsumerList(hop, uipCandHopHM);
if (pb instanceof IfProgramBlock || pb instanceof WhileProgramBlock || //TODO
(pb instanceof ForProgramBlock && !(pb instanceof ParForProgramBlock)))
rGetUIPConsumerList(pb, uipCandHopHM);
}
}
use of org.apache.sysml.runtime.controlprogram.ProgramBlock in project incubator-systemml by apache.
the class OptimizerRuleBased method rResetVisitStatus.
private void rResetVisitStatus(OptNode pn) throws DMLRuntimeException {
if (!pn.isLeaf()) {
if (pn.getNodeType() == OptNode.NodeType.FUNCCALL) {
Hop hopFunc = (Hop) OptTreeConverter.getAbstractPlanMapping().getMappedHop(pn.getID());
hopFunc.resetVisitStatus();
return;
}
ProgramBlock pb = (ProgramBlock) OptTreeConverter.getAbstractPlanMapping().getMappedProg(pn.getID())[1];
ArrayList<ProgramBlock> childBlocks = null;
ArrayList<ProgramBlock> elseBlocks = null;
if (pb instanceof WhileProgramBlock)
childBlocks = ((WhileProgramBlock) pb).getChildBlocks();
else if (pb instanceof ForProgramBlock)
childBlocks = ((ForProgramBlock) pb).getChildBlocks();
else if (pb instanceof IfProgramBlock) {
childBlocks = ((IfProgramBlock) pb).getChildBlocksIfBody();
elseBlocks = ((IfProgramBlock) pb).getChildBlocksElseBody();
}
if (childBlocks != null) {
for (ProgramBlock childBlock : childBlocks) {
try {
Hop.resetVisitStatus(childBlock.getStatementBlock().get_hops());
} catch (Exception e) {
throw new DMLRuntimeException(e);
}
}
}
if (elseBlocks != null) {
for (ProgramBlock childBlock : elseBlocks) {
try {
Hop.resetVisitStatus(childBlock.getStatementBlock().get_hops());
} catch (Exception e) {
throw new DMLRuntimeException(e);
}
}
}
for (OptNode optNode : pn.getChilds()) {
rResetVisitStatus(optNode);
}
} else {
Hop hop = (Hop) OptTreeConverter.getAbstractPlanMapping().getMappedHop(pn.getID());
if (hop != null) {
hop.resetVisitStatus();
}
}
}
Aggregations