Search in sources :

Example 1 with MMTSJCPInstruction

use of org.apache.sysml.runtime.instructions.cp.MMTSJCPInstruction in project incubator-systemml by apache.

the class CostEstimator method extractCPInstStatistics.

private Object[] extractCPInstStatistics(Instruction inst, HashMap<String, VarStats> stats) {
    //stats, attrs
    Object[] ret = new Object[2];
    VarStats[] vs = new VarStats[3];
    String[] attr = null;
    if (inst instanceof UnaryCPInstruction) {
        if (inst instanceof DataGenCPInstruction) {
            DataGenCPInstruction rinst = (DataGenCPInstruction) inst;
            vs[0] = _unknownStats;
            vs[1] = _unknownStats;
            vs[2] = stats.get(rinst.output.getName());
            //prepare attributes for cost estimation
            //full rand
            int type = 2;
            if (rinst.getMinValue() == 0.0 && rinst.getMaxValue() == 0.0)
                type = 0;
            else if (rinst.getSparsity() == 1.0 && rinst.getMinValue() == rinst.getMaxValue())
                type = 1;
            attr = new String[] { String.valueOf(type) };
        } else if (inst instanceof StringInitCPInstruction) {
            StringInitCPInstruction rinst = (StringInitCPInstruction) inst;
            vs[0] = _unknownStats;
            vs[1] = _unknownStats;
            vs[2] = stats.get(rinst.output.getName());
        } else //general unary
        {
            UnaryCPInstruction uinst = (UnaryCPInstruction) inst;
            vs[0] = stats.get(uinst.input1.getName());
            vs[1] = _unknownStats;
            vs[2] = stats.get(uinst.output.getName());
            if (//scalar input, e.g., print
            vs[0] == null)
                vs[0] = _scalarStats;
            if (//scalar output
            vs[2] == null)
                vs[2] = _scalarStats;
            if (inst instanceof MMTSJCPInstruction) {
                String type = ((MMTSJCPInstruction) inst).getMMTSJType().toString();
                attr = new String[] { type };
            } else if (inst instanceof AggregateUnaryCPInstruction) {
                String[] parts = InstructionUtils.getInstructionParts(inst.toString());
                String opcode = parts[0];
                if (opcode.equals("cm"))
                    attr = new String[] { parts[parts.length - 2] };
            }
        }
    } else if (inst instanceof BinaryCPInstruction) {
        BinaryCPInstruction binst = (BinaryCPInstruction) inst;
        vs[0] = stats.get(binst.input1.getName());
        vs[1] = stats.get(binst.input2.getName());
        vs[2] = stats.get(binst.output.getName());
        if (//scalar input, 
        vs[0] == null)
            vs[0] = _scalarStats;
        if (//scalar input, 
        vs[1] == null)
            vs[1] = _scalarStats;
        if (//scalar output
        vs[2] == null)
            vs[2] = _scalarStats;
    } else if (inst instanceof AggregateTernaryCPInstruction) {
        AggregateTernaryCPInstruction binst = (AggregateTernaryCPInstruction) inst;
        //of same dimension anyway but missing third input
        vs[0] = stats.get(binst.input1.getName());
        vs[1] = stats.get(binst.input2.getName());
        vs[2] = stats.get(binst.output.getName());
        if (//scalar input, 
        vs[0] == null)
            vs[0] = _scalarStats;
        if (//scalar input, 
        vs[1] == null)
            vs[1] = _scalarStats;
        if (//scalar output
        vs[2] == null)
            vs[2] = _scalarStats;
    } else if (inst instanceof ParameterizedBuiltinCPInstruction) {
        //ParameterizedBuiltinCPInstruction pinst = (ParameterizedBuiltinCPInstruction) inst;
        String[] parts = InstructionUtils.getInstructionParts(inst.toString());
        String opcode = parts[0];
        if (opcode.equals("groupedagg")) {
            HashMap<String, String> paramsMap = ParameterizedBuiltinCPInstruction.constructParameterMap(parts);
            String fn = paramsMap.get("fn");
            String order = paramsMap.get("order");
            AggregateOperationTypes type = CMOperator.getAggOpType(fn, order);
            attr = new String[] { String.valueOf(type.ordinal()) };
        } else if (opcode.equals("rmempty")) {
            HashMap<String, String> paramsMap = ParameterizedBuiltinCPInstruction.constructParameterMap(parts);
            attr = new String[] { String.valueOf(paramsMap.get("margin").equals("rows") ? 0 : 1) };
        }
        vs[0] = stats.get(parts[1].substring(7).replaceAll(Lop.VARIABLE_NAME_PLACEHOLDER, ""));
        //TODO
        vs[1] = _unknownStats;
        vs[2] = stats.get(parts[parts.length - 1]);
        if (//scalar input
        vs[0] == null)
            vs[0] = _scalarStats;
        if (//scalar output
        vs[2] == null)
            vs[2] = _scalarStats;
    } else if (inst instanceof MultiReturnBuiltinCPInstruction) {
        //applies to qr, lu, eigen (cost computation on input1)
        MultiReturnBuiltinCPInstruction minst = (MultiReturnBuiltinCPInstruction) inst;
        vs[0] = stats.get(minst.input1.getName());
        vs[1] = stats.get(minst.getOutput(0).getName());
        vs[2] = stats.get(minst.getOutput(1).getName());
    } else if (inst instanceof VariableCPInstruction) {
        setUnknownStats(vs);
        VariableCPInstruction varinst = (VariableCPInstruction) inst;
        if (varinst.getOpcode().equals("write")) {
            //special handling write of matrix objects (non existing if scalar)
            if (stats.containsKey(varinst.getInput1().getName()))
                vs[0] = stats.get(varinst.getInput1().getName());
            attr = new String[] { varinst.getInput3().getName() };
        }
    } else {
        setUnknownStats(vs);
    }
    //maintain var status (CP output always inmem)
    vs[2]._inmem = true;
    ret[0] = vs;
    ret[1] = attr;
    return ret;
}
Also used : StringInitCPInstruction(org.apache.sysml.runtime.instructions.cp.StringInitCPInstruction) ParameterizedBuiltinCPInstruction(org.apache.sysml.runtime.instructions.cp.ParameterizedBuiltinCPInstruction) AggregateUnaryCPInstruction(org.apache.sysml.runtime.instructions.cp.AggregateUnaryCPInstruction) HashMap(java.util.HashMap) VariableCPInstruction(org.apache.sysml.runtime.instructions.cp.VariableCPInstruction) AggregateOperationTypes(org.apache.sysml.runtime.matrix.operators.CMOperator.AggregateOperationTypes) MMTSJCPInstruction(org.apache.sysml.runtime.instructions.cp.MMTSJCPInstruction) MultiReturnBuiltinCPInstruction(org.apache.sysml.runtime.instructions.cp.MultiReturnBuiltinCPInstruction) MatrixObject(org.apache.sysml.runtime.controlprogram.caching.MatrixObject) AggregateTernaryCPInstruction(org.apache.sysml.runtime.instructions.cp.AggregateTernaryCPInstruction) DataGenCPInstruction(org.apache.sysml.runtime.instructions.cp.DataGenCPInstruction) AggregateUnaryCPInstruction(org.apache.sysml.runtime.instructions.cp.AggregateUnaryCPInstruction) UnaryCPInstruction(org.apache.sysml.runtime.instructions.cp.UnaryCPInstruction) BinaryCPInstruction(org.apache.sysml.runtime.instructions.cp.BinaryCPInstruction)

