Search in sources :

Example 16 with DMLRuntimeException

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

the class ConvolutionOp method inferOutputCharacteristics.

@Override
protected long[] inferOutputCharacteristics(MemoTable memo) {
    // [numRows, numCols, NNZ] 
    long[] ret = new long[3];
    if (op == ConvOp.BIAS_ADD || op == ConvOp.BIAS_MULTIPLY) {
        MatrixCharacteristics[] mc = memo.getAllInputStats(getInput());
        ret[0] = mc[0].rowsKnown() ? mc[0].getRows() : -1;
        ret[1] = mc[0].colsKnown() ? mc[0].getCols() : -1;
        ret[2] = -1;
        return (ret[0] > 0 && ret[1] > 0) ? ret : null;
    }
    ConvolutionParameters params;
    try {
        params = parseInput();
    } catch (DMLRuntimeException e) {
        throw new RuntimeException(e);
    }
    switch(op) {
        case MAX_POOLING:
            {
                // input
                long N = getInput().get(0)._dim1;
                ret[0] = N;
                ret[1] = getExtractedVal(params.C, params.P, params.Q);
                ret[2] = -1;
                break;
            }
        case DIRECT_CONV2D:
            {
                // input, filter
                long N = getInput().get(0)._dim1;
                ret[0] = N;
                ret[1] = getExtractedVal(params.K, params.P, params.Q);
                ret[2] = -1;
                break;
            }
        case DIRECT_CONV2D_BACKWARD_FILTER:
            {
                // input, dout	
                ret[0] = params.K;
                ret[1] = getExtractedVal(params.C, params.R, params.S);
                ret[2] = -1;
                break;
            }
        case MAX_POOLING_BACKWARD:
            {
                // input, dout
                ret[0] = getInput().get(0)._dim1;
                ret[1] = getInput().get(0)._dim2;
                ret[2] = -1;
                break;
            }
        case DIRECT_CONV2D_BACKWARD_DATA:
            {
                // filter, dout
                long N = getInput().get(1)._dim1;
                ret[0] = N;
                ret[1] = getExtractedVal(params.C, params.H, params.W);
                ret[2] = -1;
                break;
            }
        default:
            throw new RuntimeException("Unsupported op:" + op.name());
    }
    if (LOG.isDebugEnabled() && (ret[0] <= 0 || ret[1] <= 0)) {
        LOG.debug("Unknown dimensions for ConvolutionOp in inferOutputCharacteristics:" + op.name() + " " + ret[0] + " " + ret[1] + " img_dim=[" + params.N + " " + params.C + " " + params.H + " " + params.W + "]" + " filter_dim=[" + params.K + " " + params.C + " " + params.H + " " + params.W + "]" + " output_feature_map=[" + params.P + " " + params.Q + "] stride=[" + params.stride_h + " " + params.stride_w + "]" + " pad=[" + params.pad_h + " " + params.pad_w + "]");
    }
    //safe return (create entry only if at least dims known)
    return (ret[0] > 0 && ret[1] > 0) ? ret : null;
}
Also used : ConvolutionParameters(org.apache.sysml.runtime.matrix.data.ConvolutionParameters) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException) MatrixCharacteristics(org.apache.sysml.runtime.matrix.MatrixCharacteristics) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException)

Example 17 with DMLRuntimeException

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

the class GPUObject method copyFromDeviceToHost.

