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