Search in sources :

Example 11 with LiteralOp

use of org.apache.sysml.hops.LiteralOp in project incubator-systemml by apache.

the class IPAPassInlineFunctions method rCountOperators.

private static int rCountOperators(Hop current) {
    if (current.isVisited())
        return 0;
    int count = !(current instanceof DataOp || current instanceof LiteralOp) ? 1 : 0;
    for (Hop c : current.getInput()) count += rCountOperators(c);
    current.setVisited();
    return count;
}
Also used : Hop(org.apache.sysml.hops.Hop) LiteralOp(org.apache.sysml.hops.LiteralOp) DataOp(org.apache.sysml.hops.DataOp)

Example 12 with LiteralOp

use of org.apache.sysml.hops.LiteralOp in project incubator-systemml by apache.

the class IPAPassRemoveConstantBinaryOps method rRemoveConstantBinaryOp.

private static void rRemoveConstantBinaryOp(Hop hop, HashMap<String, Hop> mOnes) {
    if (hop.isVisited())
        return;
    if (hop instanceof BinaryOp && ((BinaryOp) hop).getOp() == OpOp2.MULT && !((BinaryOp) hop).isOuterVectorOperator() && hop.getInput().get(0).getDataType() == DataType.MATRIX && hop.getInput().get(1) instanceof DataOp && mOnes.containsKey(hop.getInput().get(1).getName())) {
        // replace matrix of ones with literal 1 (later on removed by
        // algebraic simplification rewrites; otherwise more complex
        // recursive processing of childs and rewiring required)
        HopRewriteUtils.removeChildReferenceByPos(hop, hop.getInput().get(1), 1);
        HopRewriteUtils.addChildReference(hop, new LiteralOp(1), 1);
    }
    // recursively process child nodes
    for (Hop c : hop.getInput()) rRemoveConstantBinaryOp(c, mOnes);
    hop.setVisited();
}
Also used : Hop(org.apache.sysml.hops.Hop) LiteralOp(org.apache.sysml.hops.LiteralOp) DataOp(org.apache.sysml.hops.DataOp) BinaryOp(org.apache.sysml.hops.BinaryOp)

Example 13 with LiteralOp

use of org.apache.sysml.hops.LiteralOp in project incubator-systemml by apache.

the class InterProceduralAnalysis method extractExternalFunctionCallReturnStatistics.

private static void extractExternalFunctionCallReturnStatistics(ExternalFunctionStatement fstmt, FunctionOp fop, LocalVariableMap callVars) {
    String className = fstmt.getOtherParams().get(ExternalFunctionStatement.CLASS_NAME);
    if (className.equals(OrderWrapper.class.getName())) {
        Hop input = fop.getInput().get(0);
        long lnnz = className.equals(OrderWrapper.class.getName()) ? input.getNnz() : -1;
        MatrixObject moOut = createOutputMatrix(input.getDim1(), input.getDim2(), lnnz);
        callVars.put(fop.getOutputVariableNames()[0], moOut);
    } else if (className.equals(DynamicReadMatrixCP.class.getName()) || className.equals(DynamicReadMatrixRcCP.class.getName())) {
        // rows
        Hop input1 = fop.getInput().get(1);
        // cols
        Hop input2 = fop.getInput().get(2);
        if (input1 instanceof LiteralOp && input2 instanceof LiteralOp)
            callVars.put(fop.getOutputVariableNames()[0], createOutputMatrix(((LiteralOp) input1).getLongValue(), ((LiteralOp) input2).getLongValue(), -1));
    } else {
        extractFunctionCallUnknownReturnStatistics(fstmt, fop, callVars);
    }
}
Also used : MatrixObject(org.apache.sysml.runtime.controlprogram.caching.MatrixObject) OrderWrapper(org.apache.sysml.udf.lib.OrderWrapper) DynamicReadMatrixRcCP(org.apache.sysml.udf.lib.DynamicReadMatrixRcCP) Hop(org.apache.sysml.hops.Hop) DynamicReadMatrixCP(org.apache.sysml.udf.lib.DynamicReadMatrixCP) LiteralOp(org.apache.sysml.hops.LiteralOp)

Example 14 with LiteralOp

use of org.apache.sysml.hops.LiteralOp in project incubator-systemml by apache.

the class LiteralReplacement method replaceLiteralValueTypeCastLiteral.

