Search in sources :

Example 46 with ForProgramBlock

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

the class DMLDebuggerProgramInfo method setProgramBlockInstMap.

/**
 * For each program block, get runtime instructions (if any)
 * @param pb Current program block
 */
private void setProgramBlockInstMap(ProgramBlock pb) {
    if (pb instanceof FunctionProgramBlock) {
        FunctionProgramBlock fpb = (FunctionProgramBlock) pb;
        for (ProgramBlock pbc : fpb.getChildBlocks()) setProgramBlockInstMap(pbc);
    } else if (pb instanceof WhileProgramBlock) {
        WhileProgramBlock wpb = (WhileProgramBlock) pb;
        this.setInstMap(wpb.getPredicate());
        for (ProgramBlock pbc : wpb.getChildBlocks()) setProgramBlockInstMap(pbc);
    } else if (pb instanceof IfProgramBlock) {
        IfProgramBlock ipb = (IfProgramBlock) pb;
        this.setInstMap(ipb.getPredicate());
        for (ProgramBlock pbc : ipb.getChildBlocksIfBody()) setProgramBlockInstMap(pbc);
        if (!ipb.getChildBlocksElseBody().isEmpty()) {
            for (ProgramBlock pbc : ipb.getChildBlocksElseBody()) setProgramBlockInstMap(pbc);
        }
    } else if (// incl parfor
    pb instanceof ForProgramBlock) {
        ForProgramBlock fpb = (ForProgramBlock) pb;
        this.setInstMap(fpb.getFromInstructions());
        this.setInstMap(fpb.getToInstructions());
        this.setInstMap(fpb.getIncrementInstructions());
        for (ProgramBlock pbc : fpb.getChildBlocks()) setProgramBlockInstMap(pbc);
    } else {
        this.setInstMap(pb.getInstructions());
    }
}
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 47 with ForProgramBlock

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

the class Recompiler method recompileProgramBlockInstructions.

/**
 * This method does NO full program block recompile (no stats update, no rewrites, no recursion) but
 * only regenerates lops and instructions. The primary use case is recompilation after are hop configuration
 * changes which allows to preserve statistics (e.g., propagated worst case stats from other program blocks)
 * and better performance for recompiling individual program blocks.
 *
 * @param pb program block
 * @throws IOException if IOException occurs
 */
public static void recompileProgramBlockInstructions(ProgramBlock pb) throws IOException {
    if (pb instanceof WhileProgramBlock) {
        // recompile while predicate instructions
        WhileProgramBlock wpb = (WhileProgramBlock) pb;
        WhileStatementBlock wsb = (WhileStatementBlock) pb.getStatementBlock();
        if (wsb != null && wsb.getPredicateHops() != null)
            wpb.setPredicate(recompileHopsDagInstructions(wsb.getPredicateHops()));
    } else if (pb instanceof IfProgramBlock) {
        // recompile if predicate instructions
        IfProgramBlock ipb = (IfProgramBlock) pb;
        IfStatementBlock isb = (IfStatementBlock) pb.getStatementBlock();
        if (isb != null && isb.getPredicateHops() != null)
            ipb.setPredicate(recompileHopsDagInstructions(isb.getPredicateHops()));
    } else if (pb instanceof ForProgramBlock) {
        // recompile for/parfor predicate instructions
        ForProgramBlock fpb = (ForProgramBlock) pb;
        ForStatementBlock fsb = (ForStatementBlock) pb.getStatementBlock();
        if (fsb != null && fsb.getFromHops() != null)
            fpb.setFromInstructions(recompileHopsDagInstructions(fsb.getFromHops()));
        if (fsb != null && fsb.getToHops() != null)
            fpb.setToInstructions(recompileHopsDagInstructions(fsb.getToHops()));
        if (fsb != null && fsb.getIncrementHops() != null)
            fpb.setIncrementInstructions(recompileHopsDagInstructions(fsb.getIncrementHops()));
    } else {
        // recompile last-level program block instructions
        StatementBlock sb = pb.getStatementBlock();
        if (sb != null && sb.getHops() != null) {
            pb.setInstructions(recompileHopsDagInstructions(sb, sb.getHops()));
        }
    }
}
Also used : IfProgramBlock(org.apache.sysml.runtime.controlprogram.IfProgramBlock) ForStatementBlock(org.apache.sysml.parser.ForStatementBlock) ForProgramBlock(org.apache.sysml.runtime.controlprogram.ForProgramBlock) ParForProgramBlock(org.apache.sysml.runtime.controlprogram.ParForProgramBlock) WhileProgramBlock(org.apache.sysml.runtime.controlprogram.WhileProgramBlock) WhileStatementBlock(org.apache.sysml.parser.WhileStatementBlock) 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 48 with ForProgramBlock

use of org.apache.sysml.runtime.controlprogram.ForProgramBlock 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
 */
public static ArrayList<ProgramBlock> rcreateDeepCopyProgramBlocks(ArrayList<ProgramBlock> childBlocks, long pid, int IDPrefix, HashSet<String> fnStack, HashSet<String> fnCreated, boolean plain, boolean forceDeepCopy) {
    ArrayList<ProgramBlock> tmp = new ArrayList<>();
    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)

