Search in sources :

Example 1 with DataGenOp

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

the class OptimizerRuleBased method rIsInLoop.

/* 	
	 * This will check if candidate LeftIndexingOp are in loop (while, for or parfor).
	 * 
	 * @param pn:				OpNode of parfor loop
	 * @param uipCandHopHM:		Hashmap of UIPCandidateHop with name as a key.		
	 * @throws DMLRuntimeException
	 */
private void rIsInLoop(OptNode pn, HashMap<String, ArrayList<UIPCandidateHop>> uipCandHopHM, boolean bInLoop) throws DMLRuntimeException {
    if (!pn.isLeaf()) {
        ProgramBlock pb = (ProgramBlock) OptTreeConverter.getAbstractPlanMapping().getMappedProg(pn.getID())[1];
        VariableSet varUpdated = pb.getStatementBlock().variablesUpdated();
        boolean bUIPCandHopUpdated = false;
        for (Entry<String, ArrayList<UIPCandidateHop>> entry : uipCandHopHM.entrySet()) {
            String uipCandHopID = entry.getKey();
            if (varUpdated.containsVariable(uipCandHopID)) {
                bUIPCandHopUpdated = true;
                break;
            }
        }
        // As none of the UIP candidates updated in this DAG, no need for further processing within this DAG
        if (!bUIPCandHopUpdated)
            return;
        boolean bLoop = false;
        if (bInLoop || pb instanceof WhileProgramBlock || (pb instanceof ParForProgramBlock && ((ParForProgramBlock) pb).getDegreeOfParallelism() == 1) || (pb instanceof ForProgramBlock && !(pb instanceof ParForProgramBlock)))
            bLoop = true;
        for (OptNode optNode : pn.getChilds()) {
            rIsInLoop(optNode, uipCandHopHM, bLoop);
        }
    } else {
        Hop hop = (Hop) OptTreeConverter.getAbstractPlanMapping().getMappedHop(pn.getID());
        for (Entry<String, ArrayList<UIPCandidateHop>> entry : uipCandHopHM.entrySet()) {
            ArrayList<UIPCandidateHop> uipCandHopList = entry.getValue();
            if (uipCandHopList != null) {
                for (UIPCandidateHop uipCandHop : uipCandHopList) {
                    //Identify where intermediate object has been defined.
                    if (hop instanceof DataGenOp && hop.getName().equals(uipCandHop.getLixHop().getName())) {
                        uipCandHop.setHop(hop);
                        uipCandHop.setLocation(hop.getBeginLine());
                        uipCandHop.setIntermediate(true);
                    }
                    //Update if candiate hop defined outside this loop, and leftindexing is within this loop.
                    if ((bInLoop) && (uipCandHop.getLocation() <= hop.getBeginLine() && uipCandHop.getLixHop().getBeginLine() <= hop.getEndLine()))
                        uipCandHop.setIsLoopApplicable(true);
                }
            }
        }
    }
}
Also used : ForProgramBlock(org.apache.sysml.runtime.controlprogram.ForProgramBlock) ParForProgramBlock(org.apache.sysml.runtime.controlprogram.ParForProgramBlock) ArrayList(java.util.ArrayList) Hop(org.apache.sysml.hops.Hop) MultiThreadedHop(org.apache.sysml.hops.Hop.MultiThreadedHop) WhileProgramBlock(org.apache.sysml.runtime.controlprogram.WhileProgramBlock) ParForProgramBlock(org.apache.sysml.runtime.controlprogram.ParForProgramBlock) VariableSet(org.apache.sysml.parser.VariableSet) DataGenOp(org.apache.sysml.hops.DataGenOp) FunctionProgramBlock(org.apache.sysml.runtime.controlprogram.FunctionProgramBlock) WhileProgramBlock(org.apache.sysml.runtime.controlprogram.WhileProgramBlock) ForProgramBlock(org.apache.sysml.runtime.controlprogram.ForProgramBlock) IfProgramBlock(org.apache.sysml.runtime.controlprogram.IfProgramBlock) ProgramBlock(org.apache.sysml.runtime.controlprogram.ProgramBlock) ParForProgramBlock(org.apache.sysml.runtime.controlprogram.ParForProgramBlock)

Example 2 with DataGenOp

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

the class HopRewriteUtils method createDataGenOpByVal.

