Search in sources :

Example 1 with ExternalFunctionInvocationInstruction

use of org.apache.sysml.udf.ExternalFunctionInvocationInstruction in project incubator-systemml by apache.

the class ExternalFunctionProgramBlockCP method createInstructions.

@Override
protected void createInstructions() {
    _inst = new ArrayList<Instruction>();
    // assemble information provided through keyvalue pairs
    String className = _otherParams.get(ExternalFunctionStatement.CLASS_NAME);
    String configFile = _otherParams.get(ExternalFunctionStatement.CONFIG_FILE);
    // class name cannot be null, however, configFile and execLocation can be null
    if (className == null)
        throw new RuntimeException(this.printBlockErrorLocation() + ExternalFunctionStatement.CLASS_NAME + " not provided!");
    // assemble input and output param strings
    String inputParameterString = getParameterString(getInputParams());
    String outputParameterString = getParameterString(getOutputParams());
    // generate instruction
    ExternalFunctionInvocationInstruction einst = new ExternalFunctionInvocationInstruction(className, configFile, inputParameterString, outputParameterString);
    _inst.add(einst);
}
Also used : ExternalFunctionInvocationInstruction(org.apache.sysml.udf.ExternalFunctionInvocationInstruction) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException) ExternalFunctionInvocationInstruction(org.apache.sysml.udf.ExternalFunctionInvocationInstruction) Instruction(org.apache.sysml.runtime.instructions.Instruction)

Example 2 with ExternalFunctionInvocationInstruction

use of org.apache.sysml.udf.ExternalFunctionInvocationInstruction in project incubator-systemml by apache.

the class ExternalFunctionProgramBlock method executeInstruction.

/**
	 * Method to execute an external function invocation instruction.
	 * 
	 * @param ec execution context
	 * @param inst external function invocation instructions
	 * @throws DMLRuntimeException if DMLRuntimeException occurs
	 */
@SuppressWarnings("unchecked")
public void executeInstruction(ExecutionContext ec, ExternalFunctionInvocationInstruction inst) throws DMLRuntimeException {
    String className = inst.getClassName();
    String configFile = inst.getConfigFile();
    if (className == null)
        throw new DMLRuntimeException(this.printBlockErrorLocation() + "Class name can't be null");
    // create instance of package function.
    Object o;
    try {
        Class<Instruction> cla = (Class<Instruction>) Class.forName(className);
        o = cla.newInstance();
    } catch (Exception e) {
        throw new DMLRuntimeException(this.printBlockErrorLocation() + "Error generating package function object ", e);
    }
    if (!(o instanceof PackageFunction))
        throw new DMLRuntimeException(this.printBlockErrorLocation() + "Class is not of type PackageFunction");
    PackageFunction func = (PackageFunction) o;
    // add inputs to this package function based on input parameter
    // and their mappings.
    setupInputs(func, inst.getInputParams(), ec.getVariables());
    func.setConfiguration(configFile);
    func.setBaseDir(_baseDir);
    //executes function
    func.execute();
    // verify output of function execution matches declaration
    // and add outputs to variableMapping and Metadata
    verifyAndAttachOutputs(ec, func, inst.getOutputParams());
}
Also used : BooleanObject(org.apache.sysml.runtime.instructions.cp.BooleanObject) MatrixObject(org.apache.sysml.runtime.controlprogram.caching.MatrixObject) IntObject(org.apache.sysml.runtime.instructions.cp.IntObject) BinaryObject(org.apache.sysml.udf.BinaryObject) ScalarObject(org.apache.sysml.runtime.instructions.cp.ScalarObject) DoubleObject(org.apache.sysml.runtime.instructions.cp.DoubleObject) StringObject(org.apache.sysml.runtime.instructions.cp.StringObject) PackageFunction(org.apache.sysml.udf.PackageFunction) MRJobInstruction(org.apache.sysml.runtime.instructions.MRJobInstruction) VariableCPInstruction(org.apache.sysml.runtime.instructions.cp.VariableCPInstruction) ExternalFunctionInvocationInstruction(org.apache.sysml.udf.ExternalFunctionInvocationInstruction) Instruction(org.apache.sysml.runtime.instructions.Instruction) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException) CacheException(org.apache.sysml.runtime.controlprogram.caching.CacheException) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException)

