Search in sources :

Example 11 with HopsException

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

the class RewriteMatrixMultChainOptimization method clearLinksWithinChain.

private static void clearLinksWithinChain(Hop hop, ArrayList<Hop> operators) {
    for (int i = 0; i < operators.size(); i++) {
        Hop op = operators.get(i);
        if (op.getInput().size() != 2 || (i != 0 && op.getParent().size() > 1)) {
            throw new HopsException(hop.printErrorLocation() + "Unexpected error while applying optimization on matrix-mult chain. \n");
        }
        Hop input1 = op.getInput().get(0);
        Hop input2 = op.getInput().get(1);
        op.getInput().clear();
        input1.getParent().remove(op);
        input2.getParent().remove(op);
    }
}
Also used : Hop(org.apache.sysml.hops.Hop) HopsException(org.apache.sysml.hops.HopsException)

Example 12 with HopsException

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

the class RewriteSplitDagUnknownCSVRead method rewriteStatementBlock.

@Override
public List<StatementBlock> rewriteStatementBlock(StatementBlock sb, ProgramRewriteStatus state) {
    // DAG splits not required for forced single node
    if (DMLScript.rtplatform == RUNTIME_PLATFORM.SINGLE_NODE || !HopRewriteUtils.isLastLevelStatementBlock(sb))
        return Arrays.asList(sb);
    ArrayList<StatementBlock> ret = new ArrayList<>();
    // collect all unknown csv reads hops
    ArrayList<Hop> cand = new ArrayList<>();
    collectCSVReadHopsUnknownSize(sb.getHops(), cand);
    // split hop dag on demand
    if (!cand.isEmpty()) {
        try {
            // duplicate sb incl live variable sets
            StatementBlock sb1 = new StatementBlock();
            sb1.setDMLProg(sb.getDMLProg());
            sb1.setParseInfo(sb);
            sb1.setLiveIn(new VariableSet());
            sb1.setLiveOut(new VariableSet());
            // move csv reads incl reblock to new statement block
            // (and replace original persistent read with transient read)
            ArrayList<Hop> sb1hops = new ArrayList<>();
            for (Hop reblock : cand) {
                long rlen = reblock.getDim1();
                long clen = reblock.getDim2();
                long nnz = reblock.getNnz();
                UpdateType update = reblock.getUpdateType();
                int brlen = reblock.getRowsInBlock();
                int bclen = reblock.getColsInBlock();
                // (otherwise, for instance, literal ops are shared across dags)
                for (int i = 0; i < reblock.getInput().size(); i++) if (reblock.getInput().get(i) instanceof LiteralOp)
                    HopRewriteUtils.replaceChildReference(reblock, reblock.getInput().get(i), new LiteralOp((LiteralOp) reblock.getInput().get(i)));
                // create new transient read
                DataOp tread = new DataOp(reblock.getName(), reblock.getDataType(), reblock.getValueType(), DataOpTypes.TRANSIENTREAD, null, rlen, clen, nnz, update, brlen, bclen);
                HopRewriteUtils.copyLineNumbers(reblock, tread);
                // replace reblock with transient read
                ArrayList<Hop> parents = new ArrayList<>(reblock.getParent());
                for (int i = 0; i < parents.size(); i++) {
                    Hop parent = parents.get(i);
                    HopRewriteUtils.replaceChildReference(parent, reblock, tread);
                }
                // add reblock sub dag to first statement block
                DataOp twrite = new DataOp(reblock.getName(), reblock.getDataType(), reblock.getValueType(), reblock, DataOpTypes.TRANSIENTWRITE, null);
                twrite.setOutputParams(rlen, clen, nnz, update, brlen, bclen);
                HopRewriteUtils.copyLineNumbers(reblock, twrite);
                sb1hops.add(twrite);
                // update live in and out of new statement block (for piggybacking)
                DataIdentifier diVar = sb.variablesRead().getVariable(reblock.getName());
                if (diVar != null) {
                    // var read should always exist because persistent read
                    sb1.liveOut().addVariable(reblock.getName(), new DataIdentifier(diVar));
                    sb.liveIn().addVariable(reblock.getName(), new DataIdentifier(diVar));
                }
            }
            sb1.setHops(sb1hops);
            sb1.updateRecompilationFlag();
            // statement block with csv reblocks
            ret.add(sb1);
            // statement block with remaining hops
            ret.add(sb);
            // avoid later merge by other rewrites
            sb.setSplitDag(true);
        } catch (Exception ex) {
            throw new HopsException("Failed to split hops dag for csv read with unknown size.", ex);
        }
        LOG.debug("Applied splitDagUnknownCSVRead.");
    } else // keep original hop dag
    {
        ret.add(sb);
    }
    return ret;
}
Also used : DataIdentifier(org.apache.sysml.parser.DataIdentifier) ArrayList(java.util.ArrayList) Hop(org.apache.sysml.hops.Hop) HopsException(org.apache.sysml.hops.HopsException) UpdateType(org.apache.sysml.runtime.controlprogram.caching.MatrixObject.UpdateType) HopsException(org.apache.sysml.hops.HopsException) VariableSet(org.apache.sysml.parser.VariableSet) LiteralOp(org.apache.sysml.hops.LiteralOp) DataOp(org.apache.sysml.hops.DataOp) StatementBlock(org.apache.sysml.parser.StatementBlock)

