Search in sources :

Example 16 with PreparedScript

use of org.apache.sysml.api.jmlc.PreparedScript in project incubator-systemml by apache.

the class JMLCParfor2ForCompileTest method runJMLCParFor2ForTest.

private void runJMLCParFor2ForTest(boolean par) throws IOException {
    try {
        Connection conn = !par ? new Connection() : new Connection(ConfigType.PARALLEL_LOCAL_OR_REMOTE_PARFOR);
        String script = "  X = rand(rows=10, cols=10);" + "R = matrix(0, rows=10, cols=1)" + "parfor(i in 1:nrow(X))" + "  R[i,] = sum(X[i,])" + "print(sum(R))";
        DMLScript.STATISTICS = true;
        Statistics.reset();
        PreparedScript pscript = conn.prepareScript(script, new String[] {}, new String[] {}, false);
        pscript.executeScript();
        conn.close();
    } catch (Exception ex) {
        Assert.fail("JMLC parfor test failed: " + ex.getMessage());
    }
    // check for existing or non-existing parfor
    Assert.assertTrue(Statistics.getParforOptCount() == (par ? 1 : 0));
}
Also used : PreparedScript(org.apache.sysml.api.jmlc.PreparedScript) Connection(org.apache.sysml.api.jmlc.Connection) IOException(java.io.IOException)

Example 17 with PreparedScript

use of org.apache.sysml.api.jmlc.PreparedScript in project incubator-systemml by apache.

the class APICodegenTest method runMLContextParforDatasetTest.

