Search in sources :

Example 91 with DMLRuntimeException

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());
    }
}
Also used : MatrixObject(org.apache.sysml.runtime.controlprogram.caching.MatrixObject) CacheableData(org.apache.sysml.runtime.controlprogram.caching.CacheableData) CacheableData(org.apache.sysml.runtime.controlprogram.caching.CacheableData) MetaData(org.apache.sysml.runtime.matrix.MetaData) MatrixObject(org.apache.sysml.runtime.controlprogram.caching.MatrixObject) FrameObject(org.apache.sysml.runtime.controlprogram.caching.FrameObject) FrameObject(org.apache.sysml.runtime.controlprogram.caching.FrameObject) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException)

Example 92 with DMLRuntimeException

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

the class VariableCPInstruction method processCopyInstruction.

/**
 * Handler for cpvar instructions.
 * Example: cpvar &lt;srcvar&gt; &lt;destvar&gt;
 *
 * @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);
}
Also used : CacheableData(org.apache.sysml.runtime.controlprogram.caching.CacheableData) CacheableData(org.apache.sysml.runtime.controlprogram.caching.CacheableData) MetaData(org.apache.sysml.runtime.matrix.MetaData) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException)

Example 93 with DMLRuntimeException

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);
        }
    }
}
Also used : OutputInfo(org.apache.sysml.runtime.matrix.data.OutputInfo) MetaDataFormat(org.apache.sysml.runtime.matrix.MetaDataFormat) MatrixObject(org.apache.sysml.runtime.controlprogram.caching.MatrixObject) WriterTextCSV(org.apache.sysml.runtime.io.WriterTextCSV) IOException(java.io.IOException) MatrixCharacteristics(org.apache.sysml.runtime.matrix.MatrixCharacteristics) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException)

Example 94 with DMLRuntimeException

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.");
        }
    }
}
Also used : OutputInfo(org.apache.sysml.runtime.matrix.data.OutputInfo) MetaDataFormat(org.apache.sysml.runtime.matrix.MetaDataFormat) MatrixObject(org.apache.sysml.runtime.controlprogram.caching.MatrixObject) IOException(java.io.IOException) MatrixCharacteristics(org.apache.sysml.runtime.matrix.MatrixCharacteristics) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException)

Example 95 with DMLRuntimeException

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);
    }
}
Also used : Path(org.apache.hadoop.fs.Path) LocalFileSystem(org.apache.hadoop.fs.LocalFileSystem) FileSystem(org.apache.hadoop.fs.FileSystem) LocalFileSystem(org.apache.hadoop.fs.LocalFileSystem) IOException(java.io.IOException) 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