use of org.apache.sysml.runtime.matrix.data.OutputInfo in project incubator-systemml by apache.
the class OptimizerRuleBased method determineFlagCellFormatWoCompare.
protected boolean determineFlagCellFormatWoCompare(ArrayList<String> resultVars, LocalVariableMap vars) {
boolean ret = true;
for (String rVar : resultVars) {
Data dat = vars.get(rVar);
if (dat == null || !(dat instanceof MatrixObject)) {
ret = false;
break;
} else {
MatrixObject mo = (MatrixObject) dat;
MatrixFormatMetaData meta = (MatrixFormatMetaData) mo.getMetaData();
OutputInfo oi = meta.getOutputInfo();
long nnz = meta.getMatrixCharacteristics().getNonZeros();
if (oi == OutputInfo.BinaryBlockOutputInfo || nnz != 0) {
ret = false;
break;
}
}
}
return ret;
}
use of org.apache.sysml.runtime.matrix.data.OutputInfo in project incubator-systemml by apache.
the class ResultMergeRemoteSpark method executeParallelMerge.
@Override
public MatrixObject executeParallelMerge(int par) {
// always create new matrix object (required for nested parallelism)
MatrixObject moNew = null;
if (LOG.isTraceEnabled())
LOG.trace("ResultMerge (remote, spark): Execute serial merge for output " + _output.hashCode() + " (fname=" + _output.getFileName() + ")");
try {
if (_inputs != null && _inputs.length > 0) {
// prepare compare
MetaDataFormat metadata = (MetaDataFormat) _output.getMetaData();
MatrixCharacteristics mcOld = metadata.getMatrixCharacteristics();
MatrixObject compare = (mcOld.getNonZeros() == 0) ? null : _output;
// actual merge
RDDObject ro = executeMerge(compare, _inputs, mcOld.getRows(), mcOld.getCols(), mcOld.getRowsPerBlock(), mcOld.getColsPerBlock());
// create new output matrix (e.g., to prevent potential export<->read file access conflict
moNew = new MatrixObject(_output.getValueType(), _outputFName);
OutputInfo oiOld = metadata.getOutputInfo();
InputInfo iiOld = metadata.getInputInfo();
MatrixCharacteristics mc = new MatrixCharacteristics(mcOld);
mc.setNonZeros(_isAccum ? -1 : computeNonZeros(_output, Arrays.asList(_inputs)));
MetaDataFormat meta = new MetaDataFormat(mc, oiOld, iiOld);
moNew.setMetaData(meta);
moNew.setRDDHandle(ro);
} else {
// return old matrix, to prevent copy
moNew = _output;
}
} catch (Exception ex) {
throw new DMLRuntimeException(ex);
}
return moNew;
}
use of org.apache.sysml.runtime.matrix.data.OutputInfo in project incubator-systemml by apache.
the class VariableCPInstruction method writeCSVFile.
/**
* Helper function to write CSV files to HDFS.
*
* @param ec execution context
* @param fname file name
*/
private void writeCSVFile(ExecutionContext ec, String fname) {
MatrixObject mo = ec.getMatrixObject(getInput1().getName());
String outFmt = "csv";
if (mo.isDirty()) {
// there exist data computed in CP that is not backed up on HDFS
// i.e., it is either in-memory or in evicted space
mo.exportData(fname, outFmt, _formatProperties);
} else {
try {
OutputInfo oi = ((MetaDataFormat) mo.getMetaData()).getOutputInfo();
MatrixCharacteristics mc = ((MetaDataFormat) mo.getMetaData()).getMatrixCharacteristics();
if (oi == OutputInfo.CSVOutputInfo) {
WriterTextCSV writer = new WriterTextCSV((CSVFileFormatProperties) _formatProperties);
writer.addHeaderToCSV(mo.getFileName(), fname, mc.getRows(), mc.getCols());
} else if (oi == OutputInfo.BinaryBlockOutputInfo || oi == OutputInfo.TextCellOutputInfo) {
mo.exportData(fname, outFmt, _formatProperties);
} else {
throw new DMLRuntimeException("Unexpected data format (" + OutputInfo.outputInfoToString(oi) + "): can not export into CSV format.");
}
// Write Metadata file
MapReduceTool.writeMetaDataFile(fname + ".mtd", mo.getValueType(), mc, OutputInfo.CSVOutputInfo, _formatProperties);
} catch (IOException e) {
throw new DMLRuntimeException(e);
}
}
}
use of org.apache.sysml.runtime.matrix.data.OutputInfo in project incubator-systemml by apache.
the class VariableCPInstruction method writeMMFile.
/**
* Helper function to write MM files to HDFS.
*
* @param ec execution context
* @param fname file name
*/
private void writeMMFile(ExecutionContext ec, String fname) {
MatrixObject mo = ec.getMatrixObject(getInput1().getName());
String outFmt = "matrixmarket";
if (mo.isDirty()) {
// there exist data computed in CP that is not backed up on HDFS
// i.e., it is either in-memory or in evicted space
mo.exportData(fname, outFmt);
} else {
OutputInfo oi = ((MetaDataFormat) mo.getMetaData()).getOutputInfo();
MatrixCharacteristics mc = mo.getMatrixCharacteristics();
if (oi == OutputInfo.TextCellOutputInfo) {
try {
WriterMatrixMarket.mergeTextcellToMatrixMarket(mo.getFileName(), fname, mc.getRows(), mc.getCols(), mc.getNonZeros());
} catch (IOException e) {
throw new DMLRuntimeException(e);
}
} else if (oi == OutputInfo.BinaryBlockOutputInfo) {
mo.exportData(fname, outFmt);
} else {
throw new DMLRuntimeException("Unexpected data format (" + OutputInfo.outputInfoToString(oi) + "): can not export into MatrixMarket format.");
}
}
}
use of org.apache.sysml.runtime.matrix.data.OutputInfo in project incubator-systemml by apache.
the class OptimizerRuleBased method determineFlagCellFormatWoCompare.
protected boolean determineFlagCellFormatWoCompare(ArrayList<ResultVar> resultVars, LocalVariableMap vars) {
boolean ret = true;
for (ResultVar rVar : resultVars) {
Data dat = vars.get(rVar._name);
if (dat == null || !(dat instanceof MatrixObject)) {
ret = false;
break;
} else {
MatrixObject mo = (MatrixObject) dat;
MetaDataFormat meta = (MetaDataFormat) mo.getMetaData();
OutputInfo oi = meta.getOutputInfo();
long nnz = meta.getMatrixCharacteristics().getNonZeros();
if (oi == OutputInfo.BinaryBlockOutputInfo || nnz != 0) {
ret = false;
break;
}
}
}
return ret;
}
Aggregations