Search in sources :

Example 96 with ProgramBlock

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

the class ResourceOptimizer method compileProgram.

private static ArrayList<ProgramBlock> compileProgram(ArrayList<ProgramBlock> prog, ArrayList<ProgramBlock> B, double cp, double mr) {
    if (B == null) {
        // init
        B = new ArrayList<>();
        InfrastructureAnalyzer.setLocalMaxMemory((long) cp);
        InfrastructureAnalyzer.setRemoteMaxMemoryMap((long) mr);
        InfrastructureAnalyzer.setRemoteMaxMemoryReduce((long) mr);
        // dependent on cp, mr
        OptimizerUtils.resetDefaultSize();
    }
    for (ProgramBlock pb : prog) compileProgram(pb, B, cp, mr);
    return B;
}
Also used : 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)

Example 97 with ProgramBlock

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

the class ResourceOptimizer method recompileProgramBlocks.

private static void recompileProgramBlocks(ArrayList<ProgramBlock> pbs, long cp, double[][] memo) {
    for (int i = 0; i < pbs.size(); i++) {
        ProgramBlock pb = pbs.get(i);
        long mr = (long) memo[i][0];
        recompileProgramBlock(pb, cp, mr);
    }
}
Also used : 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)

Example 98 with ProgramBlock

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

the class ResourceOptimizer method pruneProgramBlocks.

private static ArrayList<ProgramBlock> pruneProgramBlocks(ArrayList<ProgramBlock> B) {
    // prune all program blocks w/o mr instructions (mr budget does not matter)
    if (PRUNING_SMALL) {
        ArrayList<ProgramBlock> Bp = new ArrayList<>();
        for (ProgramBlock pb : B) if (OptTreeConverter.containsMRJobInstruction(pb.getInstructions(), false, true))
            Bp.add(pb);
        B = Bp;
    }
    // prune all program blocks, where all mr hops are due to unknowns
    if (PRUNING_UNKNOWN) {
        ArrayList<ProgramBlock> Bp = new ArrayList<>();
        for (ProgramBlock pb : B) if (!pruneHasOnlyUnknownMR(pb))
            Bp.add(pb);
        B = Bp;
    }
    return B;
}
Also used : ArrayList(java.util.ArrayList) 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)

Example 99 with ProgramBlock

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

the class DMLTranslator method createRuntimeProgramBlock.

