use of org.apache.sysml.runtime.controlprogram.ProgramBlock in project incubator-systemml by apache.
the class ProgramConverter method rParseForProgramBlock.
private static ForProgramBlock rParseForProgramBlock(String in, Program prog, int id) {
String lin = in.substring(PARFOR_PB_FOR.length(), in.length() - PARFOR_PB_END.length());
HierarchyAwareStringTokenizer st = new HierarchyAwareStringTokenizer(lin, COMPONENTS_DELIM);
// inputs
String iterVar = st.nextToken();
// instructions
ArrayList<Instruction> from = parseInstructions(st.nextToken(), id);
ArrayList<Instruction> to = parseInstructions(st.nextToken(), id);
ArrayList<Instruction> incr = parseInstructions(st.nextToken(), id);
// exit instructions
ArrayList<Instruction> exit = parseInstructions(st.nextToken(), id);
// program blocks
ArrayList<ProgramBlock> pbs = rParseProgramBlocks(st.nextToken(), prog, id);
ForProgramBlock fpb = new ForProgramBlock(prog, iterVar);
fpb.setFromInstructions(from);
fpb.setToInstructions(to);
fpb.setIncrementInstructions(incr);
fpb.setExitInstructions(exit);
fpb.setChildBlocks(pbs);
return fpb;
}
use of org.apache.sysml.runtime.controlprogram.ProgramBlock in project incubator-systemml by apache.
the class ProgramConverter method rParseWhileProgramBlock.
private static WhileProgramBlock rParseWhileProgramBlock(String in, Program prog, int id) {
String lin = in.substring(PARFOR_PB_WHILE.length(), in.length() - PARFOR_PB_END.length());
HierarchyAwareStringTokenizer st = new HierarchyAwareStringTokenizer(lin, COMPONENTS_DELIM);
// predicate instructions
ArrayList<Instruction> inst = parseInstructions(st.nextToken(), id);
// exit instructions
ArrayList<Instruction> exit = parseInstructions(st.nextToken(), id);
// program blocks
ArrayList<ProgramBlock> pbs = rParseProgramBlocks(st.nextToken(), prog, id);
WhileProgramBlock wpb = new WhileProgramBlock(prog, inst);
wpb.setExitInstructions2(exit);
wpb.setChildBlocks(pbs);
return wpb;
}
use of org.apache.sysml.runtime.controlprogram.ProgramBlock in project incubator-systemml by apache.
the class ProgramConverter method rParseExternalFunctionProgramBlock.
private static ExternalFunctionProgramBlock rParseExternalFunctionProgramBlock(String in, Program prog, int id) {
String lin = in.substring(PARFOR_PB_EFC.length(), in.length() - PARFOR_PB_END.length());
HierarchyAwareStringTokenizer st = new HierarchyAwareStringTokenizer(lin, COMPONENTS_DELIM);
// LocalVariableMap vars = parseVariables(st.nextToken());
// inputs, outputs and params
ArrayList<DataIdentifier> dat1 = parseDataIdentifiers(st.nextToken());
ArrayList<DataIdentifier> dat2 = parseDataIdentifiers(st.nextToken());
HashMap<String, String> dat3 = parseStringHashMap(st.nextToken());
// basedir
String basedir = st.nextToken();
// instructions (required for removing INST BEGIN, END)
parseInstructions(st.nextToken(), id);
// program blocks
ArrayList<ProgramBlock> pbs = rParseProgramBlocks(st.nextToken(), prog, id);
ArrayList<DataIdentifier> tmp1 = new ArrayList<>(dat1);
ArrayList<DataIdentifier> tmp2 = new ArrayList<>(dat2);
// only CP external functions, because no nested MR jobs for reblocks
ExternalFunctionProgramBlockCP efpb = new ExternalFunctionProgramBlockCP(prog, tmp1, tmp2, dat3, basedir);
efpb.setChildBlocks(pbs);
return efpb;
}
use of org.apache.sysml.runtime.controlprogram.ProgramBlock in project incubator-systemml by apache.
the class CostEstimatorRuntime method getLeafNodeEstimate.
@Override
public double getLeafNodeEstimate(TestMeasure measure, OptNode node, ExecType et) {
// use CostEstimatorHops to get the memory estimate
if (measure == TestMeasure.MEMORY_USAGE)
return _costMem.getLeafNodeEstimate(measure, node, et);
// use static cost estimator based on floating point operations
// (currently only called for entire parfor program in order to
// decide for LOCAL vs REMOTE parfor execution)
double ret = DEFAULT_TIME_ESTIMATE;
boolean isCP = (et == ExecType.CP || et == null);
if (!node.isLeaf() && isCP) {
ProgramBlock pb = (ProgramBlock) _map.getMappedProg(node.getID())[1];
ret = CostEstimationWrapper.getTimeEstimate(pb, _ec, true);
}
return ret;
}
use of org.apache.sysml.runtime.controlprogram.ProgramBlock in project incubator-systemml by apache.
the class OptTreeConverter method rCreateAbstractOptNodes.
public static ArrayList<OptNode> rCreateAbstractOptNodes(Hop hop, LocalVariableMap vars, Set<String> memo) {
ArrayList<OptNode> ret = new ArrayList<>();
ArrayList<Hop> in = hop.getInput();
if (hop.isVisited())
return ret;
// general case
if (!(hop instanceof DataOp || hop instanceof LiteralOp || hop instanceof FunctionOp)) {
OptNode node = new OptNode(NodeType.HOP);
String opstr = hop.getOpString();
node.addParam(ParamType.OPSTRING, opstr);
// handle execution type
LopProperties.ExecType et = (hop.getExecType() != null) ? hop.getExecType() : LopProperties.ExecType.CP;
switch(et) {
case CP:
case GPU:
node.setExecType(ExecType.CP);
break;
case SPARK:
node.setExecType(ExecType.SPARK);
break;
case MR:
node.setExecType(ExecType.MR);
break;
default:
throw new DMLRuntimeException("Unsupported optnode exec type: " + et);
}
// handle degree of parallelism
if (et == LopProperties.ExecType.CP && hop instanceof MultiThreadedHop) {
MultiThreadedHop mtop = (MultiThreadedHop) hop;
node.setK(OptimizerUtils.getConstrainedNumThreads(mtop.getMaxNumThreads()));
}
// assign node to return
_hlMap.putHopMapping(hop, node);
ret.add(node);
} else // process function calls
if (hop instanceof FunctionOp && INCLUDE_FUNCTIONS) {
FunctionOp fhop = (FunctionOp) hop;
String fname = fhop.getFunctionName();
String fnspace = fhop.getFunctionNamespace();
String fKey = fhop.getFunctionKey();
Object[] prog = _hlMap.getRootProgram();
OptNode node = new OptNode(NodeType.FUNCCALL);
_hlMap.putHopMapping(fhop, node);
node.setExecType(ExecType.CP);
node.addParam(ParamType.OPSTRING, fKey);
if (!fnspace.equals(DMLProgram.INTERNAL_NAMESPACE)) {
FunctionProgramBlock fpb = ((Program) prog[1]).getFunctionProgramBlock(fnspace, fname);
FunctionStatementBlock fsb = ((DMLProgram) prog[0]).getFunctionStatementBlock(fnspace, fname);
FunctionStatement fs = (FunctionStatement) fsb.getStatement(0);
// process body; NOTE: memo prevents inclusion of functions multiple times
if (!memo.contains(fKey)) {
memo.add(fKey);
int len = fs.getBody().size();
for (int i = 0; i < fpb.getChildBlocks().size() && i < len; i++) {
ProgramBlock lpb = fpb.getChildBlocks().get(i);
StatementBlock lsb = fs.getBody().get(i);
node.addChild(rCreateAbstractOptNode(lsb, lpb, vars, false, memo));
}
memo.remove(fKey);
} else
node.addParam(ParamType.RECURSIVE_CALL, "true");
}
ret.add(node);
}
if (in != null)
for (Hop hin : in) if (// no need for opt nodes
!(hin instanceof DataOp || hin instanceof LiteralOp))
ret.addAll(rCreateAbstractOptNodes(hin, vars, memo));
hop.setVisited();
return ret;
}
Aggregations