use of org.apache.sysml.parser.Expression.DataType in project incubator-systemml by apache.
the class HopRewriteUtils method createUnary.
public static UnaryOp createUnary(Hop input, OpOp1 type) {
DataType dt = (type == OpOp1.CAST_AS_SCALAR) ? DataType.SCALAR : (type == OpOp1.CAST_AS_MATRIX) ? DataType.MATRIX : input.getDataType();
ValueType vt = (type == OpOp1.CAST_AS_MATRIX) ? ValueType.DOUBLE : input.getValueType();
UnaryOp unary = new UnaryOp(input.getName(), dt, vt, type, input);
unary.setOutputBlocksizes(input.getRowsInBlock(), input.getColsInBlock());
if (type == OpOp1.CAST_AS_SCALAR || type == OpOp1.CAST_AS_MATRIX) {
int dim = (type == OpOp1.CAST_AS_SCALAR) ? 0 : 1;
int blksz = (type == OpOp1.CAST_AS_SCALAR) ? 0 : ConfigurationManager.getBlocksize();
setOutputParameters(unary, dim, dim, blksz, blksz, -1);
}
copyLineNumbers(input, unary);
unary.refreshSizeInformation();
return unary;
}
use of org.apache.sysml.parser.Expression.DataType in project incubator-systemml by apache.
the class ParForStatementBlock method rCheckCandidates.
/**
* This method recursively checks a candidate against StatementBlocks for anti, data and output dependencies.
* A LanguageException is raised if at least one dependency is found, where it is guaranteed that no false negatives
* (undetected dependency) but potentially false positives (misdetected dependency) can appear.
*
* @param c candidate
* @param cdt candidate data type
* @param asb list of statement blocks
* @param sCount statement count
* @param dep array of boolean potential output dependencies
*/
private void rCheckCandidates(Candidate c, DataType cdt, ArrayList<StatementBlock> asb, Integer sCount, boolean[] dep) {
// check candidate only (output dependency if scalar or constant matrix subscript)
if (cdt == DataType.SCALAR || // dat2 checked for other candidate
cdt == DataType.OBJECT) {
// every write to a scalar or complete data object is an output dependency
dep[0] = true;
if (ABORT_ON_FIRST_DEPENDENCY)
return;
} else if (cdt == DataType.MATRIX) {
if (runConstantCheck(c._dat) && !c._isAccum) {
if (LOG.isTraceEnabled())
LOG.trace("PARFOR: Possible output dependency detected via constant self-check: var '" + c._var + "'.");
dep[0] = true;
if (ABORT_ON_FIRST_DEPENDENCY)
return;
}
}
// check candidate against all statements
for (StatementBlock sb : asb) for (Statement s : sb._statements) {
sCount++;
if (s instanceof ForStatement) {
// incl parfor
// despite separate dependency analysis for each nested parfor, we need to
// recursively check nested parfor as well in order to ensure correcteness
// of constantChecks with regard to outer indexes
rCheckCandidates(c, cdt, ((ForStatement) s).getBody(), sCount, dep);
} else if (s instanceof WhileStatement) {
rCheckCandidates(c, cdt, ((WhileStatement) s).getBody(), sCount, dep);
} else if (s instanceof IfStatement) {
rCheckCandidates(c, cdt, ((IfStatement) s).getIfBody(), sCount, dep);
rCheckCandidates(c, cdt, ((IfStatement) s).getElseBody(), sCount, dep);
} else if (s instanceof FunctionStatement) {
rCheckCandidates(c, cdt, ((FunctionStatement) s).getBody(), sCount, dep);
} else {
// CHECK output dependencies
List<DataIdentifier> datsUpdated = getDataIdentifiers(s, true);
if (datsUpdated != null) {
for (DataIdentifier write : datsUpdated) {
if (!c._var.equals(write.getName()))
continue;
if (cdt != DataType.MATRIX) {
// cannot infer type, need to exit (conservative approach)
throw new LanguageException("PARFOR loop dependency analysis: " + "cannot check for dependencies due to unknown datatype of var '" + c._var + "'.");
}
DataIdentifier dat2 = write;
// skip self-check
if (c._dat == dat2)
continue;
if (runEqualsCheck(c._dat, dat2)) {
// intra-iteration output dependencies (same index function) are OK
} else if (runBanerjeeGCDTest(c._dat, dat2)) {
LOG.trace("PARFOR: Possible output dependency detected via GCD/Banerjee: var '" + write + "'.");
dep[0] = true;
if (ABORT_ON_FIRST_DEPENDENCY)
return;
}
}
}
List<DataIdentifier> datsRead = getDataIdentifiers(s, false);
if (datsRead == null)
continue;
// check data and anti dependencies
for (DataIdentifier read : datsRead) {
if (!c._var.equals(read.getName()))
continue;
DataIdentifier dat2 = read;
DataType dat2dt = _vsParent.getVariables().get(read.getName()).getDataType();
if (cdt == DataType.SCALAR || cdt == DataType.OBJECT || dat2dt == DataType.SCALAR || dat2dt == DataType.OBJECT) {
// every write, read combination involving a scalar is a data dependency
dep[1] = true;
if (ABORT_ON_FIRST_DEPENDENCY)
return;
} else if (cdt == DataType.MATRIX && dat2dt == DataType.MATRIX) {
boolean invalid = false;
if (runEqualsCheck(c._dat, dat2))
// read/write on same index, and not constant (checked for output) is OK
invalid = runConstantCheck(dat2);
else if (runBanerjeeGCDTest(c._dat, dat2))
invalid = true;
else if (!(dat2 instanceof IndexedIdentifier))
// non-indexed access to candidate result variable -> always a dependency
invalid = true;
if (invalid) {
LOG.trace("PARFOR: Possible data/anti dependency detected via GCD/Banerjee: var '" + read + "'.");
dep[1] = true;
dep[2] = true;
if (ABORT_ON_FIRST_DEPENDENCY)
return;
}
} else {
// cannot infer type, need to exit (conservative approach)
throw new LanguageException("PARFOR loop dependency analysis: " + "cannot check for dependencies due to unknown datatype of var '" + c._var + "'.");
}
}
}
}
}
use of org.apache.sysml.parser.Expression.DataType in project incubator-systemml by apache.
the class ParForProgramBlock method createEmptyUnscopedVariables.
/**
* Create empty matrix objects and scalars for all unscoped vars
* (created within the parfor).
*
* NOTE: parfor gives no guarantees on the values of those objects - hence
* we return -1 for sclars and empty matrix objects.
*
* @param out local variable map
* @param sb statement block
*/
private static void createEmptyUnscopedVariables(LocalVariableMap out, StatementBlock sb) {
VariableSet updated = sb.variablesUpdated();
VariableSet livein = sb.liveIn();
// for all vars IN <updated> AND NOT IN <livein>
for (String var : updated.getVariableNames()) if (!livein.containsVariable(var)) {
// create empty output
DataIdentifier dat = updated.getVariable(var);
DataType datatype = dat.getDataType();
ValueType valuetype = dat.getValueType();
Data dataObj = null;
switch(datatype) {
case SCALAR:
switch(valuetype) {
case BOOLEAN:
dataObj = new BooleanObject(false);
break;
case INT:
dataObj = new IntObject(-1);
break;
case DOUBLE:
dataObj = new DoubleObject(-1d);
break;
case STRING:
dataObj = new StringObject("-1");
break;
default:
throw new DMLRuntimeException("Value type not supported: " + valuetype);
}
break;
case MATRIX:
case FRAME:
// because metadata (e.g., outputinfo) not known at this place.
break;
case UNKNOWN:
break;
default:
throw new DMLRuntimeException("Data type not supported: " + datatype);
}
if (dataObj != null)
out.put(var, dataObj);
}
}
use of org.apache.sysml.parser.Expression.DataType in project incubator-systemml by apache.
the class GenerateClassesForMLContext method getParamTypeAsString.
/**
* Obtain a string representation of a parameter type, where a Matrix or
* Frame is represented by its full class name.
*
* @param param
* the function parameter
* @return string representation of a parameter type
*/
public static String getParamTypeAsString(DataIdentifier param) {
DataType dt = param.getDataType();
ValueType vt = param.getValueType();
if ((dt == DataType.SCALAR) && (vt == ValueType.INT)) {
return "long";
} else if ((dt == DataType.SCALAR) && (vt == ValueType.DOUBLE)) {
return "double";
} else if ((dt == DataType.SCALAR) && (vt == ValueType.BOOLEAN)) {
return "boolean";
} else if ((dt == DataType.SCALAR) && (vt == ValueType.STRING)) {
return "String";
} else if (dt == DataType.MATRIX) {
return "org.apache.sysml.api.mlcontext.Matrix";
} else if (dt == DataType.FRAME) {
return "org.apache.sysml.api.mlcontext.Frame";
}
return null;
}
use of org.apache.sysml.parser.Expression.DataType in project incubator-systemml by apache.
the class GenerateClassesForMLContext method getSimpleParamTypeAsString.
/**
* Obtain a string representation of a parameter type, where a Matrix or
* Frame is represented by its simple class name.
*
* @param param
* the function parameter
* @return string representation of a parameter type
*/
public static String getSimpleParamTypeAsString(DataIdentifier param) {
DataType dt = param.getDataType();
ValueType vt = param.getValueType();
if ((dt == DataType.SCALAR) && (vt == ValueType.INT)) {
return "long";
} else if ((dt == DataType.SCALAR) && (vt == ValueType.DOUBLE)) {
return "double";
} else if ((dt == DataType.SCALAR) && (vt == ValueType.BOOLEAN)) {
return "boolean";
} else if ((dt == DataType.SCALAR) && (vt == ValueType.STRING)) {
return "String";
} else if (dt == DataType.MATRIX) {
return "Matrix";
} else if (dt == DataType.FRAME) {
return "Frame";
}
return null;
}
Aggregations