Search in sources :

Example 71 with DMLRuntimeException

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

the class ZipmmSPInstruction method parseInstruction.

public static ZipmmSPInstruction parseInstruction(String str) {
    String[] parts = InstructionUtils.getInstructionPartsWithValueType(str);
    String opcode = parts[0];
    if (opcode.equalsIgnoreCase("zipmm")) {
        CPOperand in1 = new CPOperand(parts[1]);
        CPOperand in2 = new CPOperand(parts[2]);
        CPOperand out = new CPOperand(parts[3]);
        boolean tRewrite = Boolean.parseBoolean(parts[4]);
        AggregateOperator agg = new AggregateOperator(0, Plus.getPlusFnObject());
        AggregateBinaryOperator aggbin = new AggregateBinaryOperator(Multiply.getMultiplyFnObject(), agg);
        return new ZipmmSPInstruction(aggbin, in1, in2, out, tRewrite, opcode, str);
    } else {
        throw new DMLRuntimeException("ZipmmSPInstruction.parseInstruction():: Unknown opcode " + opcode);
    }
}
Also used : AggregateOperator(org.apache.sysml.runtime.matrix.operators.AggregateOperator) AggregateBinaryOperator(org.apache.sysml.runtime.matrix.operators.AggregateBinaryOperator) CPOperand(org.apache.sysml.runtime.instructions.cp.CPOperand) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException)

Example 72 with DMLRuntimeException

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

the class ProgramConverter method createWhileStatementBlockCopy.

public static WhileStatementBlock createWhileStatementBlockCopy(WhileStatementBlock sb, long pid, boolean plain, boolean forceDeepCopy) {
    WhileStatementBlock ret = null;
    try {
        if (ConfigurationManager.getCompilerConfigFlag(ConfigType.ALLOW_PARALLEL_DYN_RECOMPILATION) && // forced deep copy for function recompile
        sb != null && (Recompiler.requiresRecompilation(sb.getPredicateHops()) || forceDeepCopy)) {
            // create new statement (shallow copy livein/liveout for recompile, line numbers for explain)
            ret = new WhileStatementBlock();
            ret.setDMLProg(sb.getDMLProg());
            ret.setParseInfo(sb);
            ret.setLiveIn(sb.liveIn());
            ret.setLiveOut(sb.liveOut());
            ret.setUpdatedVariables(sb.variablesUpdated());
            ret.setReadVariables(sb.variablesRead());
            ret.setUpdateInPlaceVars(sb.getUpdateInPlaceVars());
            // shallow copy child statements
            ret.setStatements(sb.getStatements());
            // deep copy predicate hops dag for concurrent recompile
            Hop hops = Recompiler.deepCopyHopsDag(sb.getPredicateHops());
            ret.setPredicateHops(hops);
            ret.updatePredicateRecompilationFlag();
        } else {
            ret = sb;
        }
    } catch (Exception ex) {
        throw new DMLRuntimeException(ex);
    }
    return ret;
}
Also used : Hop(org.apache.sysml.hops.Hop) WhileStatementBlock(org.apache.sysml.parser.WhileStatementBlock) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException)

Example 73 with DMLRuntimeException

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

the class ProgramConverter method serializeDataObject.

