use of org.apache.sysml.hops.MemoTable in project incubator-systemml by apache.
the class Recompiler method recompile.
/**
* Core internal primitive for the dynamic recompilation of any DAGs/predicate,
* including all variants with slightly different configurations.
*
* @param sb statement block of DAG, null for predicates
* @param hops list of DAG root nodes
* @param vars symbol table
* @param status recompilation status
* @param inplace modify DAG in place, otherwise deep copy
* @param replaceLit replace literals (only applicable on deep copy)
* @param updateStats update statistics, rewrites, and memory estimates
* @param forceEt force a given execution type, null for reset
* @param pred recompile for predicate DAG
* @param et given execution type
* @param tid thread id, 0 for main or before worker creation
* @return modified list of instructions
*/
private static ArrayList<Instruction> recompile(StatementBlock sb, ArrayList<Hop> hops, LocalVariableMap vars, RecompileStatus status, boolean inplace, boolean replaceLit, boolean updateStats, boolean forceEt, boolean pred, ExecType et, long tid) {
// prepare hops dag for recompile
if (!inplace) {
// deep copy hop dag (for non-reversable rewrites)
hops = deepCopyHopsDag(hops);
} else {
// clear existing lops
Hop.resetVisitStatus(hops);
for (Hop hopRoot : hops) rClearLops(hopRoot);
}
// replace scalar reads with literals
if (!inplace && replaceLit) {
Hop.resetVisitStatus(hops);
for (Hop hopRoot : hops) rReplaceLiterals(hopRoot, vars, false);
}
// force exec type (et=null for reset)
if (forceEt) {
Hop.resetVisitStatus(hops);
for (Hop hopRoot : hops) rSetExecType(hopRoot, et);
Hop.resetVisitStatus(hops);
}
// update statistics, rewrites, and mem estimates
if (updateStats) {
// refresh matrix characteristics (update stats)
Hop.resetVisitStatus(hops);
for (Hop hopRoot : hops) rUpdateStatistics(hopRoot, vars);
// dynamic hop rewrites
if (!inplace) {
_rewriter.get().rewriteHopDAG(hops, null);
// update stats after rewrites
Hop.resetVisitStatus(hops);
for (Hop hopRoot : hops) rUpdateStatistics(hopRoot, vars);
}
// refresh memory estimates (based on updated stats,
// before: init memo table with propagated worst-case estimates,
// after: extract worst-case estimates from memo table
Hop.resetVisitStatus(hops);
MemoTable memo = new MemoTable();
memo.init(hops, status);
Hop.resetVisitStatus(hops);
for (Hop hopRoot : hops) hopRoot.refreshMemEstimates(memo);
memo.extract(hops, status);
}
// codegen if enabled
if (ConfigurationManager.isCodegenEnabled() && // not on reset
!(forceEt && et == null) && SpoofCompiler.RECOMPILE_CODEGEN) {
// create deep copy for in-place
if (inplace)
hops = deepCopyHopsDag(hops);
Hop.resetVisitStatus(hops);
hops = SpoofCompiler.optimize(hops, (status == null || !status.isInitialCodegen()));
}
// construct lops
Dag<Lop> dag = new Dag<>();
for (Hop hopRoot : hops) {
Lop lops = hopRoot.constructLops();
lops.addToDag(dag);
}
// generate runtime instructions (incl piggybacking)
ArrayList<Instruction> newInst = dag.getJobs(sb, ConfigurationManager.getDMLConfig());
// defer the explain of instructions after additional modifications
if (DMLScript.EXPLAIN == ExplainType.RECOMPILE_HOPS) {
if (pred)
logExplainPred(hops.get(0), newInst);
else
logExplainDAG(sb, hops, newInst);
}
return newInst;
}
Aggregations