Search in sources :

Example 6 with Program

use of org.apache.sysml.runtime.controlprogram.Program in project incubator-systemml by apache.

the class DMLProgram method getRuntimeProgram.

public Program getRuntimeProgram(DMLConfig config) throws IOException, LanguageException, DMLRuntimeException, LopsException {
    // constructor resets the set of registered functions
    Program rtprog = new Program();
    // for all namespaces, translate function statement blocks into function program blocks
    for (String namespace : _namespaces.keySet()) {
        for (String fname : getFunctionStatementBlocks(namespace).keySet()) {
            // add program block to program
            FunctionStatementBlock fsb = getFunctionStatementBlocks(namespace).get(fname);
            FunctionProgramBlock rtpb = (FunctionProgramBlock) createRuntimeProgramBlock(rtprog, fsb, config);
            rtprog.addFunctionProgramBlock(namespace, fname, rtpb);
            rtpb.setRecompileOnce(fsb.isRecompileOnce());
        }
    }
    // for each top-level block
    for (StatementBlock sb : _blocks) {
        // add program block to program
        ProgramBlock rtpb = createRuntimeProgramBlock(rtprog, sb, config);
        rtprog.addProgramBlock(rtpb);
    }
    return rtprog;
}
Also used : FunctionProgramBlock(org.apache.sysml.runtime.controlprogram.FunctionProgramBlock) ExternalFunctionProgramBlock(org.apache.sysml.runtime.controlprogram.ExternalFunctionProgramBlock) Program(org.apache.sysml.runtime.controlprogram.Program) ForProgramBlock(org.apache.sysml.runtime.controlprogram.ForProgramBlock) IfProgramBlock(org.apache.sysml.runtime.controlprogram.IfProgramBlock) FunctionProgramBlock(org.apache.sysml.runtime.controlprogram.FunctionProgramBlock) ProgramBlock(org.apache.sysml.runtime.controlprogram.ProgramBlock) WhileProgramBlock(org.apache.sysml.runtime.controlprogram.WhileProgramBlock) ParForProgramBlock(org.apache.sysml.runtime.controlprogram.ParForProgramBlock) ExternalFunctionProgramBlock(org.apache.sysml.runtime.controlprogram.ExternalFunctionProgramBlock)

Example 7 with Program

use of org.apache.sysml.runtime.controlprogram.Program in project incubator-systemml by apache.

the class OptimizerRuleBased method removeRecursiveParFor.

protected int removeRecursiveParFor(OptNode n, HashSet<ParForProgramBlock> recPBs) throws DMLRuntimeException {
    int count = 0;
    if (!n.isLeaf()) {
        for (OptNode sub : n.getChilds()) {
            if (sub.getNodeType() == NodeType.PARFOR) {
                long id = sub.getID();
                Object[] progobj = OptTreeConverter.getAbstractPlanMapping().getMappedProg(id);
                ParForStatementBlock pfsb = (ParForStatementBlock) progobj[0];
                ParForProgramBlock pfpb = (ParForProgramBlock) progobj[1];
                if (recPBs.contains(pfpb)) {
                    //create for pb as replacement
                    Program prog = pfpb.getProgram();
                    ForProgramBlock fpb = ProgramConverter.createShallowCopyForProgramBlock(pfpb, prog);
                    //replace parfor with for, and update objectmapping
                    OptTreeConverter.replaceProgramBlock(n, sub, pfpb, fpb, false);
                    //update link to statement block
                    fpb.setStatementBlock(pfsb);
                    //update node
                    sub.setNodeType(NodeType.FOR);
                    sub.setK(1);
                    count++;
                }
            }
            count += removeRecursiveParFor(sub, recPBs);
        }
    }
    return count;
}
Also used : DMLProgram(org.apache.sysml.parser.DMLProgram) Program(org.apache.sysml.runtime.controlprogram.Program) ForProgramBlock(org.apache.sysml.runtime.controlprogram.ForProgramBlock) ParForProgramBlock(org.apache.sysml.runtime.controlprogram.ParForProgramBlock) ParForStatementBlock(org.apache.sysml.parser.ParForStatementBlock) MatrixObject(org.apache.sysml.runtime.controlprogram.caching.MatrixObject) RDDObject(org.apache.sysml.runtime.instructions.spark.data.RDDObject) ParForProgramBlock(org.apache.sysml.runtime.controlprogram.ParForProgramBlock)

Example 8 with Program

use of org.apache.sysml.runtime.controlprogram.Program in project incubator-systemml by apache.

