Search in sources :

Example 6 with DMLTranslator

use of org.apache.sysml.parser.DMLTranslator in project incubator-systemml by apache.

the class DataTypeChangeTest method runValidateTest.

private void runValidateTest(String fullTestName, boolean expectedException) {
    boolean raisedException = false;
    try {
        // Tell the superclass about the name of this test, so that the superclass can
        // create temporary directories.
        TestConfiguration testConfig = new TestConfiguration(TEST_CLASS_DIR, fullTestName, new String[] {});
        addTestConfiguration(fullTestName, 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(fullTestName))) {
            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.liveVariableAnalysis(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) DMLException(org.apache.sysml.api.DMLException) 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 7 with DMLTranslator

use of org.apache.sysml.parser.DMLTranslator in project incubator-systemml by apache.

the class ProgramRecompiler method generatePartitialRuntimeProgram.

public static ArrayList<ProgramBlock> generatePartitialRuntimeProgram(Program rtprog, ArrayList<StatementBlock> sbs) {
    ArrayList<ProgramBlock> ret = new ArrayList<>();
    DMLConfig config = ConfigurationManager.getDMLConfig();
    // construct lops from hops if not existing
    DMLTranslator dmlt = new DMLTranslator(sbs.get(0).getDMLProg());
    for (StatementBlock sb : sbs) {
        dmlt.constructLops(sb);
    }
    // construct runtime program from lops
    for (StatementBlock sb : sbs) {
        ret.add(dmlt.createRuntimeProgramBlock(rtprog, sb, config));
    }
    // enhance runtime program by automatic operator fusion
    if (ConfigurationManager.isCodegenEnabled() && SpoofCompiler.INTEGRATION == IntegrationType.RUNTIME) {
        for (ProgramBlock pb : ret) dmlt.codgenHopsDAG(pb);
    }
    return ret;
}
Also used : DMLConfig(org.apache.sysml.conf.DMLConfig) ArrayList(java.util.ArrayList) ForProgramBlock(org.apache.sysml.runtime.controlprogram.ForProgramBlock) IfProgramBlock(org.apache.sysml.runtime.controlprogram.IfProgramBlock) ProgramBlock(org.apache.sysml.runtime.controlprogram.ProgramBlock) WhileProgramBlock(org.apache.sysml.runtime.controlprogram.WhileProgramBlock) DMLTranslator(org.apache.sysml.parser.DMLTranslator) IfStatementBlock(org.apache.sysml.parser.IfStatementBlock) WhileStatementBlock(org.apache.sysml.parser.WhileStatementBlock) ForStatementBlock(org.apache.sysml.parser.ForStatementBlock) StatementBlock(org.apache.sysml.parser.StatementBlock)

Aggregations

DMLTranslator (org.apache.sysml.parser.DMLTranslator)7 DMLConfig (org.apache.sysml.conf.DMLConfig)6 DMLProgram (org.apache.sysml.parser.DMLProgram)5 ParserWrapper (org.apache.sysml.parser.ParserWrapper)5 LanguageException (org.apache.sysml.parser.LanguageException)4 BufferedReader (java.io.BufferedReader)3 FileReader (java.io.FileReader)3 HashMap (java.util.HashMap)3 DMLRuntimeException (org.apache.sysml.runtime.DMLRuntimeException)3 DMLException (org.apache.sysml.api.DMLException)2 CompilerConfig (org.apache.sysml.conf.CompilerConfig)2 Program (org.apache.sysml.runtime.controlprogram.Program)2 Closeable (java.io.Closeable)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Map (java.util.Map)1 FileSystem (org.apache.hadoop.fs.FileSystem)1