public static String serializeDataObject(String key, Data dat) {
    // SCHEMA: <name>|<datatype>|<valuetype>|value
    // (scalars are serialize by value, matrices by filename)
    StringBuilder sb = new StringBuilder();
    // prepare data for serialization
    String name = key;
    DataType datatype = dat.getDataType();
    ValueType valuetype = dat.getValueType();
    String value = null;
    String[] matrixMetaData = null;
    switch(datatype) {
        case SCALAR:
            ScalarObject so = (ScalarObject) dat;
            // name = so.getName();
            value = so.getStringValue();
            break;
        case MATRIX:
            MatrixObject mo = (MatrixObject) dat;
            MetaDataFormat md = (MetaDataFormat) dat.getMetaData();
            MatrixCharacteristics mc = md.getMatrixCharacteristics();
            value = mo.getFileName();
            PartitionFormat partFormat = (mo.getPartitionFormat() != null) ? new PartitionFormat(mo.getPartitionFormat(), mo.getPartitionSize()) : PartitionFormat.NONE;
            matrixMetaData = new String[9];
            matrixMetaData[0] = String.valueOf(mc.getRows());
            matrixMetaData[1] = String.valueOf(mc.getCols());
            matrixMetaData[2] = String.valueOf(mc.getRowsPerBlock());
            matrixMetaData[3] = String.valueOf(mc.getColsPerBlock());
            matrixMetaData[4] = String.valueOf(mc.getNonZeros());
            matrixMetaData[5] = InputInfo.inputInfoToString(md.getInputInfo());
            matrixMetaData[6] = OutputInfo.outputInfoToString(md.getOutputInfo());
            matrixMetaData[7] = String.valueOf(partFormat);
            matrixMetaData[8] = String.valueOf(mo.getUpdateType());
            break;
        default:
            throw new DMLRuntimeException("Unable to serialize datatype " + datatype);
    }
    // serialize data
    sb.append(name);
    sb.append(DATA_FIELD_DELIM);
    sb.append(datatype);
    sb.append(DATA_FIELD_DELIM);
    sb.append(valuetype);
    sb.append(DATA_FIELD_DELIM);
    sb.append(value);
    if (matrixMetaData != null)
        for (int i = 0; i < matrixMetaData.length; i++) {
            sb.append(DATA_FIELD_DELIM);
            sb.append(matrixMetaData[i]);
        }
    return sb.toString();
}
Also used : ScalarObject(org.apache.sysml.runtime.instructions.cp.ScalarObject) MetaDataFormat(org.apache.sysml.runtime.matrix.MetaDataFormat) MatrixObject(org.apache.sysml.runtime.controlprogram.caching.MatrixObject) ValueType(org.apache.sysml.parser.Expression.ValueType) DataType(org.apache.sysml.parser.Expression.DataType) PartitionFormat(org.apache.sysml.runtime.controlprogram.ParForProgramBlock.PartitionFormat) PDataPartitionFormat(org.apache.sysml.runtime.controlprogram.ParForProgramBlock.PDataPartitionFormat) MatrixCharacteristics(org.apache.sysml.runtime.matrix.MatrixCharacteristics) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException)

Example 74 with DMLRuntimeException

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

the class ProgramConverter method rSerializeProgramBlock.

