Search in sources :

Example 16 with ProgramBlock

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

the class ProgramConverter method parseParForBody.

// //////////////////////////////
// PARSING
// //////////////////////////////
public static ParForBody parseParForBody(String in, int id) {
    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<ResultVar> rvars = parseResultVariables(rvarStr);
    body.setResultVariables(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) ResultVar(org.apache.sysml.parser.ParForStatementBlock.ResultVar) 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 17 with ProgramBlock

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

the class ProgramConverter method rParseIfProgramBlock.

private static IfProgramBlock rParseIfProgramBlock(String in, Program prog, int id) {
    String lin = in.substring(PARFOR_PB_IF.length(), in.length() - PARFOR_PB_END.length());
    HierarchyAwareStringTokenizer st = new HierarchyAwareStringTokenizer(lin, COMPONENTS_DELIM);
    // predicate instructions
    ArrayList<Instruction> inst = parseInstructions(st.nextToken(), id);
    // exit instructions
    ArrayList<Instruction> exit = parseInstructions(st.nextToken(), id);
    // program blocks: if and else
    ArrayList<ProgramBlock> pbs1 = rParseProgramBlocks(st.nextToken(), prog, id);
    ArrayList<ProgramBlock> pbs2 = rParseProgramBlocks(st.nextToken(), prog, id);
    IfProgramBlock ipb = new IfProgramBlock(prog, inst);
    ipb.setExitInstructions2(exit);
    ipb.setChildBlocksIfBody(pbs1);
    ipb.setChildBlocksElseBody(pbs2);
    return ipb;
}
Also used : IfProgramBlock(org.apache.sysml.runtime.controlprogram.IfProgramBlock) 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) GPUInstruction(org.apache.sysml.runtime.instructions.gpu.GPUInstruction) MRJobInstruction(org.apache.sysml.runtime.instructions.MRJobInstruction) CPInstruction(org.apache.sysml.runtime.instructions.cp.CPInstruction) ExternalFunctionInvocationInstruction(org.apache.sysml.udf.ExternalFunctionInvocationInstruction) SpoofCPInstruction(org.apache.sysml.runtime.instructions.cp.SpoofCPInstruction) Instruction(org.apache.sysml.runtime.instructions.Instruction) SPInstruction(org.apache.sysml.runtime.instructions.spark.SPInstruction) VariableCPInstruction(org.apache.sysml.runtime.instructions.cp.VariableCPInstruction) FunctionCallCPInstruction(org.apache.sysml.runtime.instructions.cp.FunctionCallCPInstruction) MRInstruction(org.apache.sysml.runtime.instructions.mr.MRInstruction)

Example 18 with ProgramBlock

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

the class ProgramConverter method serializeParForBody.

