use of org.apache.sysml.parser.ParForStatementBlock.ResultVar in project incubator-systemml by apache.
the class OptimizerRuleBased method rewriteRemoveUnnecessaryCompareMatrix.
// /////
// REWRITE remove compare matrix (for result merge, needs to be invoked before setting result merge)
// /
protected void rewriteRemoveUnnecessaryCompareMatrix(OptNode n, ExecutionContext ec) {
ParForProgramBlock pfpb = (ParForProgramBlock) OptTreeConverter.getAbstractPlanMapping().getMappedProg(n.getID())[1];
ArrayList<ResultVar> cleanedVars = new ArrayList<>();
ArrayList<ResultVar> resultVars = pfpb.getResultVariables();
String itervar = pfpb.getIterVar();
for (ResultVar rvar : resultVars) {
Data dat = ec.getVariable(rvar._name);
if (// subject to result merge with compare
dat instanceof MatrixObject && ((MatrixObject) dat).getNnz() != 0 && // guaranteed no conditional indexing
n.hasOnlySimpleChilds() && // guaranteed full matrix replace
rContainsResultFullReplace(n, rvar._name, itervar, (MatrixObject) dat) && // && !pfsb.variablesRead().containsVariable(rvar) //never read variable in loop body
!// never read variable in loop body
rIsReadInRightIndexing(n, rvar._name) && ((MatrixObject) dat).getNumRows() <= Integer.MAX_VALUE && ((MatrixObject) dat).getNumColumns() <= Integer.MAX_VALUE) {
// replace existing matrix object with empty matrix
MatrixObject mo = (MatrixObject) dat;
ec.cleanupCacheableData(mo);
ec.setMatrixOutput(rvar._name, new MatrixBlock((int) mo.getNumRows(), (int) mo.getNumColumns(), false), null);
// keep track of cleaned result variables
cleanedVars.add(rvar);
}
}
_numEvaluatedPlans++;
LOG.debug(getOptMode() + " OPT: rewrite 'remove unnecessary compare matrix' - result=" + (!cleanedVars.isEmpty()) + " (" + ProgramConverter.serializeResultVariables(cleanedVars) + ")");
}
use of org.apache.sysml.parser.ParForStatementBlock.ResultVar in project incubator-systemml by apache.
the class OptimizerRuleBased method determineFlagCellFormatWoCompare.
protected boolean determineFlagCellFormatWoCompare(ArrayList<ResultVar> resultVars, LocalVariableMap vars) {
boolean ret = true;
for (ResultVar rVar : resultVars) {
Data dat = vars.get(rVar._name);
if (dat == null || !(dat instanceof MatrixObject)) {
ret = false;
break;
} else {
MatrixObject mo = (MatrixObject) dat;
MetaDataFormat meta = (MetaDataFormat) mo.getMetaData();
OutputInfo oi = meta.getOutputInfo();
long nnz = meta.getMatrixCharacteristics().getNonZeros();
if (oi == OutputInfo.BinaryBlockOutputInfo || nnz != 0) {
ret = false;
break;
}
}
}
return ret;
}
use of org.apache.sysml.parser.ParForStatementBlock.ResultVar in project incubator-systemml by apache.
the class ProgramConverter method parseParForBody.
// //////////////////////////////
// PARSING
// //////////////////////////////
public static ParForBody parseParForBody(String in, int id) {
ParForBody body = new ParForBody();
// header elimination
// normalization
String tmpin = in.replaceAll(NEWLINE, "");
// remove start/end
tmpin = tmpin.substring(PARFORBODY_BEGIN.length(), tmpin.length() - PARFORBODY_END.length());
HierarchyAwareStringTokenizer st = new HierarchyAwareStringTokenizer(tmpin, COMPONENTS_DELIM);
// handle DMLScript UUID (NOTE: set directly in DMLScript)
// (master UUID is used for all nodes (in order to simply cleanup))
DMLScript.setUUID(st.nextToken());
// handle DML config (NOTE: set directly in ConfigurationManager)
String confStr = st.nextToken();
JobConf job = ConfigurationManager.getCachedJobConf();
if (!InfrastructureAnalyzer.isLocalMode(job)) {
if (confStr != null && !confStr.trim().isEmpty()) {
DMLConfig dmlconf = DMLConfig.parseDMLConfig(confStr);
CompilerConfig cconf = OptimizerUtils.constructCompilerConfig(dmlconf);
ConfigurationManager.setLocalConfig(dmlconf);
ConfigurationManager.setLocalConfig(cconf);
}
// init internal configuration w/ parsed or default config
ParForProgramBlock.initInternalConfigurations(ConfigurationManager.getDMLConfig());
}
// handle additional configs
String aconfs = st.nextToken();
parseAndSetAdditionalConfigurations(aconfs);
// handle program
String progStr = st.nextToken();
Program prog = parseProgram(progStr, id);
// handle result variable names
String rvarStr = st.nextToken();
ArrayList<ResultVar> rvars = parseResultVariables(rvarStr);
body.setResultVariables(rvars);
// handle execution context
String ecStr = st.nextToken();
ExecutionContext ec = parseExecutionContext(ecStr, prog);
// handle program blocks
String spbs = st.nextToken();
ArrayList<ProgramBlock> pbs = rParseProgramBlocks(spbs, prog, id);
body.setChildBlocks(pbs);
body.setEc(ec);
return body;
}
use of org.apache.sysml.parser.ParForStatementBlock.ResultVar in project incubator-systemml by apache.
the class ProgramConverter method serializeParForBody.
public static String serializeParForBody(ParForBody body, HashMap<String, byte[]> clsMap) {
ArrayList<ProgramBlock> pbs = body.getChildBlocks();
ArrayList<ResultVar> rVnames = body.getResultVariables();
ExecutionContext ec = body.getEc();
if (pbs.isEmpty())
return PARFORBODY_BEGIN + PARFORBODY_END;
Program prog = pbs.get(0).getProgram();
StringBuilder sb = new StringBuilder();
sb.append(PARFORBODY_BEGIN);
sb.append(NEWLINE);
// handle DMLScript UUID (propagate original uuid for writing to scratch space)
sb.append(DMLScript.getUUID());
sb.append(COMPONENTS_DELIM);
sb.append(NEWLINE);
// handle DML config
sb.append(ConfigurationManager.getDMLConfig().serializeDMLConfig());
sb.append(COMPONENTS_DELIM);
sb.append(NEWLINE);
// handle additional configurations
sb.append(PARFOR_CONF_STATS + "=" + DMLScript.STATISTICS);
sb.append(COMPONENTS_DELIM);
sb.append(NEWLINE);
// handle program
sb.append(PARFOR_PROG_BEGIN);
sb.append(NEWLINE);
sb.append(serializeProgram(prog, pbs, clsMap));
sb.append(PARFOR_PROG_END);
sb.append(NEWLINE);
sb.append(COMPONENTS_DELIM);
sb.append(NEWLINE);
// handle result variable names
sb.append(serializeResultVariables(rVnames));
sb.append(COMPONENTS_DELIM);
// handle execution context
// note: this includes also the symbol table (serialize only the top-level variable map,
// (symbol tables for nested/child blocks are created at parse time, on the remote side)
sb.append(PARFOR_EC_BEGIN);
sb.append(serializeExecutionContext(ec));
sb.append(PARFOR_EC_END);
sb.append(NEWLINE);
sb.append(COMPONENTS_DELIM);
sb.append(NEWLINE);
// handle program blocks -- ONLY instructions, not variables.
sb.append(PARFOR_PBS_BEGIN);
sb.append(NEWLINE);
sb.append(rSerializeProgramBlocks(pbs, clsMap));
sb.append(PARFOR_PBS_END);
sb.append(NEWLINE);
sb.append(PARFORBODY_END);
return sb.toString();
}
use of org.apache.sysml.parser.ParForStatementBlock.ResultVar in project incubator-systemml by apache.
the class ProgramConverter method rParseParForProgramBlock.
private static ParForProgramBlock rParseParForProgramBlock(String in, Program prog, int id) {
String lin = in.substring(PARFOR_PB_PARFOR.length(), in.length() - PARFOR_PB_END.length());
HierarchyAwareStringTokenizer st = new HierarchyAwareStringTokenizer(lin, COMPONENTS_DELIM);
// inputs
String iterVar = st.nextToken();
ArrayList<ResultVar> resultVars = parseResultVariables(st.nextToken());
HashMap<String, String> params = parseStringHashMap(st.nextToken());
// instructions
ArrayList<Instruction> from = parseInstructions(st.nextToken(), 0);
ArrayList<Instruction> to = parseInstructions(st.nextToken(), 0);
ArrayList<Instruction> incr = parseInstructions(st.nextToken(), 0);
// exit instructions
ArrayList<Instruction> exit = parseInstructions(st.nextToken(), 0);
// program blocks //reset id to preinit state, replaced during exec
ArrayList<ProgramBlock> pbs = rParseProgramBlocks(st.nextToken(), prog, 0);
ParForProgramBlock pfpb = new ParForProgramBlock(id, prog, iterVar, params, resultVars);
// already done in top-level parfor
pfpb.disableOptimization();
pfpb.setFromInstructions(from);
pfpb.setToInstructions(to);
pfpb.setIncrementInstructions(incr);
pfpb.setExitInstructions(exit);
pfpb.setChildBlocks(pbs);
return pfpb;
}
Aggregations