public ProgramBlock createRuntimeProgramBlock(Program prog, StatementBlock sb, DMLConfig config) {
    Dag<Lop> dag = null;
    Dag<Lop> pred_dag = null;
    ArrayList<Instruction> instruct;
    ArrayList<Instruction> pred_instruct = null;
    ProgramBlock retPB = null;
    // process While Statement - add runtime program blocks to program
    if (sb instanceof WhileStatementBlock) {
        // create DAG for loop predicates
        pred_dag = new Dag<>();
        ((WhileStatementBlock) sb).get_predicateLops().addToDag(pred_dag);
        // create instructions for loop predicates
        pred_instruct = new ArrayList<>();
        ArrayList<Instruction> pInst = pred_dag.getJobs(null, config);
        for (Instruction i : pInst) {
            pred_instruct.add(i);
        }
        // create while program block
        WhileProgramBlock rtpb = new WhileProgramBlock(prog, pred_instruct);
        // // process the body of the while statement block ////
        WhileStatementBlock wsb = (WhileStatementBlock) sb;
        WhileStatement wstmt = (WhileStatement) wsb.getStatement(0);
        for (StatementBlock sblock : wstmt.getBody()) {
            // process the body
            ProgramBlock childBlock = createRuntimeProgramBlock(prog, sblock, config);
            rtpb.addProgramBlock(childBlock);
        }
        retPB = rtpb;
        // add statement block
        retPB.setStatementBlock(sb);
        // add location information
        retPB.setParseInfo(sb);
    } else // process If Statement - add runtime program blocks to program
    if (sb instanceof IfStatementBlock) {
        // create DAG for loop predicates
        pred_dag = new Dag<>();
        ((IfStatementBlock) sb).get_predicateLops().addToDag(pred_dag);
        // create instructions for loop predicates
        pred_instruct = new ArrayList<>();
        ArrayList<Instruction> pInst = pred_dag.getJobs(null, config);
        for (Instruction i : pInst) {
            pred_instruct.add(i);
        }
        // create if program block
        IfProgramBlock rtpb = new IfProgramBlock(prog, pred_instruct);
        // process the body of the if statement block
        IfStatementBlock isb = (IfStatementBlock) sb;
        IfStatement istmt = (IfStatement) isb.getStatement(0);
        // process the if body
        for (StatementBlock sblock : istmt.getIfBody()) {
            ProgramBlock childBlock = createRuntimeProgramBlock(prog, sblock, config);
            rtpb.addProgramBlockIfBody(childBlock);
        }
        // process the else body
        for (StatementBlock sblock : istmt.getElseBody()) {
            ProgramBlock childBlock = createRuntimeProgramBlock(prog, sblock, config);
            rtpb.addProgramBlockElseBody(childBlock);
        }
        retPB = rtpb;
        // post processing for generating missing instructions
        // retPB = verifyAndCorrectProgramBlock(sb.liveIn(), sb.liveOut(), sb._kill, retPB);
        // add statement block
        retPB.setStatementBlock(sb);
        // add location information
        retPB.setParseInfo(sb);
    } else // NOTE: applies to ForStatementBlock and ParForStatementBlock
    if (sb instanceof ForStatementBlock) {
        ForStatementBlock fsb = (ForStatementBlock) sb;
        // create DAGs for loop predicates
        Dag<Lop> fromDag = new Dag<>();
        Dag<Lop> toDag = new Dag<>();
        Dag<Lop> incrementDag = new Dag<>();
        if (fsb.getFromHops() != null)
            fsb.getFromLops().addToDag(fromDag);
        if (fsb.getToHops() != null)
            fsb.getToLops().addToDag(toDag);
        if (fsb.getIncrementHops() != null)
            fsb.getIncrementLops().addToDag(incrementDag);
        // create instructions for loop predicates
        ArrayList<Instruction> fromInstructions = fromDag.getJobs(null, config);
        ArrayList<Instruction> toInstructions = toDag.getJobs(null, config);
        ArrayList<Instruction> incrementInstructions = incrementDag.getJobs(null, config);
        // create for program block
        ForProgramBlock rtpb = null;
        IterablePredicate iterPred = fsb.getIterPredicate();
        if (sb instanceof ParForStatementBlock && ConfigurationManager.isParallelParFor()) {
            rtpb = new ParForProgramBlock(prog, iterPred.getIterVar().getName(), iterPred.getParForParams(), ((ParForStatementBlock) sb).getResultVariables());
            ParForProgramBlock pfrtpb = (ParForProgramBlock) rtpb;
            // used for optimization and creating unscoped variables
            pfrtpb.setStatementBlock((ParForStatementBlock) sb);
        } else {
            // ForStatementBlock
            rtpb = new ForProgramBlock(prog, iterPred.getIterVar().getName());
        }
        rtpb.setFromInstructions(fromInstructions);
        rtpb.setToInstructions(toInstructions);
        rtpb.setIncrementInstructions(incrementInstructions);
        // process the body of the for statement block
        ForStatement fs = (ForStatement) fsb.getStatement(0);
        for (StatementBlock sblock : fs.getBody()) {
            ProgramBlock childBlock = createRuntimeProgramBlock(prog, sblock, config);
            rtpb.addProgramBlock(childBlock);
        }
        retPB = rtpb;
        // add statement block
        retPB.setStatementBlock(sb);
        // add location information
        retPB.setParseInfo(sb);
    } else // process function statement block - add runtime program blocks to program
    if (sb instanceof FunctionStatementBlock) {
        FunctionStatementBlock fsb = (FunctionStatementBlock) sb;
        FunctionStatement fstmt = (FunctionStatement) fsb.getStatement(0);
        FunctionProgramBlock rtpb = null;
        if (fstmt instanceof ExternalFunctionStatement) {
            // create external function program block
            String execType = ((ExternalFunctionStatement) fstmt).getOtherParams().get(ExternalFunctionStatement.EXEC_TYPE);
            boolean isCP = (execType.equals(ExternalFunctionStatement.IN_MEMORY)) ? true : false;
            StringBuilder buff = new StringBuilder();
            buff.append(config.getTextValue(DMLConfig.SCRATCH_SPACE));
            buff.append(Lop.FILE_SEPARATOR);
            buff.append(Lop.PROCESS_PREFIX);
            buff.append(DMLScript.getUUID());
            buff.append(Lop.FILE_SEPARATOR);
            buff.append(ProgramConverter.CP_ROOT_THREAD_ID);
            buff.append(Lop.FILE_SEPARATOR);
            buff.append("PackageSupport");
            buff.append(Lop.FILE_SEPARATOR);
            String basedir = buff.toString();
            if (isCP) {
                rtpb = new ExternalFunctionProgramBlockCP(prog, fstmt.getInputParams(), fstmt.getOutputParams(), ((ExternalFunctionStatement) fstmt).getOtherParams(), basedir);
            } else {
                rtpb = new ExternalFunctionProgramBlock(prog, fstmt.getInputParams(), fstmt.getOutputParams(), ((ExternalFunctionStatement) fstmt).getOtherParams(), basedir);
            }
            if (!fstmt.getBody().isEmpty()) {
                LOG.error(fstmt.printErrorLocation() + "ExternalFunctionStatementBlock should have no statement blocks in body");
                throw new LopsException(fstmt.printErrorLocation() + "ExternalFunctionStatementBlock should have no statement blocks in body");
            }
        } else {
            // create function program block
            rtpb = new FunctionProgramBlock(prog, fstmt.getInputParams(), fstmt.getOutputParams());
            // process the function statement body
            for (StatementBlock sblock : fstmt.getBody()) {
                // process the body
                ProgramBlock childBlock = createRuntimeProgramBlock(prog, sblock, config);
                rtpb.addProgramBlock(childBlock);
            }
        }
        // check there are actually Lops in to process (loop stmt body will not have any)
        if (fsb.getLops() != null && !fsb.getLops().isEmpty()) {
            LOG.error(fsb.printBlockErrorLocation() + "FunctionStatementBlock should have no Lops");
            throw new LopsException(fsb.printBlockErrorLocation() + "FunctionStatementBlock should have no Lops");
        }
        retPB = rtpb;
        // add location information
        retPB.setParseInfo(sb);
    } else {
        // handle general case
        ProgramBlock rtpb = new ProgramBlock(prog);
        // DAGs for Lops
        dag = new Dag<>();
        // check there are actually Lops in to process (loop stmt body will not have any)
        if (sb.getLops() != null && !sb.getLops().isEmpty()) {
            for (Lop l : sb.getLops()) {
                l.addToDag(dag);
            }
            // Instructions for Lops DAGs
            instruct = dag.getJobs(sb, config);
            rtpb.addInstructions(instruct);
        }
        retPB = rtpb;
        // post processing for generating missing instructions
        // retPB = verifyAndCorrectProgramBlock(sb.liveIn(), sb.liveOut(), sb._kill, retPB);
        // add statement block
        retPB.setStatementBlock(sb);
        // add location information
        retPB.setParseInfo(sb);
    }
    return retPB;
}
Also used : IfProgramBlock(org.apache.sysml.runtime.controlprogram.IfProgramBlock) ArrayList(java.util.ArrayList) WhileProgramBlock(org.apache.sysml.runtime.controlprogram.WhileProgramBlock) Instruction(org.apache.sysml.runtime.instructions.Instruction) ExternalFunctionProgramBlockCP(org.apache.sysml.runtime.controlprogram.ExternalFunctionProgramBlockCP) ExternalFunctionProgramBlock(org.apache.sysml.runtime.controlprogram.ExternalFunctionProgramBlock) 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) FunctionProgramBlock(org.apache.sysml.runtime.controlprogram.FunctionProgramBlock) ExternalFunctionProgramBlock(org.apache.sysml.runtime.controlprogram.ExternalFunctionProgramBlock) ForProgramBlock(org.apache.sysml.runtime.controlprogram.ForProgramBlock) ParForProgramBlock(org.apache.sysml.runtime.controlprogram.ParForProgramBlock) Dag(org.apache.sysml.lops.compile.Dag) Lop(org.apache.sysml.lops.Lop) ParForProgramBlock(org.apache.sysml.runtime.controlprogram.ParForProgramBlock) LopsException(org.apache.sysml.lops.LopsException)

