use of org.apache.sysml.runtime.DMLScriptException in project incubator-systemml by apache.
the class DMLAppMaster method runApplicationMaster.
public void runApplicationMaster(String[] args) throws YarnException, IOException {
_conf = new YarnConfiguration();
//obtain application ID
String containerIdString = System.getenv(Environment.CONTAINER_ID.name());
ContainerId containerId = ConverterUtils.toContainerId(containerIdString);
_appId = containerId.getApplicationAttemptId().getApplicationId();
LOG.info("SystemML appplication master (applicationID: " + _appId + ")");
//initialize clients to ResourceManager
AMRMClient<ContainerRequest> rmClient = AMRMClient.createAMRMClient();
rmClient.init(_conf);
rmClient.start();
//register with ResourceManager
//host, port for rm communication
rmClient.registerApplicationMaster("", 0, "");
LOG.debug("Registered the SystemML application master with resource manager");
//start status reporter to ResourceManager
DMLAppMasterStatusReporter reporter = new DMLAppMasterStatusReporter(rmClient, 10000);
reporter.start();
LOG.debug("Started status reporter (heartbeat to resource manager)");
//set DMLscript app master context
DMLScript.setActiveAM();
//parse input arguments
String[] otherArgs = new GenericOptionsParser(_conf, args).getRemainingArgs();
//run SystemML CP
FinalApplicationStatus status = null;
try {
//core dml script execution (equivalent to non-AM runtime)
boolean success = DMLScript.executeScript(_conf, otherArgs);
if (success)
status = FinalApplicationStatus.SUCCEEDED;
else
status = FinalApplicationStatus.FAILED;
} catch (DMLScriptException ex) {
LOG.error(DMLYarnClient.APPMASTER_NAME + ": Failed to executed DML script due to stop call:\n\t" + ex.getMessage());
status = FinalApplicationStatus.FAILED;
writeMessageToHDFSWorkingDir(ex.getMessage());
} catch (Exception ex) {
LOG.error(DMLYarnClient.APPMASTER_NAME + ": Failed to executed DML script.", ex);
status = FinalApplicationStatus.FAILED;
} finally {
//stop periodic status reports
reporter.stopStatusReporter();
LOG.debug("Stopped status reporter");
//unregister resource manager client
rmClient.unregisterApplicationMaster(status, "", "");
LOG.debug("Unregistered the SystemML application master");
}
}
use of org.apache.sysml.runtime.DMLScriptException in project incubator-systemml by apache.
the class ScalarBuiltinCPInstruction method processInstruction.
@Override
public void processInstruction(ExecutionContext ec) throws DMLRuntimeException {
String opcode = getOpcode();
SimpleOperator dop = (SimpleOperator) _optr;
ScalarObject sores = null;
ScalarObject so = null;
//get the scalar input
so = ec.getScalarInput(input1.getName(), input1.getValueType(), input1.isLiteral());
//core execution
if (opcode.equalsIgnoreCase("print")) {
String outString = so.getLanguageSpecificStringValue();
// The flag will be set, for example, when SystemML is invoked in fenced mode from Jaql.
if (!DMLScript.suppressPrint2Stdout())
System.out.println(outString);
// String that is printed on stdout will be inserted into symbol table (dummy, not necessary!)
sores = new StringObject(outString);
} else if (opcode.equalsIgnoreCase("stop")) {
throw new DMLScriptException(so.getStringValue());
} else {
//Inputs for all builtins other than PRINT are treated as DOUBLE.
if (so instanceof IntObject && output.getValueType() == ValueType.INT) {
long rval = (long) dop.fn.execute(so.getLongValue());
sores = (ScalarObject) new IntObject(rval);
} else {
double rval = dop.fn.execute(so.getDoubleValue());
sores = (ScalarObject) new DoubleObject(rval);
}
}
ec.setScalarOutput(output.getName(), sores);
}
use of org.apache.sysml.runtime.DMLScriptException in project incubator-systemml by apache.
the class FunctionCallCPInstruction method processInstruction.
@Override
public void processInstruction(ExecutionContext ec) throws DMLRuntimeException {
if (LOG.isTraceEnabled()) {
LOG.trace("Executing instruction : " + this.toString());
}
// get the function program block (stored in the Program object)
FunctionProgramBlock fpb = ec.getProgram().getFunctionProgramBlock(_namespace, _functionName);
// sanity check number of function paramters
if (_boundInputParamNames.size() < fpb.getInputParams().size()) {
throw new DMLRuntimeException("Number of bound input parameters does not match the function signature " + "(" + _boundInputParamNames.size() + ", but " + fpb.getInputParams().size() + " expected)");
}
// create bindings to formal parameters for given function call
// These are the bindings passed to the FunctionProgramBlock for function execution
LocalVariableMap functionVariables = new LocalVariableMap();
for (int i = 0; i < fpb.getInputParams().size(); i++) {
DataIdentifier currFormalParam = fpb.getInputParams().get(i);
String currFormalParamName = currFormalParam.getName();
Data currFormalParamValue = null;
CPOperand operand = _boundInputParamOperands.get(i);
String varname = operand.getName();
//error handling non-existing variables
if (!operand.isLiteral() && !ec.containsVariable(varname)) {
throw new DMLRuntimeException("Input variable '" + varname + "' not existing on call of " + DMLProgram.constructFunctionKey(_namespace, _functionName) + " (line " + getLineNum() + ").");
}
//get input matrix/frame/scalar
currFormalParamValue = (operand.getDataType() != DataType.SCALAR) ? ec.getVariable(varname) : ec.getScalarInput(varname, operand.getValueType(), operand.isLiteral());
//graceful value type conversion for scalar inputs with wrong type
if (currFormalParamValue.getDataType() == DataType.SCALAR && currFormalParamValue.getValueType() != operand.getValueType()) {
ScalarObject so = (ScalarObject) currFormalParamValue;
currFormalParamValue = ScalarObjectFactory.createScalarObject(operand.getValueType(), so);
}
functionVariables.put(currFormalParamName, currFormalParamValue);
}
// Pin the input variables so that they do not get deleted
// from pb's symbol table at the end of execution of function
HashMap<String, Boolean> pinStatus = ec.pinVariables(_boundInputParamNames);
// Create a symbol table under a new execution context for the function invocation,
// and copy the function arguments into the created table.
ExecutionContext fn_ec = ExecutionContextFactory.createContext(false, ec.getProgram());
if (DMLScript.USE_ACCELERATOR) {
fn_ec.setGPUContext(ec.getGPUContext());
ec.setGPUContext(null);
fn_ec.getGPUContext().initializeThread();
}
fn_ec.setVariables(functionVariables);
// execute the function block
try {
fpb._functionName = this._functionName;
fpb._namespace = this._namespace;
fpb.execute(fn_ec);
} catch (DMLScriptException e) {
throw e;
} catch (Exception e) {
String fname = DMLProgram.constructFunctionKey(_namespace, _functionName);
throw new DMLRuntimeException("error executing function " + fname, e);
}
LocalVariableMap retVars = fn_ec.getVariables();
// cleanup all returned variables w/o binding
Collection<String> retVarnames = new LinkedList<String>(retVars.keySet());
HashSet<String> probeVars = new HashSet<String>();
for (DataIdentifier di : fpb.getOutputParams()) probeVars.add(di.getName());
for (String var : retVarnames) {
if (//cleanup candidate
!probeVars.contains(var)) {
Data dat = fn_ec.removeVariable(var);
if (dat != null && dat instanceof MatrixObject)
fn_ec.cleanupMatrixObject((MatrixObject) dat);
}
}
// Unpin the pinned variables
ec.unpinVariables(_boundInputParamNames, pinStatus);
if (DMLScript.USE_ACCELERATOR) {
ec.setGPUContext(fn_ec.getGPUContext());
fn_ec.setGPUContext(null);
ec.getGPUContext().initializeThread();
}
// add the updated binding for each return variable to the variables in original symbol table
for (int i = 0; i < fpb.getOutputParams().size(); i++) {
String boundVarName = _boundOutputParamNames.get(i);
Data boundValue = retVars.get(fpb.getOutputParams().get(i).getName());
if (boundValue == null)
throw new DMLRuntimeException(boundVarName + " was not assigned a return value");
//cleanup existing data bound to output variable name
Data exdata = ec.removeVariable(boundVarName);
if (exdata != null && exdata instanceof MatrixObject && exdata != boundValue) {
ec.cleanupMatrixObject((MatrixObject) exdata);
}
//add/replace data in symbol table
if (boundValue instanceof MatrixObject)
((MatrixObject) boundValue).setVarName(boundVarName);
ec.setVariable(boundVarName, boundValue);
}
}
use of org.apache.sysml.runtime.DMLScriptException in project incubator-systemml by apache.
the class DMLScript method main.
/**
*
* @param args command-line arguments
* @throws IOException if an IOException occurs
* @throws DMLException if a DMLException occurs
*/
public static void main(String[] args) throws IOException, DMLException {
Configuration conf = new Configuration(ConfigurationManager.getCachedJobConf());
String[] otherArgs = new GenericOptionsParser(conf, args).getRemainingArgs();
try {
DMLScript.executeScript(conf, otherArgs);
} catch (ParseException pe) {
System.err.println(pe.getMessage());
} catch (DMLScriptException e) {
// In case of DMLScriptException, simply print the error message.
System.err.println(e.getMessage());
}
}
use of org.apache.sysml.runtime.DMLScriptException in project incubator-systemml by apache.
the class FunctionProgramBlock method execute.
@Override
public void execute(ExecutionContext ec) throws DMLRuntimeException {
//dynamically recompile entire function body (according to function inputs)
try {
if (ConfigurationManager.isDynamicRecompilation() && isRecompileOnce() && ParForProgramBlock.RESET_RECOMPILATION_FLAGs) {
long t0 = DMLScript.STATISTICS ? System.nanoTime() : 0;
//note: it is important to reset the recompilation flags here
// (1) it is safe to reset recompilation flags because a 'recompile_once'
// function will be recompiled for every execution.
// (2) without reset, there would be no benefit in recompiling the entire function
LocalVariableMap tmp = (LocalVariableMap) ec.getVariables().clone();
Recompiler.recompileProgramBlockHierarchy(_childBlocks, tmp, _tid, true);
if (DMLScript.STATISTICS) {
long t1 = System.nanoTime();
Statistics.incrementFunRecompileTime(t1 - t0);
Statistics.incrementFunRecompiles();
}
}
} catch (Exception ex) {
throw new DMLRuntimeException("Error recompiling function body.", ex);
}
// for each program block
try {
for (int i = 0; i < this._childBlocks.size(); i++) {
ec.updateDebugState(i);
_childBlocks.get(i).execute(ec);
}
} catch (DMLScriptException e) {
throw e;
} catch (Exception e) {
throw new DMLRuntimeException(this.printBlockErrorLocation() + "Error evaluating function program block", e);
}
// check return values
checkOutputParameters(ec.getVariables());
}
Aggregations