Search in sources :

Example 21 with FunctionCallCPInstruction

use of org.apache.sysml.runtime.instructions.cp.FunctionCallCPInstruction in project systemml by apache.

the class Statistics method getCPHeavyHitterCode.

public static String getCPHeavyHitterCode(Instruction inst) {
    String opcode = null;
    if (inst instanceof MRJobInstruction) {
        MRJobInstruction mrinst = (MRJobInstruction) inst;
        opcode = "MR-Job_" + mrinst.getJobType();
    } else if (inst instanceof SPInstruction) {
        opcode = "SP_" + InstructionUtils.getOpCode(inst.toString());
        if (inst instanceof FunctionCallCPInstruction) {
            FunctionCallCPInstruction extfunct = (FunctionCallCPInstruction) inst;
            opcode = extfunct.getFunctionName();
        }
    } else // CPInstructions
    {
        opcode = InstructionUtils.getOpCode(inst.toString());
        if (inst instanceof FunctionCallCPInstruction) {
            FunctionCallCPInstruction extfunct = (FunctionCallCPInstruction) inst;
            opcode = extfunct.getFunctionName();
        }
    }
    return opcode;
}
Also used : SPInstruction(org.apache.sysml.runtime.instructions.spark.SPInstruction) MRJobInstruction(org.apache.sysml.runtime.instructions.MRJobInstruction) FunctionCallCPInstruction(org.apache.sysml.runtime.instructions.cp.FunctionCallCPInstruction)

Example 22 with FunctionCallCPInstruction

use of org.apache.sysml.runtime.instructions.cp.FunctionCallCPInstruction in project 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)

Example 23 with FunctionCallCPInstruction

use of org.apache.sysml.runtime.instructions.cp.FunctionCallCPInstruction in project systemml by apache.

the class ProgramConverter method createDeepCopyInstructionSet.

/**
 * Creates a deep copy of an array of instructions and replaces the placeholders of parworker
 * IDs with the concrete IDs of this parfor instance. This is a helper method uses for generating
 * deep copies of program blocks.
 *
 * @param instSet list of instructions
 * @param pid ?
 * @param IDPrefix ?
 * @param prog runtime program
 * @param fnStack ?
 * @param fnCreated ?
 * @param plain ?
 * @param cpFunctions ?
 * @return list of instructions
 */
public static ArrayList<Instruction> createDeepCopyInstructionSet(ArrayList<Instruction> instSet, long pid, int IDPrefix, Program prog, HashSet<String> fnStack, HashSet<String> fnCreated, boolean plain, boolean cpFunctions) {
    ArrayList<Instruction> tmp = new ArrayList<>();
    for (Instruction inst : instSet) {
        if (inst instanceof FunctionCallCPInstruction && cpFunctions) {
            FunctionCallCPInstruction finst = (FunctionCallCPInstruction) inst;
            createDeepCopyFunctionProgramBlock(finst.getNamespace(), finst.getFunctionName(), pid, IDPrefix, prog, fnStack, fnCreated, plain);
        }
        tmp.add(cloneInstruction(inst, pid, plain, cpFunctions));
    }
    return tmp;
}
Also used : FunctionCallCPInstruction(org.apache.sysml.runtime.instructions.cp.FunctionCallCPInstruction) ArrayList(java.util.ArrayList) 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 24 with FunctionCallCPInstruction

use of org.apache.sysml.runtime.instructions.cp.FunctionCallCPInstruction in project systemml by apache.

the class CostEstimator method maintainCPInstVariableStatistics.