protected void copyFromDeviceToHost() throws DMLRuntimeException {
    LOG.trace("GPU : copyFromDeviceToHost, on " + this + ", GPUContext=" + getGPUContext());
    if (getJcudaDenseMatrixPtr() != null && getJcudaSparseMatrixPtr() != null) {
        throw new DMLRuntimeException("Invalid state : JCuda dense/sparse pointer are both allocated");
    }
    if (getJcudaDenseMatrixPtr() != null) {
        long start = 0;
        if (DMLScript.STATISTICS)
            start = System.nanoTime();
        MatrixBlock tmp = new MatrixBlock(toIntExact(mat.getNumRows()), toIntExact(mat.getNumColumns()), false);
        tmp.allocateDenseBlock();
        double[] data = tmp.getDenseBlock();
        cudaMemcpy(Pointer.to(data), getJcudaDenseMatrixPtr(), getDoubleSizeOf(data.length), cudaMemcpyDeviceToHost);
        tmp.recomputeNonZeros();
        mat.acquireModify(tmp);
        mat.release();
        if (DMLScript.STATISTICS)
            GPUStatistics.cudaFromDevTime.addAndGet(System.nanoTime() - start);
        if (DMLScript.STATISTICS)
            GPUStatistics.cudaFromDevCount.addAndGet(1);
    } else if (getJcudaSparseMatrixPtr() != null) {
        if (!LibMatrixCUDA.isInSparseFormat(getGPUContext(), mat))
            throw new DMLRuntimeException("Block not in sparse format on host yet the device sparse matrix pointer is not null");
        if (this.isSparseAndEmpty()) {
            // Empty Block
            MatrixBlock tmp = new MatrixBlock();
            mat.acquireModify(tmp);
            mat.release();
        } else {
            long start = 0;
            if (DMLScript.STATISTICS)
                start = System.nanoTime();
            int rows = toIntExact(mat.getNumRows());
            int cols = toIntExact(mat.getNumColumns());
            int nnz = toIntExact(getJcudaSparseMatrixPtr().nnz);
            int[] rowPtr = new int[rows + 1];
            int[] colInd = new int[nnz];
            double[] values = new double[nnz];
            CSRPointer.copyToHost(getJcudaSparseMatrixPtr(), rows, nnz, rowPtr, colInd, values);
            SparseBlockCSR sparseBlock = new SparseBlockCSR(rowPtr, colInd, values, nnz);
            MatrixBlock tmp = new MatrixBlock(rows, cols, nnz, sparseBlock);
            mat.acquireModify(tmp);
            mat.release();
            if (DMLScript.STATISTICS)
                GPUStatistics.cudaFromDevTime.addAndGet(System.nanoTime() - start);
            if (DMLScript.STATISTICS)
                GPUStatistics.cudaFromDevCount.addAndGet(1);
        }
    } else {
        throw new DMLRuntimeException("Cannot copy from device to host as JCuda dense/sparse pointer is not allocated");
    }
    dirty = false;
}
Also used : MatrixBlock(org.apache.sysml.runtime.matrix.data.MatrixBlock) SparseBlockCSR(org.apache.sysml.runtime.matrix.data.SparseBlockCSR) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException)

Example 18 with DMLRuntimeException

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

the class BinaryBlockFrame method getFrameBlock.

/**
	 * Obtain a SystemML binary-block frame as a {@code FrameBlock}
	 * 
	 * @return the SystemML binary-block frame as a {@code FrameBlock}
	 */
public FrameBlock getFrameBlock() {
    try {
        MatrixCharacteristics mc = getMatrixCharacteristics();
        FrameSchema frameSchema = frameMetadata.getFrameSchema();
        return SparkExecutionContext.toFrameBlock(binaryBlocks, frameSchema.getSchema().toArray(new ValueType[0]), (int) mc.getRows(), (int) mc.getCols());
    } catch (DMLRuntimeException e) {
        throw new MLContextException("Exception while getting FrameBlock from binary-block frame", e);
    }
}
Also used : ValueType(org.apache.sysml.parser.Expression.ValueType) MatrixCharacteristics(org.apache.sysml.runtime.matrix.MatrixCharacteristics) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException)

Example 19 with DMLRuntimeException

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

the class MLContextConversionUtil method javaRDDStringCSVToFrameObject.

/**
	 * Convert a {@code JavaRDD<String>} in CSV format to a {@code FrameObject}
	 * 
	 * @param variableName
	 *            name of the variable associated with the frame
	 * @param javaRDD
	 *            the Java RDD of strings
	 * @param frameMetadata
	 *            frame metadata
	 * @return the {@code JavaRDD<String>} converted to a {@code FrameObject}
	 */