public static Hop createDataGenOpByVal(ArrayList<LiteralOp> values, long rows, long cols) {
    StringBuilder sb = new StringBuilder();
    for (LiteralOp lit : values) {
        if (sb.length() > 0)
            sb.append(StringInitCPInstruction.DELIM);
        sb.append(lit.getStringValue());
    }
    LiteralOp str = new LiteralOp(sb.toString());
    HashMap<String, Hop> params = new HashMap<>();
    params.put(DataExpression.RAND_ROWS, new LiteralOp(rows));
    params.put(DataExpression.RAND_COLS, new LiteralOp(cols));
    params.put(DataExpression.RAND_MIN, str);
    params.put(DataExpression.RAND_MAX, str);
    params.put(DataExpression.RAND_SEED, new LiteralOp(DataGenOp.UNSPECIFIED_SEED));
    Hop datagen = new DataGenOp(DataGenMethod.SINIT, new DataIdentifier("tmp"), params);
    int blksz = ConfigurationManager.getBlocksize();
    datagen.setOutputBlocksizes(blksz, blksz);
    copyLineNumbers(values.get(0), datagen);
    return datagen;
}
Also used : DataIdentifier(org.apache.sysml.parser.DataIdentifier) HashMap(java.util.HashMap) DataGenOp(org.apache.sysml.hops.DataGenOp) Hop(org.apache.sysml.hops.Hop) LiteralOp(org.apache.sysml.hops.LiteralOp)

Example 3 with DataGenOp

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

the class HopRewriteUtils method isBasic1NSequence.

public static boolean isBasic1NSequence(Hop hop) {
    if (hop instanceof DataGenOp && ((DataGenOp) hop).getOp() == DataGenMethod.SEQ) {
        DataGenOp dgop = (DataGenOp) hop;
        Hop from = dgop.getInput().get(dgop.getParamIndex(Statement.SEQ_FROM));
        Hop incr = dgop.getInput().get(dgop.getParamIndex(Statement.SEQ_INCR));
        return (from instanceof LiteralOp && getDoubleValueSafe((LiteralOp) from) == 1) && (incr instanceof LiteralOp && getDoubleValueSafe((LiteralOp) incr) == 1);
    }
    return false;
}
Also used : DataGenOp(org.apache.sysml.hops.DataGenOp) Hop(org.apache.sysml.hops.Hop) LiteralOp(org.apache.sysml.hops.LiteralOp)

Example 4 with DataGenOp

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

the class HopRewriteUtils method createDataGenOp.

public static Hop createDataGenOp(Hop rowInput, boolean tRowInput, Hop colInput, boolean tColInput, double value) {
    long nrow = tRowInput ? rowInput.getDim2() : rowInput.getDim1();
    long ncol = tColInput ? colInput.getDim1() : rowInput.getDim2();
    Hop rows = (nrow >= 0) ? new LiteralOp(nrow) : new UnaryOp("tmprows", DataType.SCALAR, ValueType.INT, tRowInput ? OpOp1.NCOL : OpOp1.NROW, rowInput);
    Hop cols = (ncol >= 0) ? new LiteralOp(ncol) : new UnaryOp("tmpcols", DataType.SCALAR, ValueType.INT, tColInput ? OpOp1.NROW : OpOp1.NCOL, colInput);
    Hop val = new LiteralOp(value);
    HashMap<String, Hop> params = new HashMap<>();
    params.put(DataExpression.RAND_ROWS, rows);
    params.put(DataExpression.RAND_COLS, cols);
    params.put(DataExpression.RAND_MIN, val);
    params.put(DataExpression.RAND_MAX, val);
    params.put(DataExpression.RAND_PDF, new LiteralOp(DataExpression.RAND_PDF_UNIFORM));
    params.put(DataExpression.RAND_LAMBDA, new LiteralOp(-1.0));
    params.put(DataExpression.RAND_SPARSITY, new LiteralOp(1.0));
    params.put(DataExpression.RAND_SEED, new LiteralOp(DataGenOp.UNSPECIFIED_SEED));
    // note internal refresh size information
    Hop datagen = new DataGenOp(DataGenMethod.RAND, new DataIdentifier("tmp"), params);
    datagen.setOutputBlocksizes(rowInput.getRowsInBlock(), colInput.getColsInBlock());
    copyLineNumbers(rowInput, datagen);
    if (value == 0)
        datagen.setNnz(0);
    return datagen;
}
Also used : AggUnaryOp(org.apache.sysml.hops.AggUnaryOp) UnaryOp(org.apache.sysml.hops.UnaryOp) DataIdentifier(org.apache.sysml.parser.DataIdentifier) HashMap(java.util.HashMap) DataGenOp(org.apache.sysml.hops.DataGenOp) Hop(org.apache.sysml.hops.Hop) LiteralOp(org.apache.sysml.hops.LiteralOp)