the class ProgramConverter method parseParForBody.

////////////////////////////////
// PARSING 
////////////////////////////////
public static ParForBody parseParForBody(String in, int id) throws DMLRuntimeException {
    ParForBody body = new ParForBody();
    //header elimination
    //normalization
    String tmpin = in.replaceAll(NEWLINE, "");
    //remove start/end
    tmpin = tmpin.substring(PARFORBODY_BEGIN.length(), tmpin.length() - PARFORBODY_END.length());
    HierarchyAwareStringTokenizer st = new HierarchyAwareStringTokenizer(tmpin, COMPONENTS_DELIM);
    //handle DMLScript UUID (NOTE: set directly in DMLScript)
    //(master UUID is used for all nodes (in order to simply cleanup))
    DMLScript.setUUID(st.nextToken());
    //handle DML config (NOTE: set directly in ConfigurationManager)
    String confStr = st.nextToken();
    JobConf job = ConfigurationManager.getCachedJobConf();
    if (!InfrastructureAnalyzer.isLocalMode(job)) {
        if (confStr != null && !confStr.trim().isEmpty()) {
            DMLConfig dmlconf = DMLConfig.parseDMLConfig(confStr);
            CompilerConfig cconf = OptimizerUtils.constructCompilerConfig(dmlconf);
            ConfigurationManager.setLocalConfig(dmlconf);
            ConfigurationManager.setLocalConfig(cconf);
        }
        //init internal configuration w/ parsed or default config
        ParForProgramBlock.initInternalConfigurations(ConfigurationManager.getDMLConfig());
    }
    //handle additional configs
    String aconfs = st.nextToken();
    parseAndSetAdditionalConfigurations(aconfs);
    //handle program
    String progStr = st.nextToken();
    Program prog = parseProgram(progStr, id);
    //handle result variable names
    String rvarStr = st.nextToken();
    ArrayList<String> rvars = parseStringArrayList(rvarStr);
    body.setResultVarNames(rvars);
    //handle execution context
    String ecStr = st.nextToken();
    ExecutionContext ec = parseExecutionContext(ecStr, prog);
    //handle program blocks
    String spbs = st.nextToken();
    ArrayList<ProgramBlock> pbs = rParseProgramBlocks(spbs, prog, id);
    body.setChildBlocks(pbs);
    body.setEc(ec);
    return body;
}
Also used : DMLConfig(org.apache.sysml.conf.DMLConfig) DMLProgram(org.apache.sysml.parser.DMLProgram) Program(org.apache.sysml.runtime.controlprogram.Program) ExecutionContext(org.apache.sysml.runtime.controlprogram.context.ExecutionContext) FunctionProgramBlock(org.apache.sysml.runtime.controlprogram.FunctionProgramBlock) WhileProgramBlock(org.apache.sysml.runtime.controlprogram.WhileProgramBlock) ExternalFunctionProgramBlock(org.apache.sysml.runtime.controlprogram.ExternalFunctionProgramBlock) ForProgramBlock(org.apache.sysml.runtime.controlprogram.ForProgramBlock) IfProgramBlock(org.apache.sysml.runtime.controlprogram.IfProgramBlock) ProgramBlock(org.apache.sysml.runtime.controlprogram.ProgramBlock) ParForProgramBlock(org.apache.sysml.runtime.controlprogram.ParForProgramBlock) JobConf(org.apache.hadoop.mapred.JobConf) CompilerConfig(org.apache.sysml.conf.CompilerConfig)

Example 9 with Program

use of org.apache.sysml.runtime.controlprogram.Program in project incubator-systemml by apache.

the class ProgramConverter method serializeParForBody.

