Search in sources :

Example 86 with DMLRuntimeException

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

the class ParameterizedBuiltinCPInstruction method parseInstruction.

public static ParameterizedBuiltinCPInstruction parseInstruction(String str) {
    String[] parts = InstructionUtils.getInstructionPartsWithValueType(str);
    // first part is always the opcode
    String opcode = parts[0];
    // last part is always the output
    CPOperand out = new CPOperand(parts[parts.length - 1]);
    // process remaining parts and build a hash map
    HashMap<String, String> paramsMap = constructParameterMap(parts);
    // determine the appropriate value function
    ValueFunction func = null;
    if (opcode.equalsIgnoreCase("cdf")) {
        if (paramsMap.get("dist") == null)
            throw new DMLRuntimeException("Invalid distribution: " + str);
        func = ParameterizedBuiltin.getParameterizedBuiltinFnObject(opcode, paramsMap.get("dist"));
        // Determine appropriate Function Object based on opcode
        return new ParameterizedBuiltinCPInstruction(new SimpleOperator(func), paramsMap, out, opcode, str);
    } else if (opcode.equalsIgnoreCase("invcdf")) {
        if (paramsMap.get("dist") == null)
            throw new DMLRuntimeException("Invalid distribution: " + str);
        func = ParameterizedBuiltin.getParameterizedBuiltinFnObject(opcode, paramsMap.get("dist"));
        // Determine appropriate Function Object based on opcode
        return new ParameterizedBuiltinCPInstruction(new SimpleOperator(func), paramsMap, out, opcode, str);
    } else if (opcode.equalsIgnoreCase("groupedagg")) {
        // check for mandatory arguments
        String fnStr = paramsMap.get("fn");
        if (fnStr == null)
            throw new DMLRuntimeException("Function parameter is missing in groupedAggregate.");
        if (fnStr.equalsIgnoreCase("centralmoment")) {
            if (paramsMap.get("order") == null)
                throw new DMLRuntimeException("Mandatory \"order\" must be specified when fn=\"centralmoment\" in groupedAggregate.");
        }
        Operator op = GroupedAggregateInstruction.parseGroupedAggOperator(fnStr, paramsMap.get("order"));
        return new ParameterizedBuiltinCPInstruction(op, paramsMap, out, opcode, str);
    } else if (opcode.equalsIgnoreCase("rmempty") || opcode.equalsIgnoreCase("replace") || opcode.equalsIgnoreCase("rexpand")) {
        func = ParameterizedBuiltin.getParameterizedBuiltinFnObject(opcode);
        return new ParameterizedBuiltinCPInstruction(new SimpleOperator(func), paramsMap, out, opcode, str);
    } else if (opcode.equals("transformapply") || opcode.equals("transformdecode") || opcode.equals("transformcolmap") || opcode.equals("transformmeta")) {
        return new ParameterizedBuiltinCPInstruction(null, paramsMap, out, opcode, str);
    } else if (opcode.equals("toString")) {
        return new ParameterizedBuiltinCPInstruction(null, paramsMap, out, opcode, str);
    } else {
        throw new DMLRuntimeException("Unknown opcode (" + opcode + ") for ParameterizedBuiltin Instruction.");
    }
}
Also used : ValueFunction(org.apache.sysml.runtime.functionobjects.ValueFunction) Operator(org.apache.sysml.runtime.matrix.operators.Operator) SimpleOperator(org.apache.sysml.runtime.matrix.operators.SimpleOperator) SimpleOperator(org.apache.sysml.runtime.matrix.operators.SimpleOperator) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException)

Example 87 with DMLRuntimeException

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

the class QuantilePickCPInstruction method parseInstruction.

