Search in sources :

Example 6 with ProgramBlock

use of org.apache.sysml.runtime.controlprogram.ProgramBlock 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 ProgramBlock

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

the class DMLDebuggerProgramInfo method accessProgramBlockBreakpoint.

/**
 * Access breakpoint instruction at specified line number in program block (if valid)
 * @param pb Current program block
 * @param lineNumber Location for inserting breakpoint
 * @param op Breakpoint operation
 * @param status Current breakpoint status
 */
private void accessProgramBlockBreakpoint(ProgramBlock pb, int lineNumber, int op, BPINSTRUCTION_STATUS status) {
    if (pb instanceof FunctionProgramBlock) {
        FunctionProgramBlock fpb = (FunctionProgramBlock) pb;
        for (ProgramBlock pbc : fpb.getChildBlocks()) accessProgramBlockBreakpoint(pbc, lineNumber, op, status);
    } else if (pb instanceof WhileProgramBlock) {
        WhileProgramBlock wpb = (WhileProgramBlock) pb;
        this.accesBreakpointInstruction(wpb.getPredicate(), lineNumber, op, status);
        for (ProgramBlock pbc : wpb.getChildBlocks()) accessProgramBlockBreakpoint(pbc, lineNumber, op, status);
    } else if (pb instanceof IfProgramBlock) {
        IfProgramBlock ipb = (IfProgramBlock) pb;
        this.accesBreakpointInstruction(ipb.getPredicate(), lineNumber, op, status);
        for (ProgramBlock pbc : ipb.getChildBlocksIfBody()) accessProgramBlockBreakpoint(pbc, lineNumber, op, status);
        if (!ipb.getChildBlocksElseBody().isEmpty()) {
            for (ProgramBlock pbc : ipb.getChildBlocksElseBody()) accessProgramBlockBreakpoint(pbc, lineNumber, op, status);
        }
    } else if (// incl parfor
    pb instanceof ForProgramBlock) {
        ForProgramBlock fpb = (ForProgramBlock) pb;
        this.accesBreakpointInstruction(fpb.getFromInstructions(), lineNumber, op, status);
        this.accesBreakpointInstruction(fpb.getToInstructions(), lineNumber, op, status);
        this.accesBreakpointInstruction(fpb.getIncrementInstructions(), lineNumber, op, status);
        for (ProgramBlock pbc : fpb.getChildBlocks()) accessProgramBlockBreakpoint(pbc, lineNumber, op, status);
    } else {
        this.accesBreakpointInstruction(pb.getInstructions(), lineNumber, op, status);
    }
}
Also used : ExternalFunctionProgramBlock(org.apache.sysml.runtime.controlprogram.ExternalFunctionProgramBlock) FunctionProgramBlock(org.apache.sysml.runtime.controlprogram.FunctionProgramBlock) IfProgramBlock(org.apache.sysml.runtime.controlprogram.IfProgramBlock) ForProgramBlock(org.apache.sysml.runtime.controlprogram.ForProgramBlock) ForProgramBlock(org.apache.sysml.runtime.controlprogram.ForProgramBlock) ExternalFunctionProgramBlock(org.apache.sysml.runtime.controlprogram.ExternalFunctionProgramBlock) 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) WhileProgramBlock(org.apache.sysml.runtime.controlprogram.WhileProgramBlock)

Example 8 with ProgramBlock

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

the class SpoofCompiler method generateCodeFromProgramBlock.