public static String serializeParForBody(ParForBody body, HashMap<String, byte[]> clsMap) throws DMLRuntimeException {
    ArrayList<ProgramBlock> pbs = body.getChildBlocks();
    ArrayList<String> rVnames = body.getResultVarNames();
    ExecutionContext ec = body.getEc();
    if (pbs.isEmpty())
        return PARFORBODY_BEGIN + PARFORBODY_END;
    Program prog = pbs.get(0).getProgram();
    StringBuilder sb = new StringBuilder();
    sb.append(PARFORBODY_BEGIN);
    sb.append(NEWLINE);
    //handle DMLScript UUID (propagate original uuid for writing to scratch space)
    sb.append(DMLScript.getUUID());
    sb.append(COMPONENTS_DELIM);
    sb.append(NEWLINE);
    //handle DML config
    sb.append(ConfigurationManager.getDMLConfig().serializeDMLConfig());
    sb.append(COMPONENTS_DELIM);
    sb.append(NEWLINE);
    //handle additional configurations
    sb.append(PARFOR_CONF_STATS + "=" + DMLScript.STATISTICS);
    sb.append(COMPONENTS_DELIM);
    sb.append(NEWLINE);
    //handle program
    sb.append(PARFOR_PROG_BEGIN);
    sb.append(NEWLINE);
    sb.append(serializeProgram(prog, pbs, clsMap));
    sb.append(PARFOR_PROG_END);
    sb.append(NEWLINE);
    sb.append(COMPONENTS_DELIM);
    sb.append(NEWLINE);
    //handle result variable names
    sb.append(serializeStringArrayList(rVnames));
    sb.append(COMPONENTS_DELIM);
    //handle execution context
    //note: this includes also the symbol table (serialize only the top-level variable map,
    //      (symbol tables for nested/child blocks are created at parse time, on the remote side)
    sb.append(PARFOR_EC_BEGIN);
    sb.append(serializeExecutionContext(ec));
    sb.append(PARFOR_EC_END);
    sb.append(NEWLINE);
    sb.append(COMPONENTS_DELIM);
    sb.append(NEWLINE);
    //handle program blocks -- ONLY instructions, not variables.
    sb.append(PARFOR_PBS_BEGIN);
    sb.append(NEWLINE);
    sb.append(rSerializeProgramBlocks(pbs, clsMap));
    sb.append(PARFOR_PBS_END);
    sb.append(NEWLINE);
    sb.append(PARFORBODY_END);
    return sb.toString();
}
Also used : ExecutionContext(org.apache.sysml.runtime.controlprogram.context.ExecutionContext) DMLProgram(org.apache.sysml.parser.DMLProgram) Program(org.apache.sysml.runtime.controlprogram.Program) FunctionProgramBlock(org.apache.sysml.runtime.controlprogram.FunctionProgramBlock) WhileProgramBlock(org.apache.sysml.runtime.controlprogram.WhileProgramBlock) ExternalFunctionProgramBlock(org.apache.sysml.runtime.controlprogram.ExternalFunctionProgramBlock) ForProgramBlock(org.apache.sysml.runtime.controlprogram.ForProgramBlock) IfProgramBlock(org.apache.sysml.runtime.controlprogram.IfProgramBlock) ProgramBlock(org.apache.sysml.runtime.controlprogram.ProgramBlock) ParForProgramBlock(org.apache.sysml.runtime.controlprogram.ParForProgramBlock)

Example 10 with Program

use of org.apache.sysml.runtime.controlprogram.Program in project incubator-systemml by apache.

the class ProgramConverter method rcreateDeepCopyProgramBlocks.

/**
	 * This recursively creates a deep copy of program blocks and transparently replaces filenames according to the
	 * specified parallel worker in order to avoid conflicts between parworkers. This happens recursively in order
	 * to support arbitrary control-flow constructs within a parfor. 
	 * 
	 * @param childBlocks child program blocks
	 * @param pid ?
	 * @param IDPrefix ?
	 * @param fnStack ?
	 * @param fnCreated ?
	 * @param plain if true, full deep copy without id replacement
	 * @param forceDeepCopy if true, force deep copy
	 * @return list of program blocks
	 * @throws DMLRuntimeException if DMLRuntimeException occurs
	 */
