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);
}
}
}
}
}
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;
}
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;
}
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;
}
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;
}
Aggregations