public static void generateCodeFromProgramBlock(ProgramBlock current) {
    if (current instanceof FunctionProgramBlock) {
        FunctionProgramBlock fsb = (FunctionProgramBlock) current;
        for (ProgramBlock pb : fsb.getChildBlocks()) generateCodeFromProgramBlock(pb);
    } else if (current instanceof WhileProgramBlock) {
        WhileProgramBlock wpb = (WhileProgramBlock) current;
        WhileStatementBlock wsb = (WhileStatementBlock) wpb.getStatementBlock();
        if (wsb != null && wsb.getPredicateHops() != null)
            wpb.setPredicate(generateCodeFromHopDAGsToInst(wsb.getPredicateHops()));
        for (ProgramBlock sb : wpb.getChildBlocks()) generateCodeFromProgramBlock(sb);
    } else if (current instanceof IfProgramBlock) {
        IfProgramBlock ipb = (IfProgramBlock) current;
        IfStatementBlock isb = (IfStatementBlock) ipb.getStatementBlock();
        if (isb != null && isb.getPredicateHops() != null)
            ipb.setPredicate(generateCodeFromHopDAGsToInst(isb.getPredicateHops()));
        for (ProgramBlock pb : ipb.getChildBlocksIfBody()) generateCodeFromProgramBlock(pb);
        for (ProgramBlock pb : ipb.getChildBlocksElseBody()) generateCodeFromProgramBlock(pb);
    } else if (// incl parfor
    current instanceof ForProgramBlock) {
        ForProgramBlock fpb = (ForProgramBlock) current;
        ForStatementBlock fsb = (ForStatementBlock) fpb.getStatementBlock();
        if (fsb != null && fsb.getFromHops() != null)
            fpb.setFromInstructions(generateCodeFromHopDAGsToInst(fsb.getFromHops()));
        if (fsb != null && fsb.getToHops() != null)
            fpb.setToInstructions(generateCodeFromHopDAGsToInst(fsb.getToHops()));
        if (fsb != null && fsb.getIncrementHops() != null)
            fpb.setIncrementInstructions(generateCodeFromHopDAGsToInst(fsb.getIncrementHops()));
        for (ProgramBlock pb : fpb.getChildBlocks()) generateCodeFromProgramBlock(pb);
    } else // generic (last-level)
    {
        StatementBlock sb = current.getStatementBlock();
        current.setInstructions(generateCodeFromHopDAGsToInst(sb, sb.getHops()));
    }
}
Also used : FunctionProgramBlock(org.apache.sysml.runtime.controlprogram.FunctionProgramBlock) IfProgramBlock(org.apache.sysml.runtime.controlprogram.IfProgramBlock) ForStatementBlock(org.apache.sysml.parser.ForStatementBlock) ForProgramBlock(org.apache.sysml.runtime.controlprogram.ForProgramBlock) FunctionProgramBlock(org.apache.sysml.runtime.controlprogram.FunctionProgramBlock) WhileProgramBlock(org.apache.sysml.runtime.controlprogram.WhileProgramBlock) 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) WhileStatementBlock(org.apache.sysml.parser.WhileStatementBlock) FunctionStatementBlock(org.apache.sysml.parser.FunctionStatementBlock) IfStatementBlock(org.apache.sysml.parser.IfStatementBlock) WhileStatementBlock(org.apache.sysml.parser.WhileStatementBlock) ForStatementBlock(org.apache.sysml.parser.ForStatementBlock) StatementBlock(org.apache.sysml.parser.StatementBlock) IfStatementBlock(org.apache.sysml.parser.IfStatementBlock)

Example 9 with ProgramBlock

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

the class ProgramConverter method rParseGenericProgramBlock.

private static ProgramBlock rParseGenericProgramBlock(String in, Program prog, int id) {
    String lin = in.substring(PARFOR_PB_BEGIN.length(), in.length() - PARFOR_PB_END.length());
    StringTokenizer st = new StringTokenizer(lin, COMPONENTS_DELIM);
    ArrayList<Instruction> inst = parseInstructions(st.nextToken(), id);
    ProgramBlock pb = new ProgramBlock(prog);
    pb.setInstructions(inst);
    return pb;
}
Also used : StringTokenizer(java.util.StringTokenizer) 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 10 with ProgramBlock

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

the class ProgramConverter method rFindSerializationCandidates.

private static void rFindSerializationCandidates(ArrayList<ProgramBlock> pbs, HashSet<String> cand) {
    for (ProgramBlock pb : pbs) {
        if (pb instanceof WhileProgramBlock) {
            WhileProgramBlock wpb = (WhileProgramBlock) pb;
            rFindSerializationCandidates(wpb.getChildBlocks(), cand);
        } else if (pb instanceof ForProgramBlock || pb instanceof ParForProgramBlock) {
            ForProgramBlock fpb = (ForProgramBlock) pb;
            rFindSerializationCandidates(fpb.getChildBlocks(), cand);
        } else if (pb instanceof IfProgramBlock) {
            IfProgramBlock ipb = (IfProgramBlock) pb;
            rFindSerializationCandidates(ipb.getChildBlocksIfBody(), cand);
            if (ipb.getChildBlocksElseBody() != null)
                rFindSerializationCandidates(ipb.getChildBlocksElseBody(), cand);
        } else // all generic program blocks
        {
            for (Instruction inst : pb.getInstructions()) if (inst instanceof FunctionCallCPInstruction) {
                FunctionCallCPInstruction fci = (FunctionCallCPInstruction) inst;
                String fkey = DMLProgram.constructFunctionKey(fci.getNamespace(), fci.getFunctionName());
                if (// memoization for multiple calls, recursion
                !cand.contains(fkey)) {
                    // add to candidates
                    cand.add(fkey);
                    // investigate chains of function calls
                    FunctionProgramBlock fpb = pb.getProgram().getFunctionProgramBlock(fci.getNamespace(), fci.getFunctionName());
                    rFindSerializationCandidates(fpb.getChildBlocks(), cand);
                }
            }
        }
    }
}
Also used : IfProgramBlock(org.apache.sysml.runtime.controlprogram.IfProgramBlock) FunctionProgramBlock(org.apache.sysml.runtime.controlprogram.FunctionProgramBlock) ExternalFunctionProgramBlock(org.apache.sysml.runtime.controlprogram.ExternalFunctionProgramBlock) FunctionCallCPInstruction(org.apache.sysml.runtime.instructions.cp.FunctionCallCPInstruction) ForProgramBlock(org.apache.sysml.runtime.controlprogram.ForProgramBlock) ParForProgramBlock(org.apache.sysml.runtime.controlprogram.ParForProgramBlock) 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) 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)

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