Search in sources :

Example 36 with ProgramBlock

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

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

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

the class RewriteConstantFolding method evalScalarOperation.

/**
 * In order to (1) prevent unexpected side effects from constant folding and
 * (2) for simplicity with regard to arbitrary value type combinations,
 * we use the same compilation and runtime for constant folding as we would
 * use for actual instruction execution.
 *
 * @param bop high-level operator
 * @return literal op
 */
private LiteralOp evalScalarOperation(Hop bop) {
    // Timing time = new Timing( true );
    DataOp tmpWrite = new DataOp(TMP_VARNAME, bop.getDataType(), bop.getValueType(), bop, DataOpTypes.TRANSIENTWRITE, TMP_VARNAME);
    // generate runtime instruction
    Dag<Lop> dag = new Dag<>();
    // prevent lops reuse
    Recompiler.rClearLops(tmpWrite);
    // reconstruct lops
    Lop lops = tmpWrite.constructLops();
    lops.addToDag(dag);
    ArrayList<Instruction> inst = dag.getJobs(null, ConfigurationManager.getDMLConfig());
    // execute instructions
    ExecutionContext ec = getExecutionContext();
    ProgramBlock pb = getProgramBlock();
    pb.setInstructions(inst);
    pb.execute(ec);
    // get scalar result (check before invocation) and create literal according
    // to observed scalar output type (not hop type) for runtime consistency
    ScalarObject so = (ScalarObject) ec.getVariable(TMP_VARNAME);
    LiteralOp literal = null;
    switch(so.getValueType()) {
        case DOUBLE:
            literal = new LiteralOp(so.getDoubleValue());
            break;
        case INT:
            literal = new LiteralOp(so.getLongValue());
            break;
        case BOOLEAN:
            literal = new LiteralOp(so.getBooleanValue());
            break;
        case STRING:
            literal = new LiteralOp(so.getStringValue());
            break;
        default:
            throw new HopsException("Unsupported literal value type: " + bop.getValueType());
    }
    // cleanup
    tmpWrite.getInput().clear();
    bop.getParent().remove(tmpWrite);
    pb.setInstructions(null);
    ec.getVariables().removeAll();
    // set literal properties (scalar)
    HopRewriteUtils.setOutputParametersForScalar(literal);
    return literal;
}
Also used : ScalarObject(org.apache.sysml.runtime.instructions.cp.ScalarObject) ExecutionContext(org.apache.sysml.runtime.controlprogram.context.ExecutionContext) ProgramBlock(org.apache.sysml.runtime.controlprogram.ProgramBlock) Dag(org.apache.sysml.lops.compile.Dag) HopsException(org.apache.sysml.hops.HopsException) Lop(org.apache.sysml.lops.Lop) Instruction(org.apache.sysml.runtime.instructions.Instruction) LiteralOp(org.apache.sysml.hops.LiteralOp) DataOp(org.apache.sysml.hops.DataOp)

Example 39 with ProgramBlock

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

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

the class ProgramConverter method rSerializeProgramBlocks.

private static String rSerializeProgramBlocks(ArrayList<ProgramBlock> pbs, HashMap<String, byte[]> clsMap) {
    StringBuilder sb = new StringBuilder();
    int count = 0;
    for (ProgramBlock pb : pbs) {
        if (count > 0) {
            sb.append(ELEMENT_DELIM);
            sb.append(NEWLINE);
        }
        sb.append(rSerializeProgramBlock(pb, clsMap));
        count++;
    }
    return sb.toString();
}
Also used : 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)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