public static FrameObject javaRDDStringCSVToFrameObject(String variableName, JavaRDD<String> javaRDD, FrameMetadata frameMetadata) {
    JavaPairRDD<LongWritable, Text> javaPairRDD = javaRDD.mapToPair(new ConvertStringToLongTextPair());
    MatrixCharacteristics mc = (frameMetadata != null) ? frameMetadata.asMatrixCharacteristics() : new MatrixCharacteristics();
    JavaPairRDD<LongWritable, Text> javaPairRDDText = javaPairRDD.mapToPair(new CopyTextInputFunction());
    FrameObject frameObject = new FrameObject(OptimizerUtils.getUniqueTempFileName(), new MatrixFormatMetaData(mc, OutputInfo.BinaryBlockOutputInfo, InputInfo.BinaryBlockInputInfo), frameMetadata.getFrameSchema().getSchema().toArray(new ValueType[0]));
    JavaPairRDD<Long, FrameBlock> rdd;
    try {
        rdd = FrameRDDConverterUtils.csvToBinaryBlock(jsc(), javaPairRDDText, mc, frameObject.getSchema(), false, ",", false, -1);
    } catch (DMLRuntimeException e) {
        e.printStackTrace();
        return null;
    }
    frameObject.setRDDHandle(new RDDObject(rdd, variableName));
    return frameObject;
}
Also used : ValueType(org.apache.sysml.parser.Expression.ValueType) Text(org.apache.hadoop.io.Text) FrameObject(org.apache.sysml.runtime.controlprogram.caching.FrameObject) MatrixFormatMetaData(org.apache.sysml.runtime.matrix.MatrixFormatMetaData) MatrixCharacteristics(org.apache.sysml.runtime.matrix.MatrixCharacteristics) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException) CopyTextInputFunction(org.apache.sysml.runtime.instructions.spark.functions.CopyTextInputFunction) ConvertStringToLongTextPair(org.apache.sysml.runtime.instructions.spark.functions.ConvertStringToLongTextPair) FrameBlock(org.apache.sysml.runtime.matrix.data.FrameBlock) RDDObject(org.apache.sysml.runtime.instructions.spark.data.RDDObject) LongWritable(org.apache.hadoop.io.LongWritable)

Example 20 with DMLRuntimeException

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

the class MLContextConversionUtil method frameObjectToBinaryBlockFrame.

/**
	 * Convert a {@code FrameObject} to a {@code BinaryBlockFrame}.
	 * 
	 * @param frameObject
	 *            the {@code FrameObject}
	 * @param sparkExecutionContext
	 *            the Spark execution context
	 * @return the {@code FrameObject} converted to a {@code BinaryBlockFrame}
	 */
public static BinaryBlockFrame frameObjectToBinaryBlockFrame(FrameObject frameObject, SparkExecutionContext sparkExecutionContext) {
    try {
        @SuppressWarnings("unchecked") JavaPairRDD<Long, FrameBlock> binaryBlock = (JavaPairRDD<Long, FrameBlock>) sparkExecutionContext.getRDDHandleForFrameObject(frameObject, InputInfo.BinaryBlockInputInfo);
        MatrixCharacteristics matrixCharacteristics = frameObject.getMatrixCharacteristics();
        FrameSchema fs = new FrameSchema(Arrays.asList(frameObject.getSchema()));
        FrameMetadata fm = new FrameMetadata(fs, matrixCharacteristics);
        return new BinaryBlockFrame(binaryBlock, fm);
    } catch (DMLRuntimeException e) {
        throw new MLContextException("DMLRuntimeException while converting frame object to BinaryBlockFrame", e);
    }
}
Also used : FrameBlock(org.apache.sysml.runtime.matrix.data.FrameBlock) JavaPairRDD(org.apache.spark.api.java.JavaPairRDD) MatrixCharacteristics(org.apache.sysml.runtime.matrix.MatrixCharacteristics) 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