public static String serializeParForBody(ParForBody body, HashMap<String, byte[]> clsMap) {
    ArrayList<ProgramBlock> pbs = body.getChildBlocks();
    ArrayList<ResultVar> rVnames = body.getResultVariables();
    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(serializeResultVariables(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) ResultVar(org.apache.sysml.parser.ParForStatementBlock.ResultVar) 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 19 with ProgramBlock

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

the class ProgramConverter method rParseParForProgramBlock.

private static ParForProgramBlock rParseParForProgramBlock(String in, Program prog, int id) {
    String lin = in.substring(PARFOR_PB_PARFOR.length(), in.length() - PARFOR_PB_END.length());
    HierarchyAwareStringTokenizer st = new HierarchyAwareStringTokenizer(lin, COMPONENTS_DELIM);
    // inputs
    String iterVar = st.nextToken();
    ArrayList<ResultVar> resultVars = parseResultVariables(st.nextToken());
    HashMap<String, String> params = parseStringHashMap(st.nextToken());
    // instructions
    ArrayList<Instruction> from = parseInstructions(st.nextToken(), 0);
    ArrayList<Instruction> to = parseInstructions(st.nextToken(), 0);
    ArrayList<Instruction> incr = parseInstructions(st.nextToken(), 0);
    // exit instructions
    ArrayList<Instruction> exit = parseInstructions(st.nextToken(), 0);
    // program blocks //reset id to preinit state, replaced during exec
    ArrayList<ProgramBlock> pbs = rParseProgramBlocks(st.nextToken(), prog, 0);
    ParForProgramBlock pfpb = new ParForProgramBlock(id, prog, iterVar, params, resultVars);
    // already done in top-level parfor
    pfpb.disableOptimization();
    pfpb.setFromInstructions(from);
    pfpb.setToInstructions(to);
    pfpb.setIncrementInstructions(incr);
    pfpb.setExitInstructions(exit);
    pfpb.setChildBlocks(pbs);
    return pfpb;
}
Also used : ResultVar(org.apache.sysml.parser.ParForStatementBlock.ResultVar) 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) GPUInstruction(org.apache.sysml.runtime.instructions.gpu.GPUInstruction) MRJobInstruction(org.apache.sysml.runtime.instructions.MRJobInstruction) CPInstruction(org.apache.sysml.runtime.instructions.cp.CPInstruction) ExternalFunctionInvocationInstruction(org.apache.sysml.udf.ExternalFunctionInvocationInstruction) SpoofCPInstruction(org.apache.sysml.runtime.instructions.cp.SpoofCPInstruction) Instruction(org.apache.sysml.runtime.instructions.Instruction) SPInstruction(org.apache.sysml.runtime.instructions.spark.SPInstruction) VariableCPInstruction(org.apache.sysml.runtime.instructions.cp.VariableCPInstruction) FunctionCallCPInstruction(org.apache.sysml.runtime.instructions.cp.FunctionCallCPInstruction) MRInstruction(org.apache.sysml.runtime.instructions.mr.MRInstruction) ParForProgramBlock(org.apache.sysml.runtime.controlprogram.ParForProgramBlock)

Example 20 with ProgramBlock

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

the class ProgramConverter method rParseFunctionProgramBlock.

private static FunctionProgramBlock rParseFunctionProgramBlock(String in, Program prog, int id) {
    String lin = in.substring(PARFOR_PB_FC.length(), in.length() - PARFOR_PB_END.length());
    HierarchyAwareStringTokenizer st = new HierarchyAwareStringTokenizer(lin, COMPONENTS_DELIM);
    // inputs and outputs
    ArrayList<DataIdentifier> dat1 = parseDataIdentifiers(st.nextToken());
    ArrayList<DataIdentifier> dat2 = parseDataIdentifiers(st.nextToken());
    // instructions
    ArrayList<Instruction> inst = parseInstructions(st.nextToken(), id);
    // program blocks
    ArrayList<ProgramBlock> pbs = rParseProgramBlocks(st.nextToken(), prog, id);
    ArrayList<DataIdentifier> tmp1 = new ArrayList<>(dat1);
    ArrayList<DataIdentifier> tmp2 = new ArrayList<>(dat2);
    FunctionProgramBlock fpb = new FunctionProgramBlock(prog, tmp1, tmp2);
    fpb.setInstructions(inst);
    fpb.setChildBlocks(pbs);
    return fpb;
}
Also used : FunctionProgramBlock(org.apache.sysml.runtime.controlprogram.FunctionProgramBlock) ExternalFunctionProgramBlock(org.apache.sysml.runtime.controlprogram.ExternalFunctionProgramBlock) DataIdentifier(org.apache.sysml.parser.DataIdentifier) 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) GPUInstruction(org.apache.sysml.runtime.instructions.gpu.GPUInstruction) MRJobInstruction(org.apache.sysml.runtime.instructions.MRJobInstruction) CPInstruction(org.apache.sysml.runtime.instructions.cp.CPInstruction) ExternalFunctionInvocationInstruction(org.apache.sysml.udf.ExternalFunctionInvocationInstruction) SpoofCPInstruction(org.apache.sysml.runtime.instructions.cp.SpoofCPInstruction) Instruction(org.apache.sysml.runtime.instructions.Instruction) SPInstruction(org.apache.sysml.runtime.instructions.spark.SPInstruction) VariableCPInstruction(org.apache.sysml.runtime.instructions.cp.VariableCPInstruction) FunctionCallCPInstruction(org.apache.sysml.runtime.instructions.cp.FunctionCallCPInstruction) MRInstruction(org.apache.sysml.runtime.instructions.mr.MRInstruction)

Aggregations

ProgramBlock (org.apache.sysml.runtime.controlprogram.ProgramBlock)64 ForProgramBlock (org.apache.sysml.runtime.controlprogram.ForProgramBlock)58 FunctionProgramBlock (org.apache.sysml.runtime.controlprogram.FunctionProgramBlock)56 IfProgramBlock (org.apache.sysml.runtime.controlprogram.IfProgramBlock)54 WhileProgramBlock (org.apache.sysml.runtime.controlprogram.WhileProgramBlock)54 ParForProgramBlock (org.apache.sysml.runtime.controlprogram.ParForProgramBlock)38 ExternalFunctionProgramBlock (org.apache.sysml.runtime.controlprogram.ExternalFunctionProgramBlock)26 ArrayList (java.util.ArrayList)20 Instruction (org.apache.sysml.runtime.instructions.Instruction)18 StatementBlock (org.apache.sysml.parser.StatementBlock)13 FunctionCallCPInstruction (org.apache.sysml.runtime.instructions.cp.FunctionCallCPInstruction)13 ForStatementBlock (org.apache.sysml.parser.ForStatementBlock)11 IfStatementBlock (org.apache.sysml.parser.IfStatementBlock)11 WhileStatementBlock (org.apache.sysml.parser.WhileStatementBlock)11 Hop (org.apache.sysml.hops.Hop)10 VariableCPInstruction (org.apache.sysml.runtime.instructions.cp.VariableCPInstruction)10 DMLRuntimeException (org.apache.sysml.runtime.DMLRuntimeException)9 Program (org.apache.sysml.runtime.controlprogram.Program)9 DMLProgram (org.apache.sysml.parser.DMLProgram)8 FunctionStatementBlock (org.apache.sysml.parser.FunctionStatementBlock)7