use of org.apache.sysml.runtime.DMLRuntimeException in project incubator-systemml by apache.
the class VariableCPInstruction method processMoveInstruction.
/**
* Handler for mvvar instructions.
* Example: mvvar <srcvar> <destFile> <format>
* Move the file pointed by srcvar to destFile.
* Currently, applicable only when format=binaryblock.
*
* @param ec execution context
*/
@SuppressWarnings("rawtypes")
private void processMoveInstruction(ExecutionContext ec) {
if (getInput3() == null) {
// example: mvvar tempA A
// get source variable
Data srcData = ec.getVariable(getInput1().getName());
if (srcData == null) {
throw new DMLRuntimeException("Unexpected error: could not find a data object " + "for variable name:" + getInput1().getName() + ", while processing instruction ");
}
if (getInput2().getDataType().isMatrix() || getInput2().getDataType().isFrame()) {
// remove existing variable bound to target name
Data tgt = ec.removeVariable(getInput2().getName());
// cleanup matrix data on fs/hdfs (if necessary)
if (tgt != null && tgt instanceof CacheableData) {
ec.cleanupCacheableData((CacheableData<?>) tgt);
}
}
// do the actual move
ec.setVariable(getInput2().getName(), srcData);
ec.removeVariable(getInput1().getName());
} else {
// example instruction: mvvar <srcVar> <destFile> <format>
if (ec.getVariable(getInput1().getName()) == null)
throw new DMLRuntimeException("Unexpected error: could not find a data object for variable name:" + getInput1().getName() + ", while processing instruction " + this.toString());
Object object = ec.getVariable(getInput1().getName());
if (getInput3().getName().equalsIgnoreCase("binaryblock")) {
boolean success = false;
success = ((CacheableData) object).moveData(getInput2().getName(), getInput3().getName());
if (!success) {
throw new DMLRuntimeException("Failed to move var " + getInput1().getName() + " to file " + getInput2().getName() + ".");
}
} else if (object instanceof MatrixObject)
throw new DMLRuntimeException("Unexpected formats while copying: from matrix blocks [" + ((MatrixObject) object).getNumRowsPerBlock() + "," + ((MatrixObject) object).getNumColumnsPerBlock() + "] to " + getInput3().getName());
else if (object instanceof FrameObject)
throw new DMLRuntimeException("Unexpected formats while copying: from fram object [" + ((FrameObject) object).getNumColumns() + "," + ((FrameObject) object).getNumColumns() + "] to " + getInput3().getName());
}
}
use of org.apache.sysml.runtime.DMLRuntimeException in project incubator-systemml by apache.
the class VariableCPInstruction method processCopyInstruction.
/**
* Handler for cpvar instructions.
* Example: cpvar <srcvar> <destvar>
*
* @param ec execution context
*/
private void processCopyInstruction(ExecutionContext ec) {
// get source variable
Data dd = ec.getVariable(getInput1().getName());
if (dd == null)
throw new DMLRuntimeException("Unexpected error: could not find a data object for variable name:" + getInput1().getName() + ", while processing instruction " + this.toString());
// remove existing variable bound to target name
Data input2_data = ec.removeVariable(getInput2().getName());
// cleanup matrix data on fs/hdfs (if necessary)
if (input2_data != null && input2_data instanceof CacheableData) {
ec.cleanupCacheableData((CacheableData<?>) input2_data);
}
// do the actual copy!
ec.setVariable(getInput2().getName(), dd);
}
use of org.apache.sysml.runtime.DMLRuntimeException 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.DMLRuntimeException 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.DMLRuntimeException in project incubator-systemml by apache.
the class VariableCPInstruction method writeScalarToHDFS.
/**
* Helper function to write scalars to HDFS based on its value type.
*
* @param ec execution context
* @param fname file name
*/
private void writeScalarToHDFS(ExecutionContext ec, String fname) {
try {
ScalarObject scalar = ec.getScalarInput(getInput1().getName(), getInput1().getValueType(), getInput1().isLiteral());
MapReduceTool.writeObjectToHDFS(scalar.getValue(), fname);
MapReduceTool.writeScalarMetaDataFile(fname + ".mtd", getInput1().getValueType());
FileSystem fs = IOUtilFunctions.getFileSystem(fname);
if (fs instanceof LocalFileSystem) {
Path path = new Path(fname);
IOUtilFunctions.deleteCrcFilesFromLocalFileSystem(fs, path);
}
} catch (IOException e) {
throw new DMLRuntimeException(e);
}
}
Aggregations