private static void maintainCPInstVariableStatistics(CPInstruction inst, HashMap<String, VarStats> stats) {
    if (inst instanceof VariableCPInstruction) {
        String optype = inst.getOpcode();
        String[] parts = InstructionUtils.getInstructionParts(inst.toString());
        if (optype.equals("createvar")) {
            if (parts.length < 10)
                return;
            String varname = parts[1];
            long rlen = Long.parseLong(parts[6]);
            long clen = Long.parseLong(parts[7]);
            int brlen = Integer.parseInt(parts[8]);
            int bclen = Integer.parseInt(parts[9]);
            long nnz = Long.parseLong(parts[10]);
            VarStats vs = new VarStats(rlen, clen, brlen, bclen, nnz, false);
            stats.put(varname, vs);
        } else if (optype.equals("cpvar")) {
            String varname = parts[1];
            String varname2 = parts[2];
            VarStats vs = stats.get(varname);
            stats.put(varname2, vs);
        } else if (optype.equals("mvvar")) {
            String varname = parts[1];
            String varname2 = parts[2];
            VarStats vs = stats.remove(varname);
            stats.put(varname2, vs);
        } else if (optype.equals("rmvar")) {
            String varname = parts[1];
            stats.remove(varname);
        }
    } else if (inst instanceof DataGenCPInstruction) {
        DataGenCPInstruction randInst = (DataGenCPInstruction) inst;
        String varname = randInst.output.getName();
        long rlen = randInst.getRows();
        long clen = randInst.getCols();
        int brlen = randInst.getRowsInBlock();
        int bclen = randInst.getColsInBlock();
        long nnz = (long) (randInst.getSparsity() * rlen * clen);
        VarStats vs = new VarStats(rlen, clen, brlen, bclen, nnz, true);
        stats.put(varname, vs);
    } else if (inst instanceof StringInitCPInstruction) {
        StringInitCPInstruction iinst = (StringInitCPInstruction) inst;
        String varname = iinst.output.getName();
        long rlen = iinst.getRows();
        long clen = iinst.getCols();
        VarStats vs = new VarStats(rlen, clen, ConfigurationManager.getBlocksize(), ConfigurationManager.getBlocksize(), rlen * clen, true);
        stats.put(varname, vs);
    } else if (inst instanceof FunctionCallCPInstruction) {
        FunctionCallCPInstruction finst = (FunctionCallCPInstruction) inst;
        ArrayList<String> outVars = finst.getBoundOutputParamNames();
        for (String varname : outVars) stats.put(varname, _unknownStats);
    }
}
Also used : StringInitCPInstruction(org.apache.sysml.runtime.instructions.cp.StringInitCPInstruction) FunctionCallCPInstruction(org.apache.sysml.runtime.instructions.cp.FunctionCallCPInstruction) VariableCPInstruction(org.apache.sysml.runtime.instructions.cp.VariableCPInstruction) ArrayList(java.util.ArrayList) DataGenCPInstruction(org.apache.sysml.runtime.instructions.cp.DataGenCPInstruction)

Aggregations

FunctionCallCPInstruction (org.apache.sysml.runtime.instructions.cp.FunctionCallCPInstruction)24 Instruction (org.apache.sysml.runtime.instructions.Instruction)14 MRJobInstruction (org.apache.sysml.runtime.instructions.MRJobInstruction)12 VariableCPInstruction (org.apache.sysml.runtime.instructions.cp.VariableCPInstruction)12 ArrayList (java.util.ArrayList)10 FunctionProgramBlock (org.apache.sysml.runtime.controlprogram.FunctionProgramBlock)10 CPInstruction (org.apache.sysml.runtime.instructions.cp.CPInstruction)10 ForProgramBlock (org.apache.sysml.runtime.controlprogram.ForProgramBlock)8 ProgramBlock (org.apache.sysml.runtime.controlprogram.ProgramBlock)8 MRInstruction (org.apache.sysml.runtime.instructions.mr.MRInstruction)8 SPInstruction (org.apache.sysml.runtime.instructions.spark.SPInstruction)8 IfProgramBlock (org.apache.sysml.runtime.controlprogram.IfProgramBlock)6 ParForProgramBlock (org.apache.sysml.runtime.controlprogram.ParForProgramBlock)6 WhileProgramBlock (org.apache.sysml.runtime.controlprogram.WhileProgramBlock)6 SpoofCPInstruction (org.apache.sysml.runtime.instructions.cp.SpoofCPInstruction)6 GPUInstruction (org.apache.sysml.runtime.instructions.gpu.GPUInstruction)6 ExternalFunctionInvocationInstruction (org.apache.sysml.udf.ExternalFunctionInvocationInstruction)6 FunctionOp (org.apache.sysml.hops.FunctionOp)4 DMLRuntimeException (org.apache.sysml.runtime.DMLRuntimeException)4 ExternalFunctionProgramBlock (org.apache.sysml.runtime.controlprogram.ExternalFunctionProgramBlock)4