Example 100 with ProgramBlock

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

the class DMLTranslator method getRuntimeProgram.

public Program getRuntimeProgram(DMLProgram prog, DMLConfig config) throws IOException, LanguageException, DMLRuntimeException, LopsException, HopsException {
    // 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 : prog.getNamespaces().keySet()) {
        for (String fname : prog.getFunctionStatementBlocks(namespace).keySet()) {
            // add program block to program
            FunctionStatementBlock fsb = prog.getFunctionStatementBlocks(namespace).get(fname);
            FunctionProgramBlock rtpb = (FunctionProgramBlock) createRuntimeProgramBlock(rtprog, fsb, config);
            rtprog.addFunctionProgramBlock(namespace, fname, rtpb);
            rtpb.setRecompileOnce(fsb.isRecompileOnce());
        }
    }
    // translate all top-level statement blocks to program blocks
    for (StatementBlock sb : prog.getStatementBlocks()) {
        // add program block to program
        ProgramBlock rtpb = createRuntimeProgramBlock(rtprog, sb, config);
        rtprog.addProgramBlock(rtpb);
    }
    // enhance runtime program by automatic operator fusion
    if (ConfigurationManager.isCodegenEnabled() && SpoofCompiler.INTEGRATION == IntegrationType.RUNTIME) {
        codgenHopsDAG(rtprog);
    }
    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) 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)