Example 5 with DataGenOp

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

the class HopRewriteUtils method copyDataGenOp.

/**
 * Assumes that min and max are literal ops, needs to be checked from outside.
 *
 * @param inputGen input data gen op
 * @param scale the scale
 * @param shift the shift
 * @return data gen op
 */
public static DataGenOp copyDataGenOp(DataGenOp inputGen, double scale, double shift) {
    HashMap<String, Integer> params = inputGen.getParamIndexMap();
    Hop rows = inputGen.getInput().get(params.get(DataExpression.RAND_ROWS));
    Hop cols = inputGen.getInput().get(params.get(DataExpression.RAND_COLS));
    Hop min = inputGen.getInput().get(params.get(DataExpression.RAND_MIN));
    Hop max = inputGen.getInput().get(params.get(DataExpression.RAND_MAX));
    Hop pdf = inputGen.getInput().get(params.get(DataExpression.RAND_PDF));
    Hop mean = inputGen.getInput().get(params.get(DataExpression.RAND_LAMBDA));
    Hop sparsity = inputGen.getInput().get(params.get(DataExpression.RAND_SPARSITY));
    Hop seed = inputGen.getInput().get(params.get(DataExpression.RAND_SEED));
    // check for literal ops
    if (!(min instanceof LiteralOp) || !(max instanceof LiteralOp))
        return null;
    // scale and shift
    double smin = getDoubleValue((LiteralOp) min);
    double smax = getDoubleValue((LiteralOp) max);
    smin = smin * scale + shift;
    smax = smax * scale + shift;
    Hop sminHop = new LiteralOp(smin);
    Hop smaxHop = new LiteralOp(smax);
    HashMap<String, Hop> params2 = new HashMap<>();
    params2.put(DataExpression.RAND_ROWS, rows);
    params2.put(DataExpression.RAND_COLS, cols);
    params2.put(DataExpression.RAND_MIN, sminHop);
    params2.put(DataExpression.RAND_MAX, smaxHop);
    params2.put(DataExpression.RAND_PDF, pdf);
    params2.put(DataExpression.RAND_LAMBDA, mean);
    params2.put(DataExpression.RAND_SPARSITY, sparsity);
    params2.put(DataExpression.RAND_SEED, seed);
    // note internal refresh size information
    DataGenOp datagen = new DataGenOp(DataGenMethod.RAND, new DataIdentifier("tmp"), params2);
    datagen.setOutputBlocksizes(inputGen.getRowsInBlock(), inputGen.getColsInBlock());
    copyLineNumbers(inputGen, datagen);
    if (smin == 0 && smax == 0)
        datagen.setNnz(0);
    return datagen;
}
Also used : DataIdentifier(org.apache.sysml.parser.DataIdentifier) HashMap(java.util.HashMap) DataGenOp(org.apache.sysml.hops.DataGenOp) Hop(org.apache.sysml.hops.Hop) LiteralOp(org.apache.sysml.hops.LiteralOp)

Aggregations

DataGenOp (org.apache.sysml.hops.DataGenOp)41 Hop (org.apache.sysml.hops.Hop)41 LiteralOp (org.apache.sysml.hops.LiteralOp)26 HashMap (java.util.HashMap)18 DataIdentifier (org.apache.sysml.parser.DataIdentifier)12 ArrayList (java.util.ArrayList)11 ReorgOp (org.apache.sysml.hops.ReorgOp)10 AggBinaryOp (org.apache.sysml.hops.AggBinaryOp)8 AggUnaryOp (org.apache.sysml.hops.AggUnaryOp)8 BinaryOp (org.apache.sysml.hops.BinaryOp)8 UnaryOp (org.apache.sysml.hops.UnaryOp)8 DataOp (org.apache.sysml.hops.DataOp)4 List (java.util.List)2 ConvolutionOp (org.apache.sysml.hops.ConvolutionOp)2 DataGenMethod (org.apache.sysml.hops.Hop.DataGenMethod)2 OpOp2 (org.apache.sysml.hops.Hop.OpOp2)2 OpOpN (org.apache.sysml.hops.Hop.OpOpN)2 HopsException (org.apache.sysml.hops.HopsException)2 IndexingOp (org.apache.sysml.hops.IndexingOp)2 NaryOp (org.apache.sysml.hops.NaryOp)2