use of org.apache.sysml.runtime.instructions.Instruction in project incubator-systemml by apache.
the class ProgramConverter method createDeepCopyInstructionSet.
/**
* Creates a deep copy of an array of instructions and replaces the placeholders of parworker
* IDs with the concrete IDs of this parfor instance. This is a helper method uses for generating
* deep copies of program blocks.
*
* @param instSet list of instructions
* @param pid ?
* @param IDPrefix ?
* @param prog runtime program
* @param fnStack ?
* @param fnCreated ?
* @param plain ?
* @param cpFunctions ?
* @return list of instructions
*/
public static ArrayList<Instruction> createDeepCopyInstructionSet(ArrayList<Instruction> instSet, long pid, int IDPrefix, Program prog, HashSet<String> fnStack, HashSet<String> fnCreated, boolean plain, boolean cpFunctions) {
ArrayList<Instruction> tmp = new ArrayList<>();
for (Instruction inst : instSet) {
if (inst instanceof FunctionCallCPInstruction && cpFunctions) {
FunctionCallCPInstruction finst = (FunctionCallCPInstruction) inst;
createDeepCopyFunctionProgramBlock(finst.getNamespace(), finst.getFunctionName(), pid, IDPrefix, prog, fnStack, fnCreated, plain);
}
tmp.add(cloneInstruction(inst, pid, plain, cpFunctions));
}
return tmp;
}
use of org.apache.sysml.runtime.instructions.Instruction in project incubator-systemml by apache.
the class ProgramConverter method createDeepCopyWhileProgramBlock.
public static WhileProgramBlock createDeepCopyWhileProgramBlock(WhileProgramBlock wpb, long pid, int IDPrefix, Program prog, HashSet<String> fnStack, HashSet<String> fnCreated, boolean plain, boolean forceDeepCopy) {
ArrayList<Instruction> predinst = createDeepCopyInstructionSet(wpb.getPredicate(), pid, IDPrefix, prog, fnStack, fnCreated, plain, true);
WhileProgramBlock tmpPB = new WhileProgramBlock(prog, predinst);
tmpPB.setStatementBlock(createWhileStatementBlockCopy((WhileStatementBlock) wpb.getStatementBlock(), pid, plain, forceDeepCopy));
tmpPB.setThreadID(pid);
tmpPB.setExitInstructions2(createDeepCopyInstructionSet(wpb.getExitInstructions(), pid, IDPrefix, prog, fnStack, fnCreated, plain, true));
tmpPB.setChildBlocks(rcreateDeepCopyProgramBlocks(wpb.getChildBlocks(), pid, IDPrefix, fnStack, fnCreated, plain, forceDeepCopy));
return tmpPB;
}
use of org.apache.sysml.runtime.instructions.Instruction in project incubator-systemml by apache.
the class ProgramConverter method parseInstructions.
private static ArrayList<Instruction> parseInstructions(String in, int id) {
ArrayList<Instruction> insts = new ArrayList<>();
String lin = in.substring(PARFOR_INST_BEGIN.length(), in.length() - PARFOR_INST_END.length());
StringTokenizer st = new StringTokenizer(lin, ELEMENT_DELIM);
while (st.hasMoreTokens()) {
// Note that at this point only CP instructions and External function instruction can occur
String instStr = st.nextToken();
try {
Instruction tmpinst = CPInstructionParser.parseSingleInstruction(instStr);
tmpinst = saveReplaceThreadID(tmpinst, CP_ROOT_THREAD_ID, CP_CHILD_THREAD + id);
insts.add(tmpinst);
} catch (Exception ex) {
throw new DMLRuntimeException("Failed to parse instruction: " + instStr, ex);
}
}
return insts;
}
use of org.apache.sysml.runtime.instructions.Instruction in project incubator-systemml by apache.
the class GPUInstruction method preprocessInstruction.
@Override
public Instruction preprocessInstruction(ExecutionContext ec) {
// default preprocess behavior (e.g., debug state)
Instruction tmp = super.preprocessInstruction(ec);
// instruction patching
if (tmp.requiresLabelUpdate()) {
// update labels only if required
// note: no exchange of updated instruction as labels might change in the general case
String updInst = RunMRJobs.updateLabels(tmp.toString(), ec.getVariables());
tmp = GPUInstructionParser.parseSingleInstruction(updInst);
}
return tmp;
}
use of org.apache.sysml.runtime.instructions.Instruction in project incubator-systemml by apache.
the class OptTreePlanChecker method checkFunctionNames.
private static void checkFunctionNames(Program prog, DMLProgram dprog, Hop root, ArrayList<Instruction> inst, Set<String> fnStack) {
// reset visit status of dag
root.resetVisitStatus();
// get all function op in this dag
HashMap<String, FunctionOp> fops = new HashMap<>();
getAllFunctionOps(root, fops);
for (Instruction linst : inst) if (linst instanceof FunctionCallCPInstruction) {
FunctionCallCPInstruction flinst = (FunctionCallCPInstruction) linst;
String fnamespace = flinst.getNamespace();
String fname = flinst.getFunctionName();
String key = DMLProgram.constructFunctionKey(fnamespace, fname);
// check 1: instruction name equal to hop name
if (!fops.containsKey(key))
throw new DMLRuntimeException("Function Check: instruction and hop names differ (" + key + ", " + fops.keySet() + ")");
// check 2: function exists
if (!prog.getFunctionProgramBlocks().containsKey(key))
throw new DMLRuntimeException("Function Check: function does not exits (" + key + ")");
// check 3: recursive program check
FunctionProgramBlock fpb = prog.getFunctionProgramBlock(fnamespace, fname);
FunctionStatementBlock fsb = dprog.getFunctionStatementBlock(fnamespace, fname);
if (!fnStack.contains(key)) {
fnStack.add(key);
checkProgramCorrectness(fpb, fsb, fnStack);
fnStack.remove(key);
}
}
}
Aggregations