Search in sources :

Example 21 with FunctionProgramBlock

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

the class DMLDebuggerProgramInfo method accessBreakpoint.

/**
 * Access breakpoint instruction at specified line number in runtime program (if valid)
 * @param lineNumber Location for breakpoint operation
 * @param op Breakpoint operation (op=0 for create, op=1 for enable/disable, op=2 for delete)
 * @param status Current breakpoint status
 */
public void accessBreakpoint(int lineNumber, int op, BPINSTRUCTION_STATUS status) {
    if (this.rtprog != null) {
        // Functions: For each function program block (if any), get instructions corresponding to each line number
        HashMap<String, FunctionProgramBlock> funcMap = this.rtprog.getFunctionProgramBlocks();
        if (funcMap != null && !funcMap.isEmpty()) {
            for (Entry<String, FunctionProgramBlock> e : funcMap.entrySet()) {
                location = e.getKey();
                FunctionProgramBlock fpb = e.getValue();
                if (fpb instanceof ExternalFunctionProgramBlock)
                    continue;
                else {
                    for (ProgramBlock pb : fpb.getChildBlocks()) accessProgramBlockBreakpoint(pb, lineNumber, op, status);
                }
            }
        }
        // Main program: for each program block, get instructions corresponding to current line number (if any)
        location = DMLProgram.constructFunctionKey(DMLProgram.DEFAULT_NAMESPACE, "main");
        for (ProgramBlock pb : this.rtprog.getProgramBlocks()) {
            if (pb != null)
                accessProgramBlockBreakpoint(pb, lineNumber, op, status);
        }
    }
}
Also used : ExternalFunctionProgramBlock(org.apache.sysml.runtime.controlprogram.ExternalFunctionProgramBlock) FunctionProgramBlock(org.apache.sysml.runtime.controlprogram.FunctionProgramBlock) ExternalFunctionProgramBlock(org.apache.sysml.runtime.controlprogram.ExternalFunctionProgramBlock) 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)

Example 22 with FunctionProgramBlock

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

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

the class ProgramConverter method createDeepCopyFunctionProgramBlock.

/**
 * This creates a deep copy of a function program block. The central reference to singletons of function program blocks
 * poses the need for explicit copies in order to prevent conflicting writes of temporary variables (see ExternalFunctionProgramBlock.
 *
 * @param namespace function namespace
 * @param oldName ?
 * @param pid ?
 * @param IDPrefix ?
 * @param prog runtime program
 * @param fnStack ?
 * @param fnCreated ?
 * @param plain ?
 */
public static void createDeepCopyFunctionProgramBlock(String namespace, String oldName, long pid, int IDPrefix, Program prog, HashSet<String> fnStack, HashSet<String> fnCreated, boolean plain) {
    // fpb guaranteed to be non-null (checked inside getFunctionProgramBlock)
    FunctionProgramBlock fpb = prog.getFunctionProgramBlock(namespace, oldName);
    String fnameNew = (plain) ? oldName : (oldName + CP_CHILD_THREAD + pid);
    String fnameNewKey = DMLProgram.constructFunctionKey(namespace, fnameNew);
    if (prog.getFunctionProgramBlocks().containsKey(fnameNewKey))
        // prevent redundant deep copy if already existent
        return;
    // create deep copy
    FunctionProgramBlock copy = null;
    ArrayList<DataIdentifier> tmp1 = new ArrayList<>();
    ArrayList<DataIdentifier> tmp2 = new ArrayList<>();
    if (fpb.getInputParams() != null)
        tmp1.addAll(fpb.getInputParams());
    if (fpb.getOutputParams() != null)
        tmp2.addAll(fpb.getOutputParams());
    if (fpb instanceof ExternalFunctionProgramBlockCP) {
        ExternalFunctionProgramBlockCP efpb = (ExternalFunctionProgramBlockCP) fpb;
        HashMap<String, String> tmp3 = efpb.getOtherParams();
        if (IDPrefix != -1)
            copy = new ExternalFunctionProgramBlockCP(prog, tmp1, tmp2, tmp3, saveReplaceFilenameThreadID(efpb.getBaseDir(), CP_CHILD_THREAD + IDPrefix, CP_CHILD_THREAD + pid));
        else
            copy = new ExternalFunctionProgramBlockCP(prog, tmp1, tmp2, tmp3, saveReplaceFilenameThreadID(efpb.getBaseDir(), CP_ROOT_THREAD_ID, CP_CHILD_THREAD + pid));
    } else if (fpb instanceof ExternalFunctionProgramBlock) {
        ExternalFunctionProgramBlock efpb = (ExternalFunctionProgramBlock) fpb;
        HashMap<String, String> tmp3 = efpb.getOtherParams();
        if (IDPrefix != -1)
            copy = new ExternalFunctionProgramBlock(prog, tmp1, tmp2, tmp3, saveReplaceFilenameThreadID(efpb.getBaseDir(), CP_CHILD_THREAD + IDPrefix, CP_CHILD_THREAD + pid));
        else
            copy = new ExternalFunctionProgramBlock(prog, tmp1, tmp2, tmp3, saveReplaceFilenameThreadID(efpb.getBaseDir(), CP_ROOT_THREAD_ID, CP_CHILD_THREAD + pid));
    } else {
        if (!fnStack.contains(fnameNewKey)) {
            fnStack.add(fnameNewKey);
            copy = new FunctionProgramBlock(prog, tmp1, tmp2);
            copy.setChildBlocks(rcreateDeepCopyProgramBlocks(fpb.getChildBlocks(), pid, IDPrefix, fnStack, fnCreated, plain, fpb.isRecompileOnce()));
            copy.setRecompileOnce(fpb.isRecompileOnce());
            copy.setThreadID(pid);
            fnStack.remove(fnameNewKey);
        } else
            // stop deep copy for recursive function calls
            copy = fpb;
    }
    // copy.setVariables( (LocalVariableMap) fpb.getVariables() ); //implicit cloning
    // note: instructions not used by function program block
    // put
    prog.addFunctionProgramBlock(namespace, fnameNew, copy);
    fnCreated.add(DMLProgram.constructFunctionKey(namespace, fnameNew));
}
Also used : FunctionProgramBlock(org.apache.sysml.runtime.controlprogram.FunctionProgramBlock) ExternalFunctionProgramBlock(org.apache.sysml.runtime.controlprogram.ExternalFunctionProgramBlock) DataIdentifier(org.apache.sysml.parser.DataIdentifier) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ExternalFunctionProgramBlock(org.apache.sysml.runtime.controlprogram.ExternalFunctionProgramBlock) ExternalFunctionProgramBlockCP(org.apache.sysml.runtime.controlprogram.ExternalFunctionProgramBlockCP)

