Search in sources :

Example 6 with ExternalFunctionProgramBlock

use of org.apache.sysml.runtime.controlprogram.ExternalFunctionProgramBlock 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 ?
	 * @throws DMLRuntimeException if DMLRuntimeException occurs
	 */
public static void createDeepCopyFunctionProgramBlock(String namespace, String oldName, long pid, int IDPrefix, Program prog, HashSet<String> fnStack, HashSet<String> fnCreated, boolean plain) throws DMLRuntimeException {
    //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<DataIdentifier>();
    ArrayList<DataIdentifier> tmp2 = new ArrayList<DataIdentifier>();
    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 7 with ExternalFunctionProgramBlock

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

the class Explain method countCompiledInstructions.

/**
	 * Recursively counts the number of compiled MRJob instructions in the
	 * given runtime program block. 
	 * 
	 * @param pb program block
	 * @param counts explain countst
	 * @param MR if true, count Hadoop instructions
	 * @param CP if true, count CP instructions
	 * @param SP if true, count Spark instructions
	 */
private static void countCompiledInstructions(ProgramBlock pb, ExplainCounts counts, boolean MR, boolean CP, boolean SP) {
    if (pb instanceof WhileProgramBlock) {
        WhileProgramBlock tmp = (WhileProgramBlock) pb;
        countCompiledInstructions(tmp.getPredicate(), counts, MR, CP, SP);
        for (ProgramBlock pb2 : tmp.getChildBlocks()) countCompiledInstructions(pb2, counts, MR, CP, SP);
    } else if (pb instanceof IfProgramBlock) {
        IfProgramBlock tmp = (IfProgramBlock) pb;
        countCompiledInstructions(tmp.getPredicate(), counts, MR, CP, SP);
        for (ProgramBlock pb2 : tmp.getChildBlocksIfBody()) countCompiledInstructions(pb2, counts, MR, CP, SP);
        for (ProgramBlock pb2 : tmp.getChildBlocksElseBody()) countCompiledInstructions(pb2, counts, MR, CP, SP);
    } else if (//includes ParFORProgramBlock
    pb instanceof ForProgramBlock) {
        ForProgramBlock tmp = (ForProgramBlock) pb;
        countCompiledInstructions(tmp.getFromInstructions(), counts, MR, CP, SP);
        countCompiledInstructions(tmp.getToInstructions(), counts, MR, CP, SP);
        countCompiledInstructions(tmp.getIncrementInstructions(), counts, MR, CP, SP);
        for (ProgramBlock pb2 : tmp.getChildBlocks()) countCompiledInstructions(pb2, counts, MR, CP, SP);
    //additional parfor jobs counted during runtime
    } else if (//includes ExternalFunctionProgramBlock and ExternalFunctionProgramBlockCP
    pb instanceof FunctionProgramBlock) {
        FunctionProgramBlock fpb = (FunctionProgramBlock) pb;
        for (ProgramBlock pb2 : fpb.getChildBlocks()) countCompiledInstructions(pb2, counts, MR, CP, SP);
    } else {
        countCompiledInstructions(pb.getInstructions(), counts, MR, CP, SP);
    }
}
Also used : IfProgramBlock(org.apache.sysml.runtime.controlprogram.IfProgramBlock) 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) 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)

Example 8 with ExternalFunctionProgramBlock

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

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

the class DMLProgram method addCleanupInstruction.

/**
	 * Adds the generated cleanup RMVAR instruction to the given program block.
	 * In case of generic (last-level) programblocks it is added to the end of 
	 * the list of instructions, while for complex program blocks it is added to
	 * the end of the list of exit instructions.
	 * 
	 * @param pb program block
	 * @param inst instruction
	 * @throws DMLRuntimeException if DMLRuntimeException occurs
	 */
private void addCleanupInstruction(ProgramBlock pb, Instruction inst) throws DMLRuntimeException {
    if (pb instanceof WhileProgramBlock) {
        WhileProgramBlock wpb = (WhileProgramBlock) pb;
        ArrayList<ProgramBlock> childs = wpb.getChildBlocks();
        if (//generic last level pb
        !childs.get(childs.size() - 1).getInstructions().isEmpty())
            childs.get(childs.size() - 1).addInstruction(inst);
        else {
            ProgramBlock pbNew = new ProgramBlock(pb.getProgram());
            pbNew.addInstruction(inst);
            childs.add(pbNew);
        }
    } else if (//includes ParFORProgramBlock
    pb instanceof ForProgramBlock) {
        ForProgramBlock wpb = (ForProgramBlock) pb;
        ArrayList<ProgramBlock> childs = wpb.getChildBlocks();
        if (//generic last level pb
        !childs.get(childs.size() - 1).getInstructions().isEmpty())
            childs.get(childs.size() - 1).addInstruction(inst);
        else {
            ProgramBlock pbNew = new ProgramBlock(pb.getProgram());
            pbNew.addInstruction(inst);
            childs.add(pbNew);
        }
    } else if (pb instanceof IfProgramBlock)
        ((IfProgramBlock) pb).addExitInstruction(inst);
    else if (//includes ExternalFunctionProgramBlock and ExternalFunctionProgramBlockCP)
    pb instanceof FunctionProgramBlock)
        //do nothing
        ;
    else {
        //add inst at end of pb	
        pb.addInstruction(inst);
    }
}
Also used : IfProgramBlock(org.apache.sysml.runtime.controlprogram.IfProgramBlock) 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) 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) ParForProgramBlock(org.apache.sysml.runtime.controlprogram.ParForProgramBlock) ExternalFunctionProgramBlock(org.apache.sysml.runtime.controlprogram.ExternalFunctionProgramBlock) WhileProgramBlock(org.apache.sysml.runtime.controlprogram.WhileProgramBlock)

Aggregations

ExternalFunctionProgramBlock (org.apache.sysml.runtime.controlprogram.ExternalFunctionProgramBlock)9 FunctionProgramBlock (org.apache.sysml.runtime.controlprogram.FunctionProgramBlock)9 ForProgramBlock (org.apache.sysml.runtime.controlprogram.ForProgramBlock)8 IfProgramBlock (org.apache.sysml.runtime.controlprogram.IfProgramBlock)8 WhileProgramBlock (org.apache.sysml.runtime.controlprogram.WhileProgramBlock)8 ProgramBlock (org.apache.sysml.runtime.controlprogram.ProgramBlock)7 ParForProgramBlock (org.apache.sysml.runtime.controlprogram.ParForProgramBlock)6 ArrayList (java.util.ArrayList)5 ExternalFunctionProgramBlockCP (org.apache.sysml.runtime.controlprogram.ExternalFunctionProgramBlockCP)4 DMLProgram (org.apache.sysml.parser.DMLProgram)2 DataIdentifier (org.apache.sysml.parser.DataIdentifier)2 DMLRuntimeException (org.apache.sysml.runtime.DMLRuntimeException)2 Instruction (org.apache.sysml.runtime.instructions.Instruction)2 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 FunctionCallGraph (org.apache.sysml.hops.ipa.FunctionCallGraph)1 Lop (org.apache.sysml.lops.Lop)1 LopsException (org.apache.sysml.lops.LopsException)1 Dag (org.apache.sysml.lops.compile.Dag)1