Example 49 with ForProgramBlock

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

the class ProgramConverter method createDeepCopyForProgramBlock.

public static ForProgramBlock createDeepCopyForProgramBlock(ForProgramBlock fpb, long pid, int IDPrefix, Program prog, HashSet<String> fnStack, HashSet<String> fnCreated, boolean plain, boolean forceDeepCopy) {
    ForProgramBlock tmpPB = new ForProgramBlock(prog, fpb.getIterVar());
    tmpPB.setStatementBlock(createForStatementBlockCopy((ForStatementBlock) fpb.getStatementBlock(), pid, plain, forceDeepCopy));
    tmpPB.setThreadID(pid);
    tmpPB.setFromInstructions(createDeepCopyInstructionSet(fpb.getFromInstructions(), pid, IDPrefix, prog, fnStack, fnCreated, plain, true));
    tmpPB.setToInstructions(createDeepCopyInstructionSet(fpb.getToInstructions(), pid, IDPrefix, prog, fnStack, fnCreated, plain, true));
    tmpPB.setIncrementInstructions(createDeepCopyInstructionSet(fpb.getIncrementInstructions(), pid, IDPrefix, prog, fnStack, fnCreated, plain, true));
    tmpPB.setExitInstructions(createDeepCopyInstructionSet(fpb.getExitInstructions(), pid, IDPrefix, prog, fnStack, fnCreated, plain, true));
    tmpPB.setChildBlocks(rcreateDeepCopyProgramBlocks(fpb.getChildBlocks(), pid, IDPrefix, fnStack, fnCreated, plain, forceDeepCopy));
    return tmpPB;
}
Also used : ParForStatementBlock(org.apache.sysml.parser.ParForStatementBlock) ForStatementBlock(org.apache.sysml.parser.ForStatementBlock) ForProgramBlock(org.apache.sysml.runtime.controlprogram.ForProgramBlock) ParForProgramBlock(org.apache.sysml.runtime.controlprogram.ParForProgramBlock)

Example 50 with ForProgramBlock

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

the class ProgramConverter method rParseForProgramBlock.

private static ForProgramBlock rParseForProgramBlock(String in, Program prog, int id) {
    String lin = in.substring(PARFOR_PB_FOR.length(), in.length() - PARFOR_PB_END.length());
    HierarchyAwareStringTokenizer st = new HierarchyAwareStringTokenizer(lin, COMPONENTS_DELIM);
    // inputs
    String iterVar = st.nextToken();
    // instructions
    ArrayList<Instruction> from = parseInstructions(st.nextToken(), id);
    ArrayList<Instruction> to = parseInstructions(st.nextToken(), id);
    ArrayList<Instruction> incr = parseInstructions(st.nextToken(), id);
    // exit instructions
    ArrayList<Instruction> exit = parseInstructions(st.nextToken(), id);
    // program blocks
    ArrayList<ProgramBlock> pbs = rParseProgramBlocks(st.nextToken(), prog, id);
    ForProgramBlock fpb = new ForProgramBlock(prog, iterVar);
    fpb.setFromInstructions(from);
    fpb.setToInstructions(to);
    fpb.setIncrementInstructions(incr);
    fpb.setExitInstructions(exit);
    fpb.setChildBlocks(pbs);
    return fpb;
}
Also used : 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) 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

ForProgramBlock (org.apache.sysml.runtime.controlprogram.ForProgramBlock)69 IfProgramBlock (org.apache.sysml.runtime.controlprogram.IfProgramBlock)61 WhileProgramBlock (org.apache.sysml.runtime.controlprogram.WhileProgramBlock)61 FunctionProgramBlock (org.apache.sysml.runtime.controlprogram.FunctionProgramBlock)53 ProgramBlock (org.apache.sysml.runtime.controlprogram.ProgramBlock)47 ParForProgramBlock (org.apache.sysml.runtime.controlprogram.ParForProgramBlock)43 ForStatementBlock (org.apache.sysml.parser.ForStatementBlock)28 IfStatementBlock (org.apache.sysml.parser.IfStatementBlock)26 StatementBlock (org.apache.sysml.parser.StatementBlock)26 WhileStatementBlock (org.apache.sysml.parser.WhileStatementBlock)26 ExternalFunctionProgramBlock (org.apache.sysml.runtime.controlprogram.ExternalFunctionProgramBlock)22 ArrayList (java.util.ArrayList)21 Instruction (org.apache.sysml.runtime.instructions.Instruction)20 MRJobInstruction (org.apache.sysml.runtime.instructions.MRJobInstruction)12 DMLProgram (org.apache.sysml.parser.DMLProgram)10 ParForStatementBlock (org.apache.sysml.parser.ParForStatementBlock)10 Program (org.apache.sysml.runtime.controlprogram.Program)10 FunctionCallCPInstruction (org.apache.sysml.runtime.instructions.cp.FunctionCallCPInstruction)10 Hop (org.apache.sysml.hops.Hop)9 DMLRuntimeException (org.apache.sysml.runtime.DMLRuntimeException)9