public static QuantilePickCPInstruction parseInstruction(String str) {
    String[] parts = InstructionUtils.getInstructionPartsWithValueType(str);
    String opcode = parts[0];
    if (!opcode.equalsIgnoreCase("qpick"))
        throw new DMLRuntimeException("Unknown opcode while parsing a QuantilePickCPInstruction: " + str);
    // instruction parsing
    if (parts.length == 4) {
        // instructions of length 4 originate from unary - mr-iqm
        // TODO this should be refactored to use pickvaluecount lops
        CPOperand in1 = new CPOperand(parts[1]);
        CPOperand in2 = new CPOperand(parts[2]);
        CPOperand out = new CPOperand(parts[3]);
        OperationTypes ptype = OperationTypes.IQM;
        boolean inmem = false;
        return new QuantilePickCPInstruction(null, in1, in2, out, ptype, inmem, opcode, str);
    } else if (parts.length == 5) {
        CPOperand in1 = new CPOperand(parts[1]);
        CPOperand out = new CPOperand(parts[2]);
        OperationTypes ptype = OperationTypes.valueOf(parts[3]);
        boolean inmem = Boolean.parseBoolean(parts[4]);
        return new QuantilePickCPInstruction(null, in1, out, ptype, inmem, opcode, str);
    } else if (parts.length == 6) {
        CPOperand in1 = new CPOperand(parts[1]);
        CPOperand in2 = new CPOperand(parts[2]);
        CPOperand out = new CPOperand(parts[3]);
        OperationTypes ptype = OperationTypes.valueOf(parts[4]);
        boolean inmem = Boolean.parseBoolean(parts[5]);
        return new QuantilePickCPInstruction(null, in1, in2, out, ptype, inmem, opcode, str);
    }
    return null;
}
Also used : OperationTypes(org.apache.sysml.lops.PickByCount.OperationTypes) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException)

Example 88 with DMLRuntimeException

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

the class QuantileSortCPInstruction method parseInstruction.

public static QuantileSortCPInstruction parseInstruction(String str) {
    CPOperand in1 = new CPOperand("", ValueType.UNKNOWN, DataType.UNKNOWN);
    CPOperand in2 = null;
    CPOperand out = new CPOperand("", ValueType.UNKNOWN, DataType.UNKNOWN);
    String[] parts = InstructionUtils.getInstructionPartsWithValueType(str);
    String opcode = parts[0];
    if (opcode.equalsIgnoreCase(SortKeys.OPCODE)) {
        if (parts.length == 3) {
            // Example: sort:mVar1:mVar2 (input=mVar1, output=mVar2)
            parseUnaryInstruction(str, in1, out);
            return new QuantileSortCPInstruction(new SimpleOperator(null), in1, out, opcode, str);
        } else if (parts.length == 4) {
            // Example: sort:mVar1:mVar2:mVar3 (input=mVar1, weights=mVar2, output=mVar3)
            in2 = new CPOperand("", ValueType.UNKNOWN, DataType.UNKNOWN);
            parseUnaryInstruction(str, in1, in2, out);
            return new QuantileSortCPInstruction(new SimpleOperator(null), in1, in2, out, opcode, str);
        } else {
            throw new DMLRuntimeException("Invalid number of operands in instruction: " + str);
        }
    } else {
        throw new DMLRuntimeException("Unknown opcode while parsing a QuantileSortCPInstruction: " + str);
    }
}
Also used : SimpleOperator(org.apache.sysml.runtime.matrix.operators.SimpleOperator) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException)

Example 89 with DMLRuntimeException

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

the class ReorgCPInstruction method parseInstruction.

public static ReorgCPInstruction parseInstruction(String str) {
    CPOperand in = new CPOperand("", ValueType.UNKNOWN, DataType.UNKNOWN);
    CPOperand out = new CPOperand("", ValueType.UNKNOWN, DataType.UNKNOWN);
    String[] parts = InstructionUtils.getInstructionPartsWithValueType(str);
    String opcode = parts[0];
    if (opcode.equalsIgnoreCase("r'")) {
        InstructionUtils.checkNumFields(str, 2, 3);
        in.split(parts[1]);
        out.split(parts[2]);
        int k = Integer.parseInt(parts[3]);
        return new ReorgCPInstruction(new ReorgOperator(SwapIndex.getSwapIndexFnObject(), k), in, out, opcode, str);
    } else if (opcode.equalsIgnoreCase("rev")) {
        // max 2 operands
        parseUnaryInstruction(str, in, out);
        return new ReorgCPInstruction(new ReorgOperator(RevIndex.getRevIndexFnObject()), in, out, opcode, str);
    } else if (opcode.equalsIgnoreCase("rdiag")) {
        // max 2 operands
        parseUnaryInstruction(str, in, out);
        return new ReorgCPInstruction(new ReorgOperator(DiagIndex.getDiagIndexFnObject()), in, out, opcode, str);
    } else if (opcode.equalsIgnoreCase("rsort")) {
        InstructionUtils.checkNumFields(parts, 5);
        in.split(parts[1]);
        out.split(parts[5]);
        CPOperand col = new CPOperand(parts[2]);
        CPOperand desc = new CPOperand(parts[3]);
        CPOperand ixret = new CPOperand(parts[4]);
        return new ReorgCPInstruction(new ReorgOperator(new SortIndex(1, false, false)), in, out, col, desc, ixret, opcode, str);
    } else {
        throw new DMLRuntimeException("Unknown opcode while parsing a ReorgInstruction: " + str);
    }
}
Also used : SortIndex(org.apache.sysml.runtime.functionobjects.SortIndex) ReorgOperator(org.apache.sysml.runtime.matrix.operators.ReorgOperator) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException)