private static LiteralOp replaceLiteralValueTypeCastLiteral(Hop c, LocalVariableMap vars) {
    LiteralOp ret = null;
    // rewrite in same dag) - literal replacement
    if (c instanceof UnaryOp && (((UnaryOp) c).getOp() == OpOp1.CAST_AS_DOUBLE || ((UnaryOp) c).getOp() == OpOp1.CAST_AS_INT || ((UnaryOp) c).getOp() == OpOp1.CAST_AS_BOOLEAN) && c.getInput().get(0) instanceof LiteralOp) {
        LiteralOp sdat = (LiteralOp) c.getInput().get(0);
        UnaryOp cast = (UnaryOp) c;
        try {
            switch(cast.getOp()) {
                case CAST_AS_INT:
                    long ival = HopRewriteUtils.getIntValue(sdat);
                    ret = new LiteralOp(ival);
                    break;
                case CAST_AS_DOUBLE:
                    double dval = HopRewriteUtils.getDoubleValue(sdat);
                    ret = new LiteralOp(dval);
                    break;
                case CAST_AS_BOOLEAN:
                    boolean bval = HopRewriteUtils.getBooleanValue(sdat);
                    ret = new LiteralOp(bval);
                    break;
                default:
            }
        } catch (HopsException ex) {
            throw new DMLRuntimeException(ex);
        }
    }
    return ret;
}
Also used : AggUnaryOp(org.apache.sysml.hops.AggUnaryOp) UnaryOp(org.apache.sysml.hops.UnaryOp) HopsException(org.apache.sysml.hops.HopsException) LiteralOp(org.apache.sysml.hops.LiteralOp) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException)

Example 15 with LiteralOp

use of org.apache.sysml.hops.LiteralOp in project incubator-systemml by apache.

the class LiteralReplacement method replaceLiteralValueTypeCastScalarRead.

private static LiteralOp replaceLiteralValueTypeCastScalarRead(Hop c, LocalVariableMap vars) {
    LiteralOp ret = null;
    // as.double/as.integer/as.boolean over scalar read - literal replacement
    if (c instanceof UnaryOp && (((UnaryOp) c).getOp() == OpOp1.CAST_AS_DOUBLE || ((UnaryOp) c).getOp() == OpOp1.CAST_AS_INT || ((UnaryOp) c).getOp() == OpOp1.CAST_AS_BOOLEAN) && c.getInput().get(0) instanceof DataOp && c.getDataType() == DataType.SCALAR) {
        Data dat = vars.get(c.getInput().get(0).getName());
        if (// required for selective constant propagation
        dat != null) {
            ScalarObject sdat = (ScalarObject) dat;
            UnaryOp cast = (UnaryOp) c;
            switch(cast.getOp()) {
                case CAST_AS_INT:
                    ret = new LiteralOp(sdat.getLongValue());
                    break;
                case CAST_AS_DOUBLE:
                    ret = new LiteralOp(sdat.getDoubleValue());
                    break;
                case CAST_AS_BOOLEAN:
                    ret = new LiteralOp(sdat.getBooleanValue());
                    break;
                default:
            }
        }
    }
    return ret;
}
Also used : ScalarObject(org.apache.sysml.runtime.instructions.cp.ScalarObject) AggUnaryOp(org.apache.sysml.hops.AggUnaryOp) UnaryOp(org.apache.sysml.hops.UnaryOp) Data(org.apache.sysml.runtime.instructions.cp.Data) LiteralOp(org.apache.sysml.hops.LiteralOp) DataOp(org.apache.sysml.hops.DataOp)

Aggregations

LiteralOp (org.apache.sysml.hops.LiteralOp)102 Hop (org.apache.sysml.hops.Hop)88 AggUnaryOp (org.apache.sysml.hops.AggUnaryOp)30 BinaryOp (org.apache.sysml.hops.BinaryOp)27 AggBinaryOp (org.apache.sysml.hops.AggBinaryOp)25 UnaryOp (org.apache.sysml.hops.UnaryOp)24 DataOp (org.apache.sysml.hops.DataOp)23 IndexingOp (org.apache.sysml.hops.IndexingOp)17 ArrayList (java.util.ArrayList)13 DataGenOp (org.apache.sysml.hops.DataGenOp)13 LeftIndexingOp (org.apache.sysml.hops.LeftIndexingOp)12 HashMap (java.util.HashMap)11 DataIdentifier (org.apache.sysml.parser.DataIdentifier)10 ReorgOp (org.apache.sysml.hops.ReorgOp)9 MatrixObject (org.apache.sysml.runtime.controlprogram.caching.MatrixObject)9 HopsException (org.apache.sysml.hops.HopsException)8 ParameterizedBuiltinOp (org.apache.sysml.hops.ParameterizedBuiltinOp)8 StatementBlock (org.apache.sysml.parser.StatementBlock)8 TernaryOp (org.apache.sysml.hops.TernaryOp)7 CNodeData (org.apache.sysml.hops.codegen.cplan.CNodeData)6