Search in sources :

Example 1 with PackageFunction

use of org.apache.sysml.udf.PackageFunction 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 2 with PackageFunction

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

the class ExternalFunctionProgramBlock method createInstructions.

/**
 * method to create instructions
 */
protected void createInstructions() {
    _inst = new ArrayList<>();
    // 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);
    // 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 operands
    CPOperand[] inputs = getOperands(getInputParams());
    CPOperand[] outputs = getOperands(getOutputParams());
    // generate instruction
    PackageFunction fun = createFunctionObject(className, configFile);
    ExternalFunctionInvocationInstruction einst = new ExternalFunctionInvocationInstruction(inputs, outputs, fun, _baseDir, InputInfo.TextCellInputInfo);
    verifyFunctionInputsOutputs(fun, inputs, outputs);
    if (getInputParams().size() > 0)
        einst.setLocation(getInputParams().get(0));
    else if (getOutputParams().size() > 0)
        einst.setLocation(getOutputParams().get(0));
    else
        einst.setLocation(getFilename(), _beginLine, _endLine, _beginColumn, _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) CPOperand(org.apache.sysml.runtime.instructions.cp.CPOperand) PackageFunction(org.apache.sysml.udf.PackageFunction)

Example 3 with PackageFunction

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

the class ExternalFunctionProgramBlockCP method createInstructions.

@Override
protected void createInstructions() {
    _inst = new ArrayList<>();
    // 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
    CPOperand[] inputs = getOperands(getInputParams());
    CPOperand[] outputs = getOperands(getOutputParams());
    // generate instruction
    PackageFunction fun = createFunctionObject(className, configFile);
    ExternalFunctionInvocationInstruction einst = new ExternalFunctionInvocationInstruction(inputs, outputs, fun, _baseDir, InputInfo.BinaryBlockInputInfo);
    verifyFunctionInputsOutputs(fun, inputs, outputs);
    _inst.add(einst);
}
Also used : ExternalFunctionInvocationInstruction(org.apache.sysml.udf.ExternalFunctionInvocationInstruction) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException) CPOperand(org.apache.sysml.runtime.instructions.cp.CPOperand) PackageFunction(org.apache.sysml.udf.PackageFunction)

Example 4 with PackageFunction

use of org.apache.sysml.udf.PackageFunction in project systemml by apache.

the class ExternalFunctionProgramBlock method createFunctionObject.

@SuppressWarnings("unchecked")
protected PackageFunction createFunctionObject(String className, String configFile) {
    try {
        // create instance of package function
        Class<Instruction> cla = (Class<Instruction>) Class.forName(className);
        Object o = cla.newInstance();
        if (!(o instanceof PackageFunction))
            throw new DMLRuntimeException(this.printBlockErrorLocation() + "Class is not of type PackageFunction");
        PackageFunction fun = (PackageFunction) o;
        // configure package function
        fun.setConfiguration(configFile);
        fun.setBaseDir(_baseDir);
        return fun;
    } catch (Exception e) {
        throw new DMLRuntimeException(this.printBlockErrorLocation() + "Error instantiating package function ", e);
    }
}
Also used : MatrixObject(org.apache.sysml.runtime.controlprogram.caching.MatrixObject) 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) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException)

Example 5 with PackageFunction

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

the class ExternalFunctionProgramBlock method createFunctionObject.

@SuppressWarnings("unchecked")
protected PackageFunction createFunctionObject(String className, String configFile) {
    try {
        // create instance of package function
        Class<Instruction> cla = (Class<Instruction>) Class.forName(className);
        Object o = cla.newInstance();
        if (!(o instanceof PackageFunction))
            throw new DMLRuntimeException(this.printBlockErrorLocation() + "Class is not of type PackageFunction");
        PackageFunction fun = (PackageFunction) o;
        // configure package function
        fun.setConfiguration(configFile);
        fun.setBaseDir(_baseDir);
        return fun;
    } catch (Exception e) {
        throw new DMLRuntimeException(this.printBlockErrorLocation() + "Error instantiating package function ", e);
    }
}
Also used : MatrixObject(org.apache.sysml.runtime.controlprogram.caching.MatrixObject) 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) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException)

Aggregations

DMLRuntimeException (org.apache.sysml.runtime.DMLRuntimeException)7 ExternalFunctionInvocationInstruction (org.apache.sysml.udf.ExternalFunctionInvocationInstruction)7 PackageFunction (org.apache.sysml.udf.PackageFunction)7 CPOperand (org.apache.sysml.runtime.instructions.cp.CPOperand)4 MatrixObject (org.apache.sysml.runtime.controlprogram.caching.MatrixObject)3 Instruction (org.apache.sysml.runtime.instructions.Instruction)3 MRJobInstruction (org.apache.sysml.runtime.instructions.MRJobInstruction)3 VariableCPInstruction (org.apache.sysml.runtime.instructions.cp.VariableCPInstruction)3 CacheException (org.apache.sysml.runtime.controlprogram.caching.CacheException)1 BooleanObject (org.apache.sysml.runtime.instructions.cp.BooleanObject)1 DoubleObject (org.apache.sysml.runtime.instructions.cp.DoubleObject)1 IntObject (org.apache.sysml.runtime.instructions.cp.IntObject)1 ScalarObject (org.apache.sysml.runtime.instructions.cp.ScalarObject)1 StringObject (org.apache.sysml.runtime.instructions.cp.StringObject)1 BinaryObject (org.apache.sysml.udf.BinaryObject)1