Search in sources :

Example 16 with FunctionCallCPInstruction

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);
        }
    }
}
Also used : FunctionProgramBlock(org.apache.sysml.runtime.controlprogram.FunctionProgramBlock) FunctionStatementBlock(org.apache.sysml.parser.FunctionStatementBlock) FunctionCallCPInstruction(org.apache.sysml.runtime.instructions.cp.FunctionCallCPInstruction) HashMap(java.util.HashMap) FunctionOp(org.apache.sysml.hops.FunctionOp) FunctionCallCPInstruction(org.apache.sysml.runtime.instructions.cp.FunctionCallCPInstruction) Instruction(org.apache.sysml.runtime.instructions.Instruction) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException)

Example 17 with FunctionCallCPInstruction

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());
}
Also used : FunctionCallCPInstruction(org.apache.sysml.runtime.instructions.cp.FunctionCallCPInstruction)

Example 18 with FunctionCallCPInstruction

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());
}
Also used : FunctionCallCPInstruction(org.apache.sysml.runtime.instructions.cp.FunctionCallCPInstruction)

Example 19 with FunctionCallCPInstruction

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);
}
Also used : MatrixObject(org.apache.sysml.runtime.controlprogram.caching.MatrixObject) Matrix(org.apache.sysml.udf.Matrix) ExecutionContext(org.apache.sysml.runtime.controlprogram.context.ExecutionContext) FunctionCallCPInstruction(org.apache.sysml.runtime.instructions.cp.FunctionCallCPInstruction) ArrayList(java.util.ArrayList) CPOperand(org.apache.sysml.runtime.instructions.cp.CPOperand) Scalar(org.apache.sysml.udf.Scalar)

Example 20 with FunctionCallCPInstruction

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;
}
Also used : SPInstruction(org.apache.sysml.runtime.instructions.spark.SPInstruction) MRJobInstruction(org.apache.sysml.runtime.instructions.MRJobInstruction) FunctionCallCPInstruction(org.apache.sysml.runtime.instructions.cp.FunctionCallCPInstruction)

Aggregations

FunctionCallCPInstruction (org.apache.sysml.runtime.instructions.cp.FunctionCallCPInstruction)24 Instruction (org.apache.sysml.runtime.instructions.Instruction)14 MRJobInstruction (org.apache.sysml.runtime.instructions.MRJobInstruction)12 VariableCPInstruction (org.apache.sysml.runtime.instructions.cp.VariableCPInstruction)12 ArrayList (java.util.ArrayList)10 FunctionProgramBlock (org.apache.sysml.runtime.controlprogram.FunctionProgramBlock)10 CPInstruction (org.apache.sysml.runtime.instructions.cp.CPInstruction)10 ForProgramBlock (org.apache.sysml.runtime.controlprogram.ForProgramBlock)8 ProgramBlock (org.apache.sysml.runtime.controlprogram.ProgramBlock)8 MRInstruction (org.apache.sysml.runtime.instructions.mr.MRInstruction)8 SPInstruction (org.apache.sysml.runtime.instructions.spark.SPInstruction)8 IfProgramBlock (org.apache.sysml.runtime.controlprogram.IfProgramBlock)6 ParForProgramBlock (org.apache.sysml.runtime.controlprogram.ParForProgramBlock)6 WhileProgramBlock (org.apache.sysml.runtime.controlprogram.WhileProgramBlock)6 SpoofCPInstruction (org.apache.sysml.runtime.instructions.cp.SpoofCPInstruction)6 GPUInstruction (org.apache.sysml.runtime.instructions.gpu.GPUInstruction)6 ExternalFunctionInvocationInstruction (org.apache.sysml.udf.ExternalFunctionInvocationInstruction)6 FunctionOp (org.apache.sysml.hops.FunctionOp)4 DMLRuntimeException (org.apache.sysml.runtime.DMLRuntimeException)4 ExternalFunctionProgramBlock (org.apache.sysml.runtime.controlprogram.ExternalFunctionProgramBlock)4