private static String rSerializeProgramBlock(ProgramBlock pb, HashMap<String, byte[]> clsMap) {
    StringBuilder sb = new StringBuilder();
    // handle header
    if (pb instanceof WhileProgramBlock)
        sb.append(PARFOR_PB_WHILE);
    else if (pb instanceof ForProgramBlock && !(pb instanceof ParForProgramBlock))
        sb.append(PARFOR_PB_FOR);
    else if (pb instanceof ParForProgramBlock)
        sb.append(PARFOR_PB_PARFOR);
    else if (pb instanceof IfProgramBlock)
        sb.append(PARFOR_PB_IF);
    else if (pb instanceof FunctionProgramBlock && !(pb instanceof ExternalFunctionProgramBlock))
        sb.append(PARFOR_PB_FC);
    else if (pb instanceof ExternalFunctionProgramBlock)
        sb.append(PARFOR_PB_EFC);
    else
        // all generic program blocks
        sb.append(PARFOR_PB_BEGIN);
    // handle body
    if (pb instanceof WhileProgramBlock) {
        WhileProgramBlock wpb = (WhileProgramBlock) pb;
        sb.append(PARFOR_INST_BEGIN);
        sb.append(serializeInstructions(wpb.getPredicate(), clsMap));
        sb.append(PARFOR_INST_END);
        sb.append(COMPONENTS_DELIM);
        sb.append(PARFOR_INST_BEGIN);
        sb.append(serializeInstructions(wpb.getExitInstructions(), clsMap));
        sb.append(PARFOR_INST_END);
        sb.append(COMPONENTS_DELIM);
        sb.append(PARFOR_PBS_BEGIN);
        sb.append(rSerializeProgramBlocks(wpb.getChildBlocks(), clsMap));
        sb.append(PARFOR_PBS_END);
    } else if (pb instanceof ForProgramBlock && !(pb instanceof ParForProgramBlock)) {
        ForProgramBlock fpb = (ForProgramBlock) pb;
        sb.append(fpb.getIterVar());
        sb.append(COMPONENTS_DELIM);
        sb.append(PARFOR_INST_BEGIN);
        sb.append(serializeInstructions(fpb.getFromInstructions(), clsMap));
        sb.append(PARFOR_INST_END);
        sb.append(COMPONENTS_DELIM);
        sb.append(PARFOR_INST_BEGIN);
        sb.append(serializeInstructions(fpb.getToInstructions(), clsMap));
        sb.append(PARFOR_INST_END);
        sb.append(COMPONENTS_DELIM);
        sb.append(PARFOR_INST_BEGIN);
        sb.append(serializeInstructions(fpb.getIncrementInstructions(), clsMap));
        sb.append(PARFOR_INST_END);
        sb.append(COMPONENTS_DELIM);
        sb.append(PARFOR_INST_BEGIN);
        sb.append(serializeInstructions(fpb.getExitInstructions(), clsMap));
        sb.append(PARFOR_INST_END);
        sb.append(COMPONENTS_DELIM);
        sb.append(PARFOR_PBS_BEGIN);
        sb.append(rSerializeProgramBlocks(fpb.getChildBlocks(), clsMap));
        sb.append(PARFOR_PBS_END);
    } else if (pb instanceof ParForProgramBlock) {
        ParForProgramBlock pfpb = (ParForProgramBlock) pb;
        // check for nested remote ParFOR
        if (PExecMode.valueOf(pfpb.getParForParams().get(ParForStatementBlock.EXEC_MODE)) == PExecMode.REMOTE_MR)
            throw new DMLRuntimeException(NOT_SUPPORTED_MR_PARFOR);
        sb.append(pfpb.getIterVar());
        sb.append(COMPONENTS_DELIM);
        sb.append(serializeResultVariables(pfpb.getResultVariables()));
        sb.append(COMPONENTS_DELIM);
        // parameters of nested parfor
        sb.append(serializeStringHashMap(pfpb.getParForParams()));
        sb.append(COMPONENTS_DELIM);
        sb.append(PARFOR_INST_BEGIN);
        sb.append(serializeInstructions(pfpb.getFromInstructions(), clsMap));
        sb.append(PARFOR_INST_END);
        sb.append(COMPONENTS_DELIM);
        sb.append(PARFOR_INST_BEGIN);
        sb.append(serializeInstructions(pfpb.getToInstructions(), clsMap));
        sb.append(PARFOR_INST_END);
        sb.append(COMPONENTS_DELIM);
        sb.append(PARFOR_INST_BEGIN);
        sb.append(serializeInstructions(pfpb.getIncrementInstructions(), clsMap));
        sb.append(PARFOR_INST_END);
        sb.append(COMPONENTS_DELIM);
        sb.append(PARFOR_INST_BEGIN);
        sb.append(serializeInstructions(pfpb.getExitInstructions(), clsMap));
        sb.append(PARFOR_INST_END);
        sb.append(COMPONENTS_DELIM);
        sb.append(PARFOR_PBS_BEGIN);
        sb.append(rSerializeProgramBlocks(pfpb.getChildBlocks(), clsMap));
        sb.append(PARFOR_PBS_END);
    } else if (pb instanceof IfProgramBlock) {
        IfProgramBlock ipb = (IfProgramBlock) pb;
        sb.append(PARFOR_INST_BEGIN);
        sb.append(serializeInstructions(ipb.getPredicate(), clsMap));
        sb.append(PARFOR_INST_END);
        sb.append(COMPONENTS_DELIM);
        sb.append(PARFOR_INST_BEGIN);
        sb.append(serializeInstructions(ipb.getExitInstructions(), clsMap));
        sb.append(PARFOR_INST_END);
        sb.append(COMPONENTS_DELIM);
        sb.append(PARFOR_PBS_BEGIN);
        sb.append(rSerializeProgramBlocks(ipb.getChildBlocksIfBody(), clsMap));
        sb.append(PARFOR_PBS_END);
        sb.append(COMPONENTS_DELIM);
        sb.append(PARFOR_PBS_BEGIN);
        sb.append(rSerializeProgramBlocks(ipb.getChildBlocksElseBody(), clsMap));
        sb.append(PARFOR_PBS_END);
    } else if (pb instanceof FunctionProgramBlock && !(pb instanceof ExternalFunctionProgramBlock)) {
        FunctionProgramBlock fpb = (FunctionProgramBlock) pb;
        sb.append(serializeDataIdentifiers(fpb.getInputParams()));
        sb.append(COMPONENTS_DELIM);
        sb.append(serializeDataIdentifiers(fpb.getOutputParams()));
        sb.append(COMPONENTS_DELIM);
        sb.append(PARFOR_INST_BEGIN);
        sb.append(serializeInstructions(fpb.getInstructions(), clsMap));
        sb.append(PARFOR_INST_END);
        sb.append(COMPONENTS_DELIM);
        sb.append(PARFOR_PBS_BEGIN);
        sb.append(rSerializeProgramBlocks(fpb.getChildBlocks(), clsMap));
        sb.append(PARFOR_PBS_END);
        sb.append(COMPONENTS_DELIM);
    } else if (pb instanceof ExternalFunctionProgramBlock) {
        if (!(pb instanceof ExternalFunctionProgramBlockCP)) {
            throw new DMLRuntimeException(NOT_SUPPORTED_EXTERNALFUNCTION_PB);
        }
        ExternalFunctionProgramBlockCP fpb = (ExternalFunctionProgramBlockCP) pb;
        sb.append(serializeDataIdentifiers(fpb.getInputParams()));
        sb.append(COMPONENTS_DELIM);
        sb.append(serializeDataIdentifiers(fpb.getOutputParams()));
        sb.append(COMPONENTS_DELIM);
        sb.append(serializeStringHashMap(fpb.getOtherParams()));
        sb.append(COMPONENTS_DELIM);
        sb.append(fpb.getBaseDir());
        sb.append(COMPONENTS_DELIM);
        sb.append(PARFOR_INST_BEGIN);
        // create on construction anyway
        sb.append(PARFOR_INST_END);
        sb.append(COMPONENTS_DELIM);
        sb.append(PARFOR_PBS_BEGIN);
        sb.append(rSerializeProgramBlocks(fpb.getChildBlocks(), clsMap));
        sb.append(PARFOR_PBS_END);
    } else // all generic program blocks
    {
        sb.append(PARFOR_INST_BEGIN);
        sb.append(serializeInstructions(pb.getInstructions(), clsMap));
        sb.append(PARFOR_INST_END);
    }
    // handle end
    sb.append(PARFOR_PB_END);
    return sb.toString();
}
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) ExternalFunctionProgramBlock(org.apache.sysml.runtime.controlprogram.ExternalFunctionProgramBlock) WhileProgramBlock(org.apache.sysml.runtime.controlprogram.WhileProgramBlock) ExternalFunctionProgramBlockCP(org.apache.sysml.runtime.controlprogram.ExternalFunctionProgramBlockCP) ParForProgramBlock(org.apache.sysml.runtime.controlprogram.ParForProgramBlock) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException)

Example 75 with DMLRuntimeException

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

the class ProgramConverter method parseInstructions.

private static ArrayList<Instruction> parseInstructions(String in, int id) {
    ArrayList<Instruction> insts = new ArrayList<>();
    String lin = in.substring(PARFOR_INST_BEGIN.length(), in.length() - PARFOR_INST_END.length());
    StringTokenizer st = new StringTokenizer(lin, ELEMENT_DELIM);
    while (st.hasMoreTokens()) {
        // Note that at this point only CP instructions and External function instruction can occur
        String instStr = st.nextToken();
        try {
            Instruction tmpinst = CPInstructionParser.parseSingleInstruction(instStr);
            tmpinst = saveReplaceThreadID(tmpinst, CP_ROOT_THREAD_ID, CP_CHILD_THREAD + id);
            insts.add(tmpinst);
        } catch (Exception ex) {
            throw new DMLRuntimeException("Failed to parse instruction: " + instStr, ex);
        }
    }
    return insts;
}
Also used : StringTokenizer(java.util.StringTokenizer) 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) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException) 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