Search in sources :

Example 36 with LanguageException

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);
}
Also used : DMLConfig(org.apache.sysml.conf.DMLConfig) HashMap(java.util.HashMap) TestConfiguration(org.apache.sysml.test.integration.TestConfiguration) DMLTranslator(org.apache.sysml.parser.DMLTranslator) LanguageException(org.apache.sysml.parser.LanguageException) LanguageException(org.apache.sysml.parser.LanguageException) BufferedReader(java.io.BufferedReader) DMLProgram(org.apache.sysml.parser.DMLProgram) FileReader(java.io.FileReader) ParserWrapper(org.apache.sysml.parser.ParserWrapper)

Example 37 with LanguageException

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);
    }
}
Also used : LanguageException(org.apache.sysml.parser.LanguageException) FunctionStatementBlock(org.apache.sysml.parser.FunctionStatementBlock) Entry(java.util.Map.Entry) HopsException(org.apache.sysml.hops.HopsException)

Example 38 with LanguageException

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);
    }
}
Also used : LanguageException(org.apache.sysml.parser.LanguageException) ProgramRewriter(org.apache.sysml.hops.rewrite.ProgramRewriter) HopsException(org.apache.sysml.hops.HopsException)

Aggregations

LanguageException (org.apache.sysml.parser.LanguageException)38 DMLProgram (org.apache.sysml.parser.DMLProgram)16 AssignmentStatement (org.apache.sysml.parser.AssignmentStatement)9 BufferedReader (java.io.BufferedReader)8 FileReader (java.io.FileReader)8 IOException (java.io.IOException)8 InputStream (java.io.InputStream)8 DMLTranslator (org.apache.sysml.parser.DMLTranslator)8 Expression (org.apache.sysml.parser.Expression)8 FunctionStatementBlock (org.apache.sysml.parser.FunctionStatementBlock)8 ParameterExpression (org.apache.sysml.parser.ParameterExpression)8 HashMap (java.util.HashMap)7 ByteArrayInputStream (java.io.ByteArrayInputStream)6 DMLConfig (org.apache.sysml.conf.DMLConfig)6 HopsException (org.apache.sysml.hops.HopsException)6 ProgramRewriter (org.apache.sysml.hops.rewrite.ProgramRewriter)6 BinaryExpression (org.apache.sysml.parser.BinaryExpression)6 BuiltinFunctionExpression (org.apache.sysml.parser.BuiltinFunctionExpression)6 DataExpression (org.apache.sysml.parser.DataExpression)6 DataIdentifier (org.apache.sysml.parser.DataIdentifier)6