use of org.apache.sysml.runtime.controlprogram.FunctionProgramBlock 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.FunctionProgramBlock 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.FunctionProgramBlock in project incubator-systemml by apache.
the class ProgramConverter method createDeepCopyFunctionProgramBlock.
/**
* This creates a deep copy of a function program block. The central reference to singletons of function program blocks
* poses the need for explicit copies in order to prevent conflicting writes of temporary variables (see ExternalFunctionProgramBlock.
*
* @param namespace function namespace
* @param oldName ?
* @param pid ?
* @param IDPrefix ?
* @param prog runtime program
* @param fnStack ?
* @param fnCreated ?
* @param plain ?
*/
public static void createDeepCopyFunctionProgramBlock(String namespace, String oldName, long pid, int IDPrefix, Program prog, HashSet<String> fnStack, HashSet<String> fnCreated, boolean plain) {
// fpb guaranteed to be non-null (checked inside getFunctionProgramBlock)
FunctionProgramBlock fpb = prog.getFunctionProgramBlock(namespace, oldName);
String fnameNew = (plain) ? oldName : (oldName + CP_CHILD_THREAD + pid);
String fnameNewKey = DMLProgram.constructFunctionKey(namespace, fnameNew);
if (prog.getFunctionProgramBlocks().containsKey(fnameNewKey))
// prevent redundant deep copy if already existent
return;
// create deep copy
FunctionProgramBlock copy = null;
ArrayList<DataIdentifier> tmp1 = new ArrayList<>();
ArrayList<DataIdentifier> tmp2 = new ArrayList<>();
if (fpb.getInputParams() != null)
tmp1.addAll(fpb.getInputParams());
if (fpb.getOutputParams() != null)
tmp2.addAll(fpb.getOutputParams());
if (fpb instanceof ExternalFunctionProgramBlockCP) {
ExternalFunctionProgramBlockCP efpb = (ExternalFunctionProgramBlockCP) fpb;
HashMap<String, String> tmp3 = efpb.getOtherParams();
if (IDPrefix != -1)
copy = new ExternalFunctionProgramBlockCP(prog, tmp1, tmp2, tmp3, saveReplaceFilenameThreadID(efpb.getBaseDir(), CP_CHILD_THREAD + IDPrefix, CP_CHILD_THREAD + pid));
else
copy = new ExternalFunctionProgramBlockCP(prog, tmp1, tmp2, tmp3, saveReplaceFilenameThreadID(efpb.getBaseDir(), CP_ROOT_THREAD_ID, CP_CHILD_THREAD + pid));
} else if (fpb instanceof ExternalFunctionProgramBlock) {
ExternalFunctionProgramBlock efpb = (ExternalFunctionProgramBlock) fpb;
HashMap<String, String> tmp3 = efpb.getOtherParams();
if (IDPrefix != -1)
copy = new ExternalFunctionProgramBlock(prog, tmp1, tmp2, tmp3, saveReplaceFilenameThreadID(efpb.getBaseDir(), CP_CHILD_THREAD + IDPrefix, CP_CHILD_THREAD + pid));
else
copy = new ExternalFunctionProgramBlock(prog, tmp1, tmp2, tmp3, saveReplaceFilenameThreadID(efpb.getBaseDir(), CP_ROOT_THREAD_ID, CP_CHILD_THREAD + pid));
} else {
if (!fnStack.contains(fnameNewKey)) {
fnStack.add(fnameNewKey);
copy = new FunctionProgramBlock(prog, tmp1, tmp2);
copy.setChildBlocks(rcreateDeepCopyProgramBlocks(fpb.getChildBlocks(), pid, IDPrefix, fnStack, fnCreated, plain, fpb.isRecompileOnce()));
copy.setRecompileOnce(fpb.isRecompileOnce());
copy.setThreadID(pid);
fnStack.remove(fnameNewKey);
} else
// stop deep copy for recursive function calls
copy = fpb;
}
// copy.setVariables( (LocalVariableMap) fpb.getVariables() ); //implicit cloning
// note: instructions not used by function program block
// put
prog.addFunctionProgramBlock(namespace, fnameNew, copy);
fnCreated.add(DMLProgram.constructFunctionKey(namespace, fnameNew));
}
use of org.apache.sysml.runtime.controlprogram.FunctionProgramBlock in project incubator-systemml by apache.
the class ProgramConverter method parseProgram.
public static Program parseProgram(String in, int id) {
String lin = in.substring(PARFOR_PROG_BEGIN.length(), in.length() - PARFOR_PROG_END.length()).trim();
Program prog = new Program();
HashMap<String, FunctionProgramBlock> fc = parseFunctionProgramBlocks(lin, prog, id);
for (Entry<String, FunctionProgramBlock> e : fc.entrySet()) {
String[] keypart = e.getKey().split(Program.KEY_DELIM);
String namespace = keypart[0];
String name = keypart[1];
prog.addFunctionProgramBlock(namespace, name, e.getValue());
}
return prog;
}
use of org.apache.sysml.runtime.controlprogram.FunctionProgramBlock in project incubator-systemml by apache.
the class ProgramConverter method createDeepCopyFunctionProgramBlock.
public static FunctionProgramBlock createDeepCopyFunctionProgramBlock(FunctionProgramBlock fpb, HashSet<String> fnStack, HashSet<String> fnCreated) {
if (fpb == null)
throw new DMLRuntimeException("Unable to create a deep copy of a non-existing FunctionProgramBlock.");
// create deep copy
FunctionProgramBlock copy = null;
ArrayList<DataIdentifier> tmp1 = new ArrayList<>();
ArrayList<DataIdentifier> tmp2 = new ArrayList<>();
if (fpb.getInputParams() != null)
tmp1.addAll(fpb.getInputParams());
if (fpb.getOutputParams() != null)
tmp2.addAll(fpb.getOutputParams());
copy = new FunctionProgramBlock(fpb.getProgram(), tmp1, tmp2);
copy.setChildBlocks(rcreateDeepCopyProgramBlocks(fpb.getChildBlocks(), 0, -1, fnStack, fnCreated, true, fpb.isRecompileOnce()));
copy.setStatementBlock(fpb.getStatementBlock());
copy.setRecompileOnce(fpb.isRecompileOnce());
return copy;
}
Aggregations