use of org.apache.sysml.runtime.controlprogram.LocalVariableMap in project systemml by apache.
the class InterProceduralAnalysis method analyzeProgram.
/**
* Main interface to perform IPA over a given DML program.
*
* @param repetitions number of IPA rounds
*/
public void analyzeProgram(int repetitions) {
// sanity check for valid number of repetitions
if (repetitions <= 0)
throw new HopsException("Invalid number of IPA repetitions: " + repetitions);
// perform number of requested IPA iterations
FunctionCallSizeInfo lastSizes = null;
for (int i = 0; i < repetitions; i++) {
if (LOG.isDebugEnabled())
LOG.debug("IPA: start IPA iteration " + (i + 1) + "/" + repetitions + ".");
// get function call size infos to obtain candidates for statistics propagation
FunctionCallSizeInfo fcallSizes = new FunctionCallSizeInfo(_fgraph);
if (LOG.isDebugEnabled())
LOG.debug("IPA: Initial FunctionCallSummary: \n" + fcallSizes);
// step 1: intra- and inter-procedural
if (INTRA_PROCEDURAL_ANALYSIS) {
// get unary dimension-preserving non-candidate functions
for (String tmp : fcallSizes.getInvalidFunctions()) if (isUnarySizePreservingFunction(_prog.getFunctionStatementBlock(tmp)))
fcallSizes.addDimsPreservingFunction(tmp);
if (LOG.isDebugEnabled())
LOG.debug("IPA: Extended FunctionCallSummary: \n" + fcallSizes);
// propagate statistics and scalars into functions and across DAGs
// (callVars used to chain outputs/inputs of multiple functions calls)
LocalVariableMap callVars = new LocalVariableMap();
for (// propagate stats into candidates
StatementBlock sb : // propagate stats into candidates
_prog.getStatementBlocks()) propagateStatisticsAcrossBlock(sb, callVars, fcallSizes, new HashSet<String>());
}
// step 2: apply additional IPA passes
for (IPAPass pass : _passes) if (pass.isApplicable(_fgraph))
pass.rewriteProgram(_prog, _fgraph, fcallSizes);
// early abort without functions or on reached fixpoint
if (_fgraph.getReachableFunctions().isEmpty() || (lastSizes != null && lastSizes.equals(fcallSizes))) {
if (LOG.isDebugEnabled())
LOG.debug("IPA: Early abort after " + (i + 1) + "/" + repetitions + " repetitions due to reached fixpoint.");
break;
}
}
// cleanup pass: remove unused functions
FunctionCallGraph graph2 = new FunctionCallGraph(_prog);
IPAPass rmFuns = new IPAPassRemoveUnusedFunctions();
if (rmFuns.isApplicable(graph2))
rmFuns.rewriteProgram(_prog, graph2, null);
}
use of org.apache.sysml.runtime.controlprogram.LocalVariableMap in project systemml by apache.
the class InterProceduralAnalysis method isUnarySizePreservingFunction.
private boolean isUnarySizePreservingFunction(FunctionStatementBlock fsb) {
FunctionStatement fstmt = (FunctionStatement) fsb.getStatement(0);
// check unary functions over matrices
boolean ret = (fstmt.getInputParams().size() == 1 && fstmt.getInputParams().get(0).getDataType() == DataType.MATRIX && fstmt.getOutputParams().size() == 1 && fstmt.getOutputParams().get(0).getDataType() == DataType.MATRIX);
// check size-preserving characteristic
if (ret) {
FunctionCallSizeInfo fcallSizes = new FunctionCallSizeInfo(_fgraph, false);
HashSet<String> fnStack = new HashSet<>();
LocalVariableMap callVars = new LocalVariableMap();
// populate input
MatrixObject mo = createOutputMatrix(7777, 3333, -1);
callVars.put(fstmt.getInputParams().get(0).getName(), mo);
// propagate statistics
for (StatementBlock sbi : fstmt.getBody()) propagateStatisticsAcrossBlock(sbi, callVars, fcallSizes, fnStack);
// compare output
MatrixObject mo2 = (MatrixObject) callVars.get(fstmt.getOutputParams().get(0).getName());
ret &= mo.getNumRows() == mo2.getNumRows() && mo.getNumColumns() == mo2.getNumColumns();
// reset function
mo.getMatrixCharacteristics().setDimension(-1, -1);
for (StatementBlock sbi : fstmt.getBody()) propagateStatisticsAcrossBlock(sbi, callVars, fcallSizes, fnStack);
}
return ret;
}
use of org.apache.sysml.runtime.controlprogram.LocalVariableMap in project systemml by apache.
the class CostEstimationWrapper method getTimeEstimate.
public static double getTimeEstimate(ProgramBlock pb, ExecutionContext ec, boolean recursive) {
Timing time = new Timing(true);
HashMap<String, VarStats> stats = new HashMap<>();
LocalVariableMap vars = (ec != null) ? ec.getVariables() : new LocalVariableMap();
double costs = _costEstim.getTimeEstimate(pb, vars, stats, recursive);
LOG.debug("Finished estimation in " + time.stop() + "ms.");
return costs;
}
use of org.apache.sysml.runtime.controlprogram.LocalVariableMap in project systemml by apache.
the class CostEstimationWrapper method getTimeEstimate.
public static double getTimeEstimate(Program rtprog, ExecutionContext ec) {
Timing time = new Timing(true);
HashMap<String, VarStats> stats = new HashMap<>();
LocalVariableMap vars = (ec != null) ? ec.getVariables() : new LocalVariableMap();
double costs = _costEstim.getTimeEstimate(rtprog, vars, stats);
LOG.debug("Finished estimation in " + time.stop() + "ms.");
return costs;
}
Aggregations