Example 90 with DMLRuntimeException

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

the class UaggOuterChainCPInstruction method parseInstruction.

public static UaggOuterChainCPInstruction parseInstruction(String str) {
    String[] parts = InstructionUtils.getInstructionPartsWithValueType(str);
    String opcode = parts[0];
    if (opcode.equalsIgnoreCase(UAggOuterChain.OPCODE)) {
        AggregateUnaryOperator uaggop = InstructionUtils.parseBasicAggregateUnaryOperator(parts[1]);
        BinaryOperator bop = InstructionUtils.parseBinaryOperator(parts[2]);
        CPOperand in1 = new CPOperand(parts[3]);
        CPOperand in2 = new CPOperand(parts[4]);
        CPOperand out = new CPOperand(parts[5]);
        // derive aggregation operator from unary operator
        String aopcode = InstructionUtils.deriveAggregateOperatorOpcode(parts[1]);
        CorrectionLocationType corrLoc = InstructionUtils.deriveAggregateOperatorCorrectionLocation(parts[1]);
        String corrExists = (corrLoc != CorrectionLocationType.NONE) ? "true" : "false";
        AggregateOperator aop = InstructionUtils.parseAggregateOperator(aopcode, corrExists, corrLoc.toString());
        return new UaggOuterChainCPInstruction(bop, uaggop, aop, in1, in2, out, opcode, str);
    } else {
        throw new DMLRuntimeException("UaggOuterChainCPInstruction.parseInstruction():: Unknown opcode " + opcode);
    }
}
Also used : AggregateUnaryOperator(org.apache.sysml.runtime.matrix.operators.AggregateUnaryOperator) AggregateOperator(org.apache.sysml.runtime.matrix.operators.AggregateOperator) BinaryOperator(org.apache.sysml.runtime.matrix.operators.BinaryOperator) CorrectionLocationType(org.apache.sysml.lops.PartialAggregate.CorrectionLocationType) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException)

Aggregations

DMLRuntimeException (org.apache.sysml.runtime.DMLRuntimeException)579 MatrixBlock (org.apache.sysml.runtime.matrix.data.MatrixBlock)104 IOException (java.io.IOException)102 MatrixCharacteristics (org.apache.sysml.runtime.matrix.MatrixCharacteristics)85 MatrixObject (org.apache.sysml.runtime.controlprogram.caching.MatrixObject)78 ArrayList (java.util.ArrayList)75 CPOperand (org.apache.sysml.runtime.instructions.cp.CPOperand)49 Path (org.apache.hadoop.fs.Path)43 MatrixIndexes (org.apache.sysml.runtime.matrix.data.MatrixIndexes)40 ExecutorService (java.util.concurrent.ExecutorService)38 Pointer (jcuda.Pointer)37 Future (java.util.concurrent.Future)35 CSRPointer (org.apache.sysml.runtime.instructions.gpu.context.CSRPointer)30 MetaDataFormat (org.apache.sysml.runtime.matrix.MetaDataFormat)26 FrameBlock (org.apache.sysml.runtime.matrix.data.FrameBlock)26 FileSystem (org.apache.hadoop.fs.FileSystem)25 JobConf (org.apache.hadoop.mapred.JobConf)23 Operator (org.apache.sysml.runtime.matrix.operators.Operator)22 KahanObject (org.apache.sysml.runtime.instructions.cp.KahanObject)20 SparkExecutionContext (org.apache.sysml.runtime.controlprogram.context.SparkExecutionContext)19