use of org.apache.sysml.runtime.instructions.cp.FunctionCallCPInstruction in project 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);
}
}
}
use of org.apache.sysml.runtime.instructions.cp.FunctionCallCPInstruction in project systemml by apache.
the class ExecutionContext method suspendIfAskedInDebugMode.
/**
* This function should be called only if user has specified -debug option.
* In this function, if the user has issued one of the step instructions or
* has enabled suspend flag in previous instruction (through breakpoint),
* then it will wait until user issues a new debugger command.
*
* @param currInst current instruction
*/
@SuppressWarnings("deprecation")
private void suspendIfAskedInDebugMode(Instruction currInst) {
if (!DMLScript.ENABLE_DEBUG_MODE) {
System.err.println("ERROR: The function suspendIfAskedInDebugMode should not be called in non-debug mode.");
}
// check for stepping options
if (!_dbState.suspend && _dbState.dbCommand != null) {
if (_dbState.dbCommand.equalsIgnoreCase("step_instruction")) {
System.out.format("Step instruction reached at %s.\n", _dbState.getPC().toString());
_dbState.suspend = true;
} else if (_dbState.dbCommand.equalsIgnoreCase("step_line") && _dbState.prevPC.getLineNumber() != currInst.getLineNum() && _dbState.prevPC.getLineNumber() != 0) {
// Don't step into first instruction of first line
// System.out.format("Step reached at %s.\n", this._prog.getPC().toString());
System.out.format("Step reached at %s.\n", _dbState.getPC().toStringWithoutInstructionID());
_dbState.suspend = true;
} else if (_dbState.dbCommand.equalsIgnoreCase("step return") && currInst instanceof FunctionCallCPInstruction) {
FunctionCallCPInstruction funCallInst = (FunctionCallCPInstruction) currInst;
if (_dbState.dbCommandArg == null || funCallInst.getFunctionName().equalsIgnoreCase(_dbState.dbCommandArg)) {
System.out.format("Step return reached at %s.\n", _dbState.getPC().toStringWithoutInstructionID());
_dbState.suspend = true;
}
}
}
// check if runtime suspend signal is set
if (_dbState.suspend) {
// flush old commands and arguments
_dbState.dbCommand = null;
_dbState.dbCommandArg = null;
// print current DML script source line
if (currInst.getLineNum() != 0)
_dbState.printDMLSourceLine(currInst.getLineNum());
// save current symbol table
_dbState.setVariables(this.getVariables());
// send next command signal to debugger control module
_dbState.nextCommand = true;
// suspend runtime execution thread
Thread.currentThread().suspend();
// reset next command signal
_dbState.nextCommand = false;
}
// reset runtime suspend signal
_dbState.suspend = false;
// update previous pc
_dbState.prevPC.setFunctionName(_dbState.getPC().getFunctionName());
_dbState.prevPC.setProgramBlockNumber(_dbState.getPC().getProgramBlockNumber());
_dbState.prevPC.setLineNumber(currInst.getLineNum());
}
use of org.apache.sysml.runtime.instructions.cp.FunctionCallCPInstruction in project incubator-systemml by apache.
the class ExecutionContext method suspendIfAskedInDebugMode.
/**
* This function should be called only if user has specified -debug option.
* In this function, if the user has issued one of the step instructions or
* has enabled suspend flag in previous instruction (through breakpoint),
* then it will wait until user issues a new debugger command.
*
* @param currInst current instruction
*/
@SuppressWarnings("deprecation")
private void suspendIfAskedInDebugMode(Instruction currInst) {
if (!DMLScript.ENABLE_DEBUG_MODE) {
System.err.println("ERROR: The function suspendIfAskedInDebugMode should not be called in non-debug mode.");
}
// check for stepping options
if (!_dbState.suspend && _dbState.dbCommand != null) {
if (_dbState.dbCommand.equalsIgnoreCase("step_instruction")) {
System.out.format("Step instruction reached at %s.\n", _dbState.getPC().toString());
_dbState.suspend = true;
} else if (_dbState.dbCommand.equalsIgnoreCase("step_line") && _dbState.prevPC.getLineNumber() != currInst.getLineNum() && _dbState.prevPC.getLineNumber() != 0) {
// Don't step into first instruction of first line
// System.out.format("Step reached at %s.\n", this._prog.getPC().toString());
System.out.format("Step reached at %s.\n", _dbState.getPC().toStringWithoutInstructionID());
_dbState.suspend = true;
} else if (_dbState.dbCommand.equalsIgnoreCase("step return") && currInst instanceof FunctionCallCPInstruction) {
FunctionCallCPInstruction funCallInst = (FunctionCallCPInstruction) currInst;
if (_dbState.dbCommandArg == null || funCallInst.getFunctionName().equalsIgnoreCase(_dbState.dbCommandArg)) {
System.out.format("Step return reached at %s.\n", _dbState.getPC().toStringWithoutInstructionID());
_dbState.suspend = true;
}
}
}
// check if runtime suspend signal is set
if (_dbState.suspend) {
// flush old commands and arguments
_dbState.dbCommand = null;
_dbState.dbCommandArg = null;
// print current DML script source line
if (currInst.getLineNum() != 0)
_dbState.printDMLSourceLine(currInst.getLineNum());
// save current symbol table
_dbState.setVariables(this.getVariables());
// send next command signal to debugger control module
_dbState.nextCommand = true;
// suspend runtime execution thread
Thread.currentThread().suspend();
// reset next command signal
_dbState.nextCommand = false;
}
// reset runtime suspend signal
_dbState.suspend = false;
// update previous pc
_dbState.prevPC.setFunctionName(_dbState.getPC().getFunctionName());
_dbState.prevPC.setProgramBlockNumber(_dbState.getPC().getProgramBlockNumber());
_dbState.prevPC.setLineNumber(currInst.getLineNum());
}
use of org.apache.sysml.runtime.instructions.cp.FunctionCallCPInstruction in project incubator-systemml by apache.
the class EvalFunction method execute.
@Override
public void execute(ExecutionContext ec) {
String fname = ((Scalar) getFunctionInput(0)).getValue();
MatrixObject in = ((Matrix) getFunctionInput(1)).getMatrixObject();
ArrayList<String> inputs = new ArrayList<>();
inputs.add("A");
ArrayList<String> outputs = new ArrayList<>();
outputs.add("B");
ExecutionContext ec2 = ExecutionContextFactory.createContext(ec.getProgram());
CPOperand inName = new CPOperand("TMP", org.apache.sysml.parser.Expression.ValueType.DOUBLE, DataType.MATRIX);
ec2.setVariable("TMP", in);
FunctionCallCPInstruction fcpi = new FunctionCallCPInstruction(null, fname, new CPOperand[] { inName }, inputs, outputs, "eval func");
fcpi.processInstruction(ec2);
MatrixObject out = (MatrixObject) ec2.getVariable("B");
_ret = new Matrix(out, ValueType.Double);
}
use of org.apache.sysml.runtime.instructions.cp.FunctionCallCPInstruction in project incubator-systemml by apache.
the class Statistics method getCPHeavyHitterCode.
public static String getCPHeavyHitterCode(Instruction inst) {
String opcode = null;
if (inst instanceof MRJobInstruction) {
MRJobInstruction mrinst = (MRJobInstruction) inst;
opcode = "MR-Job_" + mrinst.getJobType();
} else if (inst instanceof SPInstruction) {
opcode = "SP_" + InstructionUtils.getOpCode(inst.toString());
if (inst instanceof FunctionCallCPInstruction) {
FunctionCallCPInstruction extfunct = (FunctionCallCPInstruction) inst;
opcode = extfunct.getFunctionName();
}
} else // CPInstructions
{
opcode = InstructionUtils.getOpCode(inst.toString());
if (inst instanceof FunctionCallCPInstruction) {
FunctionCallCPInstruction extfunct = (FunctionCallCPInstruction) inst;
opcode = extfunct.getFunctionName();
}
}
return opcode;
}
Aggregations