Example 13 with HopsException

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

the class IPAPassApplyStaticHopRewrites method rewriteProgram.

@Override
public void rewriteProgram(DMLProgram prog, FunctionCallGraph fgraph, FunctionCallSizeInfo fcallSizes) {
    try {
        // construct rewriter w/o checkpoint injection to avoid redundancy
        ProgramRewriter rewriter = new ProgramRewriter(true, false);
        rewriter.removeStatementBlockRewrite(RewriteInjectSparkLoopCheckpointing.class);
        // rewrite program hop dags and statement blocks
        // rewrite and split
        rewriter.rewriteProgramHopDAGs(prog, true);
    } catch (LanguageException ex) {
        throw new HopsException(ex);
    }
}
Also used : LanguageException(org.apache.sysml.parser.LanguageException) ProgramRewriter(org.apache.sysml.hops.rewrite.ProgramRewriter) HopsException(org.apache.sysml.hops.HopsException)

Example 14 with HopsException

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

the class IPAPassPropagateReplaceLiterals method replaceLiterals.

private static void replaceLiterals(ArrayList<Hop> roots, LocalVariableMap constants) {
    if (roots == null)
        return;
    try {
        Hop.resetVisitStatus(roots);
        for (Hop root : roots) Recompiler.rReplaceLiterals(root, constants, true);
        Hop.resetVisitStatus(roots);
    } catch (Exception ex) {
        throw new HopsException(ex);
    }
}
Also used : Hop(org.apache.sysml.hops.Hop) HopsException(org.apache.sysml.hops.HopsException) HopsException(org.apache.sysml.hops.HopsException)

Example 15 with HopsException

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

the class IPAPassPropagateReplaceLiterals method replaceLiterals.

private static void replaceLiterals(Hop root, LocalVariableMap constants) {
    if (root == null)
        return;
    try {
        root.resetVisitStatus();
        Recompiler.rReplaceLiterals(root, constants, true);
        root.resetVisitStatus();
    } catch (Exception ex) {
        throw new HopsException(ex);
    }
}
Also used : HopsException(org.apache.sysml.hops.HopsException) HopsException(org.apache.sysml.hops.HopsException)

Aggregations

HopsException (org.apache.sysml.hops.HopsException)28 Hop (org.apache.sysml.hops.Hop)14 ArrayList (java.util.ArrayList)7 DataOp (org.apache.sysml.hops.DataOp)7 DMLRuntimeException (org.apache.sysml.runtime.DMLRuntimeException)7 HashMap (java.util.HashMap)5 LiteralOp (org.apache.sysml.hops.LiteralOp)5 StatementBlock (org.apache.sysml.parser.StatementBlock)5 AggUnaryOp (org.apache.sysml.hops.AggUnaryOp)4 UnaryOp (org.apache.sysml.hops.UnaryOp)4 DataIdentifier (org.apache.sysml.parser.DataIdentifier)4 MatrixObject (org.apache.sysml.runtime.controlprogram.caching.MatrixObject)4 HashSet (java.util.HashSet)3 ForStatementBlock (org.apache.sysml.parser.ForStatementBlock)3 FunctionStatementBlock (org.apache.sysml.parser.FunctionStatementBlock)3 IfStatementBlock (org.apache.sysml.parser.IfStatementBlock)3 LanguageException (org.apache.sysml.parser.LanguageException)3 WhileStatementBlock (org.apache.sysml.parser.WhileStatementBlock)3 LocalVariableMap (org.apache.sysml.runtime.controlprogram.LocalVariableMap)3 ProgramBlock (org.apache.sysml.runtime.controlprogram.ProgramBlock)3