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);
}
}
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;
}
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();
}
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();
}
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;
}
Aggregations