use of org.apache.sysml.parser.LanguageException in project systemml by apache.
the class ParForDependencyAnalysisTest method runTest.
private void runTest(String scriptFilename, boolean expectedException) {
boolean raisedException = false;
try {
// Tell the superclass about the name of this test, so that the superclass can
// create temporary directories.
int index = scriptFilename.lastIndexOf(".dml");
String testName = scriptFilename.substring(0, index > 0 ? index : scriptFilename.length());
TestConfiguration testConfig = new TestConfiguration(TEST_CLASS_DIR, testName, new String[] {});
addTestConfiguration(testName, testConfig);
loadTestConfiguration(testConfig);
DMLConfig conf = new DMLConfig(getCurConfigFile().getPath());
ConfigurationManager.setLocalConfig(conf);
String dmlScriptString = "";
HashMap<String, String> argVals = new HashMap<String, String>();
// read script
try (BufferedReader in = new BufferedReader(new FileReader(HOME + scriptFilename))) {
String s1 = null;
while ((s1 = in.readLine()) != null) dmlScriptString += s1 + "\n";
}
// parsing and dependency analysis
ParserWrapper parser = ParserFactory.createParser(org.apache.sysml.api.mlcontext.ScriptType.DML);
DMLProgram prog = parser.parse(DMLScript.DML_FILE_PATH_ANTLR_PARSER, dmlScriptString, argVals);
DMLTranslator dmlt = new DMLTranslator(prog);
dmlt.validateParseTree(prog);
} catch (LanguageException ex) {
raisedException = true;
if (raisedException != expectedException)
ex.printStackTrace();
} catch (Exception ex2) {
ex2.printStackTrace();
throw new RuntimeException(ex2);
// Assert.fail( "Unexpected exception occured during test run." );
}
// check correctness
Assert.assertEquals(expectedException, raisedException);
}
use of org.apache.sysml.parser.LanguageException in project systemml by apache.
the class IPAPassRemoveUnusedFunctions method rewriteProgram.
@Override
public void rewriteProgram(DMLProgram prog, FunctionCallGraph fgraph, FunctionCallSizeInfo fcallSizes) {
try {
Set<String> fnamespaces = prog.getNamespaces().keySet();
for (String fnspace : fnamespaces) {
HashMap<String, FunctionStatementBlock> fsbs = prog.getFunctionStatementBlocks(fnspace);
Iterator<Entry<String, FunctionStatementBlock>> iter = fsbs.entrySet().iterator();
while (iter.hasNext()) {
Entry<String, FunctionStatementBlock> e = iter.next();
if (!fgraph.isReachableFunction(fnspace, e.getKey())) {
iter.remove();
if (LOG.isDebugEnabled())
LOG.debug("IPA: Removed unused function: " + DMLProgram.constructFunctionKey(fnspace, e.getKey()));
}
}
}
} catch (LanguageException ex) {
throw new HopsException(ex);
}
}
use of org.apache.sysml.parser.LanguageException in project systemml by apache.
the class IPAPassApplyStaticHopRewrites method rewriteProgram.
@Override
public void rewriteProgram(DMLProgram prog, FunctionCallGraph fgraph, FunctionCallSizeInfo fcallSizes) {
try {
// construct rewriter w/o checkpoint injection to avoid redundancy
ProgramRewriter rewriter = new ProgramRewriter(true, false);
rewriter.removeStatementBlockRewrite(RewriteInjectSparkLoopCheckpointing.class);
// rewrite program hop dags and statement blocks
// rewrite and split
rewriter.rewriteProgramHopDAGs(prog, true);
} catch (LanguageException ex) {
throw new HopsException(ex);
}
}
Aggregations