Example 3 with ExternalFunctionInvocationInstruction

use of org.apache.sysml.udf.ExternalFunctionInvocationInstruction in project incubator-systemml by apache.

the class ExternalFunctionProgramBlock method createInstructions.

/**
	 * method to create instructions
	 */
protected void createInstructions() {
    _inst = new ArrayList<Instruction>();
    // unblock all input matrices
    block2CellInst = getBlock2CellInstructions(getInputParams(), _unblockedFileNames);
    // assemble information provided through keyvalue pairs
    String className = _otherParams.get(ExternalFunctionStatement.CLASS_NAME);
    String configFile = _otherParams.get(ExternalFunctionStatement.CONFIG_FILE);
    // be null
    if (className == null)
        throw new RuntimeException(this.printBlockErrorLocation() + ExternalFunctionStatement.CLASS_NAME + " not provided!");
    // assemble input and output param strings
    String inputParameterString = getParameterString(getInputParams());
    String outputParameterString = getParameterString(getOutputParams());
    // generate instruction
    ExternalFunctionInvocationInstruction einst = new ExternalFunctionInvocationInstruction(className, configFile, inputParameterString, outputParameterString);
    if (getInputParams().size() > 0)
        einst.setLocation(getInputParams().get(0));
    else if (getOutputParams().size() > 0)
        einst.setLocation(getOutputParams().get(0));
    else
        einst.setLocation(this._beginLine, this._endLine, this._beginColumn, this._endColumn);
    _inst.add(einst);
    // block output matrices
    cell2BlockInst = getCell2BlockInstructions(getOutputParams(), _blockedFileNames);
}
Also used : ExternalFunctionInvocationInstruction(org.apache.sysml.udf.ExternalFunctionInvocationInstruction) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException) MRJobInstruction(org.apache.sysml.runtime.instructions.MRJobInstruction) VariableCPInstruction(org.apache.sysml.runtime.instructions.cp.VariableCPInstruction) ExternalFunctionInvocationInstruction(org.apache.sysml.udf.ExternalFunctionInvocationInstruction) Instruction(org.apache.sysml.runtime.instructions.Instruction)

Example 4 with ExternalFunctionInvocationInstruction

use of org.apache.sysml.udf.ExternalFunctionInvocationInstruction in project incubator-systemml by apache.

the class ProgramConverter method serializeInstructions.

@SuppressWarnings("all")
private static String serializeInstructions(ArrayList<Instruction> inst, HashMap<String, byte[]> clsMap) throws DMLRuntimeException {
    StringBuilder sb = new StringBuilder();
    int count = 0;
    for (Instruction linst : inst) {
        //check that only cp instruction are transmitted 
        if (!(linst instanceof CPInstruction || linst instanceof ExternalFunctionInvocationInstruction))
            throw new DMLRuntimeException(NOT_SUPPORTED_MR_INSTRUCTION + " " + linst.getClass().getName() + "\n" + linst);
        //obtain serialized version of generated classes
        if (linst instanceof SpoofCPInstruction) {
            Class<?> cla = ((SpoofCPInstruction) linst).getOperatorClass();
            clsMap.put(cla.getName(), CodegenUtils.getClassData(cla.getName()));
        }
        if (count > 0)
            sb.append(ELEMENT_DELIM);
        sb.append(checkAndReplaceLiterals(linst.toString()));
        count++;
    }
    return sb.toString();
}
Also used : CPInstruction(org.apache.sysml.runtime.instructions.cp.CPInstruction) SpoofCPInstruction(org.apache.sysml.runtime.instructions.cp.SpoofCPInstruction) VariableCPInstruction(org.apache.sysml.runtime.instructions.cp.VariableCPInstruction) FunctionCallCPInstruction(org.apache.sysml.runtime.instructions.cp.FunctionCallCPInstruction) ExternalFunctionInvocationInstruction(org.apache.sysml.udf.ExternalFunctionInvocationInstruction) SpoofCPInstruction(org.apache.sysml.runtime.instructions.cp.SpoofCPInstruction) GPUInstruction(org.apache.sysml.runtime.instructions.gpu.GPUInstruction) MRJobInstruction(org.apache.sysml.runtime.instructions.MRJobInstruction) CPInstruction(org.apache.sysml.runtime.instructions.cp.CPInstruction) ExternalFunctionInvocationInstruction(org.apache.sysml.udf.ExternalFunctionInvocationInstruction) SpoofCPInstruction(org.apache.sysml.runtime.instructions.cp.SpoofCPInstruction) Instruction(org.apache.sysml.runtime.instructions.Instruction) SPInstruction(org.apache.sysml.runtime.instructions.spark.SPInstruction) VariableCPInstruction(org.apache.sysml.runtime.instructions.cp.VariableCPInstruction) FunctionCallCPInstruction(org.apache.sysml.runtime.instructions.cp.FunctionCallCPInstruction) MRInstruction(org.apache.sysml.runtime.instructions.mr.MRInstruction) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException)

