use of org.apache.sysml.runtime.controlprogram.ProgramBlock in project incubator-systemml by apache.
the class DMLDebuggerProgramInfo method accessBreakpoint.
/**
* Access breakpoint instruction at specified line number in runtime program (if valid)
* @param lineNumber Location for breakpoint operation
* @param op Breakpoint operation (op=0 for create, op=1 for enable/disable, op=2 for delete)
* @param status Current breakpoint status
*/
public void accessBreakpoint(int lineNumber, int op, BPINSTRUCTION_STATUS status) {
if (this.rtprog != null) {
// Functions: For each function program block (if any), get instructions corresponding to each line number
HashMap<String, FunctionProgramBlock> funcMap = this.rtprog.getFunctionProgramBlocks();
if (funcMap != null && !funcMap.isEmpty()) {
for (Entry<String, FunctionProgramBlock> e : funcMap.entrySet()) {
location = e.getKey();
FunctionProgramBlock fpb = e.getValue();
if (fpb instanceof ExternalFunctionProgramBlock)
continue;
else {
for (ProgramBlock pb : fpb.getChildBlocks()) accessProgramBlockBreakpoint(pb, lineNumber, op, status);
}
}
}
// Main program: for each program block, get instructions corresponding to current line number (if any)
location = DMLProgram.constructFunctionKey(DMLProgram.DEFAULT_NAMESPACE, "main");
for (ProgramBlock pb : this.rtprog.getProgramBlocks()) {
if (pb != null)
accessProgramBlockBreakpoint(pb, lineNumber, op, status);
}
}
}
use of org.apache.sysml.runtime.controlprogram.ProgramBlock in project incubator-systemml by apache.
the class DMLDebuggerProgramInfo method setProgramBlockInstMap.
/**
* For each program block, get runtime instructions (if any)
* @param pb Current program block
*/
private void setProgramBlockInstMap(ProgramBlock pb) {
if (pb instanceof FunctionProgramBlock) {
FunctionProgramBlock fpb = (FunctionProgramBlock) pb;
for (ProgramBlock pbc : fpb.getChildBlocks()) setProgramBlockInstMap(pbc);
} else if (pb instanceof WhileProgramBlock) {
WhileProgramBlock wpb = (WhileProgramBlock) pb;
this.setInstMap(wpb.getPredicate());
for (ProgramBlock pbc : wpb.getChildBlocks()) setProgramBlockInstMap(pbc);
} else if (pb instanceof IfProgramBlock) {
IfProgramBlock ipb = (IfProgramBlock) pb;
this.setInstMap(ipb.getPredicate());
for (ProgramBlock pbc : ipb.getChildBlocksIfBody()) setProgramBlockInstMap(pbc);
if (!ipb.getChildBlocksElseBody().isEmpty()) {
for (ProgramBlock pbc : ipb.getChildBlocksElseBody()) setProgramBlockInstMap(pbc);
}
} else if (// incl parfor
pb instanceof ForProgramBlock) {
ForProgramBlock fpb = (ForProgramBlock) pb;
this.setInstMap(fpb.getFromInstructions());
this.setInstMap(fpb.getToInstructions());
this.setInstMap(fpb.getIncrementInstructions());
for (ProgramBlock pbc : fpb.getChildBlocks()) setProgramBlockInstMap(pbc);
} else {
this.setInstMap(pb.getInstructions());
}
}
use of org.apache.sysml.runtime.controlprogram.ProgramBlock in project incubator-systemml by apache.
the class RewriteConstantFolding method evalScalarOperation.
/**
* In order to (1) prevent unexpected side effects from constant folding and
* (2) for simplicity with regard to arbitrary value type combinations,
* we use the same compilation and runtime for constant folding as we would
* use for actual instruction execution.
*
* @param bop high-level operator
* @return literal op
*/
private LiteralOp evalScalarOperation(Hop bop) {
// Timing time = new Timing( true );
DataOp tmpWrite = new DataOp(TMP_VARNAME, bop.getDataType(), bop.getValueType(), bop, DataOpTypes.TRANSIENTWRITE, TMP_VARNAME);
// generate runtime instruction
Dag<Lop> dag = new Dag<>();
// prevent lops reuse
Recompiler.rClearLops(tmpWrite);
// reconstruct lops
Lop lops = tmpWrite.constructLops();
lops.addToDag(dag);
ArrayList<Instruction> inst = dag.getJobs(null, ConfigurationManager.getDMLConfig());
// execute instructions
ExecutionContext ec = getExecutionContext();
ProgramBlock pb = getProgramBlock();
pb.setInstructions(inst);
pb.execute(ec);
// get scalar result (check before invocation) and create literal according
// to observed scalar output type (not hop type) for runtime consistency
ScalarObject so = (ScalarObject) ec.getVariable(TMP_VARNAME);
LiteralOp literal = null;
switch(so.getValueType()) {
case DOUBLE:
literal = new LiteralOp(so.getDoubleValue());
break;
case INT:
literal = new LiteralOp(so.getLongValue());
break;
case BOOLEAN:
literal = new LiteralOp(so.getBooleanValue());
break;
case STRING:
literal = new LiteralOp(so.getStringValue());
break;
default:
throw new HopsException("Unsupported literal value type: " + bop.getValueType());
}
// cleanup
tmpWrite.getInput().clear();
bop.getParent().remove(tmpWrite);
pb.setInstructions(null);
ec.getVariables().removeAll();
// set literal properties (scalar)
HopRewriteUtils.setOutputParametersForScalar(literal);
return literal;
}
use of org.apache.sysml.runtime.controlprogram.ProgramBlock in project incubator-systemml by apache.
the class ProgramConverter method rcreateDeepCopyProgramBlocks.
/**
* This recursively creates a deep copy of program blocks and transparently replaces filenames according to the
* specified parallel worker in order to avoid conflicts between parworkers. This happens recursively in order
* to support arbitrary control-flow constructs within a parfor.
*
* @param childBlocks child program blocks
* @param pid ?
* @param IDPrefix ?
* @param fnStack ?
* @param fnCreated ?
* @param plain if true, full deep copy without id replacement
* @param forceDeepCopy if true, force deep copy
* @return list of program blocks
*/
public static ArrayList<ProgramBlock> rcreateDeepCopyProgramBlocks(ArrayList<ProgramBlock> childBlocks, long pid, int IDPrefix, HashSet<String> fnStack, HashSet<String> fnCreated, boolean plain, boolean forceDeepCopy) {
ArrayList<ProgramBlock> tmp = new ArrayList<>();
for (ProgramBlock pb : childBlocks) {
Program prog = pb.getProgram();
ProgramBlock tmpPB = null;
if (pb instanceof WhileProgramBlock) {
tmpPB = createDeepCopyWhileProgramBlock((WhileProgramBlock) pb, pid, IDPrefix, prog, fnStack, fnCreated, plain, forceDeepCopy);
} else if (pb instanceof ForProgramBlock && !(pb instanceof ParForProgramBlock)) {
tmpPB = createDeepCopyForProgramBlock((ForProgramBlock) pb, pid, IDPrefix, prog, fnStack, fnCreated, plain, forceDeepCopy);
} else if (pb instanceof ParForProgramBlock) {
ParForProgramBlock pfpb = (ParForProgramBlock) pb;
if (ParForProgramBlock.ALLOW_NESTED_PARALLELISM)
tmpPB = createDeepCopyParForProgramBlock(pfpb, pid, IDPrefix, prog, fnStack, fnCreated, plain, forceDeepCopy);
else
tmpPB = createDeepCopyForProgramBlock((ForProgramBlock) pb, pid, IDPrefix, prog, fnStack, fnCreated, plain, forceDeepCopy);
} else if (pb instanceof IfProgramBlock) {
tmpPB = createDeepCopyIfProgramBlock((IfProgramBlock) pb, pid, IDPrefix, prog, fnStack, fnCreated, plain, forceDeepCopy);
} else // last-level program block
{
// general case use for most PBs
tmpPB = new ProgramBlock(prog);
// for recompile in the master node JVM
tmpPB.setStatementBlock(createStatementBlockCopy(pb.getStatementBlock(), pid, plain, forceDeepCopy));
// tmpPB.setStatementBlock(pb.getStatementBlock());
tmpPB.setThreadID(pid);
}
// copy instructions
tmpPB.setInstructions(createDeepCopyInstructionSet(pb.getInstructions(), pid, IDPrefix, prog, fnStack, fnCreated, plain, true));
// copy symbol table
// tmpPB.setVariables( pb.getVariables() ); //implicit cloning
tmp.add(tmpPB);
}
return tmp;
}
use of org.apache.sysml.runtime.controlprogram.ProgramBlock in project incubator-systemml by apache.
the class ProgramConverter method rSerializeProgramBlocks.
private static String rSerializeProgramBlocks(ArrayList<ProgramBlock> pbs, HashMap<String, byte[]> clsMap) {
StringBuilder sb = new StringBuilder();
int count = 0;
for (ProgramBlock pb : pbs) {
if (count > 0) {
sb.append(ELEMENT_DELIM);
sb.append(NEWLINE);
}
sb.append(rSerializeProgramBlock(pb, clsMap));
count++;
}
return sb.toString();
}
Aggregations