Aggregations

HashMap (java.util.HashMap)1 MatrixObject (org.apache.sysml.runtime.controlprogram.caching.MatrixObject)1 AggregateTernaryCPInstruction (org.apache.sysml.runtime.instructions.cp.AggregateTernaryCPInstruction)1 AggregateUnaryCPInstruction (org.apache.sysml.runtime.instructions.cp.AggregateUnaryCPInstruction)1 BinaryCPInstruction (org.apache.sysml.runtime.instructions.cp.BinaryCPInstruction)1 DataGenCPInstruction (org.apache.sysml.runtime.instructions.cp.DataGenCPInstruction)1 MMTSJCPInstruction (org.apache.sysml.runtime.instructions.cp.MMTSJCPInstruction)1 MultiReturnBuiltinCPInstruction (org.apache.sysml.runtime.instructions.cp.MultiReturnBuiltinCPInstruction)1 ParameterizedBuiltinCPInstruction (org.apache.sysml.runtime.instructions.cp.ParameterizedBuiltinCPInstruction)1 StringInitCPInstruction (org.apache.sysml.runtime.instructions.cp.StringInitCPInstruction)1 UnaryCPInstruction (org.apache.sysml.runtime.instructions.cp.UnaryCPInstruction)1 VariableCPInstruction (org.apache.sysml.runtime.instructions.cp.VariableCPInstruction)1 AggregateOperationTypes (org.apache.sysml.runtime.matrix.operators.CMOperator.AggregateOperationTypes)1