Aggregations

ProgramBlock (org.apache.sysml.runtime.controlprogram.ProgramBlock)114 ForProgramBlock (org.apache.sysml.runtime.controlprogram.ForProgramBlock)103 FunctionProgramBlock (org.apache.sysml.runtime.controlprogram.FunctionProgramBlock)99 IfProgramBlock (org.apache.sysml.runtime.controlprogram.IfProgramBlock)95 WhileProgramBlock (org.apache.sysml.runtime.controlprogram.WhileProgramBlock)95 ParForProgramBlock (org.apache.sysml.runtime.controlprogram.ParForProgramBlock)66 ExternalFunctionProgramBlock (org.apache.sysml.runtime.controlprogram.ExternalFunctionProgramBlock)48 Instruction (org.apache.sysml.runtime.instructions.Instruction)33 ArrayList (java.util.ArrayList)30 FunctionCallCPInstruction (org.apache.sysml.runtime.instructions.cp.FunctionCallCPInstruction)25 StatementBlock (org.apache.sysml.parser.StatementBlock)24 ForStatementBlock (org.apache.sysml.parser.ForStatementBlock)20 IfStatementBlock (org.apache.sysml.parser.IfStatementBlock)20 WhileStatementBlock (org.apache.sysml.parser.WhileStatementBlock)20 VariableCPInstruction (org.apache.sysml.runtime.instructions.cp.VariableCPInstruction)19 MRJobInstruction (org.apache.sysml.runtime.instructions.MRJobInstruction)18 Program (org.apache.sysml.runtime.controlprogram.Program)16 CPInstruction (org.apache.sysml.runtime.instructions.cp.CPInstruction)16 MRInstruction (org.apache.sysml.runtime.instructions.mr.MRInstruction)16 DMLProgram (org.apache.sysml.parser.DMLProgram)15