Example 24 with FunctionProgramBlock

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

the class ProgramConverter method parseProgram.

public static Program parseProgram(String in, int id) {
    String lin = in.substring(PARFOR_PROG_BEGIN.length(), in.length() - PARFOR_PROG_END.length()).trim();
    Program prog = new Program();
    HashMap<String, FunctionProgramBlock> fc = parseFunctionProgramBlocks(lin, prog, id);
    for (Entry<String, FunctionProgramBlock> e : fc.entrySet()) {
        String[] keypart = e.getKey().split(Program.KEY_DELIM);
        String namespace = keypart[0];
        String name = keypart[1];
        prog.addFunctionProgramBlock(namespace, name, e.getValue());
    }
    return prog;
}
Also used : FunctionProgramBlock(org.apache.sysml.runtime.controlprogram.FunctionProgramBlock) ExternalFunctionProgramBlock(org.apache.sysml.runtime.controlprogram.ExternalFunctionProgramBlock) DMLProgram(org.apache.sysml.parser.DMLProgram) Program(org.apache.sysml.runtime.controlprogram.Program)

Example 25 with FunctionProgramBlock

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

the class ProgramConverter method createDeepCopyFunctionProgramBlock.

public static FunctionProgramBlock createDeepCopyFunctionProgramBlock(FunctionProgramBlock fpb, HashSet<String> fnStack, HashSet<String> fnCreated) {
    if (fpb == null)
        throw new DMLRuntimeException("Unable to create a deep copy of a non-existing FunctionProgramBlock.");
    // create deep copy
    FunctionProgramBlock copy = null;
    ArrayList<DataIdentifier> tmp1 = new ArrayList<>();
    ArrayList<DataIdentifier> tmp2 = new ArrayList<>();
    if (fpb.getInputParams() != null)
        tmp1.addAll(fpb.getInputParams());
    if (fpb.getOutputParams() != null)
        tmp2.addAll(fpb.getOutputParams());
    copy = new FunctionProgramBlock(fpb.getProgram(), tmp1, tmp2);
    copy.setChildBlocks(rcreateDeepCopyProgramBlocks(fpb.getChildBlocks(), 0, -1, fnStack, fnCreated, true, fpb.isRecompileOnce()));
    copy.setStatementBlock(fpb.getStatementBlock());
    copy.setRecompileOnce(fpb.isRecompileOnce());
    return copy;
}
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) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException)

Aggregations

FunctionProgramBlock (org.apache.sysml.runtime.controlprogram.FunctionProgramBlock)37 ForProgramBlock (org.apache.sysml.runtime.controlprogram.ForProgramBlock)30 IfProgramBlock (org.apache.sysml.runtime.controlprogram.IfProgramBlock)29 WhileProgramBlock (org.apache.sysml.runtime.controlprogram.WhileProgramBlock)29 ProgramBlock (org.apache.sysml.runtime.controlprogram.ProgramBlock)26 ExternalFunctionProgramBlock (org.apache.sysml.runtime.controlprogram.ExternalFunctionProgramBlock)19 ParForProgramBlock (org.apache.sysml.runtime.controlprogram.ParForProgramBlock)19 ArrayList (java.util.ArrayList)13 StatementBlock (org.apache.sysml.parser.StatementBlock)11 ForStatementBlock (org.apache.sysml.parser.ForStatementBlock)10 IfStatementBlock (org.apache.sysml.parser.IfStatementBlock)10 WhileStatementBlock (org.apache.sysml.parser.WhileStatementBlock)10 DMLRuntimeException (org.apache.sysml.runtime.DMLRuntimeException)9 Instruction (org.apache.sysml.runtime.instructions.Instruction)8 DMLProgram (org.apache.sysml.parser.DMLProgram)6 FunctionStatementBlock (org.apache.sysml.parser.FunctionStatementBlock)6 Program (org.apache.sysml.runtime.controlprogram.Program)6 HashSet (java.util.HashSet)5 LocalVariableMap (org.apache.sysml.runtime.controlprogram.LocalVariableMap)5 FunctionCallCPInstruction (org.apache.sysml.runtime.instructions.cp.FunctionCallCPInstruction)5