Example 5 with ExternalFunctionInvocationInstruction

use of org.apache.sysml.udf.ExternalFunctionInvocationInstruction in project incubator-systemml by apache.

the class ExternalFunctionProgramBlockCP method execute.

/**
	 * Method to be invoked to execute instructions for the external function
	 * invocation
	 */
@Override
public void execute(ExecutionContext ec) throws DMLRuntimeException {
    _runID = _idSeq.getNextID();
    ExternalFunctionInvocationInstruction inst = null;
    // execute package function
    for (int i = 0; i < _inst.size(); i++) {
        try {
            inst = (ExternalFunctionInvocationInstruction) _inst.get(i);
            inst._namespace = _namespace;
            inst._functionName = _functionName;
            executeInstruction(ec, inst);
        } catch (Exception e) {
            throw new DMLRuntimeException(this.printBlockErrorLocation() + "Error evaluating instruction " + i + " in external function programBlock. inst: " + inst.toString(), e);
        }
    }
    // check return values
    checkOutputParameters(ec.getVariables());
}
Also used : ExternalFunctionInvocationInstruction(org.apache.sysml.udf.ExternalFunctionInvocationInstruction) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException)

Aggregations

DMLRuntimeException (org.apache.sysml.runtime.DMLRuntimeException)6 ExternalFunctionInvocationInstruction (org.apache.sysml.udf.ExternalFunctionInvocationInstruction)6 Instruction (org.apache.sysml.runtime.instructions.Instruction)5 MRJobInstruction (org.apache.sysml.runtime.instructions.MRJobInstruction)4 VariableCPInstruction (org.apache.sysml.runtime.instructions.cp.VariableCPInstruction)4 CacheException (org.apache.sysml.runtime.controlprogram.caching.CacheException)2 MatrixObject (org.apache.sysml.runtime.controlprogram.caching.MatrixObject)2 ArrayList (java.util.ArrayList)1 DataIdentifier (org.apache.sysml.parser.DataIdentifier)1 BooleanObject (org.apache.sysml.runtime.instructions.cp.BooleanObject)1 CPInstruction (org.apache.sysml.runtime.instructions.cp.CPInstruction)1 Data (org.apache.sysml.runtime.instructions.cp.Data)1 DoubleObject (org.apache.sysml.runtime.instructions.cp.DoubleObject)1 FunctionCallCPInstruction (org.apache.sysml.runtime.instructions.cp.FunctionCallCPInstruction)1 IntObject (org.apache.sysml.runtime.instructions.cp.IntObject)1 ScalarObject (org.apache.sysml.runtime.instructions.cp.ScalarObject)1 SpoofCPInstruction (org.apache.sysml.runtime.instructions.cp.SpoofCPInstruction)1 StringObject (org.apache.sysml.runtime.instructions.cp.StringObject)1 GPUInstruction (org.apache.sysml.runtime.instructions.gpu.GPUInstruction)1 MRInstruction (org.apache.sysml.runtime.instructions.mr.MRInstruction)1