private void runMLContextParforDatasetTest(boolean jmlc) {
    try {
        double[][] X = getRandomMatrix(rows, cols, -10, 10, sparsity, 76543);
        MatrixBlock mX = DataConverter.convertToMatrixBlock(X);
        String s = "X = read(\"/tmp\");" + "R = colSums(X/rowSums(X));" + "write(R, \"tmp2\")";
        // execute scripts
        if (jmlc) {
            DMLScript.STATISTICS = true;
            Connection conn = new Connection(ConfigType.CODEGEN_ENABLED, ConfigType.ALLOW_DYN_RECOMPILATION);
            PreparedScript pscript = conn.prepareScript(s, new String[] { "X" }, new String[] { "R" }, false);
            pscript.setMatrix("X", mX, false);
            pscript.executeScript();
            conn.close();
            System.out.println(Statistics.display());
        } else {
            SparkConf conf = SparkExecutionContext.createSystemMLSparkConf().setAppName("MLContextTest").setMaster("local");
            JavaSparkContext sc = new JavaSparkContext(conf);
            MLContext ml = new MLContext(sc);
            ml.setConfigProperty(DMLConfig.CODEGEN, "true");
            ml.setStatistics(true);
            Script script = dml(s).in("X", mX).out("R");
            ml.execute(script);
            ml.resetConfig();
            sc.stop();
            ml.close();
        }
        // check for generated operator
        Assert.assertTrue(heavyHittersContainsSubString("spoofRA"));
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
}
Also used : Script(org.apache.sysml.api.mlcontext.Script) PreparedScript(org.apache.sysml.api.jmlc.PreparedScript) DMLScript(org.apache.sysml.api.DMLScript) MatrixBlock(org.apache.sysml.runtime.matrix.data.MatrixBlock) PreparedScript(org.apache.sysml.api.jmlc.PreparedScript) Connection(org.apache.sysml.api.jmlc.Connection) JavaSparkContext(org.apache.spark.api.java.JavaSparkContext) SparkConf(org.apache.spark.SparkConf) MLContext(org.apache.sysml.api.mlcontext.MLContext)

Example 18 with PreparedScript

use of org.apache.sysml.api.jmlc.PreparedScript in project incubator-systemml by apache.

the class FrameEncodeTest method execDMLScriptviaJMLC.

private static ArrayList<String[][]> execDMLScriptviaJMLC(String testname, String[][] F1, boolean modelReuse) throws IOException {
    Timing time = new Timing(true);
    ArrayList<String[][]> ret = new ArrayList<String[][]>();
    // establish connection to SystemML
    Connection conn = new Connection();
    try {
        // prepare input arguments
        HashMap<String, String> args = new HashMap<String, String>();
        args.put("$TRANSFORM_SPEC", "{ \"ids\": true ,\"recode\": [ 1, 2, 3] }");
        // read and precompile script
        String script = conn.readScript(SCRIPT_DIR + TEST_DIR + testname + ".dml");
        PreparedScript pstmt = conn.prepareScript(script, args, new String[] { "F1", "M" }, new String[] { "F2" }, false);
        if (modelReuse)
            pstmt.setFrame("F1", F1, true);
        // execute script multiple times
        for (int i = 0; i < nRuns; i++) {
            // bind input parameters
            if (!modelReuse)
                pstmt.setFrame("F1", F1);
            // execute script
            ResultVariables rs = pstmt.executeScript();
            // get output parameter
            String[][] Y = rs.getFrame("F2");
            // keep result for comparison
            ret.add(Y);
        }
    } catch (Exception ex) {
        ex.printStackTrace();
        throw new IOException(ex);
    } finally {
        IOUtilFunctions.closeSilently(conn);
    }
    System.out.println("JMLC scoring w/ " + nRuns + " runs in " + time.stop() + "ms.");
    return ret;
}
Also used : PreparedScript(org.apache.sysml.api.jmlc.PreparedScript) HashMap(java.util.HashMap) ResultVariables(org.apache.sysml.api.jmlc.ResultVariables) ArrayList(java.util.ArrayList) Connection(org.apache.sysml.api.jmlc.Connection) IOException(java.io.IOException) IOException(java.io.IOException) Timing(org.apache.sysml.runtime.controlprogram.parfor.stat.Timing)

Example 19 with PreparedScript

use of org.apache.sysml.api.jmlc.PreparedScript in project incubator-systemml by apache.

the class FrameLeftIndexingTest method execDMLScriptviaJMLC.

private static ArrayList<String[][]> execDMLScriptviaJMLC(String testname, String[][] F1, String[][] M, boolean modelReuse) throws IOException {
    Timing time = new Timing(true);
    ArrayList<String[][]> ret = new ArrayList<String[][]>();
    // establish connection to SystemML
    Connection conn = new Connection();
    try {
        // prepare input arguments
        HashMap<String, String> args = new HashMap<String, String>();
        args.put("$TRANSFORM_SPEC1", "{ \"ids\": true ,\"recode\": [ 1, 2] }");
        args.put("$TRANSFORM_SPEC2", "{ \"ids\": true ,\"recode\": [ 1] }");
        // read and precompile script
        String script = conn.readScript(SCRIPT_DIR + TEST_DIR + testname + ".dml");
        PreparedScript pstmt = conn.prepareScript(script, args, new String[] { "F1", "M" }, new String[] { "F2" }, false);
        if (modelReuse)
            pstmt.setFrame("M", M, true);
        // execute script multiple times
        for (int i = 0; i < nRuns; i++) {
            // bind input parameters
            if (!modelReuse)
                pstmt.setFrame("M", M);
            pstmt.setFrame("F1", F1);
            // execute script
            ResultVariables rs = pstmt.executeScript();
            // get output parameter
            String[][] Y = rs.getFrame("F2");
            // keep result for comparison
            ret.add(Y);
        }
    } catch (Exception ex) {
        ex.printStackTrace();
        throw new IOException(ex);
    } finally {
        IOUtilFunctions.closeSilently(conn);
    }
    System.out.println("JMLC scoring w/ " + nRuns + " runs in " + time.stop() + "ms.");
    return ret;
}
Also used : PreparedScript(org.apache.sysml.api.jmlc.PreparedScript) HashMap(java.util.HashMap) ResultVariables(org.apache.sysml.api.jmlc.ResultVariables) ArrayList(java.util.ArrayList) Connection(org.apache.sysml.api.jmlc.Connection) IOException(java.io.IOException) IOException(java.io.IOException) Timing(org.apache.sysml.runtime.controlprogram.parfor.stat.Timing)

Example 20 with PreparedScript

use of org.apache.sysml.api.jmlc.PreparedScript in project incubator-systemml by apache.

the class InputToStringTest method testMatrixtoString.

@Test
public void testMatrixtoString() throws DMLException {
    try (Connection conn = new Connection()) {
        PreparedScript pscript = conn.prepareScript("m = read(\"tmp\", data_type=\"matrix\"); print(toString(m));", new String[] { "m" }, new String[] {});
        pscript.setMatrix("m", MatrixBlock.randOperations(7, 3, 1.0, 0, 1, "uniform", 7), false);
        pscript.executeScript();
    }
}
Also used : PreparedScript(org.apache.sysml.api.jmlc.PreparedScript) Connection(org.apache.sysml.api.jmlc.Connection) Test(org.junit.Test)

Aggregations

Connection (org.apache.sysml.api.jmlc.Connection)37 PreparedScript (org.apache.sysml.api.jmlc.PreparedScript)37 ResultVariables (org.apache.sysml.api.jmlc.ResultVariables)14 Test (org.junit.Test)14 IOException (java.io.IOException)12 HashMap (java.util.HashMap)11 ArrayList (java.util.ArrayList)10 Timing (org.apache.sysml.runtime.controlprogram.parfor.stat.Timing)9 DMLException (org.apache.sysml.api.DMLException)2 File (java.io.File)1 ExecutorService (java.util.concurrent.ExecutorService)1 Future (java.util.concurrent.Future)1 SparkConf (org.apache.spark.SparkConf)1 JavaSparkContext (org.apache.spark.api.java.JavaSparkContext)1 DMLScript (org.apache.sysml.api.DMLScript)1 MLContext (org.apache.sysml.api.mlcontext.MLContext)1 Script (org.apache.sysml.api.mlcontext.Script)1 ScalarObject (org.apache.sysml.runtime.instructions.cp.ScalarObject)1 FrameBlock (org.apache.sysml.runtime.matrix.data.FrameBlock)1 MatrixBlock (org.apache.sysml.runtime.matrix.data.MatrixBlock)1