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());
}
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);
}
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);
}
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);
}
}
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);
}
}
Aggregations