use of org.apache.sysml.hops.ReorgOp in project incubator-systemml by apache.
the class DMLTranslator method processParameterizedBuiltinFunctionExpression.
/**
* Construct Hops from parse tree : Process ParameterizedBuiltinFunction Expression in an
* assignment statement
*
* @param source parameterized built-in function
* @param target data identifier
* @param hops map of high-level operators
* @return high-level operator
* @throws ParseException if ParseException occurs
* @throws HopsException if HopsException occurs
*/
private Hop processParameterizedBuiltinFunctionExpression(ParameterizedBuiltinFunctionExpression source, DataIdentifier target, HashMap<String, Hop> hops) throws ParseException, HopsException {
// this expression has multiple "named" parameters
HashMap<String, Hop> paramHops = new HashMap<String, Hop>();
// -- construct hops for all input parameters
// -- store them in hashmap so that their "name"s are maintained
Hop pHop = null;
for (String paramName : source.getVarParams().keySet()) {
pHop = processExpression(source.getVarParam(paramName), null, hops);
paramHops.put(paramName, pHop);
}
Hop currBuiltinOp = null;
if (target == null) {
target = createTarget(source);
}
// construct hop based on opcode
switch(source.getOpCode()) {
case CDF:
case INVCDF:
case QNORM:
case QT:
case QF:
case QCHISQ:
case QEXP:
case PNORM:
case PT:
case PF:
case PCHISQ:
case PEXP:
currBuiltinOp = constructDfHop(target.getName(), target.getDataType(), target.getValueType(), source.getOpCode(), paramHops);
break;
case GROUPEDAGG:
currBuiltinOp = new ParameterizedBuiltinOp(target.getName(), target.getDataType(), target.getValueType(), ParamBuiltinOp.GROUPEDAGG, paramHops);
break;
case RMEMPTY:
currBuiltinOp = new ParameterizedBuiltinOp(target.getName(), target.getDataType(), target.getValueType(), ParamBuiltinOp.RMEMPTY, paramHops);
break;
case REPLACE:
currBuiltinOp = new ParameterizedBuiltinOp(target.getName(), target.getDataType(), target.getValueType(), ParamBuiltinOp.REPLACE, paramHops);
break;
case ORDER:
ArrayList<Hop> inputs = new ArrayList<Hop>();
inputs.add(paramHops.get("target"));
inputs.add(paramHops.get("by"));
inputs.add(paramHops.get("decreasing"));
inputs.add(paramHops.get("index.return"));
currBuiltinOp = new ReorgOp(target.getName(), target.getDataType(), target.getValueType(), ReOrgOp.SORT, inputs);
break;
case TRANSFORM:
currBuiltinOp = new ParameterizedBuiltinOp(target.getName(), target.getDataType(), target.getValueType(), ParamBuiltinOp.TRANSFORM, paramHops);
break;
case TRANSFORMAPPLY:
currBuiltinOp = new ParameterizedBuiltinOp(target.getName(), target.getDataType(), target.getValueType(), ParamBuiltinOp.TRANSFORMAPPLY, paramHops);
break;
case TRANSFORMDECODE:
currBuiltinOp = new ParameterizedBuiltinOp(target.getName(), target.getDataType(), target.getValueType(), ParamBuiltinOp.TRANSFORMDECODE, paramHops);
break;
case TRANSFORMMETA:
currBuiltinOp = new ParameterizedBuiltinOp(target.getName(), target.getDataType(), target.getValueType(), ParamBuiltinOp.TRANSFORMMETA, paramHops);
break;
case TOSTRING:
currBuiltinOp = new ParameterizedBuiltinOp(target.getName(), target.getDataType(), target.getValueType(), ParamBuiltinOp.TOSTRING, paramHops);
break;
default:
LOG.error(source.printErrorLocation() + "processParameterizedBuiltinFunctionExpression() -- Unknown operation: " + source.getOpCode());
throw new ParseException(source.printErrorLocation() + "processParameterizedBuiltinFunctionExpression() -- Unknown operation: " + source.getOpCode());
}
setIdentifierParams(currBuiltinOp, source.getOutput());
currBuiltinOp.setAllPositions(source.getBeginLine(), source.getBeginColumn(), source.getEndLine(), source.getEndColumn());
return currBuiltinOp;
}
use of org.apache.sysml.hops.ReorgOp in project incubator-systemml by apache.
the class RewriteAlgebraicSimplificationStatic method simplifyReverseOperation.
/**
* NOTE: this would be by definition a dynamic rewrite; however, we apply it as a static
* rewrite in order to apply it before splitting dags which would hide the table information
* if dimensions are not specified.
*
* @param parent parent high-level operator
* @param hi high-level operator
* @param pos position
* @return high-level operator
* @throws HopsException if HopsException occurs
*/
private Hop simplifyReverseOperation(Hop parent, Hop hi, int pos) throws HopsException {
if (hi instanceof AggBinaryOp && hi.getInput().get(0) instanceof TernaryOp) {
TernaryOp top = (TernaryOp) hi.getInput().get(0);
if (top.getOp() == OpOp3.CTABLE && HopRewriteUtils.isBasic1NSequence(top.getInput().get(0)) && HopRewriteUtils.isBasicN1Sequence(top.getInput().get(1)) && top.getInput().get(0).getDim1() == top.getInput().get(1).getDim1()) {
ReorgOp rop = HopRewriteUtils.createReorg(hi.getInput().get(1), ReOrgOp.REV);
HopRewriteUtils.replaceChildReference(parent, hi, rop, pos);
HopRewriteUtils.cleanupUnreferenced(hi, top);
hi = rop;
LOG.debug("Applied simplifyReverseOperation.");
}
}
return hi;
}
use of org.apache.sysml.hops.ReorgOp in project incubator-systemml by apache.
the class RewriteAlgebraicSimplificationDynamic method simplifyColSumsMVMult.
private Hop simplifyColSumsMVMult(Hop parent, Hop hi, int pos) throws HopsException {
//removed by other rewrite if unnecessary, i.e., if Y==t(Z)
if (hi instanceof AggUnaryOp) {
AggUnaryOp uhi = (AggUnaryOp) hi;
Hop input = uhi.getInput().get(0);
if (//colsums
uhi.getOp() == AggOp.SUM && uhi.getDirection() == Direction.Col && //b(*)
HopRewriteUtils.isBinary(input, OpOp2.MULT)) {
Hop left = input.getInput().get(0);
Hop right = input.getInput().get(1);
if (left.getDim1() > 1 && left.getDim2() > 1 && right.getDim1() > 1 && // MV (col vector)
right.getDim2() == 1) {
//create new operators
ReorgOp trans = HopRewriteUtils.createTranspose(right);
AggBinaryOp mmult = HopRewriteUtils.createMatrixMultiply(trans, left);
//relink new child
HopRewriteUtils.replaceChildReference(parent, hi, mmult, pos);
HopRewriteUtils.cleanupUnreferenced(uhi, input);
hi = mmult;
LOG.debug("Applied simplifyColSumsMVMult");
}
}
}
return hi;
}
use of org.apache.sysml.hops.ReorgOp in project incubator-systemml by apache.
the class HopRewriteUtils method createReorg.
public static ReorgOp createReorg(Hop input, ReOrgOp rop) {
ReorgOp transpose = new ReorgOp(input.getName(), input.getDataType(), input.getValueType(), rop, input);
transpose.setOutputBlocksizes(input.getRowsInBlock(), input.getColsInBlock());
copyLineNumbers(input, transpose);
transpose.refreshSizeInformation();
return transpose;
}
use of org.apache.sysml.hops.ReorgOp in project incubator-systemml by apache.
the class RewriteAlgebraicSimplificationDynamic method pushdownBinaryOperationOnDiag.
@SuppressWarnings("unchecked")
private Hop pushdownBinaryOperationOnDiag(Hop parent, Hop hi, int pos) {
//(2) in order to make the binary operation more efficient (dense vector vs sparse matrix)
if (HopRewriteUtils.isBinary(hi, OpOp2.MULT)) {
Hop left = hi.getInput().get(0);
Hop right = hi.getInput().get(1);
boolean applyLeft = false;
boolean applyRight = false;
//left input is diag
if (left instanceof ReorgOp && ((ReorgOp) left).getOp() == ReOrgOp.DIAG && //binary op only parent
left.getParent().size() == 1 && //col vector
left.getInput().get(0).getDim2() == 1 && right.getDataType() == DataType.SCALAR) {
applyLeft = true;
} else if (right instanceof ReorgOp && ((ReorgOp) right).getOp() == ReOrgOp.DIAG && //binary op only parent
right.getParent().size() == 1 && //col vector
right.getInput().get(0).getDim2() == 1 && left.getDataType() == DataType.SCALAR) {
applyRight = true;
}
//perform actual rewrite
if (applyLeft || applyRight) {
//remove all parent links to binary op (since we want to reorder
//we cannot just look at the current parent)
ArrayList<Hop> parents = (ArrayList<Hop>) hi.getParent().clone();
ArrayList<Integer> parentspos = new ArrayList<Integer>();
for (Hop lparent : parents) {
int lpos = HopRewriteUtils.getChildReferencePos(lparent, hi);
HopRewriteUtils.removeChildReferenceByPos(lparent, hi, lpos);
parentspos.add(lpos);
}
//rewire binop-diag-input into diag-binop-input
if (applyLeft) {
Hop input = left.getInput().get(0);
HopRewriteUtils.removeChildReferenceByPos(hi, left, 0);
HopRewriteUtils.removeChildReferenceByPos(left, input, 0);
HopRewriteUtils.addChildReference(left, hi, 0);
HopRewriteUtils.addChildReference(hi, input, 0);
hi.refreshSizeInformation();
hi = left;
} else if (applyRight) {
Hop input = right.getInput().get(0);
HopRewriteUtils.removeChildReferenceByPos(hi, right, 1);
HopRewriteUtils.removeChildReferenceByPos(right, input, 0);
HopRewriteUtils.addChildReference(right, hi, 0);
HopRewriteUtils.addChildReference(hi, input, 1);
hi.refreshSizeInformation();
hi = right;
}
//relink all parents to the diag operation
for (int i = 0; i < parents.size(); i++) {
Hop lparent = parents.get(i);
int lpos = parentspos.get(i);
HopRewriteUtils.addChildReference(lparent, hi, lpos);
}
LOG.debug("Applied pushdownBinaryOperationOnDiag.");
}
}
return hi;
}
Aggregations