use of org.apache.sysml.hops.rewrite.RewriteRemovePersistentReadWrite in project incubator-systemml by apache.
the class Connection method prepareScript.
/**
* Prepares (precompiles) a script, sets input parameter values, and registers input and output variables.
*
* @param script string representing the DML or PyDML script
* @param args map of input parameters ($) and their values
* @param inputs string array of input variables to register
* @param outputs string array of output variables to register
* @param parsePyDML {@code true} if PyDML, {@code false} if DML
* @return PreparedScript object representing the precompiled script
*/
public PreparedScript prepareScript(String script, Map<String, String> args, String[] inputs, String[] outputs, boolean parsePyDML) {
DMLScript.SCRIPT_TYPE = parsePyDML ? ScriptType.PYDML : ScriptType.DML;
// check for valid names of passed arguments
String[] invalidArgs = args.keySet().stream().filter(k -> k == null || !k.startsWith("$")).toArray(String[]::new);
if (invalidArgs.length > 0)
throw new LanguageException("Invalid argument names: " + Arrays.toString(invalidArgs));
// check for valid names of input and output variables
String[] invalidVars = UtilFunctions.asSet(inputs, outputs).stream().filter(k -> k == null || k.startsWith("$")).toArray(String[]::new);
if (invalidVars.length > 0)
throw new LanguageException("Invalid variable names: " + Arrays.toString(invalidVars));
setLocalConfigs();
// simplified compilation chain
Program rtprog = null;
try {
// parsing
ParserWrapper parser = ParserFactory.createParser(parsePyDML ? ScriptType.PYDML : ScriptType.DML);
DMLProgram prog = parser.parse(null, script, args);
// language validate
DMLTranslator dmlt = new DMLTranslator(prog);
dmlt.liveVariableAnalysis(prog);
dmlt.validateParseTree(prog);
// hop construct/rewrite
dmlt.constructHops(prog);
dmlt.rewriteHopsDAG(prog);
// rewrite persistent reads/writes
RewriteRemovePersistentReadWrite rewrite = new RewriteRemovePersistentReadWrite(inputs, outputs);
ProgramRewriter rewriter2 = new ProgramRewriter(rewrite);
rewriter2.rewriteProgramHopDAGs(prog);
// lop construct and runtime prog generation
dmlt.constructLops(prog);
rtprog = dmlt.getRuntimeProgram(prog, _dmlconf);
// final cleanup runtime prog
JMLCUtils.cleanupRuntimeProgram(rtprog, outputs);
} catch (ParseException pe) {
// don't chain ParseException (for cleaner error output)
throw pe;
} catch (Exception ex) {
throw new DMLException(ex);
}
// return newly create precompiled script
return new PreparedScript(rtprog, inputs, outputs, _dmlconf, _cconf);
}
use of org.apache.sysml.hops.rewrite.RewriteRemovePersistentReadWrite in project incubator-systemml by apache.
the class ScriptExecutor method rewritePersistentReadsAndWrites.
/**
* Replace persistent reads and writes with transient reads and writes in
* the symbol table.
*/
protected void rewritePersistentReadsAndWrites() {
LocalVariableMap symbolTable = script.getSymbolTable();
if (symbolTable != null) {
String[] inputs = (script.getInputVariables() == null) ? new String[0] : script.getInputVariables().toArray(new String[0]);
String[] outputs = (script.getOutputVariables() == null) ? new String[0] : script.getOutputVariables().toArray(new String[0]);
RewriteRemovePersistentReadWrite rewrite = new RewriteRemovePersistentReadWrite(inputs, outputs, script.getSymbolTable());
ProgramRewriter programRewriter = new ProgramRewriter(rewrite);
try {
programRewriter.rewriteProgramHopDAGs(dmlProgram);
} catch (LanguageException | HopsException e) {
throw new MLContextException("Exception occurred while rewriting persistent reads and writes", e);
}
}
}
use of org.apache.sysml.hops.rewrite.RewriteRemovePersistentReadWrite in project systemml by apache.
the class ScriptExecutor method rewritePersistentReadsAndWrites.
/**
* Replace persistent reads and writes with transient reads and writes in
* the symbol table.
*/
protected void rewritePersistentReadsAndWrites() {
LocalVariableMap symbolTable = script.getSymbolTable();
if (symbolTable != null) {
String[] inputs = (script.getInputVariables() == null) ? new String[0] : script.getInputVariables().toArray(new String[0]);
String[] outputs = (script.getOutputVariables() == null) ? new String[0] : script.getOutputVariables().toArray(new String[0]);
RewriteRemovePersistentReadWrite rewrite = new RewriteRemovePersistentReadWrite(inputs, outputs, script.getSymbolTable());
ProgramRewriter programRewriter = new ProgramRewriter(rewrite);
try {
programRewriter.rewriteProgramHopDAGs(dmlProgram);
} catch (LanguageException | HopsException e) {
throw new MLContextException("Exception occurred while rewriting persistent reads and writes", e);
}
}
}
use of org.apache.sysml.hops.rewrite.RewriteRemovePersistentReadWrite in project systemml by apache.
the class Connection method prepareScript.
/**
* Prepares (precompiles) a script, sets input parameter values, and registers input and output variables.
*
* @param script string representing the DML or PyDML script
* @param args map of input parameters ($) and their values
* @param inputs string array of input variables to register
* @param outputs string array of output variables to register
* @param parsePyDML {@code true} if PyDML, {@code false} if DML
* @return PreparedScript object representing the precompiled script
*/
public PreparedScript prepareScript(String script, Map<String, String> args, String[] inputs, String[] outputs, boolean parsePyDML) {
DMLScript.SCRIPT_TYPE = parsePyDML ? ScriptType.PYDML : ScriptType.DML;
// check for valid names of passed arguments
String[] invalidArgs = args.keySet().stream().filter(k -> k == null || !k.startsWith("$")).toArray(String[]::new);
if (invalidArgs.length > 0)
throw new LanguageException("Invalid argument names: " + Arrays.toString(invalidArgs));
// check for valid names of input and output variables
String[] invalidVars = UtilFunctions.asSet(inputs, outputs).stream().filter(k -> k == null || k.startsWith("$")).toArray(String[]::new);
if (invalidVars.length > 0)
throw new LanguageException("Invalid variable names: " + Arrays.toString(invalidVars));
setLocalConfigs();
// simplified compilation chain
Program rtprog = null;
try {
// parsing
ParserWrapper parser = ParserFactory.createParser(parsePyDML ? ScriptType.PYDML : ScriptType.DML);
DMLProgram prog = parser.parse(null, script, args);
// language validate
DMLTranslator dmlt = new DMLTranslator(prog);
dmlt.liveVariableAnalysis(prog);
dmlt.validateParseTree(prog);
// hop construct/rewrite
dmlt.constructHops(prog);
dmlt.rewriteHopsDAG(prog);
// rewrite persistent reads/writes
RewriteRemovePersistentReadWrite rewrite = new RewriteRemovePersistentReadWrite(inputs, outputs);
ProgramRewriter rewriter2 = new ProgramRewriter(rewrite);
rewriter2.rewriteProgramHopDAGs(prog);
// lop construct and runtime prog generation
dmlt.constructLops(prog);
rtprog = dmlt.getRuntimeProgram(prog, _dmlconf);
// final cleanup runtime prog
JMLCUtils.cleanupRuntimeProgram(rtprog, outputs);
} catch (ParseException pe) {
// don't chain ParseException (for cleaner error output)
throw pe;
} catch (Exception ex) {
throw new DMLException(ex);
}
// return newly create precompiled script
return new PreparedScript(rtprog, inputs, outputs, _dmlconf, _cconf);
}
Aggregations