public static ArrayList<ProgramBlock> rcreateDeepCopyProgramBlocks(ArrayList<ProgramBlock> childBlocks, long pid, int IDPrefix, HashSet<String> fnStack, HashSet<String> fnCreated, boolean plain, boolean forceDeepCopy) throws DMLRuntimeException {
    ArrayList<ProgramBlock> tmp = new ArrayList<ProgramBlock>();
    for (ProgramBlock pb : childBlocks) {
        Program prog = pb.getProgram();
        ProgramBlock tmpPB = null;
        if (pb instanceof WhileProgramBlock) {
            tmpPB = createDeepCopyWhileProgramBlock((WhileProgramBlock) pb, pid, IDPrefix, prog, fnStack, fnCreated, plain, forceDeepCopy);
        } else if (pb instanceof ForProgramBlock && !(pb instanceof ParForProgramBlock)) {
            tmpPB = createDeepCopyForProgramBlock((ForProgramBlock) pb, pid, IDPrefix, prog, fnStack, fnCreated, plain, forceDeepCopy);
        } else if (pb instanceof ParForProgramBlock) {
            ParForProgramBlock pfpb = (ParForProgramBlock) pb;
            if (ParForProgramBlock.ALLOW_NESTED_PARALLELISM)
                tmpPB = createDeepCopyParForProgramBlock(pfpb, pid, IDPrefix, prog, fnStack, fnCreated, plain, forceDeepCopy);
            else
                tmpPB = createDeepCopyForProgramBlock((ForProgramBlock) pb, pid, IDPrefix, prog, fnStack, fnCreated, plain, forceDeepCopy);
        } else if (pb instanceof IfProgramBlock) {
            tmpPB = createDeepCopyIfProgramBlock((IfProgramBlock) pb, pid, IDPrefix, prog, fnStack, fnCreated, plain, forceDeepCopy);
        } else //last-level program block
        {
            // general case use for most PBs
            tmpPB = new ProgramBlock(prog);
            //for recompile in the master node JVM
            tmpPB.setStatementBlock(createStatementBlockCopy(pb.getStatementBlock(), pid, plain, forceDeepCopy));
            //tmpPB.setStatementBlock(pb.getStatementBlock()); 
            tmpPB.setThreadID(pid);
        }
        //copy instructions
        tmpPB.setInstructions(createDeepCopyInstructionSet(pb.getInstructions(), pid, IDPrefix, prog, fnStack, fnCreated, plain, true));
        //copy symbol table
        //tmpPB.setVariables( pb.getVariables() ); //implicit cloning			
        tmp.add(tmpPB);
    }
    return tmp;
}
Also used : IfProgramBlock(org.apache.sysml.runtime.controlprogram.IfProgramBlock) DMLProgram(org.apache.sysml.parser.DMLProgram) Program(org.apache.sysml.runtime.controlprogram.Program) ForProgramBlock(org.apache.sysml.runtime.controlprogram.ForProgramBlock) ParForProgramBlock(org.apache.sysml.runtime.controlprogram.ParForProgramBlock) ArrayList(java.util.ArrayList) FunctionProgramBlock(org.apache.sysml.runtime.controlprogram.FunctionProgramBlock) WhileProgramBlock(org.apache.sysml.runtime.controlprogram.WhileProgramBlock) ExternalFunctionProgramBlock(org.apache.sysml.runtime.controlprogram.ExternalFunctionProgramBlock) ForProgramBlock(org.apache.sysml.runtime.controlprogram.ForProgramBlock) IfProgramBlock(org.apache.sysml.runtime.controlprogram.IfProgramBlock) ProgramBlock(org.apache.sysml.runtime.controlprogram.ProgramBlock) ParForProgramBlock(org.apache.sysml.runtime.controlprogram.ParForProgramBlock) WhileProgramBlock(org.apache.sysml.runtime.controlprogram.WhileProgramBlock) ParForProgramBlock(org.apache.sysml.runtime.controlprogram.ParForProgramBlock)

Aggregations

Program (org.apache.sysml.runtime.controlprogram.Program)15 DMLProgram (org.apache.sysml.parser.DMLProgram)11 ForProgramBlock (org.apache.sysml.runtime.controlprogram.ForProgramBlock)9 FunctionProgramBlock (org.apache.sysml.runtime.controlprogram.FunctionProgramBlock)8 ProgramBlock (org.apache.sysml.runtime.controlprogram.ProgramBlock)8 IfProgramBlock (org.apache.sysml.runtime.controlprogram.IfProgramBlock)7 ParForProgramBlock (org.apache.sysml.runtime.controlprogram.ParForProgramBlock)7 WhileProgramBlock (org.apache.sysml.runtime.controlprogram.WhileProgramBlock)7 ExternalFunctionProgramBlock (org.apache.sysml.runtime.controlprogram.ExternalFunctionProgramBlock)6 ExecutionContext (org.apache.sysml.runtime.controlprogram.context.ExecutionContext)6 ArrayList (java.util.ArrayList)4 DMLConfig (org.apache.sysml.conf.DMLConfig)3 ParForStatementBlock (org.apache.sysml.parser.ParForStatementBlock)3 MatrixObject (org.apache.sysml.runtime.controlprogram.caching.MatrixObject)3 CompilerConfig (org.apache.sysml.conf.CompilerConfig)2 DMLTranslator (org.apache.sysml.parser.DMLTranslator)2 FunctionStatementBlock (org.apache.sysml.parser.FunctionStatementBlock)2 ParserWrapper (org.apache.sysml.parser.ParserWrapper)2 StatementBlock (org.apache.sysml.parser.StatementBlock)2 DMLRuntimeException (org.apache.sysml.runtime.DMLRuntimeException)2